Merge remote-tracking branch 'origin/develop' into HEAD

This commit is contained in:
Alexandre Paillier
2022-09-14 17:27:25 +02:00
61 changed files with 505 additions and 72 deletions

View File

@@ -67,7 +67,12 @@ typedef enum chain_kind_e {
CHAIN_KIND_OKC,
CHAIN_KIND_CUBE,
CHAIN_KIND_SHIDEN,
CHAIN_KIND_ASTAR
CHAIN_KIND_ASTAR,
CHAIN_KIND_XDCNETWORK,
CHAIN_KIND_METER,
CHAIN_KIND_MULTIVAC,
CHAIN_KIND_TECRA,
CHAIN_KIND_APOTHEMNETWORK
} chain_kind_t;
typedef struct chain_config_s {

24
src/common_ui.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef _COMMON_UI_H_
#define _COMMON_UI_H_
#include <stdbool.h>
void ui_idle(void);
void ui_warning_contract_data(void);
void ui_display_public_eth2(void);
void ui_display_privacy_public_key(void);
void ui_display_privacy_shared_secret(void);
void ui_display_public_key(void);
void ui_display_sign(void);
void ui_sign_712_v0(void);
void ui_display_stark_public(void);
void ui_confirm_selector(void);
void ui_confirm_parameter(void);
void ui_stark_limit_order(void);
void ui_stark_unsafe_sign(void);
void ui_stark_transfer(bool selfTransfer, bool conditional);
#include "ui_callbacks.h"
#include <string.h>
#endif // _COMMON_UI_H_

View File

@@ -4,6 +4,7 @@
bool erc20_plugin_available_check(void);
void erc20_plugin_call(int message, void* parameters);
void compound_plugin_call(int message, void* parameters);
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
uint8_t copy_size = MIN(dst_size, ADDRESS_LENGTH);
@@ -28,6 +29,17 @@ static const uint8_t ERC20_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7,
const uint8_t* const ERC20_SELECTORS[NUM_ERC20_SELECTORS] = {ERC20_TRANSFER_SELECTOR,
ERC20_APPROVE_SELECTOR};
static const uint8_t COMPOUND_REDEEM_UNDERLYING_SELECTOR[SELECTOR_SIZE] = {0x85, 0x2a, 0x12, 0xe3};
static const uint8_t COMPOUND_REDEEM_SELECTOR[SELECTOR_SIZE] = {0xdb, 0x00, 0x6a, 0x75};
static const uint8_t COMPOUND_MINT_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};
static const uint8_t CETH_MINT_SELECTOR[SELECTOR_SIZE] = {0x12, 0x49, 0xc5, 0x8b};
const uint8_t* const COMPOUND_SELECTORS[NUM_COMPOUND_SELECTORS] = {
COMPOUND_REDEEM_UNDERLYING_SELECTOR,
COMPOUND_REDEEM_SELECTOR,
COMPOUND_MINT_SELECTOR,
CETH_MINT_SELECTOR};
#ifdef HAVE_ETH2
static const uint8_t ETH2_DEPOSIT_SELECTOR[SELECTOR_SIZE] = {0x22, 0x89, 0x51, 0x18};
@@ -99,6 +111,12 @@ const internalEthPlugin_t INTERNAL_ETH_PLUGINS[] = {
"-erc20",
erc20_plugin_call},
{NULL,
(const uint8_t**) COMPOUND_SELECTORS,
NUM_COMPOUND_SELECTORS,
"-cmpd",
compound_plugin_call},
#ifdef HAVE_ETH2
{NULL, (const uint8_t**) ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call},

View File

@@ -29,6 +29,9 @@ typedef struct internalEthPlugin_t {
#define NUM_ERC20_SELECTORS 2
extern const uint8_t* const ERC20_SELECTORS[NUM_ERC20_SELECTORS];
#define NUM_COMPOUND_SELECTORS 4
extern const uint8_t* const COMPOUND_SELECTORS[NUM_COMPOUND_SELECTORS];
#ifdef HAVE_ETH2
#define NUM_ETH2_SELECTORS 1

View File

@@ -1,8 +1,4 @@
#include "shared_context.h"
#ifdef HAVE_UX_FLOW
#include "ui_flow.h"
#endif
#include "ui_callbacks.h"
#include "eth_plugin_handler.h"
#include "ux.h"
#include "feature_signTx.h"

View File

@@ -17,8 +17,7 @@
#include "shared_context.h"
#include "apdu_constants.h"
#include "ui_callbacks.h"
#include "ui_flow.h"
#include "common_ui.h"
#include "os_io_seproxyhal.h"
@@ -86,24 +85,6 @@ void reset_app_context() {
memset((uint8_t *) &tmpContent, 0, sizeof(tmpContent));
}
void ui_idle(void) {
// reserve a display stack slot if none yet
if (G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_idle_flow, NULL);
}
void ui_warning_contract_data(void) {
ux_flow_init(0, ux_warning_contract_data_flow, NULL);
}
unsigned int io_seproxyhal_touch_exit(__attribute__((unused)) const bagl_element_t *e) {
// Go back to the dashboard
os_sched_exit(0);
return 0; // do not redraw the widget
}
void io_seproxyhal_send_status(uint32_t sw) {
G_io_apdu_buffer[0] = ((sw >> 8) & 0xff);
G_io_apdu_buffer[1] = (sw & 0xff);
@@ -298,6 +279,21 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) {
case CHAIN_KIND_ASTAR:
numTokens = NUM_TOKENS_ASTAR;
break;
case CHAIN_KIND_XDCNETWORK:
numTokens = NUM_TOKENS_XDCNETWORK;
break;
case CHAIN_KIND_METER:
numTokens = NUM_TOKENS_METER;
break;
case CHAIN_KIND_MULTIVAC:
numTokens = NUM_TOKENS_MULTIVAC;
break;
case CHAIN_KIND_TECRA:
numTokens = NUM_TOKENS_TECRA;
break;
case CHAIN_KIND_APOTHEMNETWORK:
numTokens = NUM_TOKENS_APOTHEMNETWORK;
break;
}
for (i = 0; i < numTokens; i++) {
switch (chainConfig->kind) {
@@ -436,6 +432,21 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) {
case CHAIN_KIND_ASTAR:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ASTAR[i]);
break;
case CHAIN_KIND_XDCNETWORK:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_XDCNETWORK[i]);
break;
case CHAIN_KIND_METER:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_METER[i]);
break;
case CHAIN_KIND_MULTIVAC:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_MULTIVAC[i]);
break;
case CHAIN_KIND_TECRA:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_TECRA[i]);
break;
case CHAIN_KIND_APOTHEMNETWORK:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_APOTHEMNETWORK[i]);
break;
}
if (memcmp(currentToken->address, tmpContent.txContent.destination, ADDRESS_LENGTH) == 0) {
return currentToken;

View File

@@ -2,10 +2,11 @@
#include "shared_context.h"
#include "stark_utils.h"
#include "ui_callbacks.h"
#include "utils.h"
#include "ethUtils.h"
extraInfo_t *getKnownToken(uint8_t *contractAddress);
static unsigned char const C_cx_Stark256_n[] = {
// n: 0x0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

View File

@@ -212,4 +212,14 @@ const tokenDefinition_t const TOKENS_ASTAR[NUM_TOKENS_ASTAR] = {};
const tokenDefinition_t const TOKENS_SHIDEN[NUM_TOKENS_SHIDEN] = {};
const tokenDefinition_t const TOKENS_XDCNETWORK[NUM_TOKENS_XDCNETWORK] = {};
const tokenDefinition_t const TOKENS_METER[NUM_TOKENS_METER] = {};
const tokenDefinition_t const TOKENS_MULTIVAC[NUM_TOKENS_MULTIVAC] = {};
const tokenDefinition_t const TOKENS_TECRA[NUM_TOKENS_TECRA] = {};
const tokenDefinition_t const TOKENS_APOTHEMNETWORK[NUM_TOKENS_APOTHEMNETWORK] = {};
#endif

View File

@@ -110,6 +110,11 @@ static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = {
#define NUM_TOKENS_CUBE 0
#define NUM_TOKENS_ASTAR 0
#define NUM_TOKENS_SHIDEN 0
#define NUM_TOKENS_XDCNETWORK 0
#define NUM_TOKENS_METER 0
#define NUM_TOKENS_MULTIVAC 0
#define NUM_TOKENS_TECRA 0
#define NUM_TOKENS_APOTHEMNETWORK 0
extern tokenDefinition_t const TOKENS_AKROMA[NUM_TOKENS_AKROMA];
extern tokenDefinition_t const TOKENS_ELLAISM[NUM_TOKENS_ELLAISM];
@@ -155,6 +160,11 @@ extern tokenDefinition_t const TOKENS_WETHIO[NUM_TOKENS_WETHIO];
extern tokenDefinition_t const TOKENS_CUBE[NUM_TOKENS_CUBE];
extern tokenDefinition_t const TOKENS_ASTAR[NUM_TOKENS_ASTAR];
extern tokenDefinition_t const TOKENS_SHIDEN[NUM_TOKENS_SHIDEN];
extern tokenDefinition_t const TOKENS_XDCNETWORK[NUM_TOKENS_XDCNETWORK];
extern tokenDefinition_t const TOKENS_METER[NUM_TOKENS_METER];
extern tokenDefinition_t const TOKENS_MULTIVAC[NUM_TOKENS_MULTIVAC];
extern tokenDefinition_t const TOKENS_TECRA[NUM_TOKENS_TECRA];
extern tokenDefinition_t const TOKENS_APOTHEMNETWORK[NUM_TOKENS_APOTHEMNETWORK];
#endif /* HAVE_TOKENS_LIST */

View File

@@ -17,6 +17,9 @@ unsigned int io_seproxyhal_touch_data_cancel(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_privacy_ok(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_privacy_cancel(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_stark_pubkey_ok(const bagl_element_t *e);
unsigned int io_seproxyhal_touch_stark_ok(const bagl_element_t *e);
void ui_idle(void);
void ui_warning_contract_data(void);

View File

@@ -1,226 +0,0 @@
#include "shared_context.h"
#include "ui_callbacks.h"
void display_settings(const ux_flow_step_t* const start_step);
void switch_settings_blind_signing(void);
void switch_settings_display_data(void);
void switch_settings_display_nonce(void);
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void);
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(
ux_idle_flow_1_step,
nn, //pnn,
{
//"", //&C_icon_dashboard,
"Application",
"is ready",
});
UX_STEP_NOCB(
ux_idle_flow_2_step,
bn,
{
"Version",
APPVERSION,
});
UX_STEP_CB(
ux_idle_flow_3_step,
pb,
display_settings(NULL),
{
&C_icon_eye,
"Settings",
});
UX_STEP_CB(
ux_idle_flow_4_step,
pb,
os_sched_exit(-1),
{
&C_icon_dashboard_x,
"Quit",
});
// clang-format on
UX_FLOW(ux_idle_flow,
&ux_idle_flow_1_step,
&ux_idle_flow_2_step,
&ux_idle_flow_3_step,
&ux_idle_flow_4_step,
FLOW_LOOP);
#if defined(TARGET_NANOS)
// clang-format off
UX_STEP_CB(
ux_settings_flow_blind_signing_step,
bnnn_paging,
switch_settings_blind_signing(),
{
.title = "Blind signing",
.text = strings.common.fullAddress,
});
UX_STEP_CB(
ux_settings_flow_display_data_step,
bnnn_paging,
switch_settings_display_data(),
{
.title = "Debug data",
.text = strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_display_nonce_step,
bnnn_paging,
switch_settings_display_nonce(),
{
.title = "Account nonce",
.text = strings.common.fullAddress + 18
});
#else
UX_STEP_CB(
ux_settings_flow_blind_signing_step,
bnnn,
switch_settings_blind_signing(),
{
"Blind signing",
"Transaction",
"blind signing",
strings.common.fullAddress,
});
UX_STEP_CB(
ux_settings_flow_display_data_step,
bnnn,
switch_settings_display_data(),
{
"Debug data",
"Show contract data",
"details",
strings.common.fullAddress + 9
});
UX_STEP_CB(
ux_settings_flow_display_nonce_step,
bnnn,
switch_settings_display_nonce(),
{
"Nonce",
"Show account nonce",
"in transactions",
strings.common.fullAddress + 18
});
#endif
#ifdef HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_verbose_eip712_step,
bnnn,
switch_settings_verbose_eip712(),
{
"Verbose EIP-712",
"Ignore filtering &",
"display raw content",
strings.common.fullAddress + 27
});
#endif // HAVE_EIP712_FULL_SUPPORT
UX_STEP_CB(
ux_settings_flow_back_step,
pb,
ui_idle(),
{
&C_icon_back_x,
"Back",
});
// clang-format on
UX_FLOW(ux_settings_flow,
&ux_settings_flow_blind_signing_step,
&ux_settings_flow_display_data_step,
&ux_settings_flow_display_nonce_step,
#ifdef HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_verbose_eip712_step,
#endif // HAVE_EIP712_FULL_SUPPORT
&ux_settings_flow_back_step);
void display_settings(const ux_flow_step_t* const start_step) {
const char* const values[] = {"Enabled", "Disabled"};
bool settings[] = {N_storage.dataAllowed,
N_storage.contractDetails,
N_storage.displayNonce,
#ifdef HAVE_EIP712_FULL_SUPPORT
N_storage.verbose_eip712
#endif // HAVE_EIP712_FULL_SUPPORT
};
uint8_t offset = 0;
uint8_t increment = MAX(strlen(values[0]), strlen(values[1])) + 1;
for (unsigned int i = 0; i < (sizeof(settings) / sizeof(settings[0])); ++i) {
strlcpy(strings.common.fullAddress + offset,
(settings[i] ? values[0] : values[1]),
sizeof(strings.common.fullAddress) - offset);
offset += increment;
}
ux_flow_init(0, ux_settings_flow, start_step);
}
void switch_settings_blind_signing(void) {
uint8_t value = (N_storage.dataAllowed ? 0 : 1);
nvm_write((void*) &N_storage.dataAllowed, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_blind_signing_step);
}
void switch_settings_display_data(void) {
uint8_t value = (N_storage.contractDetails ? 0 : 1);
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_display_data_step);
}
void switch_settings_display_nonce(void) {
uint8_t value = (N_storage.displayNonce ? 0 : 1);
nvm_write((void*) &N_storage.displayNonce, (void*) &value, sizeof(uint8_t));
display_settings(&ux_settings_flow_display_nonce_step);
}
#ifdef HAVE_EIP712_FULL_SUPPORT
void switch_settings_verbose_eip712(void) {
bool value = !N_storage.verbose_eip712;
nvm_write((void*) &N_storage.verbose_eip712, (void*) &value, sizeof(value));
display_settings(&ux_settings_flow_verbose_eip712_step);
}
#endif // HAVE_EIP712_FULL_SUPPORT
//////////////////////////////////////////////////////////////////////
// clang-format off
#if defined(TARGET_NANOS)
UX_STEP_CB(
ux_warning_contract_data_step,
bnnn_paging,
ui_idle(),
{
"Error",
"Blind signing must be enabled in Settings",
});
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2)
UX_STEP_CB(
ux_warning_contract_data_step,
pnn,
ui_idle(),
{
&C_icon_crossmark,
"Blind signing must be",
"enabled in Settings",
});
#endif
// clang-format on
UX_FLOW(ux_warning_contract_data_flow, &ux_warning_contract_data_step);

View File

@@ -1,63 +0,0 @@
#ifndef _UI_FLOW_H_
#define _UI_FLOW_H_
#include "shared_context.h"
#include "os_io_seproxyhal.h"
#include "ux.h"
extern const ux_flow_step_t* const ux_idle_flow[];
extern const ux_flow_step_t* const ux_warning_contract_data_flow[];
extern const ux_flow_step_t* const ux_settings_flow[];
extern const ux_flow_step_t* const ux_display_public_flow[];
extern const ux_flow_step_t* const ux_confirm_selector_flow[];
extern const ux_flow_step_t* const ux_confirm_parameter_flow[];
extern const ux_flow_step_t* const ux_approval_allowance_flow[];
extern const ux_flow_step_t* const ux_sign_flow[];
extern const ux_flow_step_t* const ux_sign_712_v0_flow[];
extern const ux_flow_step_t* const ux_display_public_eth2_flow[];
extern const ux_flow_step_t* const ux_display_privacy_public_key_flow[];
extern const ux_flow_step_t* const ux_display_privacy_shared_secret_flow[];
#ifdef HAVE_STARKWARE
extern const ux_flow_step_t* const ux_display_stark_public_flow[];
extern const ux_flow_step_t* const ux_stark_limit_order_flow[];
extern const ux_flow_step_t* const ux_stark_transfer_flow[];
extern const ux_flow_step_t* const ux_stark_self_transfer_flow[];
extern const ux_flow_step_t* const ux_stark_transfer_conditional_flow[];
extern const ux_flow_step_t* const ux_stark_self_transfer_conditional_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_register_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_deposit_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_withdraw_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_verify_vault_id_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_escape_flow[];
extern const ux_flow_step_t* const ux_approval_starkware_verify_escape_flow[];
extern const ux_flow_step_t* const ux_stark_unsafe_sign_flow[];
#endif
#endif // _UI_FLOW_H_