Skip to content

Commit

Permalink
check random number only on sign_masp_spends
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Sep 30, 2024
1 parent 7918426 commit a0e79c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ parser_error_t checkConverts(const parser_tx_t *txObj, parser_context_t *builder
}

if (txObj->transaction.sections.maspBuilder.metadata.n_converts_indices != txObj->transaction.sections.maspTx.data.sapling_bundle.n_shielded_converts) {
return parser_invalid_number_of_outputs;
return parser_invalid_number_of_converts;
}

for (uint32_t i = 0; i < txObj->transaction.sections.maspBuilder.builder.sapling_builder.n_converts; i++) {
Expand Down
24 changes: 18 additions & 6 deletions app/src/parser_impl_masp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ static parser_error_t readSpendDescriptionInfo(parser_context_t *ctx, masp_sapli

CHECK_ERROR(readUint32(ctx, &builder->n_spends))
#if defined(LEDGER_SPECIFIC) && !defined(APP_TESTING)
uint32_t rnd_spends = (uint32_t)transaction_get_n_spends();
if (rnd_spends < builder->n_spends) {
return parser_invalid_number_of_spends;
if (G_io_apdu_buffer[OFFSET_INS] == INS_SIGN_MASP_SPENDS) {
uint32_t rnd_spends = (uint32_t)transaction_get_n_spends();
if (rnd_spends < builder->n_spends) {
return parser_invalid_number_of_spends;
}
}
#endif

Expand Down Expand Up @@ -288,9 +290,11 @@ static parser_error_t readConvertDescriptionInfo(parser_context_t *ctx, masp_sap

CHECK_ERROR(readUint32(ctx, &builder->n_converts))
#if defined(LEDGER_SPECIFIC) && !defined(APP_TESTING)
uint32_t rnd_converts = (uint32_t)transaction_get_n_converts();
if (rnd_converts < builder->n_converts) {
return parser_invalid_number_of_converts;
if (G_io_apdu_buffer[OFFSET_INS] == INS_SIGN_MASP_SPENDS) {
uint32_t rnd_converts = (uint32_t)transaction_get_n_converts();
if (rnd_converts < builder->n_converts) {
return parser_invalid_number_of_converts;
}
}
#endif

Expand Down Expand Up @@ -332,6 +336,14 @@ static parser_error_t readSaplingOutputDescriptionInfo(parser_context_t *ctx, ma
}

CHECK_ERROR(readUint32(ctx, &builder->n_outputs))
#if defined(LEDGER_SPECIFIC) && !defined(APP_TESTING)
if (G_io_apdu_buffer[OFFSET_INS] == INS_SIGN_MASP_SPENDS) {
uint32_t rnd_outputs = (uint32_t)transaction_get_n_outputs();
if (rnd_outputs < builder->n_outputs) {
return parser_invalid_number_of_outputs;
}
}
#endif

// Get start pointer and offset to later calculate the size of the outputs
builder->outputs.ptr = ctx->buffer + ctx->offset;
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {

#define MAX_EXTRA_DATA_SECS 4
#define MAX_SIGNATURE_SECS 3

#define OFFSET_INS 1
#define ASSET_ID_LEN 32
#define ANCHOR_LEN 32
#define SHIELDED_OUTPUTS_LEN 788
Expand Down

0 comments on commit a0e79c5

Please sign in to comment.