Commit b0bb5d45 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-node: Fix OPB-10 (#3548)

* op-node: Fix OPB-10

Fixes OPB-10: No Checks for Deposit Transaction Type When Calling `L1InfoDepositTxData()`. This PR adds a check in `blockToBatch` that checks the type of the first transaction in the block, and returns an error if it isn't a deposit transaction.

* goimports
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 220ad4ef
......@@ -13,6 +13,8 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
var ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx")
type ChannelOut struct {
id ChannelID
// Frame ID of the next frame to emit. Increment after emitting
......@@ -153,6 +155,9 @@ func blockToBatch(block *types.Block, w io.Writer) error {
opaqueTxs = append(opaqueTxs, otx)
}
l1InfoTx := block.Transactions()[0]
if l1InfoTx.Type() != types.DepositTxType {
return ErrNotDepositTx
}
l1Info, err := L1InfoDepositTxData(l1InfoTx.Data())
if err != nil {
return err // TODO: wrap err
......
package derive
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)
func TestChannelOutAddBlock(t *testing.T) {
cout, err := NewChannelOut()
require.NoError(t, err)
t.Run("returns err if first tx is not an l1info tx", func(t *testing.T) {
header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)}
block := types.NewBlockWithHeader(header).WithBody(
[]*types.Transaction{
types.NewTx(&types.DynamicFeeTx{}),
},
nil,
)
err := cout.AddBlock(block)
require.Error(t, err)
require.Equal(t, ErrNotDepositTx, err)
})
}
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