Add pointer to msg_sender in Eth_plugin_finalize (#170)
* Add some PRINTF debug statements and fir additional screens init * Memzero struture and use two pointers less * Clang-format * Use ADDRESS_LENGTH where possible; Add printf statements when failing to compare contracts * clang-format * Remove 'token1' and 'token2' locals * Fix typo * apply clang-format * Add bip32path to sharedRO for plugins * Change getEthAddressStringFromKey to accept char instead of uint8_t * Update ethereum plugin sdk * Add BYPASS_SIGNATURES compilation option * Remove bip32path and pathLength from sharedRO; add msg_sender pointer to pluginFinalize.address * clang format eth_plugin_interface * Update submodule * Set address BEFORE making the finalize call * Update SDK Co-authored-by: TamtamHero <10632523+TamtamHero@users.noreply.github.com>
This commit is contained in:
@@ -88,8 +88,10 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
||||
32,
|
||||
workBuffer + offset,
|
||||
dataLength)) {
|
||||
#ifndef HAVE_BYPASS_SIGNATURES
|
||||
PRINTF("Invalid token signature\n");
|
||||
THROW(0x6A80);
|
||||
#endif
|
||||
}
|
||||
tmpCtx.transactionContext.tokenSet[tmpCtx.transactionContext.currentTokenIndex] = 1;
|
||||
THROW(0x9000);
|
||||
@@ -175,8 +177,10 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
||||
32,
|
||||
workBuffer + offset,
|
||||
dataLength)) {
|
||||
#ifndef HAVE_BYPASS_SIGNATURES
|
||||
PRINTF("Invalid token signature\n");
|
||||
THROW(0x6A80);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +197,10 @@ void handleProvideErc20TokenInformation(uint8_t p1,
|
||||
32,
|
||||
workBuffer + offset,
|
||||
dataLength)) {
|
||||
#ifndef HAVE_BYPASS_SIGNATURES
|
||||
PRINTF("Invalid token signature\n");
|
||||
THROW(0x6A80);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "ui_flow.h"
|
||||
#include "tokens.h"
|
||||
|
||||
#define CONTRACT_ADDR_SIZE 20
|
||||
#define SELECTOR_SIZE 4
|
||||
#define SELECTOR_SIZE 4
|
||||
|
||||
void handleSetExternalPlugin(uint8_t p1,
|
||||
uint8_t p2,
|
||||
@@ -19,7 +18,7 @@ void handleSetExternalPlugin(uint8_t p1,
|
||||
uint8_t hash[32];
|
||||
cx_ecfp_public_key_t tokenKey;
|
||||
uint8_t pluginNameLength = *workBuffer;
|
||||
const size_t payload_size = 1 + pluginNameLength + CONTRACT_ADDR_SIZE + SELECTOR_SIZE;
|
||||
const size_t payload_size = 1 + pluginNameLength + ADDRESS_LENGTH + SELECTOR_SIZE;
|
||||
|
||||
if (dataLength <= payload_size) {
|
||||
THROW(0x6A80);
|
||||
@@ -43,7 +42,9 @@ void handleSetExternalPlugin(uint8_t p1,
|
||||
workBuffer + payload_size,
|
||||
dataLength - payload_size)) {
|
||||
PRINTF("Invalid external plugin signature %.*H\n", payload_size, workBuffer);
|
||||
#ifndef HAVE_BYPASS_SIGNATURES
|
||||
THROW(0x6A80);
|
||||
#endif
|
||||
}
|
||||
|
||||
// move on to the rest of the payload parsing
|
||||
@@ -76,8 +77,8 @@ void handleSetExternalPlugin(uint8_t p1,
|
||||
|
||||
PRINTF("Plugin found\n");
|
||||
|
||||
memmove(dataContext.tokenContext.contract_address, workBuffer, CONTRACT_ADDR_SIZE);
|
||||
workBuffer += 20;
|
||||
memmove(dataContext.tokenContext.contract_address, workBuffer, ADDRESS_LENGTH);
|
||||
workBuffer += ADDRESS_LENGTH;
|
||||
memmove(dataContext.tokenContext.method_selector, workBuffer, SELECTOR_SIZE);
|
||||
externalPluginIsSet = true;
|
||||
|
||||
|
||||
@@ -239,12 +239,32 @@ void computeFees(char *displayBuffer, uint32_t displayBufferSize) {
|
||||
displayBuffer[tickerOffset + i] = '\0';
|
||||
}
|
||||
|
||||
static void get_public_key(uint8_t *out, uint8_t outLength) {
|
||||
uint8_t privateKeyData[INT256_LENGTH] = {0};
|
||||
cx_ecfp_private_key_t privateKey = {0};
|
||||
cx_ecfp_public_key_t publicKey = {0};
|
||||
|
||||
if (outLength < ADDRESS_LENGTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
os_perso_derive_node_bip32(CX_CURVE_256K1,
|
||||
tmpCtx.transactionContext.bip32Path,
|
||||
tmpCtx.transactionContext.pathLength,
|
||||
privateKeyData,
|
||||
NULL);
|
||||
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
|
||||
cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1);
|
||||
explicit_bzero(&privateKey, sizeof(privateKey));
|
||||
explicit_bzero(privateKeyData, sizeof(privateKeyData));
|
||||
getEthAddressFromKey(&publicKey, out, &global_sha3);
|
||||
}
|
||||
|
||||
void finalizeParsing(bool direct) {
|
||||
char displayBuffer[50];
|
||||
uint8_t decimals = WEI_TO_ETHER;
|
||||
char *ticker = get_network_ticker();
|
||||
ethPluginFinalize_t pluginFinalize;
|
||||
tokenDefinition_t *token1 = NULL, *token2 = NULL;
|
||||
bool genericUI = true;
|
||||
|
||||
// Verify the chain
|
||||
@@ -272,6 +292,11 @@ void finalizeParsing(bool direct) {
|
||||
if (dataContext.tokenContext.pluginStatus >= ETH_PLUGIN_RESULT_SUCCESSFUL) {
|
||||
genericUI = false;
|
||||
eth_plugin_prepare_finalize(&pluginFinalize);
|
||||
|
||||
uint8_t msg_sender[ADDRESS_LENGTH] = {0};
|
||||
get_public_key(msg_sender, sizeof(msg_sender));
|
||||
pluginFinalize.address = msg_sender;
|
||||
|
||||
if (!eth_plugin_call(ETH_PLUGIN_FINALIZE, (void *) &pluginFinalize)) {
|
||||
PRINTF("Plugin finalize call failed\n");
|
||||
reportFinalizeError(direct);
|
||||
@@ -281,22 +306,22 @@ void finalizeParsing(bool direct) {
|
||||
}
|
||||
// Lookup tokens if requested
|
||||
ethPluginProvideToken_t pluginProvideToken;
|
||||
eth_plugin_prepare_provide_token(&pluginProvideToken);
|
||||
if ((pluginFinalize.tokenLookup1 != NULL) || (pluginFinalize.tokenLookup2 != NULL)) {
|
||||
if (pluginFinalize.tokenLookup1 != NULL) {
|
||||
PRINTF("Lookup1: %.*H\n", ADDRESS_LENGTH, pluginFinalize.tokenLookup1);
|
||||
token1 = getKnownToken(pluginFinalize.tokenLookup1);
|
||||
if (token1 != NULL) {
|
||||
PRINTF("Token1 ticker: %s\n", token1->ticker);
|
||||
pluginProvideToken.token1 = getKnownToken(pluginFinalize.tokenLookup1);
|
||||
if (pluginProvideToken.token1 != NULL) {
|
||||
PRINTF("Token1 ticker: %s\n", pluginProvideToken.token1->ticker);
|
||||
}
|
||||
}
|
||||
if (pluginFinalize.tokenLookup2 != NULL) {
|
||||
PRINTF("Lookup2: %.*H\n", ADDRESS_LENGTH, pluginFinalize.tokenLookup2);
|
||||
token2 = getKnownToken(pluginFinalize.tokenLookup2);
|
||||
if (token2 != NULL) {
|
||||
PRINTF("Token2 ticker: %s\n", token2->ticker);
|
||||
pluginProvideToken.token2 = getKnownToken(pluginFinalize.tokenLookup2);
|
||||
if (pluginProvideToken.token2 != NULL) {
|
||||
PRINTF("Token2 ticker: %s\n", pluginProvideToken.token2->ticker);
|
||||
}
|
||||
}
|
||||
eth_plugin_prepare_provide_token(&pluginProvideToken, token1, token2);
|
||||
if (eth_plugin_call(ETH_PLUGIN_PROVIDE_TOKEN, (void *) &pluginProvideToken) <=
|
||||
ETH_PLUGIN_RESULT_UNSUCCESSFUL) {
|
||||
PRINTF("Plugin provide token call failed\n");
|
||||
@@ -331,9 +356,9 @@ void finalizeParsing(bool direct) {
|
||||
tmpContent.txContent.value.length = 32;
|
||||
memmove(tmpContent.txContent.destination, pluginFinalize.address, 20);
|
||||
tmpContent.txContent.destinationLength = 20;
|
||||
if (token1 != NULL) {
|
||||
decimals = token1->decimals;
|
||||
ticker = (char *) token1->ticker;
|
||||
if (pluginProvideToken.token1 != NULL) {
|
||||
decimals = pluginProvideToken.token1->decimals;
|
||||
ticker = (char *) pluginProvideToken.token1->ticker;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user