-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for Celo's stateful transfer precompile #11209
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
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.
supportive, because this can serve as a reference for additional precompile support.
left some pointers, re reusing the PrecompilesMap and inject dynamically.
we can likely clean up a few more things as well,
perhaps rethink how and where we call
foundry/crates/anvil/src/eth/backend/executor.rs
Lines 337 to 345 in 79d4ab2
let mut evm = new_evm_with_inspector(&mut *self.db, &env, &mut inspector); | |
if self.odyssey { | |
inject_precompiles(&mut evm, vec![(P256VERIFY, P256VERIFY_BASE_GAS_FEE)]); | |
} | |
if let Some(factory) = &self.precompile_factory { | |
inject_precompiles(&mut evm, factory.precompiles()); | |
} |
ideally we only have these in one location
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 believe this is now redundant, because we can now dynamically inject precompiles into the regular evm with PrecompilesMap via
foundry/crates/anvil/src/evm.rs
Lines 28 to 29 in 79d4ab2
evm.precompiles_mut().apply_precompile(&addr, move |_| { | |
Some(DynPrecompile::from(move |input: PrecompileInput<'_>| func(input.data, gas))) |
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.
In its current form, this can only be used to inject stateless precompiles. The PrecompileWithAddress
that is passed into this function does not take any context/state as parameter:
pub struct PrecompileWithAddress(pub Address, pub PrecompileFn);
pub type PrecompileFn = fn(&[u8], u64) -> PrecompileResult;
But now that PrecompilesMap
has gained a settable lookup
function, I can try to use that to include a stateful precompile. Unfortunately, the EvmInternals
in the PrecompileInput
don't provide access to the journal, so that I can't use the journal's transfer
method like I do in this PR. I might be able to use load_account
instead, since it returns a mutable Account
.
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 updated the code with this approach and it looks much better now.
4465f77
to
64f1632
Compare
64f1632
to
08a0fda
Compare
I'm quite happy with the current implementation and updated the PR description. Before I add tests and/or docs, some feedback on the following points would be appreciated
|
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.
sorry for the late review
this looks complete, I'm fine with the celo flag honestly.
I do want to block this until we have
which would allow a smol simplification here as well, will take over then
whoops forgot about this, will wrap up in a bit |
closing this since #11491 was merged |
Motivation
Closes #11210
The Celo blockchain makes use of a stateful
transfer
precompile. Implementing this in Anvil allows running more of our tests in Anvil.In addition to providing this feature to Celo blockchains, it also serves as an example on how to add stateful precompiles to anvil, closing #11210
Solution
Since
inject_precompiles
does not support stateful precompiles, a Celo-specific lookup function is added to thePrecompilesMap
that provides access to thetransfer
precompile.PR Checklist