Skip to content

wip: clear delegations for anvil default accounts #10747

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Jun 10, 2025

Motivation

Since the advent of 7702, anvil default accounts have been delegated to drainers such as https://etherscan.io/address/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266#authlist7702

This spoils DevX when users are running anvil in fork mode and use one of the default accounts.

This affects RPC calls such as eth_getCode, eth_call, and any other account-related calls.

Solution

WIP

This is encountered only when the RPC request block_number predates the fork_block_number. Hence, every time we encounter such a scenario involving one of the default accounts, we can manually reset the code wiping the delegation or apply state overrides in case of eth_call.

Still some cleanup to do and also apply this to other RPC methods, but opening this for feedback on the approach.

cc @mattsse @grandizzy

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Comment on lines +913 to +916
if is_default_anvil_acc(address) && code.starts_with(&[0xef, 0x01, 0x00]) {
return Ok(Bytes::new())
}
return Ok(code)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns empty bytes in case of eth_getCode

Comment on lines +204 to +215
if let Some(to) = request.to() {
if is_default_anvil_acc(to) {
// Applies StateOverride for default anvil account to wipe the delegation set on the
// forked chain.
let acc_override =
AccountOverride { code: Some(Bytes::new()), state: None, ..Default::default() };
return Ok(self
.provider()
.call(request.clone())
.block(block.into())
.account_override(to, acc_override)
.await?)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies StateOverrides to eth_call request that reset the account code

@jenpaff jenpaff moved this to In Progress in Foundry Jun 10, 2025
@jenpaff jenpaff added this to the v1.3.0 milestone Jun 10, 2025
let code = fork.get_code(address, number).await?;
// Resets the 7702 delegation code set on the default anvil account
if is_default_anvil_acc(address) && code.starts_with(&[0xef, 0x01, 0x00]) {
return Ok(Bytes::new())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't be better to return the in memory self.backend.get_code(address, Some(block_request)).await one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants