You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
SignerMiddleware::send_transaction() sends a transaction from it's signer regardless of the from field in the TransactionRequest.
The from address gets replaced with the signer address in sign_transaction(). I think that makes sense in the context of sign_transaction(), but it would be more intuitive if send_transaction() made an effort to preserve the TransactionRequest.
send_transaction honors the from field. If it receives a transaction with a from field set to an address other than the signer, it delegates to self.inner.send_transaction(). sign_transaction() in this case would either be unchanged or would return an error if asked to sign a transaction with from != self.address.
Test cases
The first shows the behavior in send_transaction() and the second shows sign_transaction(). If you put these into the tests mod in signer.rs they should be runnable with cargo test signer.
#[tokio::test]asyncfnsend_transaction_drops_from_field(){use ethers_core::utils::Ganache;// launch ganachelet ganache = Ganache::new().spawn();// grab 2 walletslet signer:LocalWallet = ganache.keys()[0].clone().into();let from:LocalWallet = ganache.keys()[1].clone().into();// connect to the networklet provider = Provider::try_from(ganache.endpoint()).unwrap();let provider = SignerMiddleware::new(provider, signer.clone());// craft the transactionlet request = TransactionRequest::new();let request = request.from(from.address());// send it!let receipt = provider
.send_transaction(request.clone(),None).await.unwrap().await.unwrap().unwrap();// retrieve the transaction that was sentlet sent_tx = provider
.get_transaction(receipt.transaction_hash).await.unwrap().unwrap();// panicsassert_eq!(sent_tx.from, request.from.unwrap());}#[tokio::test]asyncfnsign_transaction_accepts_from_not_signer(){use ethers_core::types::Address;// build a transaction with a from fieldlet from = "0x863DF6BFa4469f3ead0bE8f9F2AAE51c91A907b4".parse::<Address>().unwrap();let tx = TransactionRequest::new().nonce(0).gas_price(0).gas(0);let tx = tx.from(from);// new SignerMiddleware with signer != from field of the transactionlet provider = Provider::try_from("http://localhost:8545").unwrap();let key = LocalWallet::new(&mut rand::thread_rng());let client = SignerMiddleware::new(provider, key);// sign the transactionlet signed_tx = client.sign_transaction(tx.clone()).await.unwrap();// panicsassert_eq!(signed_tx.from, from);}
The text was updated successfully, but these errors were encountered:
Version
Latest master branch (985509a).
Description
Current Behavior
SignerMiddleware::send_transaction()
sends a transaction from it's signer regardless of thefrom
field in theTransactionRequest
.The
from
address gets replaced with the signer address insign_transaction()
. I think that makes sense in the context ofsign_transaction()
, but it would be more intuitive ifsend_transaction()
made an effort to preserve theTransactionRequest
.ethers-rs/ethers-middleware/src/signer.rs
Lines 147 to 150 in 985509a
Expected Behavior
I would expect something like the following:
send_transaction
honors thefrom
field. If it receives a transaction with a from field set to an address other than the signer, it delegates toself.inner.send_transaction()
.sign_transaction()
in this case would either be unchanged or would return an error if asked to sign a transaction withfrom != self.address
.Test cases
The first shows the behavior in
send_transaction()
and the second showssign_transaction()
. If you put these into the tests mod insigner.rs
they should be runnable withcargo test signer
.The text was updated successfully, but these errors were encountered: