Skip to content
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

feat: stateful precompiles + allowlist hooks #3

Merged
merged 9 commits into from
Sep 10, 2024

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Sep 3, 2024

Why this should be merged

Introduces:

  1. Stateful precompiles
  2. CanExecuteTransaction and CanCreateContract hooks (equivalent to subnet-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 from core.StateTransition.TransitionDb() and CanCreateContract() is called from vm.EVM.create() (the common path for EVM.Create() and EVM.Create2()). If they return nil then functionality continues as normal, otherwise their errors are propagated.

Stateful precompiles

The PR introduces into core/vm:

type vm.StatefulPrecompileRun func(...) ...
// and
func NewStatefulPrecompile(StatefulPrecompileRun, ...) PrecompiledContract

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 via core.ApplyMessage() while CanCreateContract is tested via EVM.Create() and EVM.Create2().

Stateful precompiles have integration tests exercised via the PrecompileOverride hook and vm.EVM.Call(), also demonstrating full plumbing of arguments.

The hookstest package is introduced to simplify registration of hooks for testing.

@ARR4N ARR4N added the Status: 🔴 DO NOT MERGE This PR is not meant to be merged in its current state label Sep 4, 2024
@ARR4N ARR4N force-pushed the arr4n/libevm-precompile-overrides branch from d1da077 to 639aa1c Compare September 8, 2024 16:39
@ARR4N ARR4N force-pushed the arr4n/libevm-stateful-precompiles branch from bd8180b to e6840aa Compare September 8, 2024 17:19
@ARR4N ARR4N removed the Status: 🔴 DO NOT MERGE This PR is not meant to be merged in its current state label Sep 9, 2024
@ARR4N ARR4N marked this pull request as ready for review September 9, 2024 14:18
Base automatically changed from arr4n/libevm-precompile-overrides to arr4n/libevm September 10, 2024 16:03
@ARR4N ARR4N merged commit 95774a4 into arr4n/libevm Sep 10, 2024
@ARR4N ARR4N deleted the arr4n/libevm-stateful-precompiles branch September 10, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants