Add ETH 2 deposit handling
This commit is contained in:
committed by
TamtamHero
parent
832294334f
commit
7e53de8897
@@ -11,6 +11,8 @@
|
||||
#define INS_SIGN_PERSONAL_MESSAGE 0x08
|
||||
#define INS_PROVIDE_ERC20_TOKEN_INFORMATION 0x0A
|
||||
#define INS_SIGN_EIP_712_MESSAGE 0x0C
|
||||
#define INS_GET_ETH2_PUBLIC_KEY 0x0E
|
||||
#define INS_SET_ETH2_WITHDRAWAL_INDEX 0x10
|
||||
#define P1_CONFIRM 0x01
|
||||
#define P1_NON_CONFIRM 0x00
|
||||
#define P2_NO_CHAINCODE 0x00
|
||||
@@ -48,6 +50,14 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *dataBuf
|
||||
void handleSign(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
void handleGetAppConfiguration(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
void handleSignPersonalMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
void handleSignEIP712Message(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
void handleGetEth2PublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
void handleSetEth2WinthdrawalIndex(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
|
||||
@@ -45,12 +45,16 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
|
||||
|
||||
int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init) {
|
||||
uint8_t i;
|
||||
const uint8_t **selectors;
|
||||
dataContext.tokenContext.pluginAvailable = 0;
|
||||
// Handle hardcoded plugin list
|
||||
PRINTF("Selector %.*H\n", 4, init->selector);
|
||||
for (i=0; i<NUM_INTERNAL_PLUGINS; i++) {
|
||||
const uint8_t **selectors = PIC(INTERNAL_ETH_PLUGINS[i].selectors);
|
||||
for (i=0;; i++) {
|
||||
uint8_t j;
|
||||
selectors = PIC(INTERNAL_ETH_PLUGINS[i].selectors);
|
||||
if (selectors == NULL) {
|
||||
break;
|
||||
}
|
||||
for (j=0; ((j<INTERNAL_ETH_PLUGINS[i].num_selectors) && (contractAddress != NULL)); j++) {
|
||||
if (memcmp(init->selector, PIC(selectors[j]), SELECTOR_SIZE) == 0) {
|
||||
strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias);
|
||||
@@ -96,6 +100,7 @@ int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter) {
|
||||
char tmp[PLUGIN_ID_LENGTH];
|
||||
char *alias;
|
||||
uint8_t i;
|
||||
uint8_t internalPlugin = 0;
|
||||
|
||||
pluginRW.sha3 = &global_sha3;
|
||||
pluginRO.txContent = &tmpContent.txContent;
|
||||
@@ -154,14 +159,18 @@ int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter) {
|
||||
|
||||
// Perform the call
|
||||
|
||||
for (i=0; i<NUM_INTERNAL_PLUGINS; i++) {
|
||||
for (i=0;; i++) {
|
||||
if (INTERNAL_ETH_PLUGINS[i].alias[0] == 0) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(alias, INTERNAL_ETH_PLUGINS[i].alias) == 0) {
|
||||
internalPlugin = 1;
|
||||
((PluginCall)PIC(INTERNAL_ETH_PLUGINS[i].impl))(method, parameter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == NUM_INTERNAL_PLUGINS) {
|
||||
if (!internalPlugin) {
|
||||
uint32_t params[3];
|
||||
params[0] = (uint32_t)alias;
|
||||
params[1] = method;
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
void erc20_plugin_call(int message, void *parameters);
|
||||
void compound_plugin_call(int message, void *parameters);
|
||||
#ifdef HAVE_STARKWARE
|
||||
void starkware_plugin_call(int message, void *parameters);
|
||||
#endif
|
||||
#ifdef HAVE_ETH2
|
||||
void eth2_plugin_call(int message, void *parameters);
|
||||
#endif
|
||||
|
||||
static const uint8_t const ERC20_TRANSFER_SELECTOR[SELECTOR_SIZE] = { 0xa9, 0x05, 0x9c, 0xbb };
|
||||
static const uint8_t const ERC20_APPROVE_SELECTOR[SELECTOR_SIZE] = { 0x09, 0x5e, 0xa7, 0xb3 };
|
||||
@@ -21,6 +26,16 @@ const uint8_t* const COMPOUND_SELECTORS[NUM_COMPOUND_SELECTORS] = {
|
||||
COMPOUND_MINT_SELECTOR, CETH_MINT_SELECTOR
|
||||
};
|
||||
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
static const uint8_t const ETH2_DEPOSIT_SELECTOR[SELECTOR_SIZE] = { 0x22, 0x89, 0x51, 0x18 };
|
||||
|
||||
const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS] = {
|
||||
ETH2_DEPOSIT_SELECTOR
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
static const uint8_t const STARKWARE_REGISTER_ID[SELECTOR_SIZE] = { 0x76, 0x57, 0x18, 0xd7 };
|
||||
@@ -45,21 +60,32 @@ const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = {
|
||||
|
||||
// All internal alias names start with 'minus'
|
||||
|
||||
const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[NUM_INTERNAL_PLUGINS] = {
|
||||
const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = {
|
||||
{
|
||||
ERC20_SELECTORS,
|
||||
2,
|
||||
NUM_ERC20_SELECTORS,
|
||||
"-erc20",
|
||||
erc20_plugin_call
|
||||
},
|
||||
|
||||
{
|
||||
COMPOUND_SELECTORS,
|
||||
4,
|
||||
NUM_COMPOUND_SELECTORS,
|
||||
"-cmpd",
|
||||
compound_plugin_call
|
||||
},
|
||||
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
{
|
||||
ETH2_SELECTORS,
|
||||
NUM_ETH2_SELECTORS,
|
||||
"-eth2",
|
||||
eth2_plugin_call
|
||||
},
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
{
|
||||
@@ -70,4 +96,11 @@ const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[NUM_INTERNAL_PLUGINS] = {
|
||||
},
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
NULL,
|
||||
0,
|
||||
"",
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,20 +17,20 @@ 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
|
||||
extern const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS];
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
#define NUM_INTERNAL_PLUGINS 3
|
||||
|
||||
#define NUM_STARKWARE_SELECTORS 10
|
||||
extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS];
|
||||
|
||||
#else
|
||||
|
||||
#define NUM_INTERNAL_PLUGINS 2
|
||||
|
||||
#endif
|
||||
|
||||
extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[NUM_INTERNAL_PLUGINS];
|
||||
extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[];
|
||||
|
||||
#endif
|
||||
|
||||
19
src/main.c
19
src/main.c
@@ -54,6 +54,9 @@ bool called_from_swap;
|
||||
#ifdef HAVE_STARKWARE
|
||||
bool quantumSet;
|
||||
#endif
|
||||
#ifdef HAVE_ETH2
|
||||
uint32_t eth2WithdrawalIndex;
|
||||
#endif
|
||||
|
||||
#include "ux.h"
|
||||
ux_state_t G_ux;
|
||||
@@ -70,6 +73,9 @@ void reset_app_context() {
|
||||
called_from_swap = false;
|
||||
#ifdef HAVE_STARKWARE
|
||||
quantumSet = false;
|
||||
#endif
|
||||
#ifdef HAVE_ETH2
|
||||
eth2WithdrawalIndex = 0;
|
||||
#endif
|
||||
os_memset((uint8_t*)&txContext, 0, sizeof(txContext));
|
||||
os_memset((uint8_t*)&tmpContent, 0, sizeof(tmpContent));
|
||||
@@ -426,6 +432,19 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
||||
handleSignEIP712Message(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
|
||||
break;
|
||||
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
case INS_GET_ETH2_PUBLIC_KEY:
|
||||
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
|
||||
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
|
||||
break;
|
||||
|
||||
case INS_SET_ETH2_WITHDRAWAL_INDEX:
|
||||
handleSetEth2WithdrawalIndex(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
|
||||
break;
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
case 0xFF: // return to dashboard
|
||||
goto return_to_dashboard;
|
||||
|
||||
@@ -168,6 +168,9 @@ extern uint8_t appState;
|
||||
#ifdef HAVE_STARKWARE
|
||||
extern bool quantumSet;
|
||||
#endif
|
||||
#ifdef HAVE_ETH2
|
||||
extern uint32_t eth2WithdrawalIndex;
|
||||
#endif
|
||||
|
||||
void reset_app_context(void);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ unsigned int io_seproxyhal_touch_data_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_data_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(const bagl_element_t *e);
|
||||
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e);
|
||||
|
||||
void ui_idle(void);
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ 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 [];
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
extern const ux_flow_step_t * const ux_display_stark_public_flow [];
|
||||
|
||||
Reference in New Issue
Block a user