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

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

Merged
merged 1 commit into from
Feb 22, 2023
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
5 changes: 5 additions & 0 deletions op-node/rollup/derive/l1_block_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 10 additions & 0 deletions op-node/rollup/derive/l1_block_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}