-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: master
Are you sure you want to change the base?
Conversation
if is_default_anvil_acc(address) && code.starts_with(&[0xef, 0x01, 0x00]) { | ||
return Ok(Bytes::new()) | ||
} | ||
return Ok(code) |
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.
Returns empty bytes in case of eth_getCode
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?) |
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.
Applies StateOverrides to eth_call request that reset the account code
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()) |
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.
wouldn't be better to return the in memory self.backend.get_code(address, Some(block_request)).await
one?
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 thefork_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 ofeth_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