From 16538ea0580c9c33fed9f7adabe7c6937614697d Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 21 Feb 2023 23:01:53 -0700 Subject: [PATCH] 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 --- op-node/rollup/derive/l1_block_info.go | 5 +++++ op-node/rollup/derive/l1_block_info_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/op-node/rollup/derive/l1_block_info.go b/op-node/rollup/derive/l1_block_info.go index 8d75daafb651..d228e012376a 100644 --- a/op-node/rollup/derive/l1_block_info.go +++ b/op-node/rollup/derive/l1_block_info.go @@ -74,6 +74,11 @@ func (info *L1BlockInfo) UnmarshalBinary(data []byte) error { } var padding [24]byte 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]) if !bytes.Equal(data[offset:offset+24], padding[:]) { return fmt.Errorf("l1 info number exceeds uint64 bounds: %x", data[offset:offset+32]) diff --git a/op-node/rollup/derive/l1_block_info_test.go b/op-node/rollup/derive/l1_block_info_test.go index 8cebf4abf99e..a321698e22c6 100644 --- a/op-node/rollup/derive/l1_block_info_test.go +++ b/op-node/rollup/derive/l1_block_info_test.go @@ -92,4 +92,14 @@ func TestParseL1InfoDepositTxData(t *testing.T) { _, err := L1InfoDepositTxData(make([]byte, 4+32+32+32+32+32+1)) 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") + }) }