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: precompilegen Solidity interface -> stateful precompile #72

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Nov 14, 2024

Why this should be merged

Note that this is not a full replacement for ava-labs/subnet-evm/cmd/precompilegen. The original conflates the general concept of stateful precompiles with Ava-specific functionality (e.g. implementation configuration, module registration, etc.) while this is purely a mechanism for creating precompiles that conform to Solidity interfaces. In addition to the benefits I outline below, there is a case for separation of concerns.

The primary benefit of this approach is that the implementation is separate from the wrapper that converts it into a vm.PrecompiledContract. The subnet-evm generator leaves place for custom code to be inserted, making it impossible to update the boilerplate without overwriting customisation.

How this works

Code generation is analogous to gRPC server stubs:

gRPC precompilegen
Input proto Solidity -> solc ABI output
Generated type FooServer interface type Contract interface
Construction func RegisterFooServer(..., FooServer) func New(Contract) vm.PrecompiledContract
interface IPrecompile {
    function Foo(uint256) external returns (bool);
}

becomes

type Contract interface {
    Fallback(vm.PrecompileEnvironment, []byte) ([]byte, error)
    Foo(vm.PrecompileEnvironment, *big.Int) (bool, error)
}

func New(Contract) vm.PrecompiledContract { ... }

which is used for the return values of params.RulesHooks.PrecompileOverride.

Tip

See libevm/precompilegen/testprecompile/generated.go for output and libevm/precompilegen/gen_test.go for usage.

To-do

How this was tested

Integration test exercising Solidity-based test via a simulated.Backend.

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.

1 participant