Commit d1d92907 authored by protolambda's avatar protolambda Committed by GitHub

op-node: fix parent-beacon-block-root comparison check [Ecotone] (#9071)

* op-node: fix parent-beacon-block-root comparison check

* op-node: nit in op-node/rollup/derive/engine_consolidate.go
Co-authored-by: default avatarSebastian Stammler <seb@oplabs.co>

* op-node: two-side nil parent beacon block root test case

---------
Co-authored-by: default avatarSebastian Stammler <seb@oplabs.co>
parent 3ba1ff7c
...@@ -47,8 +47,23 @@ func AttributesMatchBlock(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes ...@@ -47,8 +47,23 @@ func AttributesMatchBlock(rollupCfg *rollup.Config, attrs *eth.PayloadAttributes
if withdrawalErr := checkWithdrawalsMatch(attrs.Withdrawals, block.Withdrawals); withdrawalErr != nil { if withdrawalErr := checkWithdrawalsMatch(attrs.Withdrawals, block.Withdrawals); withdrawalErr != nil {
return withdrawalErr return withdrawalErr
} }
if envelope.ParentBeaconBlockRoot != attrs.ParentBeaconBlockRoot { if err := checkParentBeaconBlockRootMatch(attrs.ParentBeaconBlockRoot, envelope.ParentBeaconBlockRoot); err != nil {
return fmt.Errorf("parent beacon block root does not match. expected %v. got: %v", attrs.ParentBeaconBlockRoot, envelope.ParentBeaconBlockRoot) return err
}
return nil
}
func checkParentBeaconBlockRootMatch(attrRoot, blockRoot *common.Hash) error {
if blockRoot == nil {
if attrRoot != nil {
return fmt.Errorf("expected non-nil parent beacon block root %s but got nil", *attrRoot)
}
} else {
if attrRoot == nil {
return fmt.Errorf("expected nil parent beacon block root but got non-nil %s", *blockRoot)
} else if *blockRoot != *attrRoot {
return fmt.Errorf("parent beacon block root does not match. expected %s. got: %s", *attrRoot, *blockRoot)
}
} }
return nil return nil
} }
......
...@@ -71,6 +71,33 @@ func ecotoneNoParentBeaconBlockRoot() args { ...@@ -71,6 +71,33 @@ func ecotoneNoParentBeaconBlockRoot() args {
return args return args
} }
func ecotoneUnexpectedParentBeaconBlockRoot() args {
args := ecotoneArgs()
args.attrs.ParentBeaconBlockRoot = nil
return args
}
func ecotoneMismatchParentBeaconBlockRoot() args {
args := ecotoneArgs()
h := common.HexToHash("0xabc")
args.attrs.ParentBeaconBlockRoot = &h
return args
}
func ecotoneMismatchParentBeaconBlockRootPtr() args {
args := ecotoneArgs()
cpy := *args.attrs.ParentBeaconBlockRoot
args.attrs.ParentBeaconBlockRoot = &cpy
return args
}
func ecotoneNilParentBeaconBlockRoots() args {
args := ecotoneArgs()
args.attrs.ParentBeaconBlockRoot = nil
args.envelope.ParentBeaconBlockRoot = nil
return args
}
func mismatchedParentHashArgs() args { func mismatchedParentHashArgs() args {
args := ecotoneArgs() args := ecotoneArgs()
args.parentHash = common.HexToHash("0xabc") args.parentHash = common.HexToHash("0xabc")
...@@ -130,6 +157,22 @@ func TestAttributesMatch(t *testing.T) { ...@@ -130,6 +157,22 @@ func TestAttributesMatch(t *testing.T) {
shouldMatch: false, shouldMatch: false,
args: ecotoneNoParentBeaconBlockRoot(), args: ecotoneNoParentBeaconBlockRoot(),
}, },
{
shouldMatch: false,
args: ecotoneUnexpectedParentBeaconBlockRoot(),
},
{
shouldMatch: false,
args: ecotoneMismatchParentBeaconBlockRoot(),
},
{
shouldMatch: true,
args: ecotoneMismatchParentBeaconBlockRootPtr(),
},
{
shouldMatch: true,
args: ecotoneNilParentBeaconBlockRoots(),
},
{ {
shouldMatch: false, shouldMatch: false,
args: createMistmatchedPrevRandao(), args: createMistmatchedPrevRandao(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment