Added a new temporary EIP-712 half-bind mode

This commit is contained in:
Alexandre Paillier
2022-05-16 16:06:52 +02:00
parent a0551e8226
commit 239da44d0e
7 changed files with 74 additions and 2 deletions

View File

@@ -140,6 +140,7 @@ endif
# EIP-712
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_EIP712_FULL_SUPPORT
#DEFINES += HAVE_EIP712_HALF_BLIND # temporary
endif
# Enabling debug PRINTF

View File

@@ -448,6 +448,9 @@ bool handle_eip712_sign(const uint8_t *const apdu_buf)
{
return false;
}
#ifdef HAVE_EIP712_HALF_BLIND
ui_712_message_hash();
#endif // HAVE_EIP712_HALF_BLIND
ui_712_end_sign();
return true;
}

View File

@@ -66,7 +66,14 @@ bool field_hash(const uint8_t *data,
if (IS_DYN(field_type))
{
cx_keccak_init(&global_sha3, 256); // init hash
#ifdef HAVE_EIP712_HALF_BLIND
if (path_get_root_type() == ROOT_DOMAIN)
{
#endif // HAVE_EIP712_HALF_BLIND
ui_712_new_field(field_ptr, data, data_length);
#ifdef HAVE_EIP712_HALF_BLIND
}
#endif // HAVE_EIP712_HALF_BLIND
}
}
fh->remaining_size -= data_length;
@@ -123,7 +130,14 @@ bool field_hash(const uint8_t *data,
{
return false;
}
#ifdef HAVE_EIP712_HALF_BLIND
if (path_get_root_type() == ROOT_DOMAIN)
{
#endif // HAVE_EIP712_HALF_BLIND
ui_712_new_field(field_ptr, data, data_length);
#ifdef HAVE_EIP712_HALF_BLIND
}
#endif // HAVE_EIP712_HALF_BLIND
}
else
{
@@ -159,6 +173,15 @@ bool field_hash(const uint8_t *data,
path_advance();
fh->state = FHS_IDLE;
#ifdef HAVE_EIP712_HALF_BLIND
if (path_get_root_type() == ROOT_MESSAGE)
{
G_io_apdu_buffer[0] = 0x90;
G_io_apdu_buffer[1] = 0x00;
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}
#endif // HAVE_EIP712_HALF_BLIND
}
else
{

View File

@@ -382,7 +382,21 @@ bool path_set_root(const char *const struct_name, uint8_t name_length)
// because the first field could be a struct type
path_update();
#ifdef HAVE_EIP712_HALF_BLIND
// Only show field for the domain
if (path_get_root_type() == ROOT_MESSAGE)
{
G_io_apdu_buffer[0] = 0x90;
G_io_apdu_buffer[1] = 0x00;
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}
else
{
#endif // HAVE_EIP712_HALF_BLIND
ui_712_new_root_struct(path_struct->root_struct);
#ifdef HAVE_EIP712_HALF_BLIND
}
#endif // HAVE_EIP712_HALF_BLIND
return true;
}

View File

@@ -63,6 +63,7 @@ void ui_712_new_root_struct(const void *const struct_ptr)
{
return;
}
strcpy(strings.tmp.tmp2, "Review struct");
const char *struct_name;
uint8_t struct_name_length;
@@ -82,6 +83,20 @@ void ui_712_new_root_struct(const void *const struct_ptr)
}
}
#ifdef HAVE_EIP712_HALF_BLIND
void ui_712_message_hash(void)
{
strcpy(strings.tmp.tmp2, "Message hash");
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
KECCAK256_HASH_BYTESIZE,
tmpCtx.messageSigningContext712.messageHash);
G_ux.flow_stack[G_ux.stack_count - 1].index = 0;
ux_flow_next();
}
#endif // HAVE_EIP712_HALF_BLIND
/**
* Used to notify of a new field to review in the current struct (key + value)
*
@@ -98,6 +113,7 @@ void ui_712_new_field(const void *const field_ptr, const uint8_t *const data,
{
return;
}
// Key
if ((key = get_struct_field_keyname(field_ptr, &key_len)) != NULL)
{
@@ -174,7 +190,10 @@ void ui_712_end_sign(void)
return;
}
ui_ctx->end_reached = true;
#ifndef HAVE_EIP712_HALF_BLIND
ui_712_next_field();
#endif // HAVE_EIP712_HALF_BLIND
}
/**

View File

@@ -27,6 +27,9 @@ void ui_712_new_field(const void *const field_ptr, const uint8_t *const data, ui
void ui_712_end_sign(void);
unsigned int ui_712_approve(const bagl_element_t *e);
unsigned int ui_712_reject(const bagl_element_t *e);
#ifdef HAVE_EIP712_HALF_BLIND
void ui_712_message_hash(void);
#endif // HAVE_EIP712_HALF_BLIND
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,13 +1,22 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "common_712.h"
#include "ethUtils.h"
void prepare_domain_hash_v0() {
snprintf(strings.tmp.tmp, 70, "0x%.*H", 32, tmpCtx.messageSigningContext712.domainHash);
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
KECCAK256_HASH_BYTESIZE,
tmpCtx.messageSigningContext712.domainHash);
}
void prepare_message_hash_v0() {
snprintf(strings.tmp.tmp, 70, "0x%.*H", 32, tmpCtx.messageSigningContext712.messageHash);
snprintf(strings.tmp.tmp,
sizeof(strings.tmp.tmp),
"0x%.*H",
KECCAK256_HASH_BYTESIZE,
tmpCtx.messageSigningContext712.messageHash);
}
// clang-format off