Can now handle amount-join EIP-712 filtering on Permit (ERC-2612) messages

This commit is contained in:
Alexandre Paillier
2024-06-17 16:33:45 +02:00
parent cabdcd5d5d
commit 05ddb70e7f
3 changed files with 25 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
#include "ethUstream.h" // INT256_LENGTH
#include "apdu_constants.h" // APDU return codes
#include "public_keys.h"
#include "manage_asset_info.h"
#include "context_712.h"
#include "commands_712.h"
#include "typed_data.h"
@@ -17,6 +18,8 @@
#define FILT_MAGIC_DATETIME 33
#define FILT_MAGIC_RAW_FIELD 72
#define TOKEN_IDX_ADDR_IN_DOMAIN 0xff
/**
* Reconstruct the field path and hash it
*
@@ -386,6 +389,19 @@ bool filtering_amount_join_value(const uint8_t *payload, uint8_t length) {
}
// Handling
if (token_idx == TOKEN_IDX_ADDR_IN_DOMAIN) {
// Permit (ERC-2612)
int resolved_idx = get_asset_index_by_addr(eip712_context->contract_addr);
if (resolved_idx == -1) {
PRINTF("ERROR: Could not find asset info for verifyingContract address!\n");
return false;
}
token_idx = (uint8_t) resolved_idx;
// simulate as if we had received a token-join addr
ui_712_token_join_prepare_addr_check(token_idx);
amount_join_set_token_received();
}
if (!check_typename("uint") || !check_token_index(token_idx)) {
return false;
}

View File

@@ -397,6 +397,13 @@ static bool ui_712_format_amount_join(void) {
return true;
}
/**
* Simply mark the current amount-join's token address as received
*/
void amount_join_set_token_received(void) {
ui_ctx->amount.joins[ui_ctx->amount.idx].flags |= AMOUNT_JOIN_FLAG_TOKEN;
}
/**
* Update the state of the amount-join
*
@@ -413,7 +420,7 @@ static bool update_amount_join(const uint8_t *data, uint8_t length) {
if (memcmp(data, token->address, ADDRESS_LENGTH) != 0) {
return false;
}
ui_ctx->amount.joins[ui_ctx->amount.idx].flags |= AMOUNT_JOIN_FLAG_TOKEN;
amount_join_set_token_received();
break;
case AMOUNT_JOIN_STATE_VALUE:

View File

@@ -37,6 +37,7 @@ void ui_712_queue_struct_to_review(void);
void ui_712_notify_filter_change(void);
void ui_712_token_join_prepare_addr_check(uint8_t index);
void ui_712_token_join_prepare_amount(uint8_t index, const char *name, uint8_t name_length);
void amount_join_set_token_received(void);
#endif // HAVE_EIP712_FULL_SUPPORT