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: precompile override via params.Extras hooks #2

Merged
merged 5 commits into from
Sep 10, 2024

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Sep 2, 2024

Why this should be merged

Adds support for overriding precompiles.

How this works

The params.RegisterExtras type parameters are no longer any but ChainConfigHooks and RulesHooks interfaces that allow for injection of hooks, the first of which is PrecompileOverride(common.Address). The hook returns a vm.PrecompiledContract (interface) and a boolean which, if true, indicates that the returned value MUST override the default.

If params.RegisterExtras() is never called, a set of NOOPHooks is used by default. These can also be embedded into registered types that wish to propagate payloads but without modifying behaviour.

Tip

The hook returns a bool to indicate overriding, not to indicate if the address must be treated as a precompile. The latter is inferred from whether or not the returned PrecompiledContract is nil. An address that would otherwise be treated as a precompile by geth can therefore be disabled by returning nil, true.

How this was tested

Integrations tests override precompile addresses (including native ones) with a stub registered via params.RegisterExtras(), which is exercised via vm.EVM.Call(). This demonstrates complete integration.

@ARR4N ARR4N added the Status: 🔴 DO NOT MERGE This PR is not meant to be merged in its current state label Sep 2, 2024
@ARR4N ARR4N force-pushed the arr4n/libevm-params-extras branch from 5781184 to a6742fd Compare September 8, 2024 16:35
@ARR4N ARR4N force-pushed the arr4n/libevm-precompile-overrides branch from d1da077 to 639aa1c Compare September 8, 2024 16:39
@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 13:57
Base automatically changed from arr4n/libevm-params-extras to arr4n/libevm September 10, 2024 16:00
@ARR4N ARR4N merged commit a33baa3 into arr4n/libevm Sep 10, 2024
@ARR4N ARR4N deleted the arr4n/libevm-precompile-overrides 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