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.
This commit is contained in:
Jochen Hoenicke 2017-01-21 18:00:01 +01:00 committed by Pavol Rusnak
parent 505df38a84
commit f36cf5c10c
1 changed files with 4 additions and 7 deletions

View File

@ -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();