Skip to content

Commit

Permalink
Add Rules to PredicateBytesFromExtra (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Feb 28, 2025
1 parent ebc14ef commit 7effabd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
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

0 comments on commit 7effabd

Please sign in to comment.