mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-09 17:48:47 +00:00
Wanchain support (#313)
This commit is contained in:
parent
a1cde6e0ce
commit
78ece6631f
@ -43,6 +43,7 @@ static uint32_t data_total, data_left;
|
|||||||
static EthereumTxRequest msg_tx_request;
|
static EthereumTxRequest msg_tx_request;
|
||||||
static CONFIDENTIAL uint8_t privkey[32];
|
static CONFIDENTIAL uint8_t privkey[32];
|
||||||
static uint32_t chain_id;
|
static uint32_t chain_id;
|
||||||
|
static uint32_t tx_type;
|
||||||
struct SHA3_CTX keccak_ctx;
|
struct SHA3_CTX keccak_ctx;
|
||||||
|
|
||||||
static inline void hash_data(const uint8_t *buf, size_t size)
|
static inline void hash_data(const uint8_t *buf, size_t size)
|
||||||
@ -180,7 +181,7 @@ static void send_signature(void)
|
|||||||
layoutProgress(_("Signing"), 1000);
|
layoutProgress(_("Signing"), 1000);
|
||||||
|
|
||||||
/* eip-155 replay protection */
|
/* eip-155 replay protection */
|
||||||
if (chain_id != 0) {
|
if (chain_id) {
|
||||||
/* hash v=chain_id, r=0, s=0 */
|
/* hash v=chain_id, r=0, s=0 */
|
||||||
hash_rlp_number(chain_id);
|
hash_rlp_number(chain_id);
|
||||||
hash_rlp_length(0, 0);
|
hash_rlp_length(0, 0);
|
||||||
@ -239,6 +240,9 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
|
|||||||
if (bn_is_less(amnt, &bn1e9)) {
|
if (bn_is_less(amnt, &bn1e9)) {
|
||||||
suffix = " Wei";
|
suffix = " Wei";
|
||||||
decimals = 0;
|
decimals = 0;
|
||||||
|
} else {
|
||||||
|
if (tx_type == 1 || tx_type == 6) {
|
||||||
|
suffix = " WAN";
|
||||||
} else {
|
} else {
|
||||||
switch (chain_id) {
|
switch (chain_id) {
|
||||||
case 1: suffix = " ETH"; break; // Ethereum Mainnet
|
case 1: suffix = " ETH"; break; // Ethereum Mainnet
|
||||||
@ -254,6 +258,7 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
|
|||||||
default: suffix = " UNKN"; break; // unknown chain
|
default: suffix = " UNKN"; break; // unknown chain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bn_format(amnt, NULL, suffix, decimals, 0, false, buf, buflen);
|
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;
|
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_length && msg->data_length > 0) {
|
||||||
if (!msg->has_data_initial_chunk || msg->data_initial_chunk.size == 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"));
|
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->to.size, msg->to.bytes[0]);
|
||||||
rlp_length += rlp_calculate_length(msg->value.size, msg->value.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]);
|
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) {
|
if (chain_id) {
|
||||||
rlp_length += rlp_calculate_length(1, chain_id);
|
rlp_length += rlp_calculate_length(1, chain_id);
|
||||||
rlp_length += rlp_calculate_length(0, 0);
|
rlp_length += rlp_calculate_length(0, 0);
|
||||||
@ -541,6 +562,9 @@ void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node)
|
|||||||
|
|
||||||
layoutProgress(_("Signing"), 100);
|
layoutProgress(_("Signing"), 100);
|
||||||
|
|
||||||
|
if (tx_type) {
|
||||||
|
hash_rlp_number(tx_type);
|
||||||
|
}
|
||||||
hash_rlp_field(msg->nonce.bytes, msg->nonce.size);
|
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_price.bytes, msg->gas_price.size);
|
||||||
hash_rlp_field(msg->gas_limit.bytes, msg->gas_limit.size);
|
hash_rlp_field(msg->gas_limit.bytes, msg->gas_limit.size);
|
||||||
|
Loading…
Reference in New Issue
Block a user