-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
add: resetNonce cheatcode #5033
Conversation
why does or is this for convenience? |
@MATTSE
|
I like this approach: most users will only need |
@mds1 I thought about
Honestly (3) was the biggest factor here. As for (2)... well, evidently no one saw an usecase for setting the nonce to zero before either so 🤷 not a big factor there. (1) is of course not really important. |
@joaquinlpereyra yea that's all fair, I'm down to move forward with edit: ah I see @mattsse just commented about preferring the other approach 😅 ultimately I'm pretty indifferent here so up to you all |
I see, I'd like to go with @mds1 suggestion: Add a new cheatcode that "unsafely" sets the nonce, this is basically decreasing the nonce, so perhaps the name should reflect this; like |
OK! Done. There are a few tests failing (they come and go 👀 ) but I don't think they are related to this functionality. Lemme know if they are. Edit: found some issues, already pushing a new commit :) |
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!
ty for the tests!
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.
Looks good! Just some comments on the comments.
Might also need to run cargo +nightly fmt
& cargo +nightly clippy
and fix linting warnings to make tests pass
@Evalir Awesome, thanks for spotting those. I've fixed the comments and ran the nightly linters ✔️ |
failing test unrelated @joaquinlpereyra mind adding them to forge-std next: foundry-rs/forge-std#390 |
data.db, | ||
inner.0, | ||
|account| -> Result { | ||
account.info.nonce = 0; |
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.
One thing I just thought of is that contract nonces start at 1, so we probably need to check if the account has code and then set it to 1 or 0 based on that: https://eips.ethereum.org/EIPS/eip-161
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.
Pulled into #5043 to track
Motivation
Right now, it is impossible to reset the nonce of an account to zero. Surprisingly, this is the only thing missing to be able to mimic
SELFDESTRUCT
almost to the letter. This has been a complaint in the past and it is also giving us trouble when trying to reproduce some advanced attacks on learn-evm-attacks.Solution
Add a very simple
resetNonce
cheatcode to Foundry. This cheatcode simply resets an account nonce to zero. There are already other cheatcodes that modify the nonce of an account, so this one should not be particularly controversial. A new cheatcoderesetNonce
is added instead of modifying the requirement ofsetNonce
to be only incremental to maintain backwards compatibility and also to make the new behavior explicit.There's a companion PR on Forge-std which adds a
destroyAccount
cheatcode.