-
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
fix(anvil): Fix AccessList generation #2839
fix(anvil): Fix AccessList generation #2839
Conversation
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.
thanks so much, this is indefinitely better than before.
Accesslists are a bit too cursed for me -.-
love the tracer impl.
only have smol nits
anvil/src/eth/backend/mem/mod.rs
Outdated
where | ||
D: DatabaseRef, | ||
{ | ||
) -> Result<Env, BlockchainError> { |
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.
can this even return an error?
I couldn't find any ?
, so perhaps we just return the Env
?
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.
Definitely! I thought this was the kind of stuff clippy
would catch...
It's done :)
anvil/src/eth/api.rs
Outdated
let access_list = | ||
request.access_list.take().expect("the access_list was set above"); |
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.
can just flip the clone here?
clone access_list.0
at L800, so we don't need to unwrap here?
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.
Yep, was trying to save a clone
but it shouldn't matter that much here...
54818ae
to
da0a4ec
Compare
Ehe, yeah I agree, AccessLists are actually really not trivial, and there is no official spec on how to generate them... Comparing my approach here with Geth's, they are running the access list generation in an infinite loop until there is no more changes; that's wild!! Also another thing, there seems to be a few tests failing, and this is because The issue is that the So I'm not sure what the approach should be here:
I'd go with (2), but then there's not real way to compare gas usages, except by tracing the transaction I guess. WDYT? |
right, the geth docs even say
so I guess the safe way would be to always estimate if gas is not set, so your option 2 there's also: which gives some reason as to not use accesslist at all cc @gakonst |
Yeah I think the auto access-list generation should be disabled in And BTW (to address a point in #2330), access-list can definitely save gas even if the calling contract is doing [1, 23] storage accesses, if it itself calls another contract. |
needs ethers bump, |
da0a4ec
to
35d463a
Compare
Included #2872 to make sure the tests pass |
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.
awesome, ty so much
The main purpose of Access Lists is not to save gas, but to protect from bricking contracts post EIP-2929. As the EIP motivation statement puts it:
Thank you for fixing this @ngotchac and for attending to and reviewing this @mattsse |
* chore: latest ethers-solc (bumped up svm versions) * fix(anvil): Fix AccessList generation Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com>
Motivation
The generated AccessList via
createAccessList
RPC call wasn't actually correct:coinbase
address (for which info was fetched, and thus added to the state diff)to
address whether storage was read or notrevm
implementation regarding the returned state-diff, which returned read accounts even though they weren't changedSolution
I implemented a custom tracer which checks for some opcodes was address/storage slot will be read/written to.
The trace was implemented based on Geth's one: https://github.com/ethereum/go-ethereum/blob/23ac8df15302bbde098cab6d711abdd24843d66a/eth/tracers/logger/access_list_tracer.go#L140-L160
It also returns the second execution's gas-used, instead of a gas estimation (which should be higher than the gas-used, since it has to include refunds).