Skip to content

Commit

Permalink
Allow the final spend signature list length to be less than the spend…
Browse files Browse the repository at this point in the history
… parameter list length.
  • Loading branch information
murisi committed Sep 24, 2024
1 parent 76b17c0 commit 1943b30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/src/nvdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,29 @@ uint8_t transaction_get_n_converts() {
}

bool spend_signatures_more_extract() {
return transaction_header.spends_sign_index > 0;
return transaction_header.spends_sign_index < transaction_header.spends_sign_len;
}

zxerr_t spend_signatures_append(uint8_t *signature) {
if (transaction_header.spends_sign_index >=
if (transaction_header.spends_sign_len >=
transaction_header.spendlist_len) {
return zxerr_unknown;
}

MEMCPY_NV((void *)&N_transactioninfo
.spend_signatures[transaction_header.spends_sign_index],
.spend_signatures[transaction_header.spends_sign_len],
signature, SIGNATURE_SIZE);
transaction_header.spends_sign_index++;
transaction_header.spends_sign_len++;
return zxerr_ok;
}

zxerr_t get_next_spend_signature(uint8_t *result) {
const uint8_t index = transaction_header.spendlist_len - transaction_header.spends_sign_index;
if (index >= transaction_header.spendlist_len) {
const uint8_t index = transaction_header.spends_sign_index;
if (index >= transaction_header.spends_sign_len) {
return zxerr_unknown;
}
MEMCPY(result, (void *)&N_transactioninfo.spend_signatures[index], SIGNATURE_SIZE);
transaction_header.spends_sign_index--;
transaction_header.spends_sign_index++;
if (!spend_signatures_more_extract()) {
transaction_reset();
}
Expand All @@ -152,10 +152,11 @@ zxerr_t get_next_spend_signature(uint8_t *result) {
void zeroize_signatures() {
uint8_t sig[SIGNATURE_SIZE] = {0};

transaction_header.spends_sign_index = 0;
transaction_header.spends_sign_len = 0;
for (int i = 0; i < SPEND_LIST_SIZE; i++) {
spend_signatures_append(sig);
}
transaction_header.spends_sign_len = 0;
transaction_header.spends_sign_index = 0;
}

Expand Down
1 change: 1 addition & 0 deletions app/src/nvdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct {
uint8_t spendlist_len;
uint8_t outputlist_len;
uint8_t convertlist_len;
uint8_t spends_sign_len;
uint8_t spends_sign_index;
} transaction_header_t;

Expand Down

0 comments on commit 1943b30

Please sign in to comment.