-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: eip7702 cheatcodes multiple auth #10623
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
base: master
Are you sure you want to change the base?
Conversation
@grandizzy @mattsse @DaniPopes |
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.
thank you! good start, couple of things wrt nonce management
- here we need to handle the case when authority_acc is already in active delegations (hence nonce already incremented)
foundry/crates/cheatcodes/src/script.rs
Lines 135 to 136 in 3c0b3df
// If we don't have a nonce then use next auth account nonce. | |
authority_acc.data.info.nonce + 1 |
so we need to walk through SignedAuthorization within active_delegations
and increment the nonce of the last one for signer address (if any). For example if we have active delegations as
- alice
with nonce 1
- alice
with nonce 2
- bob
with nonce 1
if we add another delegation for alice
it should have nonce 3
- the same check should be done when we attach delegation / validate next nonce here
foundry/crates/cheatcodes/src/script.rs
Lines 161 to 163 in 3c0b3df
if authority_acc.data.info.nonce + 1 != auth.nonce { return Err("invalid nonce".into()); }
if authority_acc present in active delegation list then we need to compare with that incremented one
- since
return Err("invalid nonce".into());
it's quite useless, could you enhance this one to include expected / current nonce and authority address?
crates/cheatcodes/src/inspector.rs
Outdated
// Increment nonce to reflect the signed authorization. | ||
account.info.nonce += 1; | ||
// Increment nonce to reflect the signed authorizations. | ||
account.info.nonce += auth_count; |
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.
here we need to walk through auth list and get the last nonce of sender address (if any), then increment and set, e.g if sender is alice
with nonce 10 and auth list contains auth list as
bob
with nonce 1alice
with nonce 11bob
with nonce 2alice
with nonce 12
then we need to set here alice
's nonce to 13. If alice
not present in auth list then add 1 to its current nonce (to reflect parent tx).
alright, thanks for the feedback will patch this quickly |
hello @grandizzy I have added the fix as you described it, please let me know how it looks also fixed the clippy and fmt errors in ci |
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.
thank you! lgtm, made couple of changes to reflect increment of sender nonce only (if also in auth list), fix fmt and test
waiting for other reviews before merging
CC @klkvr could you also pls check?
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.
only have nits
crates/cheatcodes/src/script.rs
Outdated
broadcast: &Option<Broadcast>, | ||
account_nonce: u64, | ||
) -> u64 { | ||
match active_delegations.iter().rfind(|auth| auth.recover_authority().unwrap() == authority) { |
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 would prefer to avoid unwrap here as we have support for attaching arbitrary delegations and this might not be safe
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.
changed in 8e17fe8
Co-authored-by: Arsenii Kulikov <[email protected]>
fixes #10551
Add the ability to have multiple active delegations and signed auth. Also takes cares of correctly incrementing the nonce.
now works correctly