Commit 16538ea0 authored by Matthew Slipper's avatar Matthew Slipper

op-node: Return error when unmarshaling L1Info txs with invalid function selectors

The function selector was not being checked on unmarshal, which allows for invalid block data to pass validation.

Fixes CLI-3389
parent ab603c69
...@@ -74,6 +74,11 @@ func (info *L1BlockInfo) UnmarshalBinary(data []byte) error { ...@@ -74,6 +74,11 @@ func (info *L1BlockInfo) UnmarshalBinary(data []byte) error {
} }
var padding [24]byte var padding [24]byte
offset := 4 offset := 4
if !bytes.Equal(data[0:offset], L1InfoFuncBytes4) {
return fmt.Errorf("data does not match L1 info function signature: 0x%x", data[offset:4])
}
info.Number = binary.BigEndian.Uint64(data[offset+24 : offset+32]) info.Number = binary.BigEndian.Uint64(data[offset+24 : offset+32])
if !bytes.Equal(data[offset:offset+24], padding[:]) { if !bytes.Equal(data[offset:offset+24], padding[:]) {
return fmt.Errorf("l1 info number exceeds uint64 bounds: %x", data[offset:offset+32]) return fmt.Errorf("l1 info number exceeds uint64 bounds: %x", data[offset:offset+32])
......
...@@ -92,4 +92,14 @@ func TestParseL1InfoDepositTxData(t *testing.T) { ...@@ -92,4 +92,14 @@ func TestParseL1InfoDepositTxData(t *testing.T) {
_, err := L1InfoDepositTxData(make([]byte, 4+32+32+32+32+32+1)) _, err := L1InfoDepositTxData(make([]byte, 4+32+32+32+32+32+1))
assert.Error(t, err) assert.Error(t, err)
}) })
t.Run("invalid selector", func(t *testing.T) {
rng := rand.New(rand.NewSource(1234))
info := testutils.MakeBlockInfo(nil)(rng)
depTx, err := L1InfoDeposit(randomSeqNr(rng), info, randomL1Cfg(rng, info))
require.NoError(t, err)
_, err = rand.Read(depTx.Data[0:4])
require.NoError(t, err)
_, err = L1InfoDepositTxData(depTx.Data)
require.ErrorContains(t, err, "function signature")
})
} }
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