1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

Wanchain support (#313)

This commit is contained in:
Peter van Mourik 2018-05-02 16:33:22 +02:00 committed by Pavol Rusnak
parent a1cde6e0ce
commit 78ece6631f

View File

@ -43,6 +43,7 @@ static uint32_t data_total, data_left;
static EthereumTxRequest msg_tx_request;
static CONFIDENTIAL uint8_t privkey[32];
static uint32_t chain_id;
static uint32_t tx_type;
struct SHA3_CTX keccak_ctx;
static inline void hash_data(const uint8_t *buf, size_t size)
@ -180,7 +181,7 @@ static void send_signature(void)
layoutProgress(_("Signing"), 1000);
/* eip-155 replay protection */
if (chain_id != 0) {
if (chain_id) {
/* hash v=chain_id, r=0, s=0 */
hash_rlp_number(chain_id);
hash_rlp_length(0, 0);
@ -240,19 +241,23 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
suffix = " Wei";
decimals = 0;
} else {
switch (chain_id) {
case 1: suffix = " ETH"; break; // Ethereum Mainnet
case 61: suffix = " ETC"; break; // Ethereum Classic Mainnet
case 62: suffix = " tETC"; break; // Ethereum Classic Testnet
case 30: suffix = " RSK"; break; // Rootstock Mainnet
case 31: suffix = " tRSK"; break; // Rootstock Testnet
case 3: suffix = " tETH"; break; // Ethereum Testnet: Ropsten
case 4: suffix = " tETH"; break; // Ethereum Testnet: Rinkeby
case 42: suffix = " tETH"; break; // Ethereum Testnet: Kovan
case 2: suffix = " EXP"; break; // Expanse
case 8: suffix = " UBQ"; break; // UBIQ
default: suffix = " UNKN"; break; // unknown chain
}
if (tx_type == 1 || tx_type == 6) {
suffix = " WAN";
} else {
switch (chain_id) {
case 1: suffix = " ETH"; break; // Ethereum Mainnet
case 61: suffix = " ETC"; break; // Ethereum Classic Mainnet
case 62: suffix = " tETC"; break; // Ethereum Classic Testnet
case 30: suffix = " RSK"; break; // Rootstock Mainnet
case 31: suffix = " tRSK"; break; // Rootstock Testnet
case 3: suffix = " tETH"; break; // Ethereum Testnet: Ropsten
case 4: suffix = " tETH"; break; // Ethereum Testnet: Rinkeby
case 42: suffix = " tETH"; break; // Ethereum Testnet: Kovan
case 2: suffix = " EXP"; break; // Expanse
case 8: suffix = " UBQ"; break; // UBIQ
default: suffix = " UNKN"; break; // unknown chain
}
}
}
bn_format(amnt, NULL, suffix, decimals, 0, false, buf, buflen);
}
@ -450,6 +455,19 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
chain_id = 0;
}
/* Wanchain txtype */
if (msg->has_tx_type) {
if (msg->tx_type == 1 || msg->tx_type == 6) {
tx_type = msg->tx_type;
} else {
fsm_sendFailure(FailureType_Failure_DataError, _("Txtype out of bounds"));
ethereum_signing_abort();
return;
}
} else {
tx_type = 0;
}
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_DataError, _("Data length provided, but no initial chunk"));
@ -530,6 +548,9 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
rlp_length += rlp_calculate_length(msg->to.size, msg->to.bytes[0]);
rlp_length += rlp_calculate_length(msg->value.size, msg->value.bytes[0]);
rlp_length += rlp_calculate_length(data_total, msg->data_initial_chunk.bytes[0]);
if (tx_type) {
rlp_length += rlp_calculate_length(1, tx_type);
}
if (chain_id) {
rlp_length += rlp_calculate_length(1, chain_id);
rlp_length += rlp_calculate_length(0, 0);
@ -541,6 +562,9 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
layoutProgress(_("Signing"), 100);
if (tx_type) {
hash_rlp_number(tx_type);
}
hash_rlp_field(msg->nonce.bytes, msg->nonce.size);
hash_rlp_field(msg->gas_price.bytes, msg->gas_price.size);
hash_rlp_field(msg->gas_limit.bytes, msg->gas_limit.size);