Now only compiles full EIP-712 support for capable devices

This commit is contained in:
Alexandre Paillier
2022-05-16 10:59:20 +02:00
parent b9820774ba
commit 2fa6379470
26 changed files with 109 additions and 6 deletions

View File

@@ -137,6 +137,11 @@ DEFINES += HAVE_NFT_TESTING_KEY
endif
endif
# EIP-712
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_EIP712_FULL_SUPPORT
endif
# Enabling debug PRINTF
DEBUG:=0
ifneq ($(DEBUG),0)

View File

@@ -675,8 +675,12 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
}
else
{
#ifdef HAVE_EIP712_FULL_SUPPORT
*flags |= IO_ASYNCH_REPLY;
handle_eip712_sign(G_io_apdu_buffer);
#else
THROW(0x6B00);
#endif // HAVE_EIP712_FULL_SUPPORT
}
break;
@@ -703,6 +707,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
#endif
#ifdef HAVE_EIP712_FULL_SUPPORT
case INS_EIP712_STRUCT_DEF:
*flags |= IO_ASYNCH_REPLY;
handle_eip712_struct_def(G_io_apdu_buffer);
@@ -712,6 +717,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
*flags |= IO_ASYNCH_REPLY;
handle_eip712_struct_impl(G_io_apdu_buffer);
break;
#endif // HAVE_EIP712_FULL_SUPPORT
#if 0
case 0xFF: // return to dashboard

View File

@@ -23,6 +23,8 @@
#include "cx.h"
#include "chainConfig.h"
#define KECCAK256_HASH_BYTESIZE 32
/**
* @brief Decode an RLP encoded field - see
* https://github.com/ethereum/wiki/wiki/RLP

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <string.h>
#include <stdint.h>
#include "context.h"
@@ -64,3 +66,5 @@ void eip712_context_deinit(void)
mem_reset();
eip712_context_initialized = false;
}
#endif

View File

@@ -1,8 +1,9 @@
#ifndef EIP712_CTX_H_
#define EIP712_CTX_H_
#include <stdbool.h>
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdbool.h>
extern uint8_t *typenames_array;
extern uint8_t *structs_array;
@@ -13,4 +14,6 @@ void eip712_context_deinit(void);
extern bool eip712_context_initialized;
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // EIP712_CTX_H_

View File

@@ -1,6 +1,8 @@
#ifndef EIP712_H_
#define EIP712_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdbool.h>
#include <stdint.h>
@@ -51,8 +53,6 @@ typedef enum
EIP712_STRUCT_HASH
} e_eip712_hash_type;
#define KECCAK256_HASH_BYTESIZE 32
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define DOMAIN_STRUCT_NAME "EIP712Domain"
@@ -84,4 +84,6 @@ const uint8_t *get_structn(const uint8_t *const ptr,
const void *get_array_in_mem(const void *ptr, uint8_t *const array_size);
const char *get_string_in_mem(const uint8_t *ptr, uint8_t *const string_length);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // EIP712_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include <string.h>
#include "encode_field.h"
@@ -108,3 +110,5 @@ void *encode_address(const uint8_t *const value, uint8_t length)
}
return encode_integer(value, length);
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef ENCODE_FIELD_H_
#define ENCODE_FIELD_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <stdbool.h>
@@ -11,4 +13,6 @@ void *encode_boolean(const bool *const value, uint8_t length);
void *encode_address(const uint8_t *const value, uint8_t length);
void *encode_bytes(const uint8_t *const value, uint8_t length);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // ENCODE_FIELD_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
@@ -449,3 +451,6 @@ bool handle_eip712_sign(const uint8_t *const apdu_buf)
ui_712_end_sign();
return true;
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include "field_hash.h"
#include "encode_field.h"
@@ -7,6 +9,7 @@
#include "eip712.h"
#include "shared_context.h"
#include "ui_logic.h"
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
static s_field_hashing *fh = NULL;
@@ -170,3 +173,5 @@ bool field_hash(const uint8_t *data,
return true;
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef FIELD_HASH_H_
#define FIELD_HASH_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <stdbool.h>
@@ -23,4 +25,7 @@ void field_hash_deinit(void);
bool field_hash(const uint8_t *data,
uint8_t data_length,
bool partial);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // FIELD_HASH_H_

View File

@@ -1,8 +1,9 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include "mem.h"
#include "shared_context.h"
#define SIZE_MEM_BUFFER 5120
static uint8_t mem_buffer[SIZE_MEM_BUFFER];
@@ -75,3 +76,5 @@ void mem_dealloc(size_t size)
mem_idx -= size;
}
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef MEM_H_
#define MEM_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
void mem_init(void);
@@ -12,4 +14,6 @@ void mem_dealloc(size_t size);
extern size_t mem_max;
#endif
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // MEM_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -77,3 +79,5 @@ void *mem_alloc_and_align(size_t size, size_t alignment)
}
return mem_alloc(size);
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef MEM_UTILS_H_
#define MEM_UTILS_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <stdbool.h>
@@ -11,4 +13,6 @@ void *mem_alloc_and_copy(const void *data, size_t size);
char *mem_alloc_and_format_uint(uint32_t value, uint8_t *const written_chars);
void *mem_alloc_and_align(size_t size, size_t alignment);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // MEM_UTILS_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <string.h>
#include "path.h"
@@ -614,3 +616,5 @@ void path_deinit(void)
{
path_struct = NULL;
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef PATH_H_
#define PATH_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <stdbool.h>
@@ -36,4 +38,6 @@ bool path_init(void);
void path_deinit(void);
bool path_new_array_depth(uint8_t size);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // PATH_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include <string.h>
#include "sol_typenames.h"
@@ -130,3 +132,5 @@ const char *get_struct_field_sol_typename(const uint8_t *field_ptr,
}
return NULL; // Not found
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef SOL_TYPENAMES_H_
#define SOL_TYPENAMES_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdbool.h>
#include <stdint.h>
@@ -9,4 +11,6 @@ bool sol_typenames_init(void);
const char *get_struct_field_sol_typename(const uint8_t *ptr,
uint8_t *const length);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // SOL_TYPENAMES_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
@@ -6,6 +8,7 @@
#include "eip712.h"
#include "type_hash.h"
#include "shared_context.h"
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
static inline void hash_nbytes(const uint8_t *b, uint8_t n)
{
@@ -316,3 +319,5 @@ const uint8_t *type_hash(const void *const structs_array,
KECCAK256_HASH_BYTESIZE);
return hash_ptr;
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,10 +1,14 @@
#ifndef TYPE_HASH_H_
#define TYPE_HASH_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
const uint8_t *type_hash(const void *const structs_array,
const char *const struct_name,
const uint8_t struct_name_length);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // TYPE_HASH_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include "ui_flow_712.h"
#include "ui_logic.h"
#include "shared_context.h" // strings
@@ -51,3 +53,5 @@ UX_FLOW(ux_712_flow,
&ux_712_step_dummy,
&ux_712_step_approve,
&ux_712_step_reject);
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,8 +1,12 @@
#ifndef UI_FLOW_712_H_
#define UI_FLOW_712_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include "ux_flow_engine.h"
extern const ux_flow_step_t* const ux_712_flow[];
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // UI_FLOW_712_H_

View File

@@ -1,3 +1,5 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdlib.h>
#include <stdbool.h>
#include "ui_logic.h"
@@ -222,3 +224,5 @@ unsigned int ui_712_reject(const bagl_element_t *e)
eip712_context_deinit();
return 0;
}
#endif // HAVE_EIP712_FULL_SUPPORT

View File

@@ -1,6 +1,8 @@
#ifndef UI_LOGIC_712_H_
#define UI_LOGIC_712_H_
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdint.h>
#include "ux.h"
@@ -26,4 +28,6 @@ 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);
#endif // HAVE_EIP712_FULL_SUPPORT
#endif // UI_LOGIC_712_H_

View File

@@ -4,6 +4,7 @@
#include "ui_flow.h"
#include "eip712.h"
#include "common_712.h"
#include "ethUtils.h"
void handleSignEIP712Message_v0(uint8_t p1,
uint8_t p2,
@@ -11,8 +12,9 @@ void handleSignEIP712Message_v0(uint8_t p1,
uint8_t dataLength,
unsigned int *flags,
unsigned int *tx) {
UNUSED(tx);
if ((p1 != 00) || (p2 != 00)) {
(void)tx;
(void)p2;
if (p1 != 00) {
THROW(0x6B00);
}
if (appState != APP_STATE_IDLE) {