Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-712 buffer pairs to fill screen #593

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions client/src/ledger_app_clients/ethereum/eip712/InputData.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def default_handler():


autonext_handler: Callable = default_handler
is_golden_run: bool


# From a string typename, extract the type and all the array depth
Expand Down Expand Up @@ -119,7 +120,7 @@ def send_struct_def_field(typename, keyname):
return (typename, type_enum, typesize, array_lvls)


def encode_integer(value: Union[str | int], typesize: int) -> bytes:
def encode_integer(value: Union[str, int], typesize: int) -> bytes:
# Some are already represented as integers in the JSON, but most as strings
if isinstance(value, str):
value = int(value, 0)
Expand Down Expand Up @@ -394,6 +395,12 @@ def enable_autonext():
delay = 1/3
else:
delay = 1/4

# golden run has to be slower to make sure we take good snapshots
# and not processing/loading screens
if is_golden_run:
delay *= 3

signal.setitimer(signal.ITIMER_REAL, delay, delay)


Expand All @@ -404,10 +411,12 @@ def disable_autonext():
def process_data(aclient: EthAppClient,
data_json: dict,
filters: Optional[dict] = None,
autonext: Optional[Callable] = None) -> bool:
autonext: Optional[Callable] = None,
golden_run: bool = False) -> bool:
global sig_ctx
global app_client
global autonext_handler
global is_golden_run

# deepcopy because this function modifies the dict
data_json = copy.deepcopy(data_json)
Expand All @@ -422,6 +431,8 @@ def process_data(aclient: EthAppClient,
autonext_handler = autonext
signal.signal(signal.SIGALRM, next_timeout)

is_golden_run = golden_run

if filters:
init_signature_context(types, domain)

Expand Down
4 changes: 4 additions & 0 deletions src/shared_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ typedef struct txStringProperties_s {
#ifdef TARGET_NANOS
#define SHARED_CTX_FIELD_1_SIZE 100
#else
#ifdef SCREEN_SIZE_WALLET
#define SHARED_CTX_FIELD_1_SIZE 380
#else
#define SHARED_CTX_FIELD_1_SIZE 256
#endif
#endif
#define SHARED_CTX_FIELD_2_SIZE 40

typedef struct strDataTmp_s {
Expand Down
18 changes: 9 additions & 9 deletions src_features/signMessageEIP712/field_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static const uint8_t *field_hash_prepare(const void *const field_ptr,
fh->state = FHS_WAITING_FOR_MORE;
if (IS_DYN(field_type)) {
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
ui_712_new_field(field_ptr, data, *data_length);
}
return data;
end:
Expand Down Expand Up @@ -106,11 +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;
}
ui_712_new_field(field_ptr, data, data_length);
return value;
}

Expand Down Expand Up @@ -245,15 +239,19 @@ static bool field_hash_finalize(const void *const field_ptr,
bool field_hash(const uint8_t *data, uint8_t data_length, bool partial) {
const void *field_ptr;
e_type field_type;
bool first = fh->state == FHS_IDLE;

if ((fh == NULL) || ((field_ptr = path_get_field()) == NULL)) {
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
return false;
}

field_type = struct_field_type(field_ptr);
if (fh->state == FHS_IDLE) // first packet for this frame
{
// first packet for this frame
if (first) {
if (!ui_712_show_raw_key(field_ptr)) {
return false;
}
if (data_length < 2) {
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
return false;
Expand All @@ -270,6 +268,9 @@ bool field_hash(const uint8_t *data, uint8_t data_length, bool partial) {
if (IS_DYN(field_type)) {
hash_nbytes(data, data_length, (cx_hash_t *) &global_sha3);
}
if (!ui_712_feed_to_display(field_ptr, data, data_length, first, fh->remaining_size == 0)) {
return false;
}
if (fh->remaining_size == 0) {
if (partial) // only makes sense if marked as complete
{
Expand All @@ -287,7 +288,6 @@ bool field_hash(const uint8_t *data, uint8_t data_length, bool partial) {
}
handle_eip712_return_code(true);
}

return true;
}

Expand Down
Loading
Loading