From 5bf3f7354850dc2361c72bd3376c1cf36e460d63 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Wed, 15 Dec 2021 19:52:06 +0200 Subject: [PATCH] fix: contract creation on trezor (#695) * fix contract creation on trezor * handle when _to_ param is an empty string * return TrezorError when receiving an ENS name * fix typo --- ethers-signers/src/trezor/app.rs | 25 +++++++++++++++++++++++-- ethers-signers/src/trezor/types.rs | 14 ++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ethers-signers/src/trezor/app.rs b/ethers-signers/src/trezor/app.rs index 2d7a0455..8434857e 100644 --- a/ethers-signers/src/trezor/app.rs +++ b/ethers-signers/src/trezor/app.rs @@ -264,13 +264,34 @@ mod tests { #[tokio::test] #[ignore] async fn test_sign_empty_txes() { + // Contract creation (empty `to`), requires data. + // To test without the data field, we need to specify a `to` address. let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap(); { - let tx_req = Eip1559TransactionRequest::new().into(); + let tx_req = Eip1559TransactionRequest::new() + .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::
().unwrap()) + .into(); let tx = trezor.sign_transaction(&tx_req).await.unwrap(); } { - let tx_req = TransactionRequest::new().into(); + let tx_req = TransactionRequest::new() + .to("2ed7afa17473e17ac59908f088b4371d28585476".parse::().unwrap()) + .into(); + let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + } + + let data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(); + + // Contract creation (empty `to`, with data) should show on the trezor device as: + // ` "0 Wei ETH + // ` new contract?" + let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap(); + { + let tx_req = Eip1559TransactionRequest::new().data(data.clone()).into(); + let tx = trezor.sign_transaction(&tx_req).await.unwrap(); + } + { + let tx_req = TransactionRequest::new().data(data.clone()).into(); let tx = trezor.sign_transaction(&tx_req).await.unwrap(); } } diff --git a/ethers-signers/src/trezor/types.rs b/ethers-signers/src/trezor/types.rs index a3ec935c..e6881856 100644 --- a/ethers-signers/src/trezor/types.rs +++ b/ethers-signers/src/trezor/types.rs @@ -4,7 +4,7 @@ use std::fmt; use thiserror::Error; -use ethers_core::types::{transaction::eip2718::TypedTransaction, NameOrAddress, H160, U256}; +use ethers_core::types::{transaction::eip2718::TypedTransaction, NameOrAddress, U256}; use trezor_client::client::AccessListItem as Trezor_AccessListItem; #[derive(Clone, Debug)] @@ -49,6 +49,8 @@ pub enum TrezorError { /// Error when signing EIP712 struct with not compatible Trezor ETH app #[error("Trezor ethereum app requires at least version: {0:?}")] UnsupportedFirmwareVersion(String), + #[error("Does not support ENS.")] + NoENSSupport, } /// Trezor Transaction Struct @@ -72,9 +74,13 @@ impl TrezorTransaction { } pub fn load(tx: &TypedTransaction) -> Result