From 6617cd5c9cf6d26183c2b471546c4b89b80a2c00 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Thu, 6 Jun 2024 18:13:11 +0200 Subject: [PATCH] Now buffers the EIP-712 pairs to show more than one per screen --- src_features/signMessageEIP712/field_hash.c | 4 -- src_features/signMessageEIP712/ui_logic.c | 19 ++++++- src_features/signMessageEIP712/ui_logic.h | 3 + src_nbgl/ui_sign_712.c | 63 +++++++++++++++++---- 4 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index 84912d8160..bec2ff43d0 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -105,10 +105,6 @@ static const uint8_t *field_hash_finalize_static(const void *const field_ptr, apdu_response_code = APDU_RESPONSE_INVALID_DATA; PRINTF("Unknown solidity type!\n"); } - - if (value == NULL) { - return NULL; - } return value; } diff --git a/src_features/signMessageEIP712/ui_logic.c b/src_features/signMessageEIP712/ui_logic.c index 0938246b12..8169507172 100644 --- a/src_features/signMessageEIP712/ui_logic.c +++ b/src_features/signMessageEIP712/ui_logic.c @@ -56,6 +56,9 @@ typedef struct { uint8_t field_flags; uint8_t structs_to_review; s_amount_context amount; +#ifdef SCREEN_SIZE_WALLET + char ui_pairs_buffer[(SHARED_CTX_FIELD_1_SIZE + SHARED_CTX_FIELD_2_SIZE) * 2]; +#endif } t_ui_context; static t_ui_context *ui_ctx = NULL; @@ -210,6 +213,7 @@ void ui_712_message_hash(void) { sizeof(strings.tmp.tmp), tmpCtx.messageSigningContext712.messageHash, KECCAK256_HASH_BYTESIZE); + ui_ctx->end_reached = true; ui_712_redraw_generic_step(); } @@ -587,9 +591,9 @@ void ui_712_end_sign(void) { apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED; return; } - ui_ctx->end_reached = true; if (N_storage.verbose_eip712 || (ui_ctx->filtering_mode == EIP712_FILTERING_FULL)) { + ui_ctx->end_reached = true; ui_712_switch_to_sign(); } } @@ -771,4 +775,17 @@ bool ui_712_show_raw_key(const void *field_ptr) { return true; } +#ifdef SCREEN_SIZE_WALLET +/* + * Get UI pairs buffer + * + * @param[out] size buffer size + * @return pointer to the buffer + */ +char *get_ui_pairs_buffer(size_t *size) { + *size = sizeof(ui_ctx->ui_pairs_buffer); + return ui_ctx->ui_pairs_buffer; +} +#endif + #endif // HAVE_EIP712_FULL_SUPPORT diff --git a/src_features/signMessageEIP712/ui_logic.h b/src_features/signMessageEIP712/ui_logic.h index 9c8741a226..9a63ced936 100644 --- a/src_features/signMessageEIP712/ui_logic.h +++ b/src_features/signMessageEIP712/ui_logic.h @@ -42,6 +42,9 @@ 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); bool ui_712_show_raw_key(const void *field_ptr); +#ifdef SCREEN_SIZE_WALLET +char *get_ui_pairs_buffer(size_t *size); +#endif #endif // HAVE_EIP712_FULL_SUPPORT diff --git a/src_nbgl/ui_sign_712.c b/src_nbgl/ui_sign_712.c index ba148bbcc9..10b27d35da 100644 --- a/src_nbgl/ui_sign_712.c +++ b/src_nbgl/ui_sign_712.c @@ -7,11 +7,28 @@ #include "common_712.h" #include "nbgl_use_case.h" #include "ui_message_signing.h" +#include "ledger_assert.h" -static nbgl_contentTagValue_t pair; +static nbgl_contentTagValue_t pairs[6]; static nbgl_contentTagValueList_t pairs_list; +static uint8_t pair_idx; +static size_t buf_idx; static void message_progress(bool confirm) { + char *buf; + size_t buf_size; + size_t shift_off; + + if (pairs_list.nbPairs < pair_idx) { + buf = get_ui_pairs_buffer(&buf_size); + memmove(&pairs[0], &pairs[pairs_list.nbPairs], sizeof(pairs[0])); + memmove(buf, pairs[0].item, (buf + buf_idx) - pairs[0].item); + shift_off = pairs[0].item - buf; + buf_idx -= shift_off; + pairs[0].value -= shift_off; + pairs[0].item = buf; + pair_idx = 1; + } if (confirm) { if (ui_712_next_field() == EIP712_NO_MORE_FIELD) { ui_712_switch_to_sign(); @@ -22,22 +39,40 @@ static void message_progress(bool confirm) { } static void message_update(bool confirm) { + char *buf; + size_t buf_size; + size_t buf_off; + bool flag; + + buf = get_ui_pairs_buffer(&buf_size); if (confirm) { - explicit_bzero(&pair, sizeof(pair)); - explicit_bzero(&pairs_list, sizeof(pairs_list)); - - pair.item = strings.tmp.tmp2; - pair.value = strings.tmp.tmp; - pairs_list.nbPairs = 1; - pairs_list.pairs = &pair; - pairs_list.wrapping = false; - nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress); + buf_off = strlen(strings.tmp.tmp2) + 1; + LEDGER_ASSERT((buf_idx + buf_off) < buf_size, "UI pairs buffer overflow"); + pairs[pair_idx].item = memmove(buf + buf_idx, strings.tmp.tmp2, buf_off); + buf_idx += buf_off; + buf_off = strlen(strings.tmp.tmp) + 1; + LEDGER_ASSERT((buf_idx + buf_off) < buf_size, "UI pairs buffer overflow"); + pairs[pair_idx].value = memmove(buf + buf_idx, strings.tmp.tmp, buf_off); + buf_idx += buf_off; + pair_idx += 1; + pairs_list.nbPairs = nbgl_useCaseGetNbTagValuesInPage(pair_idx, &pairs_list, 0, &flag); + if (pairs_list.nbPairs < pair_idx) { + nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress); + } else { + message_progress(true); + } } else { ui_typed_message_review_choice(false); } } void ui_712_start(void) { + explicit_bzero(&pairs, sizeof(pairs)); + explicit_bzero(&pairs_list, sizeof(pairs_list)); + pairs_list.pairs = pairs; + pair_idx = 0; + buf_idx = 0; + nbgl_useCaseReviewStreamingStart(TYPE_MESSAGE, &C_Review_64px, TEXT_REVIEW_EIP712, @@ -50,7 +85,13 @@ void ui_712_switch_to_message(void) { } void ui_712_switch_to_sign(void) { - nbgl_useCaseReviewStreamingFinish(TEXT_SIGN_EIP712, ui_typed_message_review_choice); + if (pair_idx > 0) { + pairs_list.nbPairs = pair_idx; + pair_idx = 0; + nbgl_useCaseReviewStreamingContinue(&pairs_list, message_progress); + } else { + nbgl_useCaseReviewStreamingFinish(TEXT_SIGN_EIP712, ui_typed_message_review_choice); + } } #endif // HAVE_EIP712_FULL_SUPPORT