feat: stateful precompiles + allowlist hooks #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why this should be merged
Introduces:
CanExecuteTransaction
andCanCreateContract
hooks (equivalent tosubnet-evm
allowlists).a. Although this makes for a larger PR than I'd have liked, I thought it was important to demonstrate how the equivalent
ava-labs/subnet-evm
functionality can be achieved.How this works
Hooks
CanExecuteTransaction()
is called fromcore.StateTransition.TransitionDb()
andCanCreateContract()
is called fromvm.EVM.create()
(the common path forEVM.Create()
andEVM.Create2()
). If they return nil then functionality continues as normal, otherwise their errors are propagated.Stateful precompiles
The PR introduces into
core/vm
:Note that the constructor returns the same interface as ordinary precompiles, allowing the returned value to use regular geth plumbing (including the existing
PrecompileOverride
hook). However, the concrete type that it returns has special-case handling when running precompiles.How this was tested
Both hooks result in unhappy paths when working correctly so their integration tests assert the equality of returned errors, which carry all externally injected arguments to demonstrate correct plumbing.
CanExecuteTransaction
is tested viacore.ApplyMessage()
whileCanCreateContract
is tested viaEVM.Create()
andEVM.Create2()
.Stateful precompiles have integration tests exercised via the
PrecompileOverride
hook andvm.EVM.Call()
, also demonstrating full plumbing of arguments.The
hookstest
package is introduced to simplify registration of hooks for testing.