From c7e3bfda08c3bf600d235ab2cf8465b19d022d06 Mon Sep 17 00:00:00 2001 From: BTChip github Date: Mon, 5 Apr 2021 14:56:56 +0200 Subject: [PATCH 1/3] Add Deversifi proxy support --- Makefile | 4 +- src/eth_plugin_internal.c | 11 +- src/eth_plugin_internal.h | 2 +- src_plugins/starkware/starkware_plugin.c | 198 ++++++++++++++++++++++- 4 files changed, 204 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index df9c25a..c38c053 100755 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ APP_LOAD_PARAMS += --path "45'" APPVERSION_M=1 APPVERSION_N=6 -APPVERSION_P=5 -APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) +APPVERSION_P=6 +APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)-dvf1 APP_LOAD_FLAGS= --appFlags 0x240 --dep Ethereum:$(APPVERSION) ifeq ($(CHAIN),) diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index 3619493..6ff538b 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -67,6 +67,10 @@ static const uint8_t const STARKWARE_DEPOSIT_NFT_RECLAIM_ID[SELECTOR_SIZE] = {0x static const uint8_t const STARKWARE_WITHDRAW_AND_MINT_ID[SELECTOR_SIZE] = {0xd9, 0x14, 0x43, 0xb7}; static const uint8_t const STARKWARE_WITHDRAW_NFT_ID[SELECTOR_SIZE] = {0x01, 0x9b, 0x41, 0x7a}; static const uint8_t const STARKWARE_WITHDRAW_NFT_TO_ID[SELECTOR_SIZE] = {0xeb, 0xef, 0x0f, 0xd0}; +static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = { 0x10, 0x82, 0x08, 0xcf }; +static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID[SELECTOR_SIZE] = { 0xa7, 0x78, 0xc0, 0xc3 }; +static const uint8_t const STARKWARE_PROXY_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = { 0xdc, 0xca, 0xd5, 0x24 }; +static const uint8_t const STARKWARE_PROXY_DEPOSIT_ETH_ID[SELECTOR_SIZE] = { 0x6c, 0xe5, 0xd9, 0x57 }; const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { STARKWARE_REGISTER_ID, @@ -84,7 +88,12 @@ const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { STARKWARE_DEPOSIT_NFT_RECLAIM_ID, STARKWARE_WITHDRAW_AND_MINT_ID, STARKWARE_WITHDRAW_NFT_ID, - STARKWARE_WITHDRAW_NFT_TO_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 diff --git a/src/eth_plugin_internal.h b/src/eth_plugin_internal.h index 169efb2..7e76d3a 100644 --- a/src/eth_plugin_internal.h +++ b/src/eth_plugin_internal.h @@ -32,7 +32,7 @@ extern const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS]; #ifdef HAVE_STARKWARE -#define NUM_STARKWARE_SELECTORS 16 +#define NUM_STARKWARE_SELECTORS 20 extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS]; #endif diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c index b5f0d5f..71aad27 100644 --- a/src_plugins/starkware/starkware_plugin.c +++ b/src_plugins/starkware/starkware_plugin.c @@ -24,14 +24,24 @@ typedef enum { STARKWARE_DEPOSIT_NFT_RECLAIM, STARKWARE_WITHDRAW_AND_MINT, STARKWARE_WITHDRAW_NFT, - STARKWARE_WITHDRAW_NFT_TO + 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[] = {0x01, 0x5d, 0x22, 0x04, 0x5d, 0xac, 0xea, - 0xb0, 0x3b, 0x15, 0x80, 0x31, 0xec, 0xb7, - 0xd9, 0xd0, 0x6f, 0xad, 0x24, 0x60, 0x9b}; +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 @@ -112,6 +122,19 @@ static const uint8_t DEVERSIFI_CONTRACT[] = { // 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, @@ -128,7 +151,11 @@ static const uint8_t STARKWARE_EXPECTED_DATA_SIZE[] = {0, 4 + 32 + 32 + 32 + 32, 0, 4 + 32 + 32 + 32, - 4 + 32 + 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, @@ -145,7 +172,11 @@ static const uint8_t STARKWARE_NUM_SCREENS[] = {4 - 1, 6 - 1, 4 - 1, 6 - 1, - 6 - 1}; + 6 - 1, + 6 - 1, + 6 - 1, + 5 - 1, + 5 - 1}; typedef struct starkware_parameters_t { uint8_t vaultId[4]; @@ -198,6 +229,49 @@ bool starkware_verify_asset_id(uint8_t *tmp32, uint8_t *tokenId, bool assetTypeO return true; } +bool starkware_verify_token(uint8_t *token) { + if (quantumSet) { + if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) { + tokenDefinition_t *currentToken = &tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex]; + 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(uint8_t *quantum) { + if (quantumSet) { + if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) { + 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(uint8_t *tokenId) { if (!quantumSet) { PRINTF("Quantum not set\n"); @@ -389,6 +463,10 @@ void starkware_plugin_call(int message, void *parameters) { 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; @@ -426,10 +504,17 @@ void starkware_plugin_call(int message, void *parameters) { 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; } @@ -439,6 +524,8 @@ void starkware_plugin_call(int message, void *parameters) { 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; @@ -449,6 +536,8 @@ void starkware_plugin_call(int message, void *parameters) { 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; @@ -471,6 +560,7 @@ void starkware_plugin_call(int message, void *parameters) { switch (context->selectorIndex) { case STARKWARE_ESCAPE: case STARKWARE_DEPOSIT_TOKEN: + case STARKWARE_PROXY_DEPOSIT_TOKEN: memmove(context->amount, msg->parameter, 32); break; @@ -483,16 +573,77 @@ void starkware_plugin_call(int message, void *parameters) { 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; @@ -527,6 +678,8 @@ void starkware_plugin_call(int message, void *parameters) { case STARKWARE_DEPOSIT_TOKEN: case STARKWARE_DEPOSIT_ETH: case STARKWARE_DEPOSIT_NFT: + case STARKWARE_PROXY_DEPOSIT_TOKEN: + case STARKWARE_PROXY_DEPOSIT_ETH: strcpy(msg->name, "Deposit"); break; case STARKWARE_DEPOSIT_CANCEL: @@ -557,6 +710,10 @@ void starkware_plugin_call(int message, void *parameters) { case STARKWARE_WITHDRAW_NFT_TO: strcpy(msg->name, "Withdrawal To"); break; + case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: + case STARKWARE_REGISTER_AND_DEPOSIT_ETH: + strcpy(msg->name, "Register&Deposit"); + break; default: break; @@ -583,6 +740,8 @@ void starkware_plugin_call(int message, void *parameters) { case 1: switch (context->selectorIndex) { case STARKWARE_REGISTER: + case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: + case STARKWARE_REGISTER_AND_DEPOSIT_ETH: strcpy(msg->title, "From ETH Address"); starkware_print_eth_address(context->amount, msg->msg); break; @@ -592,6 +751,8 @@ void starkware_plugin_call(int message, void *parameters) { 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: @@ -619,12 +780,16 @@ void starkware_plugin_call(int message, void *parameters) { switch (context->selectorIndex) { case STARKWARE_REGISTER: case STARKWARE_ESCAPE: + case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: + case STARKWARE_REGISTER_AND_DEPOSIT_ETH: strcpy(msg->title, "Master Account"); starkware_print_stark_key(context->starkKey, msg->msg); 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: @@ -666,9 +831,12 @@ void starkware_plugin_call(int message, void *parameters) { break; case STARKWARE_DEPOSIT_TOKEN: case STARKWARE_DEPOSIT_ETH: + case STARKWARE_PROXY_DEPOSIT_TOKEN: + case STARKWARE_PROXY_DEPOSIT_ETH: strcpy(msg->title, "Amount"); starkware_print_amount( - (context->selectorIndex == STARKWARE_DEPOSIT_ETH ? NULL + (((context->selectorIndex == STARKWARE_DEPOSIT_ETH) || + (context->selectorIndex == STARKWARE_PROXY_DEPOSIT_ETH)) ? NULL : context->amount), msg->msg, false); @@ -687,6 +855,12 @@ void starkware_plugin_call(int message, void *parameters) { starkware_print_asset_contract(msg->msg); break; + case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: + case STARKWARE_REGISTER_AND_DEPOSIT_ETH: + strcpy(msg->title, "Token Account"); + starkware_print_vault_id(U4BE(context->vaultId, 0), msg->msg); + break; + default: PRINTF("Unexpected screen %d for %d\n", msg->screenIndex, @@ -706,6 +880,16 @@ void starkware_plugin_call(int message, void *parameters) { starkware_print_stark_key(dataContext.tokenContext.quantum, msg->msg); break; + case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: + case STARKWARE_REGISTER_AND_DEPOSIT_ETH: + strcpy(msg->title, "Amount"); + starkware_print_amount( + ((context->selectorIndex == STARKWARE_REGISTER_AND_DEPOSIT_ETH) ? NULL + : context->amount), + msg->msg, + false); + break; + default: PRINTF("Unexpected screen %d for %d\n", msg->screenIndex, From b5c14758009396323eb478864a60c3deee5862f7 Mon Sep 17 00:00:00 2001 From: BTChip github Date: Wed, 7 Apr 2021 12:19:51 +0200 Subject: [PATCH 2/3] Fix initialization --- Makefile | 2 +- src/eth_plugin_internal.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c38c053..ae29efa 100755 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ APP_LOAD_PARAMS += --path "45'" APPVERSION_M=1 APPVERSION_N=6 APPVERSION_P=6 -APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)-dvf1 +APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)-dvf2 APP_LOAD_FLAGS= --appFlags 0x240 --dep Ethereum:$(APPVERSION) ifeq ($(CHAIN),) diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index 6ff538b..96cc706 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -126,7 +126,7 @@ const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = { #ifdef HAVE_STARKWARE - {NULL, (const uint8_t**) STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call}, + {NULL, (const uint8_t**) STARKWARE_SELECTORS, NUM_STARKWARE_SELECTORS, "-strk", starkware_plugin_call}, #endif From 41ab56db7a4b4e9826335669528be530ffd7b290 Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:05:49 +0200 Subject: [PATCH 3/3] Apply clang-format --- src/eth_plugin_internal.c | 26 ++++-- src/eth_plugin_internal.h | 2 +- src_plugins/starkware/starkware_plugin.c | 105 +++++++++-------------- 3 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index 96cc706..d4d573f 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -67,10 +67,19 @@ static const uint8_t const STARKWARE_DEPOSIT_NFT_RECLAIM_ID[SELECTOR_SIZE] = {0x static const uint8_t const STARKWARE_WITHDRAW_AND_MINT_ID[SELECTOR_SIZE] = {0xd9, 0x14, 0x43, 0xb7}; static const uint8_t const STARKWARE_WITHDRAW_NFT_ID[SELECTOR_SIZE] = {0x01, 0x9b, 0x41, 0x7a}; static const uint8_t const STARKWARE_WITHDRAW_NFT_TO_ID[SELECTOR_SIZE] = {0xeb, 0xef, 0x0f, 0xd0}; -static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = { 0x10, 0x82, 0x08, 0xcf }; -static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID[SELECTOR_SIZE] = { 0xa7, 0x78, 0xc0, 0xc3 }; -static const uint8_t const STARKWARE_PROXY_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = { 0xdc, 0xca, 0xd5, 0x24 }; -static const uint8_t const STARKWARE_PROXY_DEPOSIT_ETH_ID[SELECTOR_SIZE] = { 0x6c, 0xe5, 0xd9, 0x57 }; +static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0x10, + 0x82, + 0x08, + 0xcf}; +static const uint8_t const STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0xa7, + 0x78, + 0xc0, + 0xc3}; +static const uint8_t const STARKWARE_PROXY_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0xdc, + 0xca, + 0xd5, + 0x24}; +static const uint8_t const STARKWARE_PROXY_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0x6c, 0xe5, 0xd9, 0x57}; const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { STARKWARE_REGISTER_ID, @@ -92,8 +101,7 @@ const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { STARKWARE_REGISTER_AND_DEPOSIT_TOKEN_ID, STARKWARE_REGISTER_AND_DEPOSIT_ETH_ID, STARKWARE_PROXY_DEPOSIT_TOKEN_ID, - STARKWARE_PROXY_DEPOSIT_ETH_ID -}; + STARKWARE_PROXY_DEPOSIT_ETH_ID}; #endif @@ -126,7 +134,11 @@ const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = { #ifdef HAVE_STARKWARE - {NULL, (const uint8_t**) STARKWARE_SELECTORS, NUM_STARKWARE_SELECTORS, "-strk", starkware_plugin_call}, + {NULL, + (const uint8_t**) STARKWARE_SELECTORS, + NUM_STARKWARE_SELECTORS, + "-strk", + starkware_plugin_call}, #endif diff --git a/src/eth_plugin_internal.h b/src/eth_plugin_internal.h index 7e76d3a..bee28d1 100644 --- a/src/eth_plugin_internal.h +++ b/src/eth_plugin_internal.h @@ -32,7 +32,7 @@ extern const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS]; #ifdef HAVE_STARKWARE -#define NUM_STARKWARE_SELECTORS 20 +#define NUM_STARKWARE_SELECTORS 20 extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS]; #endif diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c index 71aad27..1fea72a 100644 --- a/src_plugins/starkware/starkware_plugin.c +++ b/src_plugins/starkware/starkware_plugin.c @@ -33,15 +33,14 @@ typedef enum { #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}; +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 @@ -122,19 +121,17 @@ static const uint8_t DEVERSIFI_CONTRACT[] = { // 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 +// 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 +// 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, @@ -157,26 +154,9 @@ static const uint8_t STARKWARE_EXPECTED_DATA_SIZE[] = {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}; +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]; @@ -232,19 +212,18 @@ bool starkware_verify_asset_id(uint8_t *tmp32, uint8_t *tokenId, bool assetTypeO bool starkware_verify_token(uint8_t *token) { if (quantumSet) { if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) { - tokenDefinition_t *currentToken = &tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex]; + tokenDefinition_t *currentToken = + &tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex]; 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 { + } + } else { PRINTF("Quantum not set\n"); return false; } - } - else { + } else { PRINTF("Quantum not set\n"); return false; } @@ -253,19 +232,17 @@ bool starkware_verify_token(uint8_t *token) { bool starkware_verify_quantum(uint8_t *quantum) { if (quantumSet) { - if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) { + if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) { 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 { + } + } else { PRINTF("Quantum not set\n"); return false; } - } - else { + } else { PRINTF("Quantum not set\n"); return false; } @@ -585,9 +562,8 @@ void starkware_plugin_call(int message, void *parameters) { break; case 4 + 32 + 32 + 32 + 32: - switch(context->selectorIndex) { - switch(context->selectorIndex) { - + switch (context->selectorIndex) { + switch (context->selectorIndex) { case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: memmove(context->amount, msg->parameter, 32); break; @@ -599,15 +575,13 @@ void starkware_plugin_call(int message, void *parameters) { default: break; } - } msg->result = ETH_PLUGIN_RESULT_OK; break; case 4 + 32 + 32 + 32 + 32 + 32: - switch(context->selectorIndex) { - switch(context->selectorIndex) { - + switch (context->selectorIndex) { + switch (context->selectorIndex) { case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: context->validToken = starkware_verify_token(msg->parameter); break; @@ -624,9 +598,8 @@ void starkware_plugin_call(int message, void *parameters) { break; case 4 + 32 + 32 + 32 + 32 + 32 + 32: - switch(context->selectorIndex) { - switch(context->selectorIndex) { - + switch (context->selectorIndex) { + switch (context->selectorIndex) { case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN: context->validToken = starkware_verify_quantum(msg->parameter); break; @@ -835,9 +808,10 @@ void starkware_plugin_call(int message, void *parameters) { case STARKWARE_PROXY_DEPOSIT_ETH: strcpy(msg->title, "Amount"); starkware_print_amount( - (((context->selectorIndex == STARKWARE_DEPOSIT_ETH) || - (context->selectorIndex == STARKWARE_PROXY_DEPOSIT_ETH)) ? NULL - : context->amount), + (((context->selectorIndex == STARKWARE_DEPOSIT_ETH) || + (context->selectorIndex == STARKWARE_PROXY_DEPOSIT_ETH)) + ? NULL + : context->amount), msg->msg, false); break; @@ -859,7 +833,7 @@ void starkware_plugin_call(int message, void *parameters) { case STARKWARE_REGISTER_AND_DEPOSIT_ETH: strcpy(msg->title, "Token Account"); starkware_print_vault_id(U4BE(context->vaultId, 0), msg->msg); - break; + break; default: PRINTF("Unexpected screen %d for %d\n", @@ -884,11 +858,12 @@ void starkware_plugin_call(int message, void *parameters) { case STARKWARE_REGISTER_AND_DEPOSIT_ETH: strcpy(msg->title, "Amount"); starkware_print_amount( - ((context->selectorIndex == STARKWARE_REGISTER_AND_DEPOSIT_ETH) ? NULL - : context->amount), + ((context->selectorIndex == STARKWARE_REGISTER_AND_DEPOSIT_ETH) + ? NULL + : context->amount), msg->msg, false); - break; + break; default: PRINTF("Unexpected screen %d for %d\n",