From f36cf5c10c26e610f31cb1206df2d7d3e34022b1 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Sat, 21 Jan 2017 18:00:01 +0100 Subject: [PATCH] Handle edge cases for ethereum txs. Treat the case where a field is omitted identical to the case where an empty array is given. In particular - data_length == 0 is allowed now and identical to giving no data. - nonce can be omitted to indicate nonce value 0. I still do not allow to omit gas_limit and gas_price; gas_limit cannot be zero and transactions with zero gas_price will not be mined. You can still set it explicitly to zero by giving the empty array, though. See trezor/trezor-mcu#143. --- firmware/ethereum.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/firmware/ethereum.c b/firmware/ethereum.c index 5284795b84..654fdcdef5 100644 --- a/firmware/ethereum.c +++ b/firmware/ethereum.c @@ -383,7 +383,7 @@ static void layoutEthereumFee(const uint8_t *value, uint32_t value_len, static bool ethereum_signing_check(EthereumSignTx *msg) { - if (!msg->has_nonce || !msg->has_gas_price || !msg->has_gas_limit) { + if (!msg->has_gas_price || !msg->has_gas_limit) { return false; } @@ -418,13 +418,10 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) msg->data_initial_chunk.size = 0; if (!msg->has_to) msg->to.size = 0; + if (!msg->has_nonce) + msg->nonce.size = 0; - if (msg->has_data_length) { - if (msg->data_length == 0) { - fsm_sendFailure(FailureType_Failure_Other, "Invalid data length provided"); - ethereum_signing_abort(); - return; - } + if (msg->has_data_length && msg->data_length > 0) { if (!msg->has_data_initial_chunk || msg->data_initial_chunk.size == 0) { fsm_sendFailure(FailureType_Failure_Other, "Data length provided, but no initial chunk"); ethereum_signing_abort();