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

Add Rules to PredicateBytesFromExtra #845

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig

// Parse the predicate results from the extra field and store them in the
// block context.
predicateBytes := header.PredicateBytesFromExtra(blockCtx.Extra)
predicateBytes := header.PredicateBytesFromExtra(evm.chainRules.AvalancheRules, blockCtx.Extra)
if len(predicateBytes) == 0 {
return evm
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (b *Block) verifyPredicates(predicateContext *precompileconfig.PredicateCon
return fmt.Errorf("failed to marshal predicate results: %w", err)
}
extraData := b.ethBlock.Extra()
headerPredicateResultsBytes := header.PredicateBytesFromExtra(extraData)
headerPredicateResultsBytes := header.PredicateBytesFromExtra(rules.AvalancheRules, extraData)
if !bytes.Equal(headerPredicateResultsBytes, predicateResultsBytes) {
return fmt.Errorf("%w (remote: %x local: %x)", errInvalidHeaderPredicateResults, headerPredicateResultsBytes, predicateResultsBytes)
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/header/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func VerifyExtra(rules params.AvalancheRules, extra []byte) error {

// PredicateBytesFromExtra returns the predicate result bytes from the header's
// extra data. If the extra data is not long enough, an empty slice is returned.
func PredicateBytesFromExtra(extra []byte) []byte {
func PredicateBytesFromExtra(_ params.AvalancheRules, extra []byte) []byte {
// Prior to Durango, the VM enforces the extra data is smaller than or equal
// to this size.
// After Durango, the VM pre-verifies the extra data past the dynamic fee
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/header/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func TestVerifyExtra(t *testing.T) {
func TestPredicateBytesFromExtra(t *testing.T) {
tests := []struct {
name string
rules params.AvalancheRules
extra []byte
expected []byte
}{
Expand Down Expand Up @@ -359,7 +360,7 @@ func TestPredicateBytesFromExtra(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := PredicateBytesFromExtra(test.extra)
got := PredicateBytesFromExtra(test.rules, test.extra)
require.Equal(t, test.expected, got)
})
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ func testReceiveWarpMessage(

// Require the block was built with a successful predicate result
ethBlock := block2.(*chain.BlockWrapper).Block.(*Block).ethBlock
headerPredicateResultsBytes := customheader.PredicateBytesFromExtra(ethBlock.Extra())
rules := vm.chainConfig.GetAvalancheRules(ethBlock.Time())
headerPredicateResultsBytes := customheader.PredicateBytesFromExtra(rules, ethBlock.Extra())
results, err := predicate.ParseResults(headerPredicateResultsBytes)
require.NoError(err)

Expand Down
Loading