Skip to content

Commit

Permalink
EIP-712 amount-joins can now handle with missing token information
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Sep 6, 2024
1 parent daf8a90 commit a9705cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src_features/signMessageEIP712/filtering.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ static bool check_token_index(uint8_t idx) {
PRINTF("Error: token index out of range (%u)\n", idx);
return false;
}
if (!tmpCtx.transactionContext.assetSet[idx]) {
PRINTF("Error: token not set (%u)\n", idx);
return false;
}
return true;
}

Expand Down
30 changes: 21 additions & 9 deletions src_features/signMessageEIP712/ui_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,21 @@ static bool ui_712_format_uint(const uint8_t *data, uint8_t length, bool first)
* @return whether it was successful or not
*/
static bool ui_712_format_amount_join(void) {
const tokenDefinition_t *token;
token = &tmpCtx.transactionContext.extraInfo[ui_ctx->amount.idx].token;
const tokenDefinition_t *token = NULL;

if (tmpCtx.transactionContext.assetSet[ui_ctx->amount.idx]) {
token = &tmpCtx.transactionContext.extraInfo[ui_ctx->amount.idx].token;
}
if ((ui_ctx->amount.joins[ui_ctx->amount.idx].value_length == INT256_LENGTH) &&
ismaxint(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length)) {
strlcpy(strings.tmp.tmp, "Unlimited ", sizeof(strings.tmp.tmp));
strlcat(strings.tmp.tmp, token->ticker, sizeof(strings.tmp.tmp));
strlcat(strings.tmp.tmp, (token != NULL) ? token->ticker : "???", sizeof(strings.tmp.tmp));
} else {
if (!amountToString(ui_ctx->amount.joins[ui_ctx->amount.idx].value,
ui_ctx->amount.joins[ui_ctx->amount.idx].value_length,
token->decimals,
token->ticker,
(token != NULL) ? token->decimals : 0,
(token != NULL) ? token->ticker : "???",
strings.tmp.tmp,
sizeof(strings.tmp.tmp))) {
return false;
Expand Down Expand Up @@ -454,13 +456,23 @@ void amount_join_set_token_received(void) {
* @return whether it was successful or not
*/
static bool update_amount_join(const uint8_t *data, uint8_t length) {
tokenDefinition_t *token;
const tokenDefinition_t *token = NULL;

token = &tmpCtx.transactionContext.extraInfo[ui_ctx->amount.idx].token;
if (tmpCtx.transactionContext.assetSet[ui_ctx->amount.idx]) {
token = &tmpCtx.transactionContext.extraInfo[ui_ctx->amount.idx].token;
} else {
if (tmpCtx.transactionContext.currentAssetIndex == ui_ctx->amount.idx) {
// So that the following amount-join find their tokens in the expected indices
tmpCtx.transactionContext.currentAssetIndex =
(tmpCtx.transactionContext.currentAssetIndex + 1) % MAX_ASSETS;
}
}
switch (ui_ctx->amount.state) {
case AMOUNT_JOIN_STATE_TOKEN:
if (memcmp(data, token->address, ADDRESS_LENGTH) != 0) {
return false;
if (token != NULL) {
if (memcmp(data, token->address, ADDRESS_LENGTH) != 0) {
return false;
}
}
amount_join_set_token_received();
break;
Expand Down

0 comments on commit a9705cf

Please sign in to comment.