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

predicate results: alternate approach (similar to master) #679

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

darioush
Copy link
Collaborator

@darioush darioush commented Oct 29, 2024

Why this should be merged

This PR is an alternative to #675
This PR makes the precompile interface as it is in master, i.e. with
GetPredicateResults(txHash common.Hash, precompileAddress common.Address)

How this works

This PR removes the dependency from predicators package to the params package by:

  • Moving the logic related to DynamicFeeExtraDataSize out of the predicates package,
  • Breaking the dependency on params.Rules by introducing an interface that can check for the existence of predicators. As an alternative to only this bullet point, we can move the function PreparePredicateStorageSlots

After this dependency is removed, the parsing functions from predicates package can be used in params.

How this was tested

CI

@darioush darioush changed the base branch from master to use-libevm October 29, 2024 16:52
@darioush darioush changed the title Use libevm precompile predicate results: alternate approach (similar to master) Oct 29, 2024
@darioush darioush marked this pull request as ready for review October 29, 2024 17:20
@darioush darioush requested review from ceyonur and a team as code owners October 29, 2024 17:20
@@ -192,6 +196,6 @@ func (b *BlockContext) Timestamp() uint64 {
return b.time
}

func (b *BlockContext) GetPredicateResultsBytes() []byte {
return b.predicateResultsBytes
func (b *BlockContext) GetPredicateResults(txHash common.Hash, precompileAddress common.Address) []byte {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this return predicate.Results?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or keep the byte in name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it is in master so I left it like that for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the cyclic import that prevents us to have these in predicate pkg?

Copy link
Collaborator Author

@darioush darioush Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predicates imports params which needs to import predicates again to parse the predicates to make the block context for the precompiles.

I'm somewhat hopeful that we can fix this by finding a better location for the libevm hooks other than "params", which we can address next.

also I mildly dislike that the predicates package needs to know about the length of the dynamic fee window.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the dynamic fee window is the only reason we're importing params package I think it's fine to copy/move it to predicate pkg and move these util functions there

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params in general is a really bad package for constants, and in our case it's even worse.

predicate/predicate_slots.go Show resolved Hide resolved
params/hooks_libevm.go Outdated Show resolved Hide resolved
eth/tracers/api.go Outdated Show resolved Hide resolved
predicateResults, err = predicate.ParseResults(predicateResultsBytes)
if err != nil {
panic(err) // Should never happen, as results are already validated in block validation
}
}
accessableState := accessableState{
env: env,
blockContext: &BlockContext{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we cannot use vm.BlockContext directly from env? It should already have a parsed results (and other similar functions to implement required interface)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps you are looking at the subnet-evm or coreth source code?
as the vm.BlockContext here would be from the upstream libevm code here, which we modified to include the full header so we can access the extra bits (aka predicate results) here and pass it to the precompiles.

Copy link
Collaborator

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this looks way good! left a comment other than LGTM.

@darioush darioush merged commit f575788 into use-libevm Nov 6, 2024
6 checks passed
@darioush darioush deleted the use-libevm-precompile branch November 6, 2024 16:23
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