Merge remote-tracking branch 'origin' into bsc

This commit is contained in:
pscott
2021-07-27 11:14:12 +02:00
76 changed files with 843 additions and 285 deletions

View File

@@ -4,7 +4,7 @@
#include "feature_getEth2PublicKey.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_eth2_address_ok(__attribute__((unused)) const bagl_element_t *e) {
uint32_t tx = set_result_get_eth2_publicKey();
G_io_apdu_buffer[tx++] = 0x90;
G_io_apdu_buffer[tx++] = 0x00;

View File

@@ -2,7 +2,7 @@
#include "feature_getPublicKey.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_address_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_address_ok(__attribute__((unused)) const bagl_element_t *e) {
uint32_t tx = set_result_get_publicKey();
G_io_apdu_buffer[tx++] = 0x90;
G_io_apdu_buffer[tx++] = 0x00;
@@ -14,7 +14,7 @@ unsigned int io_seproxyhal_touch_address_ok(const bagl_element_t *e) {
return 0; // do not redraw the widget
}
unsigned int io_seproxyhal_touch_address_cancel(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_address_cancel(__attribute__((unused)) const bagl_element_t *e) {
G_io_apdu_buffer[0] = 0x69;
G_io_apdu_buffer[1] = 0x85;
reset_app_context();

View File

@@ -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);
@@ -102,7 +104,7 @@ void handleProvideErc20TokenInformation(uint8_t p1,
uint8_t *workBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
__attribute__((unused)) unsigned int *tx) {
UNUSED(p1);
UNUSED(p2);
UNUSED(flags);
@@ -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

View File

@@ -7,8 +7,8 @@ void handleSetEth2WithdrawalIndex(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
__attribute__((unused)) unsigned int *flags,
__attribute__((unused)) unsigned int *tx) {
if (dataLength != 4) {
THROW(0x6700);
}

View File

@@ -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
@@ -65,8 +66,8 @@ void handleSetExternalPlugin(uint8_t p1,
CATCH_OTHER(e) {
PRINTF("%s external plugin is not present\n", dataContext.tokenContext.pluginName);
memset(dataContext.tokenContext.pluginName,
sizeof(dataContext.tokenContext.pluginName),
0);
0,
sizeof(dataContext.tokenContext.pluginName));
THROW(0x6984);
}
FINALLY {
@@ -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;

View File

@@ -3,7 +3,7 @@
#include "utils.h"
#include "ui_flow.h"
static const char const SIGN_MAGIC[] =
static const char SIGN_MAGIC[] =
"\x19"
"Ethereum Signed Message:\n";

View File

@@ -1,7 +1,7 @@
#include "shared_context.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_signMessage_ok(__attribute__((unused)) const bagl_element_t *e) {
uint8_t privateKeyData[INT256_LENGTH];
uint8_t signature[100];
uint8_t signatureLength;
@@ -46,7 +46,8 @@ unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e) {
return 0; // do not redraw the widget
}
unsigned int io_seproxyhal_touch_signMessage_cancel(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_signMessage_cancel(__attribute__((unused))
const bagl_element_t *e) {
reset_app_context();
G_io_apdu_buffer[0] = 0x69;
G_io_apdu_buffer[1] = 0x85;

View File

@@ -1,9 +1,10 @@
#include "shared_context.h"
#include "ui_callbacks.h"
static const uint8_t const EIP_712_MAGIC[] = {0x19, 0x01};
static const uint8_t EIP_712_MAGIC[] = {0x19, 0x01};
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_signMessage712_v0_ok(__attribute__((unused))
const bagl_element_t *e) {
uint8_t privateKeyData[INT256_LENGTH];
uint8_t hash[INT256_LENGTH];
uint8_t signature[100];
@@ -70,7 +71,8 @@ unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e) {
return 0; // do not redraw the widget
}
unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_signMessage712_v0_cancel(__attribute__((unused))
const bagl_element_t *e) {
reset_app_context();
G_io_apdu_buffer[0] = 0x69;
G_io_apdu_buffer[1] = 0x85;

View File

@@ -2,3 +2,4 @@
customStatus_e customProcessor(txContext_t *context);
void finalizeParsing(bool direct);
void ux_approve_tx(bool dataPresent);

View File

@@ -2,10 +2,12 @@
#include "utils.h"
#include "ui_callbacks.h"
#include "ui_flow.h"
#include "feature_signTx.h"
#ifdef HAVE_STARKWARE
#include "stark_utils.h"
#endif
#include "eth_plugin_handler.h"
#include "network.h"
#define ERR_SILENT_MODE_CHECK_FAILED 0x6001
@@ -195,7 +197,7 @@ void reportFinalizeError(bool direct) {
void computeFees(char *displayBuffer, uint32_t displayBufferSize) {
uint256_t gasPrice, startGas, uint256;
uint8_t *feeTicker = (uint8_t *) PIC(chainConfig->coinName);
char *feeTicker = get_network_ticker();
uint8_t tickerOffset = 0;
uint32_t i;
@@ -237,28 +239,37 @@ 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;
uint8_t *ticker = (uint8_t *) PIC(chainConfig->coinName);
char *ticker = get_network_ticker();
ethPluginFinalize_t pluginFinalize;
tokenDefinition_t *token1 = NULL, *token2 = NULL;
bool genericUI = true;
// Verify the chain
if (chainConfig->chainId != 0) {
uint32_t id = 0;
if (txContext.txType == LEGACY) {
id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
} else if (txContext.txType == EIP2930) {
id = u32_from_BE(txContext.content->chainID.value,
txContext.content->chainID.length,
false);
} else {
PRINTF("TxType `%u` not supported while checking for chainID\n", txContext.txType);
return;
}
if (chainConfig->chainId != ETHEREUM_MAINNET_CHAINID) {
uint32_t id = get_chain_id();
if (chainConfig->chainId != id) {
PRINTF("Invalid chainID %u expected %u\n", id, chainConfig->chainId);
@@ -281,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);
@@ -290,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");
@@ -340,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 = token1->ticker;
if (pluginProvideToken.token1 != NULL) {
decimals = pluginProvideToken.token1->decimals;
ticker = (char *) pluginProvideToken.token1->ticker;
}
break;
default:
@@ -404,26 +420,22 @@ void finalizeParsing(bool direct) {
// Prepare chainID field
if (genericUI) {
if (txContext.txType == LEGACY) {
uint32_t id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
PRINTF("Chain ID: %u\n", id);
uint8_t res =
snprintf(strings.common.chainID, sizeof(strings.common.chainID), "%d", id);
if (res >= sizeof(strings.common.chainID)) {
char *name = get_network_name();
if (name == NULL) {
// No network name found so simply copy the chain ID as the network name.
uint32_t chain_id = get_chain_id();
uint8_t res = snprintf(strings.common.network_name,
sizeof(strings.common.network_name),
"%d",
chain_id);
if (res >= sizeof(strings.common.network_name)) {
// If the return value is higher or equal to the size passed in as parameter, then
// the output was truncated. Return the appropriate error code.
THROW(0x6502);
}
} else if (txContext.txType == EIP2930) {
uint256_t chainID;
convertUint256BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length,
&chainID);
tostring256(&chainID, 10, displayBuffer, sizeof(displayBuffer));
strncpy(strings.common.chainID, displayBuffer, sizeof(strings.common.chainID));
} else {
PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType);
return;
// Network name found, simply copy it.
strncpy(strings.common.network_name, name, sizeof(strings.common.network_name));
}
}

View File

@@ -2,7 +2,7 @@
#include "utils.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_tx_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_element_t *e) {
uint8_t privateKeyData[INT256_LENGTH];
uint8_t signature[100];
uint8_t signatureLength;
@@ -58,7 +58,7 @@ unsigned int io_seproxyhal_touch_tx_ok(const bagl_element_t *e) {
return 0; // do not redraw the widget
}
unsigned int io_seproxyhal_touch_tx_cancel(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_tx_cancel(__attribute__((unused)) const bagl_element_t *e) {
reset_app_context();
G_io_apdu_buffer[0] = 0x69;
G_io_apdu_buffer[1] = 0x85;
@@ -69,7 +69,7 @@ unsigned int io_seproxyhal_touch_tx_cancel(const bagl_element_t *e) {
return 0; // do not redraw the widget
}
unsigned int io_seproxyhal_touch_data_ok(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_data_ok(__attribute__((unused)) const bagl_element_t *e) {
parserStatus_e txResult = USTREAM_FINISHED;
txResult = continueTx(&txContext);
switch (txResult) {
@@ -100,7 +100,7 @@ unsigned int io_seproxyhal_touch_data_ok(const bagl_element_t *e) {
return 0;
}
unsigned int io_seproxyhal_touch_data_cancel(const bagl_element_t *e) {
unsigned int io_seproxyhal_touch_data_cancel(__attribute__((unused)) const bagl_element_t *e) {
reset_app_context();
io_seproxyhal_send_status(0x6985);
// Display back the original UX

View File

@@ -2,6 +2,8 @@
#include "ui_callbacks.h"
#include "chainConfig.h"
#include "utils.h"
#include "feature_signTx.h"
#include "network.h"
// clang-format off
UX_STEP_NOCB(
@@ -116,11 +118,11 @@ UX_STEP_NOCB(
.text = strings.common.maxFee,
});
UX_STEP_NOCB(
ux_approval_chainid_step,
ux_approval_network_step,
bnnn_paging,
{
.title = "Chain ID",
.text = strings.common.chainID,
.title = "Network",
.text = strings.common.network_name,
});
UX_STEP_CB(
ux_approval_accept_step,
@@ -171,18 +173,9 @@ void ux_approve_tx(bool dataPresent) {
ux_approval_tx_flow_[step++] = &ux_approval_nonce_step;
}
uint32_t id;
if (txContext.txType == LEGACY) {
id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
} else if (txContext.txType == EIP2930) {
id =
u32_from_BE(txContext.content->chainID.value, txContext.content->chainID.length, false);
} else {
PRINTF("TxType `%u` not supported while preparing to approve tx\n", txContext.txType);
THROW(0x6501);
}
if (id != ETHEREUM_MAINNET_CHAINID) {
ux_approval_tx_flow_[step++] = &ux_approval_chainid_step;
uint32_t chain_id = get_chain_id();
if (chainConfig->chainId == ETHEREUM_MAINNET_CHAINID && chain_id != chainConfig->chainId) {
ux_approval_tx_flow_[step++] = &ux_approval_network_step;
}
ux_approval_tx_flow_[step++] = &ux_approval_fees_step;
ux_approval_tx_flow_[step++] = &ux_approval_accept_step;

View File

@@ -4,7 +4,7 @@
#include "ui_callbacks.h"
#include "feature_stark_getPublicKey.h"
unsigned int io_seproxyhal_touch_stark_pubkey_ok(const bagl_element_t *e) {
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;

View File

@@ -5,11 +5,11 @@
#include "ui_flow.h"
void handleStarkwareProvideQuantum(uint8_t p1,
uint8_t p2,
__attribute__((unused)) uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
__attribute__((unused)) unsigned int *flags,
__attribute__((unused)) unsigned int *tx) {
size_t i = 0;
uint8_t expectedDataSize = 20 + 32;
uint8_t addressZero = 0;

View File

@@ -16,7 +16,7 @@ void handleStarkwareSignMessage(uint8_t p1,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
__attribute__((unused)) unsigned int *tx) {
uint8_t privateKeyData[INT256_LENGTH];
uint32_t i;
uint8_t bip32PathLength = *(dataBuffer);

View File

@@ -4,7 +4,7 @@
#include "stark_utils.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_stark_ok(const bagl_element_t *e) {
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;

View File

@@ -11,7 +11,7 @@ void handleStarkwareUnsafeSign(uint8_t p1,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
__attribute__((unused)) unsigned int *tx) {
uint32_t i;
uint8_t privateKeyData[INT256_LENGTH];
cx_ecfp_public_key_t publicKey;

View File

@@ -4,7 +4,8 @@
#include "stark_utils.h"
#include "ui_callbacks.h"
unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(const bagl_element_t *e) {
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];