-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(cast): Always use from field of getTransaction rpc response in cast run #10795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cast): Always use from field of getTransaction rpc response in cast run #10795
Conversation
cddd4da to
a66953c
Compare
|
Note: To fully e2e test this feature you'd have to:
I did this locally but wasn't sure if / how to add this to the CI. Lmk if this is critical (or you have a simpler idea of how to test this) and I will look into it further. |
a66953c to
b72ba35
Compare
|
Furthermore we might want to add a warning when this flag is not set and the recovered from address differs from the one returned by the |
crates/cast/src/cmd/run.rs
Outdated
| executor.set_trace_printer(self.trace_printer); | ||
|
|
||
| configure_tx_env(&mut env.as_env_mut(), &tx.inner); | ||
| configure_tx_env_assume_impersonation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that naming is not entirely consistent here. Elsewhere i call it "bypass sender recovery" whereas here i call it "assume impersonation", happy to change it to either one, or any other naming that improves readability / clairity.
mattsse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comes up from time to time.
I think instead of doing this we should just always use the from field received in the tx rpc response?
crates/evm/core/src/utils.rs
Outdated
| pub fn configure_tx_env(env: &mut EnvMut<'_>, tx: &Transaction<AnyTxEnvelope>) { | ||
| let impersonated_from = is_impersonated_tx(&tx.inner).then_some(tx.from()); | ||
| configure_tx_env_inner(env, &tx.clone(), impersonated_from); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after reviewing this again, I tink we should actually just always use the rpc response from value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
I think when running cast run at least it is fine to trust the "getTransaction" response coming back from the RPC.
I only added the additional flag to keep the default behaviour backwards compatible assuming that there are some users / use cases that depend on the transaction signature being "verified" by recovering the sender from it. Otherwise why was it done this way in the first place ?
Anyway, I will adjust this PR to remove the additional flag and just always use the rpc response as suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted to always use the rpc "from" field in cast run: 5d0c3e6
…bility with hardhat impersonated transactions
b72ba35 to
eba043d
Compare
| let from = tx.from(); | ||
| if let AnyTxEnvelope::Ethereum(tx) = &tx.inner.inner() { | ||
| configure_tx_req_env(env, &tx.clone().into(), impersonated_from).expect("cannot fail"); | ||
| configure_tx_req_env(env, &tx.clone().into(), Some(from)).expect("cannot fail"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I didn't change the configure_tx_req_env function signature or implementation to avoid having to change logic in other places where it is used such as:
I could easily change the argument name from impersonated_from to something like overwrite_from though to indicate that this value is not only used for impersonated tx's anymore.
|
Clippy failures seem unrelated to my changes so will just ignore them for now. |
mattsse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Motivation
Currently the code assumes that any impersonated transaction has been signed with a given constant key. (r=1, s=1). If this check is not passed then the
fromaddress will be recovered from the tx signature.This makes
cast runincompatible with impersonated transactions on rpc implementations where that assumption does not hold (i.e. when debugging tests in legacy hardhat projects).Solution
Add abypass-sender-recoveryflag tocast runthat makes it such that thefromaddress is always set to the corresponding field on thegetTransactionresponse from the rpc. (and not recovered from the tx signature)Always use the from address as returned by the rpc in the
getTransactionresponse.PR Checklist