Skip to content

feat(cast): Add --bypass-sender-recovery flag to cast run for compatibility with hardhat impersonated transactions #10795

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ckoopmann
Copy link
Contributor

@ckoopmann ckoopmann commented Jun 18, 2025

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 from address will be recovered from the tx signature.

This makes cast run incompatible with impersonated transactions on rpc implementations where that assumption does not hold (i.e. when debugging tests in legacy hardhat projects).

Solution

Add a bypass-sender-recovery flag to cast run that makes it such that the from address is always set to the corresponding field on the getTransaction response from the rpc. (and not recovered from the tx signature)

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@ckoopmann
Copy link
Contributor Author

ckoopmann commented Jun 18, 2025

Note: To fully e2e test this feature you'd have to:

  • Start a hardhat rpc node (or other framework that doesn't adhere to the standard impersonation signature)
  • Submit a transaction under an impersonated signer
  • Run cast run against that tx

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.

…bility with hardhat impersonated transactions
@ckoopmann
Copy link
Contributor Author

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 getTransaction rpc call as this indicates that something is going wrong. (Originally I had a bunch of "balance too low" or "nonce too high" errors that were quite hard to trace to this root cause).

@@ -261,7 +270,11 @@ impl RunArgs {
let result = {
executor.set_trace_printer(self.trace_printer);

configure_tx_env(&mut env.as_env_mut(), &tx.inner);
configure_tx_env_assume_impersonation(
Copy link
Contributor Author

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant