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: vm.PrecompileEnvironment access to block info #27

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Sep 16, 2024

Why this should be merged

Provides all extra block context required by stateful precompiles.

The warp precompile is dependent on a transformation (i.e. validation) of access lists, which is stored in types.Header.Extra, which is also made available.

Closes #23

How this works

vm.BlockContext has a *types.Header field added as an all-purpose carrier of context not otherwise included. Although there are many places that construct a BlockContext, core.NewEVMBlockContext() is in the hot path of most (and also has a types.Header argument) so it populates the new field.

A shallow copy of the header is available through vm.PrecompileEnvironment.BlockHeader(). Note that this returns an error if the BlockContext.Header pointer is nil. If this occurs then we can track the code path that led to creation of the BlockContext and populate it as necessary.

BlockNumber and BlockTime, although available via the Header are already in the BlockContext so are exposed via their own methods, neither of which return errors.

How this was tested

The existing integration test is extended to demonstrate proper plumbing of all newly accessible data. The makeOutput() function was becoming unwieldy so I abstracted it into a struct with a String() string method.

@ARR4N ARR4N marked this pull request as ready for review September 17, 2024 14:53
@ARR4N ARR4N requested review from a team, darioush, ceyonur and michaelkaplan13 and removed request for a team September 17, 2024 16:14
@ARR4N ARR4N merged commit ab357e0 into libevm Sep 17, 2024
3 checks passed
@ARR4N ARR4N deleted the arr4n/block-context-header branch September 17, 2024 17:08
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.

BlockContext extensions (used in subnet-evm for passing PredicateResults)
2 participants