From ea1709b0ea658e512643c791b4cd9aacb5281410 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 13 Feb 2024 10:40:01 +0100 Subject: [PATCH] Completely remove old Starkware internal "plugin" --- makefile_conf/chain/ethereum.mk | 4 - makefile_conf/chain/goerli.mk | 6 - makefile_conf/chain/ropsten.mk | 6 - src/apdu_constants.h | 51 - src/common_ui.h | 4 - src/eth_plugin_internal.c | 75 +- src/eth_plugin_internal.h | 7 - src/main.c | 56 -- src/poorstream.c | 43 - src/poorstream.h | 21 - src/shared_context.h | 56 -- src/starkDisplayUtils.c | 17 - src/starkDisplayUtils.h | 6 - src/stark_crypto.c | 91 -- src/stark_crypto.h | 21 - src/stark_utils.c | 245 ----- src/stark_utils.h | 35 - src/ui_callbacks.h | 3 - src_bagl/common_ui.c | 26 - src_bagl/ui_flow.h | 30 - src_bagl/ui_flow_stark_getPublicKey.c | 46 - src_bagl/ui_flow_stark_sign.c | 234 ----- src_bagl/ui_flow_stark_unsafe_sign.c | 70 -- .../cmd_getAppConfiguration.c | 4 - src_features/signTx/logic_signTx.c | 3 - .../cmd_stark_getPublicKey.c | 66 -- .../feature_stark_getPublicKey.h | 8 - .../logic_stark_getPublicKey.c | 14 - .../ui_common_stark_getPublicKey.c | 19 - .../cmd_stark_provideQuantum.c | 64 -- src_features/stark_sign/cmd_stark_sign.c | 259 ----- .../stark_sign/ui_common_stark_sign.c | 36 - .../stark_unsafe_sign/cmd_stark_unsafe_sign.c | 55 - .../ui_common_stark_unsafe_sign.c | 42 - src_nbgl/ui_get_stark_public_key.c | 29 - src_nbgl/ui_stark_limit_order.c | 68 -- src_nbgl/ui_stark_transfer.c | 134 --- src_nbgl/ui_stark_unsafe_sign.c | 70 -- src_plugins/erc20/erc20_plugin.c | 17 - src_plugins/starkware/starkware_plugin.c | 944 ------------------ 40 files changed, 1 insertion(+), 2984 deletions(-) delete mode 100644 src/poorstream.c delete mode 100644 src/poorstream.h delete mode 100644 src/starkDisplayUtils.c delete mode 100644 src/starkDisplayUtils.h delete mode 100644 src/stark_crypto.c delete mode 100644 src/stark_crypto.h delete mode 100644 src/stark_utils.c delete mode 100644 src/stark_utils.h delete mode 100644 src_bagl/ui_flow_stark_getPublicKey.c delete mode 100644 src_bagl/ui_flow_stark_sign.c delete mode 100644 src_bagl/ui_flow_stark_unsafe_sign.c delete mode 100644 src_features/stark_getPublicKey/cmd_stark_getPublicKey.c delete mode 100644 src_features/stark_getPublicKey/feature_stark_getPublicKey.h delete mode 100644 src_features/stark_getPublicKey/logic_stark_getPublicKey.c delete mode 100644 src_features/stark_getPublicKey/ui_common_stark_getPublicKey.c delete mode 100644 src_features/stark_provideQuantum/cmd_stark_provideQuantum.c delete mode 100644 src_features/stark_sign/cmd_stark_sign.c delete mode 100644 src_features/stark_sign/ui_common_stark_sign.c delete mode 100644 src_features/stark_unsafe_sign/cmd_stark_unsafe_sign.c delete mode 100644 src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c delete mode 100644 src_nbgl/ui_get_stark_public_key.c delete mode 100644 src_nbgl/ui_stark_limit_order.c delete mode 100644 src_nbgl/ui_stark_transfer.c delete mode 100644 src_nbgl/ui_stark_unsafe_sign.c delete mode 100644 src_plugins/starkware/starkware_plugin.c diff --git a/makefile_conf/chain/ethereum.mk b/makefile_conf/chain/ethereum.mk index 16e4b8c..993c930 100644 --- a/makefile_conf/chain/ethereum.mk +++ b/makefile_conf/chain/ethereum.mk @@ -2,10 +2,6 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "ETH" CHAIN_ID = 1 -# Starkware integration -APP_LOAD_PARAMS += --path "2645'/579218131'" -DEFINES += HAVE_STARKWARE -DEFINES += STARK_BIP32_PATH_0=0x80000A55 STARK_BIP32_PATH_1=0xA2862AD3 # Allow to derive ETH 2 public keys APP_LOAD_PARAMS += --path "12381/3600" --curve bls12381g1 DEFINES += HAVE_ETH2 diff --git a/makefile_conf/chain/goerli.mk b/makefile_conf/chain/goerli.mk index 1f8e37d..c01e6c9 100644 --- a/makefile_conf/chain/goerli.mk +++ b/makefile_conf/chain/goerli.mk @@ -1,12 +1,6 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "ETH" CHAIN_ID = 5 -# Starkware integration -APP_LOAD_PARAMS += --path "2645'/579218131'" -DEFINES += HAVE_STARKWARE -# Keep for Starkware Goerli tests -DEFINES += HAVE_TOKENS_EXTRA_LIST -DEFINES += STARK_BIP32_PATH_0=0x80000A55 STARK_BIP32_PATH_1=0xA2862AD3 # Allow to derive ETH 2 public keys APP_LOAD_PARAMS += --path "12381/3600" --curve bls12381g1 DEFINES += HAVE_ETH2 diff --git a/makefile_conf/chain/ropsten.mk b/makefile_conf/chain/ropsten.mk index 793a314..d709186 100644 --- a/makefile_conf/chain/ropsten.mk +++ b/makefile_conf/chain/ropsten.mk @@ -1,12 +1,6 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "ETH" CHAIN_ID = 3 -# Starkware integration -APP_LOAD_PARAMS += --path "2645'/579218131'" -DEFINES += HAVE_STARKWARE -# Keep for Starkware Ropsten tests -DEFINES += HAVE_TOKENS_EXTRA_LIST -DEFINES += STARK_BIP32_PATH_0=0x80000A55 STARK_BIP32_PATH_1=0xA2862AD3 # Allow to derive ETH 2 public keys APP_LOAD_PARAMS += --path "12381/3600" --curve bls12381g1 DEFINES += HAVE_ETH2 diff --git a/src/apdu_constants.h b/src/apdu_constants.h index 7911d6b..07e41a3 100644 --- a/src/apdu_constants.h +++ b/src/apdu_constants.h @@ -5,8 +5,6 @@ #define APP_FLAG_DATA_ALLOWED 0x01 #define APP_FLAG_EXTERNAL_TOKEN_NEEDED 0x02 -#define APP_FLAG_STARKWARE 0x04 -#define APP_FLAG_STARKWARE_V2 0x08 #define CLA 0xE0 #define INS_GET_PUBLIC_KEY 0x02 @@ -47,26 +45,6 @@ #define APDU_RESPONSE_CONDITION_NOT_SATISFIED 0x6985 #define APDU_RESPONSE_REF_DATA_NOT_FOUND 0x6a88 -#ifdef HAVE_STARKWARE - -#define STARKWARE_CLA 0xF0 -#define STARKWARE_INS_GET_PUBLIC_KEY 0x02 -#define STARKWARE_INS_SIGN_MESSAGE 0x04 -#define STARKWARE_INS_PROVIDE_QUANTUM 0x08 -#define STARKWARE_INS_UNSAFE_SIGN 0x0A - -#define P1_STARK_ORDER 0x01 -#define P1_STARK_TRANSFER 0x02 -#define P1_STARK_ORDER_V2 0x03 -#define P1_STARK_TRANSFER_V2 0x04 -#define P1_STARK_CONDITIONAL_TRANSFER 0x05 - -#define STARK_ORDER_TYPE 0 -#define STARK_TRANSFER_TYPE 1 -#define STARK_CONDITIONAL_TRANSFER_TYPE 2 - -#endif - enum { OFFSET_CLA = 0, OFFSET_INS, OFFSET_P1, OFFSET_P2, OFFSET_LC, OFFSET_CDATA }; #define ERR_APDU_EMPTY 0x6982 @@ -151,35 +129,6 @@ void handleSetEth2WinthdrawalIndex(uint8_t p1, #endif -#ifdef HAVE_STARKWARE - -void handleStarkwareGetPublicKey(uint8_t p1, - uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx); -void handleStarkwareSignMessage(uint8_t p1, - uint8_t p2, - uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx); -void handleStarkwareProvideQuantum(uint8_t p1, - uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx); -void handleStarkwareUnsafeSign(uint8_t p1, - uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx); - -#endif - extern uint16_t apdu_response_code; #endif // _APDU_CONSTANTS_H_ diff --git a/src/common_ui.h b/src/common_ui.h index d450597..97dabad 100644 --- a/src/common_ui.h +++ b/src/common_ui.h @@ -11,12 +11,8 @@ void ui_display_privacy_public_key(void); void ui_display_privacy_shared_secret(void); void ui_display_public_key(const uint64_t *chain_id); 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); // EIP-191 void ui_191_start(void); diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index ddf61bb..2cfe351 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -2,13 +2,8 @@ #include "eth_plugin_internal.h" #include "plugin_utils.h" -bool erc20_plugin_available_check(void); - void erc20_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 @@ -27,83 +22,15 @@ const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS] = {ETH2_DEPOSIT_SELECTOR #endif -#ifdef HAVE_STARKWARE - -static const uint8_t STARKWARE_REGISTER_ID[SELECTOR_SIZE] = {0xdd, 0x24, 0x14, 0xd4}; -static const uint8_t STARKWARE_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0x25, 0x05, 0xc3, 0xd9}; -static const uint8_t STARKWARE_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0x00, 0xae, 0xef, 0x8a}; -static const uint8_t STARKWARE_DEPOSIT_CANCEL_ID[SELECTOR_SIZE] = {0x7d, 0xf7, 0xdc, 0x04}; -static const uint8_t STARKWARE_DEPOSIT_RECLAIM_ID[SELECTOR_SIZE] = {0xae, 0x87, 0x38, 0x16}; -static const uint8_t STARKWARE_WITHDRAW_ID[SELECTOR_SIZE] = {0x44, 0x1a, 0x3e, 0x70}; -static const uint8_t STARKWARE_FULL_WITHDRAWAL_ID[SELECTOR_SIZE] = {0xa9, 0x33, 0x10, 0xc4}; -static const uint8_t STARKWARE_FREEZE_ID[SELECTOR_SIZE] = {0x93, 0xc1, 0xe4, 0x66}; -static const uint8_t STARKWARE_ESCAPE_ID[SELECTOR_SIZE] = {0x9e, 0x3a, 0xda, 0xc4}; -static const uint8_t STARKWARE_VERIFY_ESCAPE_ID[SELECTOR_SIZE] = {0x2d, 0xd5, 0x30, 0x06}; - -static const uint8_t STARKWARE_WITHDRAW_TO_ID[SELECTOR_SIZE] = {0x14, 0xcd, 0x70, 0xe4}; -static const uint8_t STARKWARE_DEPOSIT_NFT_ID[SELECTOR_SIZE] = {0xae, 0x1c, 0xdd, 0xe6}; -static const uint8_t STARKWARE_DEPOSIT_NFT_RECLAIM_ID[SELECTOR_SIZE] = {0xfc, 0xb0, 0x58, 0x22}; -static const uint8_t STARKWARE_WITHDRAW_AND_MINT_ID[SELECTOR_SIZE] = {0xd9, 0x14, 0x43, 0xb7}; -static const uint8_t STARKWARE_WITHDRAW_NFT_ID[SELECTOR_SIZE] = {0x01, 0x9b, 0x41, 0x7a}; -static const uint8_t STARKWARE_WITHDRAW_NFT_TO_ID[SELECTOR_SIZE] = {0xeb, 0xef, 0x0f, 0xd0}; -static const uint8_t STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0x10, - 0x82, - 0x08, - 0xcf}; -static const uint8_t STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0xa7, - 0x78, - 0xc0, - 0xc3}; -static const uint8_t STARKWARE_PROXY_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0xdc, 0xca, 0xd5, 0x24}; -static const uint8_t STARKWARE_PROXY_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0x6c, 0xe5, 0xd9, 0x57}; - -const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { - STARKWARE_REGISTER_ID, - STARKWARE_DEPOSIT_TOKEN_ID, - STARKWARE_DEPOSIT_ETH_ID, - STARKWARE_DEPOSIT_CANCEL_ID, - STARKWARE_DEPOSIT_RECLAIM_ID, - STARKWARE_WITHDRAW_ID, - STARKWARE_FULL_WITHDRAWAL_ID, - STARKWARE_FREEZE_ID, - STARKWARE_ESCAPE_ID, - STARKWARE_VERIFY_ESCAPE_ID, - STARKWARE_WITHDRAW_TO_ID, - STARKWARE_DEPOSIT_NFT_ID, - STARKWARE_DEPOSIT_NFT_RECLAIM_ID, - STARKWARE_WITHDRAW_AND_MINT_ID, - STARKWARE_WITHDRAW_NFT_ID, - STARKWARE_WITHDRAW_NFT_TO_ID, - STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID, - STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID, - STARKWARE_PROXY_DEPOSIT_TOKEN_ID, - STARKWARE_PROXY_DEPOSIT_ETH_ID}; - -#endif - // All internal alias names start with 'minus' const internalEthPlugin_t INTERNAL_ETH_PLUGINS[] = { - {erc20_plugin_available_check, - (const uint8_t**) ERC20_SELECTORS, - NUM_ERC20_SELECTORS, - "-erc20", - erc20_plugin_call}, + {NULL, (const uint8_t**) ERC20_SELECTORS, NUM_ERC20_SELECTORS, "-erc20", erc20_plugin_call}, #ifdef HAVE_ETH2 {NULL, (const uint8_t**) ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call}, -#endif - -#ifdef HAVE_STARKWARE - - {NULL, - (const uint8_t**) STARKWARE_SELECTORS, - NUM_STARKWARE_SELECTORS, - "-strk", - starkware_plugin_call}, - #endif {NULL, NULL, 0, "", NULL}}; diff --git a/src/eth_plugin_internal.h b/src/eth_plugin_internal.h index 6cc09ce..ea84e40 100644 --- a/src/eth_plugin_internal.h +++ b/src/eth_plugin_internal.h @@ -29,11 +29,4 @@ extern const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS]; #endif -#ifdef HAVE_STARKWARE - -#define NUM_STARKWARE_SELECTORS 20 -extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS]; - -#endif - extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[]; diff --git a/src/main.c b/src/main.c index ac74de4..4f5ce6d 100644 --- a/src/main.c +++ b/src/main.c @@ -32,10 +32,6 @@ #include "challenge.h" #include "domain_name.h" -#ifdef HAVE_STARKWARE -#include "stark_crypto.h" -#endif - unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]; void ui_idle(void); @@ -55,9 +51,6 @@ uint16_t apdu_response_code; bool G_called_from_swap; bool G_swap_response_ready; pluginType_t pluginType; -#ifdef HAVE_STARKWARE -bool quantumSet; -#endif #ifdef HAVE_ETH2 uint32_t eth2WithdrawalIndex; @@ -81,9 +74,6 @@ void reset_app_context() { G_called_from_swap = false; G_swap_response_ready = false; pluginType = OLD_INTERNAL; -#ifdef HAVE_STARKWARE - quantumSet = false; -#endif #ifdef HAVE_ETH2 eth2WithdrawalIndex = 0; #endif @@ -232,52 +222,6 @@ void handleApdu(unsigned int *flags, unsigned int *tx) { #endif // HAVE_WALLET_ID_SDK -#ifdef HAVE_STARKWARE - - if (G_io_apdu_buffer[OFFSET_CLA] == STARKWARE_CLA) { - switch (G_io_apdu_buffer[OFFSET_INS]) { - case STARKWARE_INS_GET_PUBLIC_KEY: - handleStarkwareGetPublicKey(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 STARKWARE_INS_SIGN_MESSAGE: - handleStarkwareSignMessage(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 STARKWARE_INS_PROVIDE_QUANTUM: - handleStarkwareProvideQuantum(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 STARKWARE_INS_UNSAFE_SIGN: - handleStarkwareUnsafeSign(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; - default: - THROW(0x6D00); - break; - } - CLOSE_TRY; - return; - } - -#endif - if (G_io_apdu_buffer[OFFSET_CLA] != CLA) { THROW(0x6E00); } diff --git a/src/poorstream.c b/src/poorstream.c deleted file mode 100644 index 2dc2fa8..0000000 --- a/src/poorstream.c +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "poorstream.h" - -void poorstream_init(poorstream_t *stream, uint8_t *buffer) { - memset((void *) stream, 0, sizeof(poorstream_t)); - stream->pointer = buffer; -} - -void poorstream_flush(poorstream_t *stream) { - // PRINTF("Flush\n"); - *(stream->pointer + 0) = (stream->accumulator >> 56); - *(stream->pointer + 1) = (stream->accumulator >> 48); - *(stream->pointer + 2) = (stream->accumulator >> 40); - *(stream->pointer + 3) = (stream->accumulator >> 32); - *(stream->pointer + 4) = (stream->accumulator >> 24); - *(stream->pointer + 5) = (stream->accumulator >> 16); - *(stream->pointer + 6) = (stream->accumulator >> 8); - *(stream->pointer + 7) = (stream->accumulator >> 0); -} - -void poorstream_write_bits(poorstream_t *stream, uint64_t bits, uint32_t num_bits) { - stream->offset += num_bits; - if (stream->offset < 64) { - stream->accumulator |= (bits << (64 - stream->offset)); - // PRINTF("ACC |= << %d\n", (64 - stream->offset)); - } else { - stream->offset -= 64; - stream->mask = ((1 << (num_bits - stream->offset)) - 1); - // PRINTF("Mask %lx\n", stream->mask); - // PRINTF("Offset %d\n", stream->offset); - stream->accumulator |= ((bits >> stream->offset) & stream->mask); - poorstream_flush(stream); - stream->accumulator = 0; - stream->pointer += 8; - if (stream->offset) { - stream->mask = ((1 << stream->offset) - 1); - stream->accumulator |= ((bits & stream->mask) << (64 - stream->offset)); - } - } -} - -#endif diff --git a/src/poorstream.h b/src/poorstream.h deleted file mode 100644 index 6ac17a5..0000000 --- a/src/poorstream.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _POORSTREAM_H_ -#define _POORSTREAM_H_ - -#include -#include -#include - -#include "os.h" - -typedef struct poorstream_t { - uint8_t *pointer; - uint32_t offset; - uint64_t mask; - uint64_t accumulator; -} poorstream_t; - -void poorstream_init(poorstream_t *stream, uint8_t *buffer); -void poorstream_flush(poorstream_t *stream); -void poorstream_write_bits(poorstream_t *stream, uint64_t bits, uint32_t num_bits); - -#endif // _POORSTREAM_H_ diff --git a/src/shared_context.h b/src/shared_context.h index 40113d3..4c15914 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -40,21 +40,6 @@ typedef struct internalStorage_t { bool initialized; } internalStorage_t; -#ifdef HAVE_STARKWARE - -typedef enum starkQuantumType_e { - - STARK_QUANTUM_LEGACY = 0x00, - STARK_QUANTUM_ETH, - STARK_QUANTUM_ERC20, - STARK_QUANTUM_ERC721, - STARK_QUANTUM_MINTABLE_ERC20, - STARK_QUANTUM_MINTABLE_ERC721 - -} starkQuantumType_e; - -#endif - typedef struct tokenContext_t { char pluginName[PLUGIN_ID_LENGTH]; @@ -78,13 +63,6 @@ typedef struct tokenContext_t { uint8_t pluginStatus; -#ifdef HAVE_STARKWARE - uint8_t quantum[32]; - uint8_t mintingBlob[32]; - uint8_t quantumIndex; - uint8_t quantumType; -#endif - } tokenContext_t; _Static_assert((offsetof(tokenContext_t, pluginContext) % 4) == 0, "Plugin context not aligned"); @@ -129,27 +107,8 @@ typedef union { char tmp[100]; } tmpContent_t; -#ifdef HAVE_STARKWARE - -typedef struct starkContext_t { - uint8_t w1[32]; - uint8_t w2[32]; - uint8_t w3[32]; - uint8_t w4[32]; - uint8_t conditional; - uint8_t transferDestination[32]; - uint8_t fact[32]; - uint8_t conditionAddress[20]; -} starkContext_t; - -#endif - typedef union { tokenContext_t tokenContext; - -#ifdef HAVE_STARKWARE - starkContext_t starkContext; -#endif } dataContext_t; typedef enum { APP_STATE_IDLE, APP_STATE_SIGNING_TX, APP_STATE_SIGNING_MESSAGE } app_state_t; @@ -158,18 +117,6 @@ typedef enum { CONTRACT_NONE, CONTRACT_ERC20, CONTRACT_ALLOWANCE, -#ifdef HAVE_STARKWARE - CONTRACT_STARKWARE_REGISTER, - CONTRACT_STARKWARE_DEPOSIT_TOKEN, - CONTRACT_STARKWARE_DEPOSIT_ETH, - CONTRACT_STARKWARE_WITHDRAW, - CONTRACT_STARKWARE_DEPOSIT_CANCEL, - CONTRACT_STARKWARE_DEPOSIT_RECLAIM, - CONTRACT_STARKWARE_FULL_WITHDRAWAL, - CONTRACT_STARKWARE_FREEZE, - CONTRACT_STARKWARE_ESCAPE, - CONTRACT_STARKWARE_VERIFY_ESCAPE -#endif } contract_call_t; // must be able to hold in decimal up to : floor(MAX_UINT64 / 2) - 36 @@ -223,9 +170,6 @@ typedef enum { extern pluginType_t pluginType; extern uint8_t appState; -#ifdef HAVE_STARKWARE -extern bool quantumSet; -#endif #ifdef HAVE_ETH2 extern uint32_t eth2WithdrawalIndex; #endif diff --git a/src/starkDisplayUtils.c b/src/starkDisplayUtils.c deleted file mode 100644 index a59ae99..0000000 --- a/src/starkDisplayUtils.c +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" - -void stark_sign_display_master_account() { - snprintf(strings.tmp.tmp, - sizeof(strings.tmp.tmp), - "0x%.*H", - 32, - dataContext.starkContext.transferDestination); -} - -void stark_sign_display_condition_fact() { - snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.fact); -} - -#endif \ No newline at end of file diff --git a/src/starkDisplayUtils.h b/src/starkDisplayUtils.h deleted file mode 100644 index 48399b8..0000000 --- a/src/starkDisplayUtils.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifdef HAVE_STARKWARE - -void stark_sign_display_master_account(); -void stark_sign_display_condition_fact(); - -#endif \ No newline at end of file diff --git a/src/stark_crypto.c b/src/stark_crypto.c deleted file mode 100644 index f5b2520..0000000 --- a/src/stark_crypto.c +++ /dev/null @@ -1,91 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "stark_utils.h" -#include "uint256.h" -#include "common_utils.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, - 0xb7, 0x81, 0x12, 0x6d, 0xca, 0xe7, 0xb2, 0x32, 0x1e, 0x66, 0xa2, 0x41, 0xad, 0xc6, 0x4d, 0x2f}; - -// C_cx_secp256k1_n - (C_cx_secp256k1_n % C_cx_Stark256_n) -static unsigned char const STARK_DERIVE_BIAS[] = { - 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, - 0x38, 0xa1, 0x3b, 0x4b, 0x92, 0x0e, 0x94, 0x11, 0xae, 0x6d, 0xa5, 0xf4, 0x0b, 0x03, 0x58, 0xb1}; - -void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_t *privateKeyData) { -#if 0 - // Sanity check - if (bip32Path[0] != STARK_BIP32_PATH_0) { - PRINTF("Invalid Stark derivation path %d\n", bip32Path[0]); - THROW(0x6a80); - } - os_perso_derive_node_bip32(CX_CURVE_256K1, bip32Path, bip32PathLength, privateKeyData, NULL); - PRINTF("Private key before processing %.*H\n", 32, privateKeyData); - // TODO - support additional schemes - cx_math_modm(privateKeyData, 32, C_cx_Stark256_n, 32); - PRINTF("Private key after processing %.*H\n", 32, privateKeyData); -#else - uint8_t tmp[33]; - uint8_t index = 0; - // Sanity check - if ((bip32PathLength < 2) || (bip32Path[0] != STARK_BIP32_PATH_0) || - (bip32Path[1] != STARK_BIP32_PATH_1)) { - PRINTF("Invalid Stark derivation path %d %d\n", bip32Path[0], bip32Path[1]); - THROW(0x6a80); - } - os_perso_derive_node_bip32(CX_CURVE_256K1, bip32Path, bip32PathLength, tmp, NULL); - PRINTF("Private key before processing %.*H\n", 32, tmp); - for (;;) { - tmp[32] = index; - cx_hash_sha256(tmp, 33, privateKeyData, 32); - PRINTF("Key hash %.*H\n", 32, privateKeyData); - if (cx_math_cmp(privateKeyData, STARK_DERIVE_BIAS, 32) < 0) { - cx_math_modm(privateKeyData, 32, C_cx_Stark256_n, 32); - break; - } - index++; - } - PRINTF("Key result %.*H\n", 32, privateKeyData); - -#endif -} - -void stark_get_amount_string(uint8_t *contractAddress, - uint8_t *quantum256, - uint8_t *amount64, - char *tmp100, - char *target100) { - uint256_t amountPre, quantum, amount; - uint8_t decimals; - char *ticker = chainConfig->coinName; - - PRINTF("stark_get_amount_string %.*H\n", 20, contractAddress); - - if (allzeroes(contractAddress, 20)) { - decimals = WEI_TO_ETHER; - PRINTF("stark_get_amount_string - ETH\n"); - } else { - tokenDefinition_t *token = &getKnownToken(contractAddress)->token; - if (token == NULL) { // caught earlier - THROW(0x6A80); - } - decimals = token->decimals; - ticker = (char *) token->ticker; - PRINTF("stark_get_amount_string - decimals %d ticker %s\n", decimals, ticker); - } - convertUint256BE(amount64, 8, &amountPre); - readu256BE(quantum256, &quantum); - mul256(&amountPre, &quantum, &amount); - tostring256(&amount, 10, tmp100, 100); - PRINTF("stark_get_amount_string - mul256 %s\n", tmp100); - strlcpy(target100, ticker, 100); - adjustDecimals(tmp100, strlen(tmp100), target100 + strlen(ticker), 100, decimals); - PRINTF("get_amount_string %s\n", target100); -} - -#endif // HAVE_STARK diff --git a/src/stark_crypto.h b/src/stark_crypto.h deleted file mode 100644 index 5ce1be3..0000000 --- a/src/stark_crypto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _STARK_CRYPTO_H_ -#define _STARK_CRYPTO_H_ - -#include -#include -#include - -#include "os.h" -#include "cx.h" - -/* EC points */ -#define FIELD_ELEMENT_SIZE (32) -#define EC_POINT_SIZE (2 * FIELD_ELEMENT_SIZE + 1) -typedef unsigned char FieldElement[FIELD_ELEMENT_SIZE]; -typedef unsigned char ECPoint[EC_POINT_SIZE]; - -void pedersen(FieldElement res, /* out */ - FieldElement a, - FieldElement b); - -#endif // _STARK_CRYPTO_H_ diff --git a/src/stark_utils.c b/src/stark_utils.c deleted file mode 100644 index 13cf548..0000000 --- a/src/stark_utils.c +++ /dev/null @@ -1,245 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "stark_crypto.h" -#include "shared_context.h" -#include "uint256.h" -#include "uint_common.h" - -#include "os_io_seproxyhal.h" - -#define SIGNATURE_MAX_LEN (72) - -static const ECPoint PEDERSEN_SHIFT[] = {{ - 0x04, - - 0x04, 0x9e, 0xe3, 0xeb, 0xa8, 0xc1, 0x60, 0x07, 0x00, 0xee, 0x1b, 0x87, 0xeb, 0x59, 0x9f, 0x16, - 0x71, 0x6b, 0x0b, 0x10, 0x22, 0x94, 0x77, 0x33, 0x55, 0x1f, 0xde, 0x40, 0x50, 0xca, 0x68, 0x04, - - 0x03, 0xca, 0x0c, 0xfe, 0x4b, 0x3b, 0xc6, 0xdd, 0xf3, 0x46, 0xd4, 0x9d, 0x06, 0xea, 0x0e, 0xd3, - 0x4e, 0x62, 0x10, 0x62, 0xc0, 0xe0, 0x56, 0xc1, 0xd0, 0x40, 0x5d, 0x26, 0x6e, 0x10, 0x26, 0x8a, -}}; - -static const ECPoint PEDERSEN_POINTS[4] = { - { - 0x04, - - 0x02, 0x34, 0x28, 0x7d, 0xcb, 0xaf, 0xfe, 0x7f, 0x96, 0x9c, 0x74, - 0x86, 0x55, 0xfc, 0xa9, 0xe5, 0x8f, 0xa8, 0x12, 0x0b, 0x6d, 0x56, - 0xeb, 0x0c, 0x10, 0x80, 0xd1, 0x79, 0x57, 0xeb, 0xe4, 0x7b, - - 0x03, 0xb0, 0x56, 0xf1, 0x00, 0xf9, 0x6f, 0xb2, 0x1e, 0x88, 0x95, - 0x27, 0xd4, 0x1f, 0x4e, 0x39, 0x94, 0x01, 0x35, 0xdd, 0x7a, 0x6c, - 0x94, 0xcc, 0x6e, 0xd0, 0x26, 0x8e, 0xe8, 0x9e, 0x56, 0x15, - }, - { - 0x04, - - 0x04, 0xfa, 0x56, 0xf3, 0x76, 0xc8, 0x3d, 0xb3, 0x3f, 0x9d, 0xab, - 0x26, 0x56, 0x55, 0x8f, 0x33, 0x99, 0x09, 0x9e, 0xc1, 0xde, 0x5e, - 0x30, 0x18, 0xb7, 0xa6, 0x93, 0x2d, 0xba, 0x8a, 0xa3, 0x78, - - 0x03, 0xfa, 0x09, 0x84, 0xc9, 0x31, 0xc9, 0xe3, 0x81, 0x13, 0xe0, - 0xc0, 0xe4, 0x7e, 0x44, 0x01, 0x56, 0x27, 0x61, 0xf9, 0x2a, 0x7a, - 0x23, 0xb4, 0x51, 0x68, 0xf4, 0xe8, 0x0f, 0xf5, 0xb5, 0x4d, - }, - { - 0x04, - - 0x04, 0xba, 0x4c, 0xc1, 0x66, 0xbe, 0x8d, 0xec, 0x76, 0x49, 0x10, - 0xf7, 0x5b, 0x45, 0xf7, 0x4b, 0x40, 0xc6, 0x90, 0xc7, 0x47, 0x09, - 0xe9, 0x0f, 0x3a, 0xa3, 0x72, 0xf0, 0xbd, 0x2d, 0x69, 0x97, - - 0x00, 0x40, 0x30, 0x1c, 0xf5, 0xc1, 0x75, 0x1f, 0x4b, 0x97, 0x1e, - 0x46, 0xc4, 0xed, 0xe8, 0x5f, 0xca, 0xc5, 0xc5, 0x9a, 0x5c, 0xe5, - 0xae, 0x7c, 0x48, 0x15, 0x1f, 0x27, 0xb2, 0x4b, 0x21, 0x9c, - }, - { - 0x04, - - 0x05, 0x43, 0x02, 0xdc, 0xb0, 0xe6, 0xcc, 0x1c, 0x6e, 0x44, 0xcc, - 0xa8, 0xf6, 0x1a, 0x63, 0xbb, 0x2c, 0xa6, 0x50, 0x48, 0xd5, 0x3f, - 0xb3, 0x25, 0xd3, 0x6f, 0xf1, 0x2c, 0x49, 0xa5, 0x82, 0x02, - - 0x01, 0xb7, 0x7b, 0x3e, 0x37, 0xd1, 0x35, 0x04, 0xb3, 0x48, 0x04, - 0x62, 0x68, 0xd8, 0xae, 0x25, 0xce, 0x98, 0xad, 0x78, 0x3c, 0x25, - 0x56, 0x1a, 0x87, 0x9d, 0xcc, 0x77, 0xe9, 0x9c, 0x24, 0x26, - }}; - -void accum_ec_mul(ECPoint *hash, uint8_t *buf, int len, int pedersen_idx) { - ECPoint tmp; - if (!allzeroes(buf, len)) { - uint8_t pad[32]; - memcpy(tmp, PEDERSEN_POINTS[pedersen_idx], sizeof(ECPoint)); - io_seproxyhal_io_heartbeat(); - memset(pad, 0, sizeof(pad)); - memmove(pad + 32 - len, buf, len); - cx_ecfp_scalar_mult(CX_CURVE_Stark256, tmp, sizeof(ECPoint), pad, sizeof(pad)); - io_seproxyhal_io_heartbeat(); - cx_ecfp_add_point(CX_CURVE_Stark256, *hash, *hash, tmp, sizeof(ECPoint)); - } -} - -void pedersen(FieldElement res, /* out */ - FieldElement a, - FieldElement b) { - ECPoint hash; - - memcpy(hash, PEDERSEN_SHIFT, sizeof(hash)); - - accum_ec_mul(&hash, a, 1, 1); - accum_ec_mul(&hash, a + 1, FIELD_ELEMENT_SIZE - 1, 0); - accum_ec_mul(&hash, b, 1, 3); - accum_ec_mul(&hash, b + 1, FIELD_ELEMENT_SIZE - 1, 2); - - memcpy(res, hash + 1, FIELD_ELEMENT_SIZE); -} - -void shift_stark_hash(FieldElement hash) { - uint256_t hash256, final_hash256; - readu256BE(hash, &hash256); - uint32_t bits_count = bits256(&hash256); - if (bits_count < 248) { - return; - } else if (bits_count >= 248 && bits_count % 8 >= 1 && bits_count % 8 <= 4) { - shiftl256(&hash256, 4, &final_hash256); - write_u64_be(hash, UPPER(UPPER_P((&final_hash256)))); - write_u64_be(hash + 8, LOWER(UPPER_P((&final_hash256)))); - write_u64_be(hash + 16, UPPER(LOWER_P((&final_hash256)))); - write_u64_be(hash + 24, LOWER(LOWER_P((&final_hash256)))); - return; - } else { - THROW(0x6A80); - } -} - -int stark_sign(uint8_t *signature, /* out */ - uint8_t *privateKeyData, - FieldElement token1, - FieldElement token2, - FieldElement msg, - FieldElement condition) { - unsigned int info = 0; - FieldElement hash; - cx_ecfp_private_key_t privateKey; - PRINTF("Stark sign msg w1 %.*H\n", 32, token1); - PRINTF("Stark sign msg w2 %.*H\n", 32, token2); - PRINTF("Stark sign w3 %.*H\n", 32, msg); - if (condition != NULL) { - PRINTF("Stark sign w4 %.*H\n", 32, condition); - } - pedersen(hash, token1, token2); - PRINTF("Pedersen hash 1 %.*H\n", 32, hash); - if (condition != NULL) { - pedersen(hash, hash, condition); - PRINTF("Pedersen hash condition %.*H\n", 32, hash); - } - pedersen(hash, hash, msg); - PRINTF("Pedersen hash 2 %.*H\n", 32, hash); - shift_stark_hash(hash); - cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey); - io_seproxyhal_io_heartbeat(); - int signatureLength = cx_ecdsa_sign(&privateKey, - CX_RND_RFC6979 | CX_LAST, - CX_SHA256, - hash, - sizeof(hash), - signature, - SIGNATURE_MAX_LEN, - &info); - PRINTF("Stark signature %.*H\n", signatureLength, signature); - return signatureLength; -} - -// ERC20Token(address) -static const uint8_t ERC20_SELECTOR[] = {0xf4, 0x72, 0x61, 0xb0}; -// ETH() -static const uint8_t ETH_SELECTOR[] = {0x83, 0x22, 0xff, 0xf2}; -// ERC721Token(address, uint256) -static const uint8_t ERC721_SELECTOR[] = {0x02, 0x57, 0x17, 0x92}; -// MintableERC20Token(address) -static const uint8_t MINTABLE_ERC20_SELECTOR[] = {0x68, 0x64, 0x6e, 0x2d}; -// MintableERC721Token(address,uint256) -static const uint8_t MINTABLE_ERC721_SELECTOR[] = {0xb8, 0xb8, 0x66, 0x72}; -static const char NFT_ASSET_ID_PREFIX[] = {'N', 'F', 'T', ':', 0}; -static const char MINTABLE_ASSET_ID_PREFIX[] = {'M', 'I', 'N', 'T', 'A', 'B', 'L', 'E', ':', 0}; - -void compute_token_id(cx_sha3_t *sha3, - uint8_t *contractAddress, - uint8_t quantumType, - uint8_t *quantum, - uint8_t *mintingBlob, - bool assetTypeOnly, - uint8_t *output) { - uint8_t tmp[36]; - cx_keccak_init(sha3, 256); - if ((contractAddress != NULL) && (!allzeroes(contractAddress, 20))) { - const uint8_t *selector = NULL; - switch (quantumType) { - case STARK_QUANTUM_ERC20: - case STARK_QUANTUM_LEGACY: - selector = ERC20_SELECTOR; - break; - case STARK_QUANTUM_ERC721: - selector = ERC721_SELECTOR; - break; - case STARK_QUANTUM_MINTABLE_ERC20: - selector = MINTABLE_ERC20_SELECTOR; - break; - case STARK_QUANTUM_MINTABLE_ERC721: - selector = MINTABLE_ERC721_SELECTOR; - break; - default: - PRINTF("Unsupported quantum type %d\n", quantumType); - return; - } - PRINTF("compute_token_id for %.*H\n", 20, contractAddress); - memset(tmp, 0, sizeof(tmp)); - memmove(tmp, selector, 4); - memmove(tmp + 16, contractAddress, 20); - cx_hash((cx_hash_t *) sha3, 0, tmp, sizeof(tmp), NULL, 0); - } else { - PRINTF("compute_token_id for ETH\n"); - cx_hash((cx_hash_t *) sha3, 0, ETH_SELECTOR, sizeof(ETH_SELECTOR), NULL, 0); - } - if ((quantumType == STARK_QUANTUM_ERC721) || (quantumType == STARK_QUANTUM_MINTABLE_ERC721)) { - memset(tmp, 0, 32); - tmp[31] = 1; - PRINTF("compute_token_id quantum %.*H\n", 32, tmp); - cx_hash((cx_hash_t *) sha3, CX_LAST, tmp, 32, output, 32); - } else { - PRINTF("compute_token_id quantum %.*H\n", 32, quantum); - cx_hash((cx_hash_t *) sha3, CX_LAST, quantum, 32, output, 32); - } - if (!assetTypeOnly && - ((quantumType != STARK_QUANTUM_LEGACY) && (quantumType != STARK_QUANTUM_ETH) && - (quantumType != STARK_QUANTUM_ERC20))) { - const char *prefix = NULL; - output[0] &= 0x03; - cx_keccak_init(sha3, 256); - switch (quantumType) { - case STARK_QUANTUM_ERC721: - prefix = NFT_ASSET_ID_PREFIX; - break; - case STARK_QUANTUM_MINTABLE_ERC20: - case STARK_QUANTUM_MINTABLE_ERC721: - prefix = MINTABLE_ASSET_ID_PREFIX; - break; - default: - PRINTF("Unsupported non default quantum type %d\n", quantumType); - return; - } - cx_hash((cx_hash_t *) sha3, 0, (const uint8_t *) prefix, strlen(prefix), NULL, 0); - cx_hash((cx_hash_t *) sha3, 0, output, 32, NULL, 0); - cx_hash((cx_hash_t *) sha3, CX_LAST, mintingBlob, 32, output, 32); - } - if (!assetTypeOnly && ((quantumType == STARK_QUANTUM_MINTABLE_ERC20) || - (quantumType == STARK_QUANTUM_MINTABLE_ERC721))) { - output[0] = 0x04; - output[1] = 0x00; - } else { - output[0] &= 0x03; - } - PRINTF("compute_token_id computed token %.*H\n", 32, output); -} - -#endif // HAVE_STARK diff --git a/src/stark_utils.h b/src/stark_utils.h deleted file mode 100644 index 9ba69a2..0000000 --- a/src/stark_utils.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _STARK_UTILS_H_ -#define _STARK_UTILS_H_ - -#include -#include -#include - -#include "os.h" -#include "cx.h" -#include "stark_crypto.h" - -void compute_token_id(cx_sha3_t *sha3, - uint8_t *contractAddress, - uint8_t quantumType, - uint8_t *quantum, - uint8_t *mintingBlob, - bool assetTypeOnly, - uint8_t *output); - -void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_t *privateKeyData); - -void stark_get_amount_string(uint8_t *contractAddress, - uint8_t *quantum256, - uint8_t *amount64, - char *tmp100, - char *target100); - -int stark_sign(uint8_t *signature, /* out */ - uint8_t *privateKeyData, - FieldElement token1, - FieldElement token2, - FieldElement msg, - FieldElement condition); - -#endif // _STARK_UTILS_H_ diff --git a/src/ui_callbacks.h b/src/ui_callbacks.h index 041f717..3063400 100644 --- a/src/ui_callbacks.h +++ b/src/ui_callbacks.h @@ -21,9 +21,6 @@ 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_warning_contract_data(void); diff --git a/src_bagl/common_ui.c b/src_bagl/common_ui.c index 19ff47e..dc64504 100644 --- a/src_bagl/common_ui.c +++ b/src_bagl/common_ui.c @@ -37,32 +37,6 @@ void ui_sign_712_v0(void) { ux_flow_init(0, ux_sign_712_v0_flow, NULL); } -#ifdef HAVE_STARKWARE -void ui_display_stark_public(void) { - ux_flow_init(0, ux_display_stark_public_flow, NULL); -} -void ui_stark_limit_order(void) { - ux_flow_init(0, ux_stark_limit_order_flow, NULL); -} - -void ui_stark_unsafe_sign(void) { - ux_flow_init(0, ux_stark_unsafe_sign_flow, NULL); -} - -void ui_stark_transfer(bool selfTransfer, bool conditional) { - if (selfTransfer) { - ux_flow_init( - 0, - (conditional ? ux_stark_self_transfer_conditional_flow : ux_stark_self_transfer_flow), - NULL); - } else { - ux_flow_init(0, - (conditional ? ux_stark_transfer_conditional_flow : ux_stark_transfer_flow), - NULL); - } -} -#endif // HAVE_STARKWARE - void ui_confirm_selector(void) { ux_flow_init(0, ux_confirm_selector_flow, NULL); } diff --git a/src_bagl/ui_flow.h b/src_bagl/ui_flow.h index 184036b..ae2590d 100644 --- a/src_bagl/ui_flow.h +++ b/src_bagl/ui_flow.h @@ -30,34 +30,4 @@ extern const ux_flow_step_t* const ux_display_privacy_shared_secret_flow[]; extern const ux_flow_step_t* ux_approval_tx_flow[15]; -#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_ diff --git a/src_bagl/ui_flow_stark_getPublicKey.c b/src_bagl/ui_flow_stark_getPublicKey.c deleted file mode 100644 index 958874f..0000000 --- a/src_bagl/ui_flow_stark_getPublicKey.c +++ /dev/null @@ -1,46 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "ui_callbacks.h" - -// clang-format off -UX_STEP_NOCB( - ux_display_stark_public_flow_1_step, - pnn, - { - &C_icon_eye, - "Verify", - "Stark key", - }); -UX_STEP_NOCB( - ux_display_stark_public_flow_2_step, - bnnn_paging, - { - .title = "Stark Key", - .text = strings.tmp.tmp, - }); -UX_STEP_CB( - ux_display_stark_public_flow_3_step, - pb, - io_seproxyhal_touch_stark_pubkey_ok(NULL), - { - &C_icon_validate_14, - "Approve", - }); -UX_STEP_CB( - ux_display_stark_public_flow_4_step, - pb, - io_seproxyhal_touch_address_cancel(NULL), - { - &C_icon_crossmark, - "Reject", - }); -// clang-format on - -UX_FLOW(ux_display_stark_public_flow, - &ux_display_stark_public_flow_1_step, - &ux_display_stark_public_flow_2_step, - &ux_display_stark_public_flow_3_step, - &ux_display_stark_public_flow_4_step); - -#endif diff --git a/src_bagl/ui_flow_stark_sign.c b/src_bagl/ui_flow_stark_sign.c deleted file mode 100644 index 18905e6..0000000 --- a/src_bagl/ui_flow_stark_sign.c +++ /dev/null @@ -1,234 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "ui_callbacks.h" -#include "starkDisplayUtils.h" -#include "apdu_constants.h" - -// clang-format off -UX_STEP_NOCB(ux_stark_limit_order_1_step, - pnn, - { - &C_icon_eye, - "Review", - "transaction", - }); - -UX_STEP_NOCB(ux_stark_limit_order_2_step, - bnnn_paging, - { - .title = "Limit", - .text = "Order" - }); - -UX_STEP_NOCB(ux_stark_limit_order_3_step, - bnnn_paging, - { - .title = "Trading", - .text = "Pair" - }); - -UX_STEP_NOCB(ux_stark_limit_order_4_step, - bnnn_paging, - { - .title = "Sell", - .text = strings.common.fullAmount - }); - -UX_STEP_NOCB(ux_stark_limit_order_5_step, - bnnn_paging, - { - .title = "Buy", - .text = strings.common.maxFee - }); - -UX_STEP_NOCB(ux_stark_limit_order_6_step, - bnnn_paging, - { - .title = "Token Account", - .text = strings.common.fullAddress - }); - -UX_STEP_CB( - ux_stark_limit_order_7_step, - pbb, - io_seproxyhal_touch_stark_ok(NULL), - { - &C_icon_validate_14, - "Accept", - "and send", - }); -UX_STEP_CB( - ux_stark_limit_order_8_step, - pb, - io_seproxyhal_touch_tx_cancel(NULL), - { - &C_icon_crossmark, - "Reject", - }); -// clang-format on - -UX_FLOW(ux_stark_limit_order_flow, - &ux_stark_limit_order_1_step, - &ux_stark_limit_order_2_step, - &ux_stark_limit_order_3_step, - &ux_stark_limit_order_4_step, - &ux_stark_limit_order_5_step, - &ux_stark_limit_order_6_step, - &ux_stark_limit_order_7_step, - &ux_stark_limit_order_8_step); - -static void stark_format_address(void) { - if (!getEthDisplayableAddress(dataContext.starkContext.conditionAddress, - strings.tmp.tmp, - sizeof(strings.tmp.tmp), - &global_sha3, - chainConfig->chainId)) { - THROW(APDU_RESPONSE_ERROR_NO_INFO); - } -} - -////////////////////////////////////////////////////////////////////// -// clang-format off -UX_STEP_NOCB(ux_stark_transfer_1_step, - pnn, - { - &C_icon_eye, - "Review", - "transaction", - }); - -UX_STEP_NOCB(ux_stark_transfer_2_step, - bnnn_paging, - { - .title = "Transfer", - .text = " " - }); - -UX_STEP_NOCB(ux_stark_self_transfer_2_step, - bnnn_paging, - { - .title = "Self", - .text = "Transfer" - }); - -UX_STEP_NOCB(ux_stark_conditional_transfer_2_step, - bnnn_paging, - { - .title = "Conditional", - .text = "Transfer" - }); - -UX_STEP_NOCB(ux_stark_self_conditional_transfer_2_step, - bnnn_paging, - { - .title = "Conditional", - .text = "Self Transfer" - }); - -UX_STEP_NOCB(ux_stark_transfer_3_step, - bnnn_paging, - { - .title = "Amount", - .text = tmpContent.tmp - }); - -UX_STEP_NOCB(ux_stark_transfer_4_step, - bnnn_paging, - { - .title = "Master Account", - .text = strings.tmp.tmp - }); - -UX_STEP_NOCB(ux_stark_transfer_5_step, - bnnn_paging, - { - .title = "Token Account", - .text = strings.tmp.tmp2 - }); - -UX_STEP_CB( - ux_stark_transfer_6_step, - pbb, - io_seproxyhal_touch_stark_ok(NULL), - { - &C_icon_validate_14, - "Accept", - "and send", - }); -UX_STEP_CB( - ux_stark_transfer_7_step, - pb, - io_seproxyhal_touch_tx_cancel(NULL), - { - &C_icon_crossmark, - "Reject", - }); - -UX_STEP_NOCB_INIT( - ux_stark_conditional_transfer_4_step, - bnnn_paging, - stark_sign_display_master_account(), - { - .title = "Master Account", - .text = strings.tmp.tmp - }); - -UX_STEP_NOCB_INIT( - ux_stark_conditional_transfer_8_step, - bnnn_paging, - stark_format_address(), - { - .title = "Cond. Address", - .text = strings.tmp.tmp - }); - -UX_STEP_NOCB_INIT( - ux_stark_conditional_transfer_9_step, - bnnn_paging, - stark_sign_display_condition_fact(), - { - .title = "Cond. Fact", - .text = strings.tmp.tmp - }); -// clang-format on - -UX_FLOW(ux_stark_transfer_flow, - &ux_stark_transfer_1_step, - &ux_stark_transfer_2_step, - &ux_stark_transfer_3_step, - &ux_stark_transfer_4_step, - &ux_stark_transfer_5_step, - &ux_stark_transfer_6_step, - &ux_stark_transfer_7_step); - -UX_FLOW(ux_stark_self_transfer_flow, - &ux_stark_transfer_1_step, - &ux_stark_self_transfer_2_step, - &ux_stark_transfer_3_step, - &ux_stark_transfer_5_step, - &ux_stark_transfer_6_step, - &ux_stark_transfer_7_step); - -UX_FLOW(ux_stark_transfer_conditional_flow, - &ux_stark_transfer_1_step, - &ux_stark_conditional_transfer_2_step, - &ux_stark_transfer_3_step, - &ux_stark_conditional_transfer_4_step, - &ux_stark_transfer_5_step, - &ux_stark_conditional_transfer_8_step, - &ux_stark_conditional_transfer_9_step, - &ux_stark_transfer_6_step, - &ux_stark_transfer_7_step); - -UX_FLOW(ux_stark_self_transfer_conditional_flow, - &ux_stark_transfer_1_step, - &ux_stark_self_conditional_transfer_2_step, - &ux_stark_transfer_3_step, - &ux_stark_transfer_5_step, - &ux_stark_conditional_transfer_8_step, - &ux_stark_conditional_transfer_9_step, - &ux_stark_transfer_6_step, - &ux_stark_transfer_7_step); - -#endif diff --git a/src_bagl/ui_flow_stark_unsafe_sign.c b/src_bagl/ui_flow_stark_unsafe_sign.c deleted file mode 100644 index 1c08058..0000000 --- a/src_bagl/ui_flow_stark_unsafe_sign.c +++ /dev/null @@ -1,70 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "ui_callbacks.h" - -unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e); - -void stark_unsafe_sign_display_account() { - snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.w1); -} - -void stark_unsafe_sign_display_hash() { - snprintf(strings.tmp.tmp, sizeof(strings.tmp.tmp), "0x%.*H", 32, dataContext.starkContext.w2); -} - -// clang-format off -UX_STEP_NOCB(ux_stark_unsafe_sign_1_step, - pnn, - { - &C_icon_warning, - "StarkNet", - "Blind Sign", - }); - -UX_STEP_NOCB_INIT( - ux_stark_unsafe_sign_2_step, - bnnn_paging, - stark_unsafe_sign_display_account(), - { - .title = "From Account", - .text = strings.tmp.tmp - }); - -UX_STEP_NOCB_INIT( - ux_stark_unsafe_sign_3_step, - bnnn_paging, - stark_unsafe_sign_display_hash(), - { - .title = "Tx Hash", - .text = strings.tmp.tmp - }); - - -UX_STEP_CB( - ux_stark_unsafe_sign_4_step, - pbb, - io_seproxyhal_touch_stark_unsafe_sign_ok(NULL), - { - &C_icon_validate_14, - "Accept", - "and send", - }); -UX_STEP_CB( - ux_stark_unsafe_sign_5_step, - pb, - io_seproxyhal_touch_tx_cancel(NULL), - { - &C_icon_crossmark, - "Reject", - }); -// clang-format on - -UX_FLOW(ux_stark_unsafe_sign_flow, - &ux_stark_unsafe_sign_1_step, - &ux_stark_unsafe_sign_2_step, - &ux_stark_unsafe_sign_3_step, - &ux_stark_unsafe_sign_4_step, - &ux_stark_unsafe_sign_5_step); - -#endif diff --git a/src_features/getAppConfiguration/cmd_getAppConfiguration.c b/src_features/getAppConfiguration/cmd_getAppConfiguration.c index fe0130e..c882b11 100644 --- a/src_features/getAppConfiguration/cmd_getAppConfiguration.c +++ b/src_features/getAppConfiguration/cmd_getAppConfiguration.c @@ -14,10 +14,6 @@ void handleGetAppConfiguration(uint8_t p1, UNUSED(flags); G_io_apdu_buffer[0] = (N_storage.dataAllowed ? APP_FLAG_DATA_ALLOWED : 0x00); G_io_apdu_buffer[0] |= APP_FLAG_EXTERNAL_TOKEN_NEEDED; -#ifdef HAVE_STARKWARE - G_io_apdu_buffer[0] |= APP_FLAG_STARKWARE; - G_io_apdu_buffer[0] |= APP_FLAG_STARKWARE_V2; -#endif G_io_apdu_buffer[1] = LEDGER_MAJOR_VERSION; G_io_apdu_buffer[2] = LEDGER_MINOR_VERSION; G_io_apdu_buffer[3] = LEDGER_PATCH_VERSION; diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index b40bfb9..b1ca065 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -2,9 +2,6 @@ #include "shared_context.h" #include "common_utils.h" #include "feature_signTx.h" -#ifdef HAVE_STARKWARE -#include "stark_utils.h" -#endif #include "uint256.h" #include "eth_plugin_handler.h" #include "network.h" diff --git a/src_features/stark_getPublicKey/cmd_stark_getPublicKey.c b/src_features/stark_getPublicKey/cmd_stark_getPublicKey.c deleted file mode 100644 index 7603188..0000000 --- a/src_features/stark_getPublicKey/cmd_stark_getPublicKey.c +++ /dev/null @@ -1,66 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "apdu_constants.h" -#include "stark_utils.h" -#include "feature_stark_getPublicKey.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" - -void handleStarkwareGetPublicKey(uint8_t p1, - uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - unsigned int *tx) { - bip32_path_t bip32; - cx_ecfp_private_key_t privateKey; - uint8_t privateKeyData[32]; - - reset_app_context(); - - if ((p1 != P1_CONFIRM) && (p1 != P1_NON_CONFIRM)) { - THROW(0x6B00); - } - - if (p2 != 0) { - THROW(0x6B00); - } - - dataBuffer = parseBip32(dataBuffer, &dataLength, &bip32); - - if (dataBuffer == NULL) { - THROW(0x6a80); - } - - io_seproxyhal_io_heartbeat(); - starkDerivePrivateKey(bip32.path, bip32.length, privateKeyData); - cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey); - io_seproxyhal_io_heartbeat(); - cx_ecfp_generate_pair(CX_CURVE_Stark256, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1); - explicit_bzero(&privateKey, sizeof(privateKey)); - explicit_bzero(privateKeyData, sizeof(privateKeyData)); - io_seproxyhal_io_heartbeat(); -#ifndef NO_CONSENT - if (p1 == P1_NON_CONFIRM) -#endif // NO_CONSENT - { - *tx = set_result_get_stark_publicKey(); - THROW(0x9000); - } -#ifndef NO_CONSENT - else { - // prepare for a UI based reply - snprintf(strings.tmp.tmp, - sizeof(strings.tmp.tmp), - "0x%.*H", - 32, - tmpCtx.publicKeyContext.publicKey.W + 1); - ui_display_stark_public(); - - *flags |= IO_ASYNCH_REPLY; - } -#endif // NO_CONSENT -} - -#endif diff --git a/src_features/stark_getPublicKey/feature_stark_getPublicKey.h b/src_features/stark_getPublicKey/feature_stark_getPublicKey.h deleted file mode 100644 index 4859722..0000000 --- a/src_features/stark_getPublicKey/feature_stark_getPublicKey.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _STARK_GET_PUB_KEY_H_ -#define _STARK_GET_PUB_KEY_H_ - -#include "shared_context.h" - -uint32_t set_result_get_stark_publicKey(void); - -#endif // _STARK_GET_PUB_KEY_H_ diff --git a/src_features/stark_getPublicKey/logic_stark_getPublicKey.c b/src_features/stark_getPublicKey/logic_stark_getPublicKey.c deleted file mode 100644 index 9338cc4..0000000 --- a/src_features/stark_getPublicKey/logic_stark_getPublicKey.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include -#include "shared_context.h" -#include "feature_stark_getPublicKey.h" - -uint32_t set_result_get_stark_publicKey() { - uint32_t tx = 0; - memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65); - tx += 65; - return tx; -} - -#endif // HAVE_STARKWARE diff --git a/src_features/stark_getPublicKey/ui_common_stark_getPublicKey.c b/src_features/stark_getPublicKey/ui_common_stark_getPublicKey.c deleted file mode 100644 index 31b9714..0000000 --- a/src_features/stark_getPublicKey/ui_common_stark_getPublicKey.c +++ /dev/null @@ -1,19 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "common_ui.h" -#include "feature_stark_getPublicKey.h" - -unsigned int io_seproxyhal_touch_stark_pubkey_ok(__attribute__((unused)) const bagl_element_t *e) { - uint32_t tx = set_result_get_stark_publicKey(); - G_io_apdu_buffer[tx++] = 0x90; - G_io_apdu_buffer[tx++] = 0x00; - reset_app_context(); - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); - // Display back the original UX - ui_idle(); - return 0; // do not redraw the widget -} - -#endif diff --git a/src_features/stark_provideQuantum/cmd_stark_provideQuantum.c b/src_features/stark_provideQuantum/cmd_stark_provideQuantum.c deleted file mode 100644 index 614669d..0000000 --- a/src_features/stark_provideQuantum/cmd_stark_provideQuantum.c +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "apdu_constants.h" -#include "common_ui.h" - -void handleStarkwareProvideQuantum(uint8_t p1, - __attribute__((unused)) uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - __attribute__((unused)) unsigned int *flags, - __attribute__((unused)) unsigned int *tx) { - size_t i = 0; - uint8_t expectedDataSize = 20 + 32; - uint8_t addressZero = 0; - tokenDefinition_t *currentToken = NULL; - if (appState != APP_STATE_IDLE) { - reset_app_context(); - } - switch (p1) { - case STARK_QUANTUM_LEGACY: - break; - case STARK_QUANTUM_ETH: - case STARK_QUANTUM_ERC20: - case STARK_QUANTUM_ERC721: - case STARK_QUANTUM_MINTABLE_ERC20: - case STARK_QUANTUM_MINTABLE_ERC721: - expectedDataSize += 32; - break; - default: - THROW(0x6B00); - } - if (dataLength != expectedDataSize) { - THROW(0x6700); - } - if (p1 == STARK_QUANTUM_LEGACY) { - addressZero = allzeroes((void *) dataBuffer, 20); - } - if ((p1 != STARK_QUANTUM_ETH) && !addressZero) { - for (i = 0; i < MAX_ITEMS; i++) { - currentToken = &tmpCtx.transactionContext.extraInfo[i].token; - if (tmpCtx.transactionContext.tokenSet[i] && - (memcmp(currentToken->address, dataBuffer, 20) == 0)) { - break; - } - } - if (i == MAX_ITEMS) { - PRINTF("Associated token not found\n"); - THROW(0x6A80); - } - } else { - i = MAX_ITEMS; - } - memmove(dataContext.tokenContext.quantum, dataBuffer + 20, 32); - if (p1 != STARK_QUANTUM_LEGACY) { - memmove(dataContext.tokenContext.mintingBlob, dataBuffer + 20 + 32, 32); - } - dataContext.tokenContext.quantumIndex = i; - dataContext.tokenContext.quantumType = p1; - quantumSet = true; - THROW(0x9000); -} - -#endif diff --git a/src_features/stark_sign/cmd_stark_sign.c b/src_features/stark_sign/cmd_stark_sign.c deleted file mode 100644 index 7810f77..0000000 --- a/src_features/stark_sign/cmd_stark_sign.c +++ /dev/null @@ -1,259 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "apdu_constants.h" -#include "stark_utils.h" -#include "poorstream.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" - -#define U8BE(buf, off) \ - (uint64_t)((((uint64_t) U4BE(buf, off)) << 32) | (((uint64_t) U4BE(buf, off + 4)) & 0xFFFFFFFF)) -#define TMP_OFFSET 140 - -void handleStarkwareSignMessage(uint8_t p1, - uint8_t p2, - uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - __attribute__((unused)) unsigned int *tx) { - uint8_t privateKeyData[INT256_LENGTH]; - uint32_t i; - uint8_t bip32PathLength; - uint8_t offset = 1; - cx_ecfp_private_key_t privateKey; - poorstream_t bitstream; - bool selfTransfer = false; - uint8_t order = 1; - uint8_t protocol = 2; - uint8_t preOffset, postOffset; - uint8_t zeroTest; - - // Initial checks - if (appState != APP_STATE_IDLE) { - reset_app_context(); - } - - if (dataLength < 1) { - PRINTF("Invalid data\n"); - THROW(0x6a80); - } - - bip32PathLength = *(dataBuffer); - - if ((bip32PathLength < 0x01) || (bip32PathLength > MAX_BIP32_PATH)) { - PRINTF("Invalid path\n"); - THROW(0x6a80); - } - switch (p1) { - case P1_STARK_ORDER: - protocol = 1; - break; - case P1_STARK_TRANSFER: - protocol = 1; - order = 0; - break; - case P1_STARK_ORDER_V2: - break; - case P1_STARK_TRANSFER_V2: - case P1_STARK_CONDITIONAL_TRANSFER: - order = 0; - break; - default: - THROW(0x6B00); - } - postOffset = (protocol == 2 ? 1 + 32 : 0); - preOffset = (protocol == 2 ? 1 : 0); - if (order) { - if (dataLength != (20 + 32 + 20 + 32 + 4 + 4 + 8 + 8 + 4 + 4 + 1 + 4 * bip32PathLength + - 2 * postOffset)) { - THROW(0x6700); - } - } else { - if (dataLength != (20 + 32 + 32 + 4 + 4 + 8 + 4 + 4 + 1 + 4 * bip32PathLength + postOffset + - (p1 == P1_STARK_CONDITIONAL_TRANSFER ? 32 + 20 : 0))) { - THROW(0x6700); - } - } - if (p2 != 0) { - THROW(0x6B00); - } - tmpCtx.transactionContext.bip32.length = bip32PathLength; - for (i = 0; i < bip32PathLength; i++) { - tmpCtx.transactionContext.bip32.path[i] = U4BE(dataBuffer, offset); - PRINTF("Storing path %d %d\n", i, tmpCtx.transactionContext.bip32.path[i]); - offset += 4; - } - // Discard the path to use part of dataBuffer as a temporary buffer - memmove(dataBuffer, dataBuffer + offset, dataLength - offset); - dataContext.starkContext.conditional = (p1 == P1_STARK_CONDITIONAL_TRANSFER); - if (dataContext.starkContext.conditional) { - memmove(dataContext.starkContext.fact, - dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4 + 8 + 4 + 4, - 32); - memmove(dataContext.starkContext.conditionAddress, - dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4 + 8 + 4 + 4 + 32, - 20); - PRINTF("Fact %.*H\n", 32, dataContext.starkContext.fact); - PRINTF("Address %.*H\n", 20, dataContext.starkContext.conditionAddress); - } - - zeroTest = allzeroes(dataBuffer + preOffset, 20); - if (zeroTest && (protocol == 2) && (dataBuffer[0] != STARK_QUANTUM_ETH)) { - PRINTF("stark - unexpected quantum descriptor type for null first address %d\n", - dataBuffer[0]); - THROW(0x6A80); - } - if (!zeroTest && getKnownToken(dataBuffer + preOffset) == NULL) { - PRINTF("stark - cannot process unknown token %.*H", 20, dataBuffer + preOffset); - THROW(0x6A80); - } - if (order) { - zeroTest = allzeroes(dataBuffer + 20 + 32 + postOffset + preOffset, 20); - if (zeroTest && (protocol == 2) && (dataBuffer[1 + 20 + 32 + 32] != STARK_QUANTUM_ETH)) { - PRINTF("stark - unexpected quantum descriptor type for null second address %d\n", - dataBuffer[1 + 20 + 32 + 32]); - THROW(0x6A80); - } - if (!zeroTest && getKnownToken(dataBuffer + 20 + 32 + postOffset + preOffset) == NULL) { - PRINTF("stark - cannot process unknown token %.*H", - 20, - dataBuffer + 20 + 32 + postOffset + preOffset); - THROW(0x6A80); - } - } - // Prepare the Stark parameters - io_seproxyhal_io_heartbeat(); - compute_token_id(&global_sha3, - dataBuffer + preOffset, - (protocol == 2 ? dataBuffer[0] : STARK_QUANTUM_LEGACY), - dataBuffer + preOffset + 20, - (protocol == 2 ? dataBuffer + 1 + 20 + 32 : NULL), - false, - dataContext.starkContext.w1); - if (order) { - io_seproxyhal_io_heartbeat(); - compute_token_id(&global_sha3, - dataBuffer + 20 + 32 + postOffset + preOffset, - (protocol == 2 ? dataBuffer[1 + 20 + 32 + 32] : STARK_QUANTUM_LEGACY), - dataBuffer + 20 + 32 + postOffset + preOffset + 20, - (protocol == 2 ? dataBuffer + 1 + 20 + 32 + 32 + 1 + 20 + 32 : NULL), - false, - dataContext.starkContext.w2); - offset = 20 + 32 + postOffset + 20 + 32 + postOffset; - } else { - memmove(dataContext.starkContext.w2, dataBuffer + 20 + 32 + postOffset, 32); - offset = 20 + 32 + postOffset + 32; - } - - poorstream_init(&bitstream, dataContext.starkContext.w3); - poorstream_write_bits(&bitstream, 0, 11); // padding - poorstream_write_bits(&bitstream, - (p1 == P1_STARK_CONDITIONAL_TRANSFER ? STARK_CONDITIONAL_TRANSFER_TYPE - : order ? STARK_ORDER_TYPE - : STARK_TRANSFER_TYPE), - 4); - poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset), 31); - poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset + 4), 31); - poorstream_write_bits(&bitstream, U8BE(dataBuffer, offset + 4 + 4), 63); - if (order) { - poorstream_write_bits(&bitstream, U8BE(dataBuffer, offset + 4 + 4 + 8), 63); - offset += 4 + 4 + 8 + 8; - } else { - poorstream_write_bits(&bitstream, 0, 63); - offset += 4 + 4 + 8; - } - poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset), 31); - poorstream_write_bits(&bitstream, U4BE(dataBuffer, offset + 4), 22); - - PRINTF("stark w1 %.*H\n", 32, dataContext.starkContext.w1); - PRINTF("stark w2 %.*H\n", 32, dataContext.starkContext.w2); - PRINTF("stark w3 %.*H\n", 32, dataContext.starkContext.w3); - - if (dataContext.starkContext.conditional) { - cx_keccak_init(&global_sha3, 256); - cx_hash((cx_hash_t *) &global_sha3, - 0, - dataContext.starkContext.conditionAddress, - 20, - NULL, - 0); - cx_hash((cx_hash_t *) &global_sha3, - CX_LAST, - dataContext.starkContext.fact, - 32, - dataContext.starkContext.w4, - 32); - dataContext.starkContext.w4[0] &= 0x03; - PRINTF("stark w4 %.*H\n", 32, dataContext.starkContext.w4); - } - // Prepare the UI - if (order) { - io_seproxyhal_io_heartbeat(); - // amount to sell - stark_get_amount_string(dataBuffer + preOffset, - dataBuffer + preOffset + 20, - dataBuffer + 20 + 32 + postOffset + 20 + 32 + postOffset + 4 + 4, - (char *) (dataBuffer + TMP_OFFSET), - strings.common.fullAmount); - io_seproxyhal_io_heartbeat(); - // amount to buy - stark_get_amount_string( - dataBuffer + 20 + 32 + postOffset + preOffset, - dataBuffer + 20 + 32 + postOffset + preOffset + 20, - dataBuffer + 20 + 32 + postOffset + 20 + 32 + postOffset + 4 + 4 + 8, - (char *) (dataBuffer + TMP_OFFSET), - strings.common.maxFee); - // src vault ID - snprintf(strings.common.fullAddress, - sizeof(strings.common.fullAddress), - "%d", - U4BE(dataBuffer, 20 + 32 + postOffset + 20 + 32 + postOffset)); - } else { - cx_ecfp_public_key_t publicKey; - // Check if the transfer is a self transfer - io_seproxyhal_io_heartbeat(); - starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path, - bip32PathLength, - privateKeyData); - cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey); - io_seproxyhal_io_heartbeat(); - cx_ecfp_generate_pair(CX_CURVE_Stark256, &publicKey, &privateKey, 1); - explicit_bzero(&privateKey, sizeof(privateKey)); - explicit_bzero(privateKeyData, sizeof(privateKeyData)); - io_seproxyhal_io_heartbeat(); - selfTransfer = (memcmp(publicKey.W + 1, dataBuffer + 20 + 32 + postOffset, 32) == 0); - PRINTF("self transfer %d\n", selfTransfer); - io_seproxyhal_io_heartbeat(); - // amount to transfer - stark_get_amount_string(dataBuffer + preOffset, - dataBuffer + preOffset + 20, - dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4, - (char *) (dataBuffer + TMP_OFFSET), - tmpContent.tmp); - // dest vault ID - snprintf(strings.tmp.tmp2, - sizeof(strings.tmp.tmp2), - "%d", - U4BE(dataBuffer, 20 + 32 + postOffset + 32 + 4)); - if (!selfTransfer) { - memmove(dataContext.starkContext.transferDestination, - dataBuffer + 20 + 32 + postOffset, - 32); - snprintf(strings.tmp.tmp, - sizeof(strings.tmp.tmp), - "0x%.*H", - 32, - dataBuffer + 20 + 32 + postOffset); - } - } - if (order) { - ui_stark_limit_order(); - } else { - ui_stark_transfer(selfTransfer, dataContext.starkContext.conditional); - } - - *flags |= IO_ASYNCH_REPLY; -} - -#endif diff --git a/src_features/stark_sign/ui_common_stark_sign.c b/src_features/stark_sign/ui_common_stark_sign.c deleted file mode 100644 index a45f7f9..0000000 --- a/src_features/stark_sign/ui_common_stark_sign.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "os_io_seproxyhal.h" -#include "shared_context.h" -#include "stark_utils.h" -#include "common_ui.h" - -unsigned int io_seproxyhal_touch_stark_ok(__attribute__((unused)) const bagl_element_t *e) { - uint8_t privateKeyData[32]; - uint8_t signature[72]; - uint32_t tx = 0; - io_seproxyhal_io_heartbeat(); - starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path, - tmpCtx.transactionContext.bip32.length, - privateKeyData); - io_seproxyhal_io_heartbeat(); - stark_sign(signature, - privateKeyData, - dataContext.starkContext.w1, - dataContext.starkContext.w2, - dataContext.starkContext.w3, - (dataContext.starkContext.conditional ? dataContext.starkContext.w4 : NULL)); - G_io_apdu_buffer[0] = 0; - format_signature_out(signature); - tx = 65; - G_io_apdu_buffer[tx++] = 0x90; - G_io_apdu_buffer[tx++] = 0x00; - reset_app_context(); - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); - // Display back the original UX - ui_idle(); - return 0; // do not redraw the widget -} - -#endif // HAVE_STARKWARE diff --git a/src_features/stark_unsafe_sign/cmd_stark_unsafe_sign.c b/src_features/stark_unsafe_sign/cmd_stark_unsafe_sign.c deleted file mode 100644 index 314fb22..0000000 --- a/src_features/stark_unsafe_sign/cmd_stark_unsafe_sign.c +++ /dev/null @@ -1,55 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "shared_context.h" -#include "apdu_constants.h" -#include "stark_utils.h" -#include "common_ui.h" -#include "os_io_seproxyhal.h" - -void handleStarkwareUnsafeSign(uint8_t p1, - uint8_t p2, - const uint8_t *dataBuffer, - uint8_t dataLength, - unsigned int *flags, - __attribute__((unused)) unsigned int *tx) { - uint8_t privateKeyData[INT256_LENGTH]; - cx_ecfp_public_key_t publicKey; - cx_ecfp_private_key_t privateKey; - - // Initial checks - if (appState != APP_STATE_IDLE) { - reset_app_context(); - } - - if ((p1 != 0) || (p2 != 0)) { - THROW(0x6B00); - } - - dataBuffer = parseBip32(dataBuffer, &dataLength, &tmpCtx.transactionContext.bip32); - - if (dataBuffer == NULL) { - THROW(0x6a80); - } - - if (dataLength != 32) { - THROW(0x6700); - } - - memmove(dataContext.starkContext.w2, dataBuffer, 32); - io_seproxyhal_io_heartbeat(); - starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path, - tmpCtx.transactionContext.bip32.length, - privateKeyData); - cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey); - io_seproxyhal_io_heartbeat(); - cx_ecfp_generate_pair(CX_CURVE_Stark256, &publicKey, &privateKey, 1); - explicit_bzero(&privateKey, sizeof(privateKey)); - explicit_bzero(privateKeyData, sizeof(privateKeyData)); - io_seproxyhal_io_heartbeat(); - memmove(dataContext.starkContext.w1, publicKey.W + 1, 32); - ui_stark_unsafe_sign(); - - *flags |= IO_ASYNCH_REPLY; -} - -#endif diff --git a/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c b/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c deleted file mode 100644 index 4774627..0000000 --- a/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c +++ /dev/null @@ -1,42 +0,0 @@ -#ifdef HAVE_STARKWARE - -#include "os_io_seproxyhal.h" -#include "shared_context.h" -#include "stark_utils.h" -#include "common_ui.h" - -unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(__attribute__((unused)) - const bagl_element_t *e) { - cx_ecfp_private_key_t privateKey; - uint8_t privateKeyData[INT256_LENGTH]; - uint8_t signature[72]; - unsigned int info = 0; - uint32_t tx = 0; - io_seproxyhal_io_heartbeat(); - starkDerivePrivateKey(tmpCtx.transactionContext.bip32.path, - tmpCtx.transactionContext.bip32.length, - privateKeyData); - io_seproxyhal_io_heartbeat(); - cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey); - cx_ecdsa_sign(&privateKey, - CX_RND_RFC6979 | CX_LAST, - CX_SHA256, - dataContext.starkContext.w2, - sizeof(dataContext.starkContext.w2), - signature, - sizeof(signature), - &info); - G_io_apdu_buffer[0] = 0; - format_signature_out(signature); - tx = 65; - G_io_apdu_buffer[tx++] = 0x90; - G_io_apdu_buffer[tx++] = 0x00; - reset_app_context(); - // Send back the response, do not restart the event loop - io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); - // Display back the original UX - ui_idle(); - return 0; // do not redraw the widget -} - -#endif // HAVE_STARKWARE diff --git a/src_nbgl/ui_get_stark_public_key.c b/src_nbgl/ui_get_stark_public_key.c deleted file mode 100644 index ce57787..0000000 --- a/src_nbgl/ui_get_stark_public_key.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include "shared_context.h" -#include "ui_callbacks.h" -#include "ui_nbgl.h" - -static void reviewReject(void) { - io_seproxyhal_touch_address_cancel(NULL); -} - -static void confirmTransation(void) { - io_seproxyhal_touch_stark_pubkey_ok(NULL); -} - -static void reviewChoice(bool confirm) { - if (confirm) { - // display a status page and go back to main - nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, confirmTransation); - } else { - nbgl_useCaseStatus("Address verification\ncancelled", false, reviewReject); - } -} - -static void buildScreen(void) { - nbgl_useCaseAddressConfirmation(strings.tmp.tmp, reviewChoice); -} - -void ui_display_stark_public(void) { - buildScreen(); -} \ No newline at end of file diff --git a/src_nbgl/ui_stark_limit_order.c b/src_nbgl/ui_stark_limit_order.c deleted file mode 100644 index 89cfdbf..0000000 --- a/src_nbgl/ui_stark_limit_order.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "common_ui.h" -#include "ui_signing.h" -#include "ui_nbgl.h" -#include "ui_callbacks.h" -#include "nbgl_use_case.h" -#include "network.h" - -#ifdef HAVE_STARKWARE - -static nbgl_layoutTagValue_t pairs[3]; - -static void reviewReject(void) { - io_seproxyhal_touch_tx_cancel(NULL); -} - -static void confirmTransation(void) { - io_seproxyhal_touch_stark_ok(NULL); -} - -static void reviewChoice(bool confirm) { - if (confirm) { - confirmTransation(); - } else { - reviewReject(); - } -} - -static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { - if (page == 0) { - pairs[0].item = "Sell"; - pairs[0].value = strings.common.fullAmount; - pairs[1].item = "Buy"; - pairs[1].value = strings.common.maxFee; - pairs[2].item = "Token Account"; - pairs[2].value = strings.common.fullAddress; - - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 3; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs; - } else if (page == 1) { - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false); - content->infoLongPress.text = "Review stark limit order"; - content->infoLongPress.longPressText = SIGN_BUTTON; - } else { - return false; - } - // valid page so return true - return true; -} - -static void reviewContinue(void) { - nbgl_useCaseRegularReview(0, 2, REJECT_BUTTON, NULL, displayTransactionPage, reviewChoice); -} - -static void buildFirstPage(void) { - nbgl_useCaseReviewStart(get_app_icon(false), - "Review stark limit order", - NULL, - REJECT_BUTTON, - reviewContinue, - reviewReject); -} - -void ui_stark_limit_order(void) { - buildFirstPage(); -} - -#endif diff --git a/src_nbgl/ui_stark_transfer.c b/src_nbgl/ui_stark_transfer.c deleted file mode 100644 index 40dca23..0000000 --- a/src_nbgl/ui_stark_transfer.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include "shared_context.h" -#include "ui_callbacks.h" -#include "ui_nbgl.h" -#include "ui_signing.h" -#include "starkDisplayUtils.h" -#include "network.h" - -#ifdef HAVE_STARKWARE - -static nbgl_layoutTagValue_t pairs[3]; -static char condAddressBuffer[43]; -struct stark_transfer_context { - bool selfTransfer; - bool conditional; -}; - -static struct stark_transfer_context context; - -static void reviewReject(void) { - io_seproxyhal_touch_tx_cancel(NULL); -} - -static void confirmTransation(void) { - io_seproxyhal_touch_stark_ok(NULL); -} - -static void reviewChoice(bool confirm) { - if (confirm) { - confirmTransation(); - } else { - reviewReject(); - } -} - -static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { - uint8_t count = 0; - if (page == 0) { - pairs[count].item = "Amount"; - pairs[count].value = tmpContent.tmp; - count++; - - if (context.selfTransfer == false && context.conditional == false) { - pairs[count].item = "Master Account"; - pairs[count].value = strings.tmp.tmp; - count++; - } - if (context.conditional) { - stark_sign_display_master_account(); - pairs[count].item = "Master Account"; - pairs[count].value = strings.tmp.tmp; - count++; - } - - pairs[count].item = "Token Account"; - pairs[count].value = strings.tmp.tmp2; - count++; - - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = count; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs; - - return true; - } - if (page == 1) { - if (context.conditional) { - if (!getEthDisplayableAddress(dataContext.starkContext.conditionAddress, - condAddressBuffer, - sizeof(condAddressBuffer), - &global_sha3, - chainConfig->chainId)) { - return false; - } - pairs[0].item = "Cond. Address"; - pairs[0].value = condAddressBuffer; - - stark_sign_display_condition_fact(); - pairs[1].item = "Cond. Address"; - pairs[1].value = strings.tmp.tmp; - - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 2; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs; - - return true; - } else { - page++; - } - } - if (page == 2) { - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false); - content->infoLongPress.text = "Review transaction"; - content->infoLongPress.longPressText = SIGN_BUTTON; - return true; - } - - return false; -} - -static void reviewContinue(void) { - nbgl_useCaseRegularReview(0, - context.conditional ? 3 : 2, - REJECT_BUTTON, - NULL, - displayTransactionPage, - reviewChoice); -} - -void ui_stark_transfer(bool selfTransfer, bool conditional) { - context.selfTransfer = selfTransfer; - context.conditional = conditional; - char *subTitle; - if (conditional) { - if (selfTransfer) { - subTitle = (char *) "Conditional Self Transfer"; - } else { - subTitle = (char *) "Conditional Transfer"; - } - } else { - if (selfTransfer) { - subTitle = (char *) "Self Transfer"; - } else { - subTitle = (char *) "Transfer"; - } - } - nbgl_useCaseReviewStart(get_app_icon(false), - "Review stark\ntransaction", - subTitle, - REJECT_BUTTON, - reviewContinue, - reviewReject); -} - -#endif // #ifdef HAVE_STARKWARE diff --git a/src_nbgl/ui_stark_unsafe_sign.c b/src_nbgl/ui_stark_unsafe_sign.c deleted file mode 100644 index 45a8556..0000000 --- a/src_nbgl/ui_stark_unsafe_sign.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "common_ui.h" -#include "ui_signing.h" -#include "ui_nbgl.h" -#include "ui_callbacks.h" -#include "nbgl_use_case.h" -#include "network.h" - -#ifdef HAVE_STARKWARE - -static nbgl_layoutTagValue_t pairs[2]; -static char from_account[64]; -static char message_hash[64]; - -static void reviewReject(void) { - io_seproxyhal_touch_tx_cancel(NULL); -} - -static void confirmTransation(void) { - io_seproxyhal_touch_stark_unsafe_sign_ok(NULL); -} - -static void reviewChoice(bool confirm) { - if (confirm) { - confirmTransation(); - } else { - reviewReject(); - } -} - -static bool displayTransactionPage(uint8_t page, nbgl_pageContent_t *content) { - snprintf(from_account, sizeof(from_account), "0x%.*H", 32, dataContext.starkContext.w1); - snprintf(message_hash, sizeof(message_hash), "0x%.*H", 32, dataContext.starkContext.w2); - - if (page == 0) { - pairs[0].item = "From Account"; - pairs[0].value = from_account; - pairs[1].item = "Hash"; - pairs[1].value = message_hash; - content->type = TAG_VALUE_LIST; - content->tagValueList.nbPairs = 2; - content->tagValueList.pairs = (nbgl_layoutTagValue_t *) pairs; - } else if (page == 1) { - content->type = INFO_LONG_PRESS, content->infoLongPress.icon = get_app_icon(false); - content->infoLongPress.text = "Unsafe Stark Sign"; - content->infoLongPress.longPressText = SIGN_BUTTON; - } else { - return false; - } - // valid page so return true - return true; -} - -static void reviewContinue(void) { - nbgl_useCaseRegularReview(0, 2, REJECT_BUTTON, NULL, displayTransactionPage, reviewChoice); -} - -static void buildFirstPage(void) { - nbgl_useCaseReviewStart(get_app_icon(false), - "Unsafe Stark Sign", - NULL, - REJECT_BUTTON, - reviewContinue, - reviewReject); -} - -void ui_stark_unsafe_sign(void) { - buildFirstPage(); -} - -#endif // HAVE_STARKWARE diff --git a/src_plugins/erc20/erc20_plugin.c b/src_plugins/erc20/erc20_plugin.c index 5e40f0d..e5b1ba0 100644 --- a/src_plugins/erc20/erc20_plugin.c +++ b/src_plugins/erc20/erc20_plugin.c @@ -73,23 +73,6 @@ bool check_contract(erc20_parameters_t *context) { return false; } -bool erc20_plugin_available_check() { -#ifdef HAVE_STARKWARE - if (quantumSet) { - switch (dataContext.tokenContext.quantumType) { - case STARK_QUANTUM_LEGACY: - case STARK_QUANTUM_ETH: - case STARK_QUANTUM_ERC20: - case STARK_QUANTUM_MINTABLE_ERC20: - return true; - default: - return false; - } - } -#endif - return true; -} - void erc20_plugin_call(int message, void *parameters) { switch (message) { case ETH_PLUGIN_INIT_CONTRACT: { diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c deleted file mode 100644 index 427fca7..0000000 --- a/src_plugins/starkware/starkware_plugin.c +++ /dev/null @@ -1,944 +0,0 @@ -#include -#include "os_io_seproxyhal.h" -#include "uint256.h" -#include "eth_plugin_interface.h" -#include "shared_context.h" // TODO : rewrite as independant code -#include "eth_plugin_internal.h" // TODO : rewrite as independant code -#include "stark_utils.h" -#include "plugin_utils.h" -#include "common_utils.h" -#include "apdu_constants.h" - -#ifdef HAVE_STARKWARE - -typedef enum { - - STARKWARE_REGISTER = 0, - STARKWARE_DEPOSIT_TOKEN, - STARKWARE_DEPOSIT_ETH, - STARKWARE_DEPOSIT_CANCEL, - STARKWARE_DEPOSIT_RECLAIM, - STARKWARE_WITHDRAW, - STARKWARE_FULL_WITHDRAW, - STARKWARE_FREEZE, - STARKWARE_ESCAPE, - STARKWARE_VERIFY_ESCAPE, - STARKWARE_WITHDRAW_TO, - STARKWARE_DEPOSIT_NFT, - STARKWARE_DEPOSIT_NFT_RECLAIM, - STARKWARE_WITHDRAW_AND_MINT, - STARKWARE_WITHDRAW_NFT, - STARKWARE_WITHDRAW_NFT_TO, - STARKWARE_REGISTER_AND_DEPOSIT_TOKEN, - STARKWARE_REGISTER_AND_DEPOSIT_ETH, - STARKWARE_PROXY_DEPOSIT_TOKEN, - STARKWARE_PROXY_DEPOSIT_ETH, -} starkwareSelector_t; - -#ifndef HAVE_TOKENS_EXTRA_LIST - -static const uint8_t DEVERSIFI_CONTRACT[] = { - 0x02, - - 0x5d, 0x22, 0x04, 0x5d, 0xac, 0xea, 0xb0, 0x3b, 0x15, 0x80, - 0x31, 0xec, 0xb7, 0xd9, 0xd0, 0x6f, 0xad, 0x24, 0x60, 0x9b, - - 0x7d, 0xe1, 0xf0, 0x42, 0x04, 0xef, 0x29, 0x22, 0x9d, 0x84, - 0xe7, 0xc0, 0xc2, 0xd1, 0x21, 0x6c, 0x28, 0x64, 0x5a, 0x15}; - -#else - -static const uint8_t DEVERSIFI_CONTRACT[] = { - 0x02, 0xe7, 0x3a, 0x39, 0x4a, 0xde, 0x4d, 0x94, 0xa0, 0x73, 0x50, 0x2d, 0xa8, 0x70, - 0x3e, 0xa2, 0x34, 0x90, 0xdc, 0x7b, 0x6a, 0x69, 0xC6, 0x39, 0x2E, 0xb0, 0x2a, 0x28, - 0x82, 0x31, 0x41, 0x34, 0xc9, 0x8D, 0xDC, 0xBF, 0x73, 0xB7, 0xAd, 0xBa, 0xb1}; - -#endif - -// register : address (20), stark key (32), drop param 3 -// Registration -// Contract Name -// From ETH address -// Master account -// deposit token : stark key (32), verify assetType (32), vaultId (4), quantized Amount (32) -// Deposit -// Contract Name -// Master Account -// Token Account -// Amount -// deposit : stark key (32), verify assetType (32), vaultId (4) -// Flow similar to deposit -// deposit cancel, deposit reclaim : stark key (32), assetType (reclaim) / assetId (cancel) (32) -// ignored, vaultId(4) full withdrawal, freeze : stark key (32), vaultId (4) Cancel Deposit | -// Reclaim Deposit | Full Withdrawal | Freeze Contract Name Master Account Token Account -// withdrawal : stark key (32), verify assetType (32) -// Withdrawal -// Contract Name -// Master Account -// To Eth Address -// Token Symbol -// withdrawal to : stark key (32), verify assetType (32), address (20) -// Withdrawal To -// Contract Name -// Master Account -// To Eth Address -// Token Symbol -// escape : stark key (32), vaultId (4), verify assetType (32), quantized Amount (32) -// Escape -// Contract Name -// Amount -// Master Account -// Token Account -// verify escape : escapeProof (ignore) -// Verify Escape -// Contract Name -// deposit NFT : stark key (32), verify assetType (32), vault id (4), token id (32) -// Deposit -// Contract Name -// Master Account -// Token Account -// NFT Contract -// Token ID -// deposit NFT reclaim : stark key (32), verify assetType (32), vault id (4), token id (32) -// Reclaim Deposit -// Contract Name -// Master Account -// Token Account -// NFT Contract -// Token ID -// withdraw and mint : stark key (32), verify assetType (32), mintable blob (ignored variable) -// Withdrawal -// Contract Name -// Master Account -// Asset Contract -// withdraw NFT : stark key (32), verify assetType (32), token id (32) -// Withdrawal -// Contract Name -// Master Account -// To Eth Address -// NFT Contract -// Token ID -// withdraw NFT To : stark key (32), verify assetType (32), token id (32), address (20) -// Withdrawal To -// Contract Name -// Master Account -// To Eth Address -// NFT Contract -// Token ID -// register and deposit token : stark key (32), variable signature, verify assetType (32), vault Id -// (4), quantized amount (32), token address (20), quantum (32) Register and deposit Contract Name -// From ETH address -// Master account -// Token Account -// Amount -// register and deposit : stark key (32), variable signature, verify assetType (32), vault Id (4) -// flow similar to register and deposit -// deposit token proxy : stark key (32), verify assetType (32), vault Id (4), quantized Amount (32), -// token address (20), quantum (32) flow similar to deposit deposit proxy : stark key (32), verify -// assetType (32), vault Id (4) flow similar to deposit - -static const uint8_t STARKWARE_EXPECTED_DATA_SIZE[] = {0, - 4 + 32 + 32 + 32 + 32, - 4 + 32 + 32 + 32, - 4 + 32 + 32 + 32, - 4 + 32 + 32 + 32, - 4 + 32 + 32, - 4 + 32 + 32, - 4 + 32 + 32, - 4 + 32 + 32 + 32 + 32, - 0, - 4 + 32 + 32 + 32, - 4 + 32 + 32 + 32 + 32, - 4 + 32 + 32 + 32 + 32, - 0, - 4 + 32 + 32 + 32, - 4 + 32 + 32 + 32 + 32, - 0, - 0, - 4 + 32 + 32 + 32 + 32 + 32 + 32, - 4 + 32 + 32 + 32}; - -static const uint8_t STARKWARE_NUM_SCREENS[] = {4 - 1, 5 - 1, 5 - 1, 4 - 1, 4 - 1, 5 - 1, 4 - 1, - 4 - 1, 5 - 1, 2 - 1, 5 - 1, 6 - 1, 6 - 1, 4 - 1, - 6 - 1, 6 - 1, 6 - 1, 6 - 1, 5 - 1, 5 - 1}; - -typedef struct starkware_parameters_t { - uint8_t vaultId[4]; - uint8_t selectorIndex; - uint8_t starkKey[32]; - uint8_t amount[32]; - uint8_t validToken; - -} starkware_parameters_t; - -#define STARK_KEY_LENGTH (2 + length * 2 + 1) -#define VAULT_ID_LENGTH 10 - -bool is_deversify_contract(const uint8_t *address) { - uint32_t offset = 0; - uint8_t i; - - for (i = 0; i < DEVERSIFI_CONTRACT[0]; i++) { - if (memcmp(address, DEVERSIFI_CONTRACT + offset + 1, 20) == 0) { - return true; - } - offset += 20; - } - return false; -} - -// TODO : rewrite as independant code -bool starkware_verify_asset_id(uint8_t *tmp32, const uint8_t *tokenId, bool assetTypeOnly) { - if (quantumSet) { - cx_sha3_t sha3; - tokenDefinition_t *currentToken = NULL; - if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { - currentToken = - &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; - } - cx_keccak_init(&sha3, 256); - compute_token_id(&sha3, - (currentToken != NULL ? currentToken->address : NULL), - dataContext.tokenContext.quantumType, - dataContext.tokenContext.quantum, - dataContext.tokenContext.mintingBlob, - assetTypeOnly, - tmp32); - if (memcmp(tokenId, tmp32, 32) != 0) { - PRINTF("Token ID not matching - computed %.*H\n", 32, tmp32); - PRINTF("Current quantum %.*H\n", 32, dataContext.tokenContext.quantum); - PRINTF("Requested %.*H\n", 32, tokenId); - return false; - } - } else { - PRINTF("Quantum not set\n"); - return false; - } - return true; -} - -bool starkware_verify_token(const uint8_t *token) { - if (quantumSet) { - if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { - tokenDefinition_t *currentToken = - &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; - if (memcmp(token + 32 - 20, currentToken->address, 20) != 0) { - PRINTF("Token not matching got %.*H\n", 20, token + 32 - 20); - PRINTF("Current token %.*H\n", 20, currentToken->address); - return false; - } - } else { - PRINTF("Quantum not set\n"); - return false; - } - } else { - PRINTF("Quantum not set\n"); - return false; - } - return true; -} - -bool starkware_verify_quantum(const uint8_t *quantum) { - if (quantumSet) { - if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { - if (memcmp(quantum, dataContext.tokenContext.quantum, 32) != 0) { - PRINTF("Quantum not matching got %.*H\n", 32, quantum); - PRINTF("Current quantum %.*H\n", 32, dataContext.tokenContext.quantum); - return false; - } - } else { - PRINTF("Quantum not set\n"); - return false; - } - } else { - PRINTF("Quantum not set\n"); - return false; - } - return true; -} - -bool starkware_verify_nft_token_id(const uint8_t *tokenId) { - if (!quantumSet) { - PRINTF("Quantum not set\n"); - return false; - } - switch (dataContext.tokenContext.quantumType) { - case STARK_QUANTUM_ERC721: - case STARK_QUANTUM_MINTABLE_ERC721: - break; - default: - PRINTF("Unexpected quantum type for NFT token id check %d\n", - dataContext.tokenContext.quantumType); - return false; - } - if (memcmp(dataContext.tokenContext.quantum, tokenId, 32) != 0) { - PRINTF("Token ID not matching - expected %.*H\n", 32, dataContext.tokenContext.quantum); - PRINTF("Current token ID %.*H\n", 32, tokenId); - return false; - } - return true; -} - -void starkware_print_vault_id(uint32_t vaultId, char *destination, size_t max_length) { - if (VAULT_ID_LENGTH > max_length) { - os_sched_exit(EXCEPTION_OVERFLOW); - } - snprintf(destination, max_length, "%d", vaultId); -} - -void starkware_print_stark_key(uint8_t *starkKey, - size_t length, - char *destination, - size_t max_length) { - if (STARK_KEY_LENGTH > max_length) { - os_sched_exit(EXCEPTION_OVERFLOW); - } - snprintf(destination, max_length, "0x%.*H", length, starkKey); -} - -// TODO : rewrite as independant code -void starkware_print_amount(uint8_t *amountData, - char *destination, - size_t destinationLength, - bool forEscape) { - uint256_t amount, amountPre, quantum; - uint8_t decimals; - char *ticker = chainConfig->coinName; - - if ((amountData == NULL) || - (forEscape && (dataContext.tokenContext.quantumIndex == MAX_ITEMS))) { - decimals = WEI_TO_ETHER; - if (!forEscape) { - convertUint256BE(tmpContent.txContent.value.value, - tmpContent.txContent.value.length, - &amount); - } else { - readu256BE(amountData, &amountPre); - } - } else { - tokenDefinition_t *token = - &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; - decimals = token->decimals; - ticker = token->ticker; - readu256BE(amountData, &amountPre); - } - if (amountData != NULL) { - readu256BE(dataContext.tokenContext.quantum, &quantum); - mul256(&amountPre, &quantum, &amount); - } - tostring256(&amount, 10, (char *) (G_io_apdu_buffer + 100), 100); - strlcpy(destination, ticker, destinationLength); - strlcat(destination, " ", destinationLength); - adjustDecimals((char *) (G_io_apdu_buffer + 100), - strlen((char *) (G_io_apdu_buffer + 100)), - destination + strlen(ticker) + 1, - destinationLength - strlen(ticker) - 1, - decimals); -} - -// TODO : rewrite as independant code -void starkware_print_ticker(char *destination, size_t destinationLength) { - char *ticker = chainConfig->coinName; - - if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { - tokenDefinition_t *token = - &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; - ticker = token->ticker; - } - strlcpy(destination, ticker, destinationLength); -} - -// TODO : rewrite as independant code -void starkware_print_asset_contract(char *destination, size_t destinationLength) { - // token has been validated to be present previously - if (dataContext.tokenContext.quantumIndex != MAX_ITEMS) { - tokenDefinition_t *token = - &tmpCtx.transactionContext.extraInfo[dataContext.tokenContext.quantumIndex].token; - if (!getEthDisplayableAddress(token->address, - destination, - destinationLength, - &global_sha3, - chainConfig->chainId)) { - THROW(APDU_RESPONSE_ERROR_NO_INFO); - } - } else { - strlcpy(destination, "UNKNOWN", destinationLength); - } -} - -// TODO : rewrite as independant code -void starkware_get_source_address(char *destination) { - uint8_t privateKeyData[INT256_LENGTH]; - cx_ecfp_private_key_t privateKey; - cx_ecfp_public_key_t publicKey; - os_perso_derive_node_bip32(CX_CURVE_256K1, - tmpCtx.transactionContext.bip32.path, - tmpCtx.transactionContext.bip32.length, - privateKeyData, - NULL); - cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); - io_seproxyhal_io_heartbeat(); - cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1); - explicit_bzero(&privateKey, sizeof(privateKey)); - explicit_bzero(privateKeyData, sizeof(privateKeyData)); - io_seproxyhal_io_heartbeat(); - destination[0] = '0'; - destination[1] = 'x'; - if (!getEthAddressStringFromKey(&publicKey, - destination + 2, - &global_sha3, - chainConfig->chainId)) { - THROW(CX_INVALID_PARAMETER); - } - destination[42] = '\0'; -} - -void starkware_plugin_call(int message, void *parameters) { - switch (message) { - case ETH_PLUGIN_INIT_CONTRACT: { - uint8_t i; - ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; - starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; - PRINTF("starkware plugin init\n"); - for (i = 0; i < NUM_STARKWARE_SELECTORS; i++) { - if (memcmp((const void *) PIC(STARKWARE_SELECTORS[i]), - msg->selector, - SELECTOR_SIZE) == 0) { - context->selectorIndex = i; - break; - } - } - if (i == NUM_STARKWARE_SELECTORS) { - PRINTF("Unknown selector %.*H\n", SELECTOR_SIZE, msg->selector); - break; - } - if (STARKWARE_EXPECTED_DATA_SIZE[context->selectorIndex] != 0) { - if (msg->dataSize != STARKWARE_EXPECTED_DATA_SIZE[context->selectorIndex]) { - PRINTF("Unexpected data size for command %d expected %d got %d\n", - context->selectorIndex, - STARKWARE_EXPECTED_DATA_SIZE[context->selectorIndex], - msg->dataSize); - break; - } - } - context->validToken = true; - msg->result = ETH_PLUGIN_RESULT_OK; - } break; - - case ETH_PLUGIN_PROVIDE_PARAMETER: { - ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters; - starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; - PRINTF("starkware plugin provide parameter %d %.*H\n", - msg->parameterOffset, - 32, - msg->parameter); - // Ignore for verify escape - if (context->selectorIndex == STARKWARE_VERIFY_ESCAPE) { - msg->result = ETH_PLUGIN_RESULT_OK; - break; - } - switch (msg->parameterOffset) { - case 4: - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - memmove(context->amount, msg->parameter + 32 - 20, 20); - break; - - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_CANCEL: - case STARKWARE_DEPOSIT_RECLAIM: - case STARKWARE_WITHDRAW: - case STARKWARE_FULL_WITHDRAW: - case STARKWARE_FREEZE: - case STARKWARE_ESCAPE: - case STARKWARE_WITHDRAW_TO: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - case STARKWARE_WITHDRAW_AND_MINT: - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - memmove(context->starkKey, msg->parameter, 32); - break; - - default: - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32: - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - memmove(context->starkKey, msg->parameter, 32); - break; - - case STARKWARE_ESCAPE: - memmove(context->vaultId, msg->parameter + 32 - 4, 4); - break; - - case STARKWARE_DEPOSIT_CANCEL: - case STARKWARE_DEPOSIT_RECLAIM: - break; - - case STARKWARE_FULL_WITHDRAW: - case STARKWARE_FREEZE: - memmove(context->vaultId, msg->parameter + 32 - 4, 4); - break; - - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_WITHDRAW: - case STARKWARE_WITHDRAW_TO: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - case STARKWARE_WITHDRAW_AND_MINT: - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - context->validToken = - starkware_verify_asset_id(context->amount, msg->parameter, true); - break; - - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - // drop variable byte array signature offset - break; - - default: - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32 + 32: - switch (context->selectorIndex) { - case STARKWARE_ESCAPE: - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - context->validToken = - starkware_verify_asset_id(context->amount, msg->parameter, true); - break; - - case STARKWARE_DEPOSIT_CANCEL: - case STARKWARE_DEPOSIT_RECLAIM: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - memmove(context->vaultId, msg->parameter + 32 - 4, 4); - break; - - case STARKWARE_WITHDRAW_TO: - memmove(context->amount, msg->parameter + 32 - 20, 20); - break; - - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - context->validToken = starkware_verify_nft_token_id(msg->parameter); - break; - - default: - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32 + 32 + 32: - switch (context->selectorIndex) { - case STARKWARE_ESCAPE: - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - memmove(context->amount, msg->parameter, 32); - break; - - case STARKWARE_WITHDRAW_NFT_TO: - memmove(context->amount, msg->parameter + 32 - 20, 20); - break; - - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - context->validToken = starkware_verify_nft_token_id(msg->parameter); - break; - - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - memmove(context->vaultId, msg->parameter + 32 - 4, 4); - break; - - default: - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32 + 32 + 32 + 32: - switch (context->selectorIndex) { - switch (context->selectorIndex) { - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - memmove(context->amount, msg->parameter, 32); - break; - - case STARKWARE_PROXY_DEPOSIT_TOKEN: - context->validToken = starkware_verify_token(msg->parameter); - break; - - default: - break; - } - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32 + 32 + 32 + 32 + 32: - switch (context->selectorIndex) { - switch (context->selectorIndex) { - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - context->validToken = starkware_verify_token(msg->parameter); - break; - - case STARKWARE_PROXY_DEPOSIT_TOKEN: - context->validToken = starkware_verify_quantum(msg->parameter); - break; - - default: - break; - } - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4 + 32 + 32 + 32 + 32 + 32 + 32: - switch (context->selectorIndex) { - switch (context->selectorIndex) { - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - context->validToken = starkware_verify_quantum(msg->parameter); - break; - - default: - break; - } - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - default: - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - case STARKWARE_VERIFY_ESCAPE: - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - default: - PRINTF("Unhandled parameter offset\n"); - break; - } - } - } break; - - case ETH_PLUGIN_FINALIZE: { - ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters; - starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; - PRINTF("starkware plugin finalize\n"); - if (!context->validToken) { - msg->result = ETH_PLUGIN_RESULT_FALLBACK; - } else { - msg->uiType = ETH_UI_TYPE_GENERIC; - msg->numScreens = STARKWARE_NUM_SCREENS[context->selectorIndex]; - msg->result = ETH_PLUGIN_RESULT_OK; - } - } break; - - case ETH_PLUGIN_QUERY_CONTRACT_ID: { - ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters; - starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; - PRINTF("starkware query contract id\n"); - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - strlcpy(msg->name, "Register", msg->nameLength); - break; - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - strlcpy(msg->name, "Deposit", msg->nameLength); - break; - case STARKWARE_DEPOSIT_CANCEL: - strlcpy(msg->name, "Cancel Deposit", msg->nameLength); - break; - case STARKWARE_DEPOSIT_RECLAIM: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - strlcpy(msg->name, "Reclaim Deposit", msg->nameLength); - break; - case STARKWARE_WITHDRAW: - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_AND_MINT: - strlcpy(msg->name, "Withdrawal", msg->nameLength); - break; - case STARKWARE_FULL_WITHDRAW: - strlcpy(msg->name, "Full Withdrawal", msg->nameLength); - break; - case STARKWARE_FREEZE: - strlcpy(msg->name, "Freeze", msg->nameLength); - break; - case STARKWARE_ESCAPE: - strlcpy(msg->name, "Escape", msg->nameLength); - break; - case STARKWARE_VERIFY_ESCAPE: - strlcpy(msg->name, "Verify Escape", msg->nameLength); - break; - case STARKWARE_WITHDRAW_TO: - case STARKWARE_WITHDRAW_NFT_TO: - strlcpy(msg->name, "Withdrawal To", msg->nameLength); - break; - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - strlcpy(msg->name, "Register&Deposit", msg->nameLength); - break; - - default: - break; - } - strlcpy( - msg->version, - is_deversify_contract(tmpContent.txContent.destination) ? "DeversiFi" : "Starkware", - msg->versionLength); - msg->result = ETH_PLUGIN_RESULT_OK; - } break; - - case ETH_PLUGIN_QUERY_CONTRACT_UI: { - ethQueryContractUI_t *msg = (ethQueryContractUI_t *) parameters; - starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; - switch (msg->screenIndex) { - case 0: - strlcpy(msg->title, "Contract Name", msg->titleLength); - if (is_deversify_contract(tmpContent.txContent.destination)) { - strlcpy(msg->msg, "DeversiFi", msg->msgLength); - } else { - if (!getEthDisplayableAddress(tmpContent.txContent.destination, - msg->msg, - msg->msgLength, - &global_sha3, - chainConfig->chainId)) { - THROW(APDU_RESPONSE_ERROR_NO_INFO); - } - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - case 1: - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - strlcpy(msg->title, "From ETH Address", msg->titleLength); - if (!getEthDisplayableAddress(context->amount, - msg->msg, - msg->msgLength, - &global_sha3, - chainConfig->chainId)) { - THROW(APDU_RESPONSE_ERROR_NO_INFO); - } - break; - case STARKWARE_ESCAPE: - strlcpy(msg->title, "Amount", msg->titleLength); - starkware_print_amount(context->amount, msg->msg, msg->msgLength, true); - break; - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_CANCEL: - case STARKWARE_DEPOSIT_RECLAIM: - case STARKWARE_WITHDRAW: - case STARKWARE_FULL_WITHDRAW: - case STARKWARE_FREEZE: - case STARKWARE_VERIFY_ESCAPE: - case STARKWARE_WITHDRAW_TO: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - case STARKWARE_WITHDRAW_AND_MINT: - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - strlcpy(msg->title, "Master Account", msg->titleLength); - starkware_print_stark_key(context->starkKey, - sizeof(context->starkKey), - msg->msg, - msg->msgLength); - break; - default: - PRINTF("Unexpected screen %d for %d\n", - msg->screenIndex, - context->selectorIndex); - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - case 2: - switch (context->selectorIndex) { - case STARKWARE_REGISTER: - case STARKWARE_ESCAPE: - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - strlcpy(msg->title, "Master Account", msg->titleLength); - starkware_print_stark_key(context->starkKey, - sizeof(context->starkKey), - msg->msg, - msg->msgLength); - break; - - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - case STARKWARE_DEPOSIT_CANCEL: - case STARKWARE_DEPOSIT_RECLAIM: - case STARKWARE_FULL_WITHDRAW: - case STARKWARE_FREEZE: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - strlcpy(msg->title, "Token Account", msg->titleLength); - starkware_print_vault_id(U4BE(context->vaultId, 0), - msg->msg, - msg->msgLength); - break; - case STARKWARE_WITHDRAW: - case STARKWARE_WITHDRAW_NFT: - strlcpy(msg->title, "To ETH Address", msg->titleLength); - starkware_get_source_address(msg->msg); - break; - case STARKWARE_WITHDRAW_TO: - case STARKWARE_WITHDRAW_NFT_TO: - strlcpy(msg->title, "To ETH Address", msg->titleLength); - if (!getEthDisplayableAddress(context->amount, - msg->msg, - msg->msgLength, - &global_sha3, - chainConfig->chainId)) { - THROW(APDU_RESPONSE_ERROR_NO_INFO); - } - break; - case STARKWARE_WITHDRAW_AND_MINT: - strlcpy(msg->title, "Asset Contract", msg->titleLength); - starkware_print_asset_contract(msg->msg, msg->msgLength); - break; - - default: - PRINTF("Unexpected screen %d for %d\n", - msg->screenIndex, - context->selectorIndex); - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 3: - switch (context->selectorIndex) { - case STARKWARE_ESCAPE: - strlcpy(msg->title, "Token Account", msg->titleLength); - starkware_print_vault_id(U4BE(context->vaultId, 0), - msg->msg, - msg->msgLength); - break; - case STARKWARE_DEPOSIT_TOKEN: - case STARKWARE_DEPOSIT_ETH: - case STARKWARE_PROXY_DEPOSIT_TOKEN: - case STARKWARE_PROXY_DEPOSIT_ETH: - strlcpy(msg->title, "Amount", msg->titleLength); - starkware_print_amount( - (((context->selectorIndex == STARKWARE_DEPOSIT_ETH) || - (context->selectorIndex == STARKWARE_PROXY_DEPOSIT_ETH)) - ? NULL - : context->amount), - msg->msg, - msg->msgLength, - false); - break; - case STARKWARE_WITHDRAW: - case STARKWARE_WITHDRAW_TO: - strlcpy(msg->title, "Token Symbol", msg->titleLength); - starkware_print_ticker(msg->msg, msg->msgLength); - break; - - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - strlcpy(msg->title, "NFT Contract", msg->titleLength); - starkware_print_asset_contract(msg->msg, msg->msgLength); - break; - - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - strlcpy(msg->title, "Token Account", msg->titleLength); - starkware_print_vault_id(U4BE(context->vaultId, 0), - msg->msg, - msg->msgLength); - break; - - default: - PRINTF("Unexpected screen %d for %d\n", - msg->screenIndex, - context->selectorIndex); - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - case 4: - switch (context->selectorIndex) { - case STARKWARE_WITHDRAW_NFT: - case STARKWARE_WITHDRAW_NFT_TO: - case STARKWARE_DEPOSIT_NFT: - case STARKWARE_DEPOSIT_NFT_RECLAIM: - strlcpy(msg->title, "TokenID", msg->titleLength); - starkware_print_stark_key(dataContext.tokenContext.quantum, - sizeof(dataContext.tokenContext.quantum), - msg->msg, - msg->msgLength); - break; - - case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: - case STARKWARE_REGISTER_AND_DEPOSIT_ETH: - strlcpy(msg->title, "Amount", msg->titleLength); - starkware_print_amount( - ((context->selectorIndex == STARKWARE_REGISTER_AND_DEPOSIT_ETH) - ? NULL - : context->amount), - msg->msg, - msg->msgLength, - false); - break; - - default: - PRINTF("Unexpected screen %d for %d\n", - msg->screenIndex, - context->selectorIndex); - break; - } - msg->result = ETH_PLUGIN_RESULT_OK; - break; - - default: - PRINTF("Unexpected screen %d for %d\n", - msg->screenIndex, - context->selectorIndex); - break; - } - } break; - - default: - PRINTF("Unhandled message %d\n", message); - } -} - -#endif