Skip to content

Commit

Permalink
Fix issues (#107)
Browse files Browse the repository at this point in the history
* fix ibc masp issue

* add test for issue

* handle the print of possible empty values on ChangeMetadata

* update snapshots

* handle the print of possible empty values on BecomeValidator
  • Loading branch information
chcmedeiros authored Jan 14, 2025
1 parent 4eb39ab commit c51e210
Show file tree
Hide file tree
Showing 158 changed files with 155 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=0
# This is the patch version of this release
APPVERSION_P=2
APPVERSION_P=3
22 changes: 11 additions & 11 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {

case BecomeValidator: {
*numItems = (app_mode_expert() ? BECOME_VALIDATOR_EXPERT_PARAMS : BECOME_VALIDATOR_NORMAL_PARAMS);
if(ctx->tx_obj->becomeValidator.name.ptr) {
if(ctx->tx_obj->becomeValidator.has_name) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.description.ptr) {
if(ctx->tx_obj->becomeValidator.has_description) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.discord_handle.ptr) {
if(ctx->tx_obj->becomeValidator.has_discord_handle) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.website.ptr) {
if(ctx->tx_obj->becomeValidator.has_website) {
(*numItems)++;
}
if(ctx->tx_obj->becomeValidator.avatar.ptr) {
if(ctx->tx_obj->becomeValidator.has_avatar) {
(*numItems)++;
}
break;
Expand Down Expand Up @@ -176,22 +176,22 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {
case ChangeValidatorMetadata: {
*numItems = app_mode_expert() ? CHANGE_VALIDATOR_METADATA_EXPERT_PARAMS : CHANGE_VALIDATOR_METADATA_NORMAL_PARAMS;

if (ctx->tx_obj->metadataChange.name.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_name) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.email.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_email) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.description.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_description) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.website.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_website) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.discord_handle.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_discord_handle) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.avatar.ptr != NULL) {
if (ctx->tx_obj->metadataChange.has_avatar) {
(*numItems)++;
}
if (ctx->tx_obj->metadataChange.has_commission_rate) {
Expand Down
38 changes: 16 additions & 22 deletions app/src/parser_impl_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,11 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
// The validator email
metadataChange->email.ptr = NULL;
metadataChange->email.len = 0;
uint8_t has_email = 0;
CHECK_ERROR(readByte(&ctx, &has_email))
if (has_email != 0 && has_email != 1) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_email))
if (metadataChange->has_email != 0 && metadataChange->has_email != 1) {
return parser_value_out_of_range;
}
if (has_email) {
if (metadataChange->has_email) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -647,12 +646,11 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
/// The validator description
metadataChange->description.ptr = NULL;
metadataChange->description.len = 0;
uint8_t has_description = 0;
CHECK_ERROR(readByte(&ctx, &has_description))
if (has_description != 0 && has_description != 1) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_description))
if (metadataChange->has_description != 0 && metadataChange->has_description != 1) {
return parser_value_out_of_range;
}
if (has_description) {
if (metadataChange->has_description) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -664,9 +662,8 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
/// The validator website
metadataChange->website.ptr = NULL;
metadataChange->website.len = 0;
uint8_t has_website;
CHECK_ERROR(readByte(&ctx, &has_website))
if (has_website) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_website))
if (metadataChange->has_website) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -678,9 +675,8 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
/// The validator's discord handle
metadataChange->discord_handle.ptr = NULL;
metadataChange->discord_handle.len = 0;
uint8_t has_discord_handle;
CHECK_ERROR(readByte(&ctx, &has_discord_handle))
if (has_discord_handle) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_discord_handle))
if (metadataChange->has_discord_handle) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -692,9 +688,8 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
/// The validator's avatar
metadataChange->avatar.ptr = NULL;
metadataChange->avatar.len = 0;
uint8_t has_avatar;
CHECK_ERROR(readByte(&ctx, &has_avatar))
if (has_avatar) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_avatar))
if (metadataChange->has_avatar) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand All @@ -706,9 +701,8 @@ static parser_error_t readChangeValidatorMetadata(const bytes_t *data, tx_metada
/// The validator's name
metadataChange->name.ptr = NULL;
metadataChange->name.len = 0;
uint8_t has_name;
CHECK_ERROR(readByte(&ctx, &has_name))
if (has_name) {
CHECK_ERROR(readByte(&ctx, &metadataChange->has_name))
if (metadataChange->has_name) {
CHECK_ERROR(readUint32(&ctx, &tmpValue));
if (tmpValue > UINT16_MAX) {
return parser_value_out_of_range;
Expand Down Expand Up @@ -1433,11 +1427,11 @@ parser_error_t verifyShieldedHash(parser_context_t *ctx) {
}
}

if (ctx->tx_obj->transfer.has_shielded_hash && memcmp(ctx->tx_obj->transfer.shielded_hash.ptr, tx_id_hash, HASH_LEN) != 0) {
if (ctx->tx_obj->typeTx == Transfer && ctx->tx_obj->transfer.has_shielded_hash && memcmp(ctx->tx_obj->transfer.shielded_hash.ptr, tx_id_hash, HASH_LEN) != 0) {
return parser_invalid_target_hash;
}

if(ctx->tx_obj->ibc.transfer.has_shielded_hash && memcmp(ctx->tx_obj->ibc.transfer.shielded_hash.ptr, tx_id_hash, HASH_LEN) != 0) {
if(ctx->tx_obj->typeTx == IBC && ctx->tx_obj->ibc.transfer.has_shielded_hash && memcmp(ctx->tx_obj->ibc.transfer.shielded_hash.ptr, tx_id_hash, HASH_LEN) != 0) {
return parser_invalid_target_hash;
}
#endif
Expand Down
74 changes: 52 additions & 22 deletions app/src/parser_print_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,19 +916,19 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {

if(displayIdx >= 9 && ctx->tx_obj->becomeValidator.name.ptr == NULL) {
if(displayIdx >= 9 && !ctx->tx_obj->becomeValidator.has_name) {
displayIdx++;
}
if(displayIdx >= 10 && ctx->tx_obj->becomeValidator.description.ptr == NULL) {
if(displayIdx >= 10 && !ctx->tx_obj->becomeValidator.has_description) {
displayIdx++;
}
if(displayIdx >= 11 && ctx->tx_obj->becomeValidator.website.ptr == NULL) {
if(displayIdx >= 11 && !ctx->tx_obj->becomeValidator.has_website) {
displayIdx++;
}
if(displayIdx >= 12 && ctx->tx_obj->becomeValidator.discord_handle.ptr == NULL) {
if(displayIdx >= 12 && !ctx->tx_obj->becomeValidator.has_discord_handle) {
displayIdx++;
}
if(displayIdx >= 13 && ctx->tx_obj->becomeValidator.avatar.ptr == NULL) {
if(displayIdx >= 13 && !ctx->tx_obj->becomeValidator.has_avatar) {
displayIdx++;
}

Expand Down Expand Up @@ -995,12 +995,14 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
}
case 9: {
snprintf(outKey, outKeyLen, "Name");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.name.ptr, ctx->tx_obj->becomeValidator.name.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.name.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.name.ptr, ctx->tx_obj->becomeValidator.name.len, pageIdx, pageCount);
}
break;
}
case 10: {
snprintf(outKey, outKeyLen, "Description");
// snprintf(outVal, outValLen, "(none)");
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.description.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.description.ptr, ctx->tx_obj->becomeValidator.description.len, pageIdx, pageCount);
Expand All @@ -1009,17 +1011,26 @@ static parser_error_t printBecomeValidatorTxn( const parser_context_t *ctx,
}
case 11: {
snprintf(outKey, outKeyLen, "Website");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.website.ptr, ctx->tx_obj->becomeValidator.website.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.website.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.website.ptr, ctx->tx_obj->becomeValidator.website.len, pageIdx, pageCount);
}
break;
}
case 12: {
snprintf(outKey, outKeyLen, "Discord handle");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.discord_handle.ptr, ctx->tx_obj->becomeValidator.discord_handle.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.discord_handle.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.discord_handle.ptr, ctx->tx_obj->becomeValidator.discord_handle.len, pageIdx, pageCount);
}
break;
}
case 13: {
snprintf(outKey, outKeyLen, "Avatar");
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.avatar.ptr, ctx->tx_obj->becomeValidator.avatar.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (ctx->tx_obj->becomeValidator.avatar.len > 0) {
pageStringExt(outVal, outValLen, (const char*)ctx->tx_obj->becomeValidator.avatar.ptr, ctx->tx_obj->becomeValidator.avatar.len, pageIdx, pageCount);
}
break;
}
case 14:
Expand Down Expand Up @@ -1820,22 +1831,22 @@ static parser_error_t printChangeValidatorMetadata( const parser_context_t *ctx

const tx_metadata_change_t *metadataChange = &ctx->tx_obj->metadataChange;

if(displayIdx >= 2 && metadataChange->name.ptr == NULL) {
if(displayIdx >= 2 && !metadataChange->has_name) {
displayIdx++;
}
if(displayIdx >= 3 && metadataChange->email.ptr == NULL) {
if(displayIdx >= 3 && !metadataChange->has_email) {
displayIdx++;
}
if(displayIdx >= 4 && metadataChange->description.ptr == NULL) {
if(displayIdx >= 4 && !metadataChange->has_description) {
displayIdx++;
}
if(displayIdx >= 5 && metadataChange->website.ptr == NULL) {
if(displayIdx >= 5 && !metadataChange->has_website) {
displayIdx++;
}
if(displayIdx >= 6 && metadataChange->discord_handle.ptr == NULL) {
if(displayIdx >= 6 && !metadataChange->has_discord_handle) {
displayIdx++;
}
if(displayIdx >= 7 && metadataChange->avatar.ptr == NULL) {
if(displayIdx >= 7 && !metadataChange->has_avatar) {
displayIdx++;
}
if(displayIdx >= 8 && !metadataChange->has_commission_rate) {
Expand Down Expand Up @@ -1863,32 +1874,51 @@ static parser_error_t printChangeValidatorMetadata( const parser_context_t *ctx
}
case 2: {
snprintf(outKey, outKeyLen, "Name");
pageStringExt(outVal, outValLen, (const char*)metadataChange->name.ptr, metadataChange->name.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->name.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->name.ptr, metadataChange->name.len, pageIdx, pageCount);
}

break;
}
case 3: {
snprintf(outKey, outKeyLen, "Email");
pageStringExt(outVal, outValLen, (const char*)metadataChange->email.ptr, metadataChange->email.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->email.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->email.ptr, metadataChange->email.len, pageIdx, pageCount);
}
break;
}
case 4: {
snprintf(outKey, outKeyLen, "Description");
pageStringExt(outVal, outValLen, (const char*)metadataChange->description.ptr, metadataChange->description.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->description.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->description.ptr, metadataChange->description.len, pageIdx, pageCount);
}
break;
}
case 5: {
snprintf(outKey, outKeyLen, "Website");
pageStringExt(outVal, outValLen, (const char*)metadataChange->website.ptr, metadataChange->website.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->website.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->website.ptr, metadataChange->website.len, pageIdx, pageCount);
}
break;
}
case 6: {
snprintf(outKey, outKeyLen, "Discord handle");
pageStringExt(outVal, outValLen, (const char*)metadataChange->discord_handle.ptr, metadataChange->discord_handle.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->discord_handle.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->discord_handle.ptr, metadataChange->discord_handle.len, pageIdx, pageCount);
}
break;
}
case 7: {
snprintf(outKey, outKeyLen, "Avatar");
pageStringExt(outVal, outValLen, (const char*)metadataChange->avatar.ptr, metadataChange->avatar.len, pageIdx, pageCount);
snprintf(outVal, outValLen, "");
if (metadataChange->avatar.len > 0) {
pageStringExt(outVal, outValLen, (const char*)metadataChange->avatar.ptr, metadataChange->avatar.len, pageIdx, pageCount);
}
break;
}
case 8: {
Expand Down
11 changes: 11 additions & 0 deletions app/src/parser_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,15 @@ typedef struct {
bytes_t max_commission_rate_change;
bytes_t email;
bytes_t description;
uint8_t has_description;
bytes_t website;
uint8_t has_website;
bytes_t discord_handle;
uint8_t has_discord_handle;
bytes_t avatar;
uint8_t has_avatar;
bytes_t name;
uint8_t has_name;
} tx_become_validator_t;

typedef struct {
Expand Down Expand Up @@ -382,12 +387,18 @@ typedef struct {
typedef struct {
AddressAlt validator;
bytes_t email;
uint8_t has_email;
bytes_t description;
uint8_t has_description;
bytes_t website;
uint8_t has_website;
bytes_t discord_handle;
uint8_t has_discord_handle;
bytes_t avatar;
uint8_t has_avatar;
uint8_t has_commission_rate;
bytes_t name;
uint8_t has_name;
bytes_t commission_rate;
} tx_metadata_change_t;

Expand Down
Loading

0 comments on commit c51e210

Please sign in to comment.