From 32d2d54e30d0403105c12774f680b1c49f7698e0 Mon Sep 17 00:00:00 2001 From: Sebastian Stammler Date: Wed, 2 Sep 2026 21:20:03 +0200 Subject: [PATCH] kona/tests/proofs,op-e2e: cover deposits in singular batches end to end Submit a singular batch carrying a deposit that mints to an unfunded account, once without its 0x7E type byte and once tagged, across the Granite to Karst fork matrix. Assert that the safe chain never applies the deposit, that the Holocene deposits-only replacement keeps only the L1 info deposit, and that kona-client proves the chain op-node and op-geth derived. The batch is submitted through GarbageChannelOut, which gains a transaction modifier applied between PayloadToSingularBatch and encoding: the batcher's block-based path filters deposit-typed transactions out of the batch and cannot carry a bare body. Regression test for #22778. Co-Authored-By: Claude Fable 5.1 --- op-e2e/actions/helpers/garbage_channel_out.go | 19 ++- .../tests/proofs/deposit_in_batch_test.go | 109 ++++++++++++++++++ 2 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 rust/kona/tests/proofs/deposit_in_batch_test.go diff --git a/op-e2e/actions/helpers/garbage_channel_out.go b/op-e2e/actions/helpers/garbage_channel_out.go index 4f01c50f18e..08b1f988206 100644 --- a/op-e2e/actions/helpers/garbage_channel_out.go +++ b/op-e2e/actions/helpers/garbage_channel_out.go @@ -58,6 +58,10 @@ func (gk GarbageKind) String() string { type GarbageChannelCfg struct { UseInvalidCompression bool MalformRLP bool + // TxModifier rewrites the transactions of each batch after the deposits have been filtered + // out and before the batch is encoded, so it can inject what the block-based batcher path + // cannot carry, like deposit-typed or non-canonical transaction bytes. + TxModifier func([]eth.Data) []eth.Data } // Writer is the interface shared between `zlib.Writer` and `gzip.Writer` @@ -160,10 +164,14 @@ func (co *GarbageChannelOut) AddBlock(rollupCfg *rollup.Config, payload *eth.Exe if co.closed { return nil, errors.New("already closed") } - batch, l1Info, err := blockToBatch(rollupCfg, payload) + singularBatch, l1Info, err := derive.PayloadToSingularBatch(rollupCfg, payload) if err != nil { return nil, err } + if co.cfg.TxModifier != nil { + singularBatch.Transactions = co.cfg.TxModifier(singularBatch.Transactions) + } + batch := derive.NewBatchData(singularBatch) // We encode to a temporary buffer to determine the encoded length to // ensure that the total size of all RLP elements is less than or equal to MAX_RLP_BYTES_PER_CHANNEL var buf bytes.Buffer @@ -253,12 +261,3 @@ func (co *GarbageChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) (uint1 return fn, nil } } - -// blockToBatch transforms a block into a batch object that can easily be RLP encoded. -func blockToBatch(rollupCfg *rollup.Config, payload *eth.ExecutionPayload) (*derive.BatchData, *derive.L1BlockInfo, error) { - singularBatch, l1Info, err := derive.PayloadToSingularBatch(rollupCfg, payload) - if err != nil { - return nil, nil, err - } - return derive.NewBatchData(singularBatch), l1Info, nil -} diff --git a/rust/kona/tests/proofs/deposit_in_batch_test.go b/rust/kona/tests/proofs/deposit_in_batch_test.go new file mode 100644 index 00000000000..4433841370f --- /dev/null +++ b/rust/kona/tests/proofs/deposit_in_batch_test.go @@ -0,0 +1,109 @@ +package proofs + +import ( + "math/big" + "testing" + + "github.com/ethereum-optimism/optimism/op-core/predeploys" + optypes "github.com/ethereum-optimism/optimism/op-core/types" + actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" + "github.com/ethereum-optimism/optimism/op-service/bigs" + "github.com/ethereum-optimism/optimism/op-service/eth" + "github.com/ethereum-optimism/optimism/rust/kona/tests/proofs/helpers" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +// bareDeposit selects the case that submits the deposit without its 0x7E type byte. +const bareDeposit = true + +// runDepositInBatchTest submits a singular batch that carries a deposit minting to an unfunded +// account and checks that neither derivation nor the deposits-only replacement ever applies it, +// and that kona-client agrees with the resulting chain. With bareDeposit, the deposit is submitted +// as a bare body without its 0x7E type byte, which passes the leading-byte batch gate and must be +// rejected by the execution engine instead; otherwise it is canonically encoded and the batch gate +// drops the whole batch. +// +// The batch goes through a GarbageChannelOut with a transaction modifier: the batcher's regular +// path filters deposit-typed transactions out of the batch, and its block modifier hook works on +// *types.Block, which cannot hold a bare body. +func runDepositInBatchTest(gt *testing.T, testCfg *helpers.TestCfg[bool]) { + t := actionsHelpers.NewDefaultTesting(gt) + env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), helpers.NewBatcherCfg()) + + // Build L2 block 1 with one user tx. + env.Alice.L2.ActResetTxOpts(t) + env.Alice.L2.ActSetTxToAddr(&env.Dp.Addresses.Bob) + env.Alice.L2.ActMakeTx(t) + env.Sequencer.ActL2StartBlock(t) + env.Engine.ActL2IncludeTx(env.Alice.Address())(t) + env.Sequencer.ActL2EndBlock(t) + + beneficiary := common.HexToAddress("0x00000000000000000000000000000000deadbeef") + deposit := &optypes.DepositTx{ + SourceHash: common.HexToHash("0x01"), + From: beneficiary, + To: &beneficiary, + Mint: big.NewInt(1e18), + Value: big.NewInt(0), + Gas: 21_000, + } + depositBytes, err := deposit.MarshalBinary() + require.NoError(t, err) + require.Equal(t, byte(optypes.DepositTxType), depositBytes[0]) + batchTx := eth.Data(depositBytes) + if testCfg.Custom == bareDeposit { + batchTx = depositBytes[1:] + require.Greater(t, batchTx[0], byte(0x7f), "a bare body must not start with a type byte") + } + + // Submit block 1 in a singular batch with the user tx replaced by the crafted deposit. + channel, err := actionsHelpers.NewGarbageChannelOut(&actionsHelpers.GarbageChannelCfg{ + TxModifier: func([]eth.Data) []eth.Data { return []eth.Data{batchTx} }, + }) + require.NoError(t, err) + env.Batcher.L2ChannelOut = channel + env.Batcher.ActAddBlockByNumber(t, 1) + env.Batcher.ActL2ChannelClose(t) + env.Batcher.ActL2BatchSubmit(t) + env.Miner.ActL1StartBlock(helpers.L1BlockTime)(t) + env.Miner.ActL1IncludeTxByHash(env.Batcher.LastSubmitted.Hash())(t) + env.Miner.ActL1EndBlock(t) + env.Sequencer.ActL1HeadSignal(t) + env.Sequencer.ActL2PipelineFull(t) + + l2SafeHead := env.Engine.L2Chain().CurrentSafeBlock() + if testCfg.Custom == bareDeposit && env.Sd.RollupCfg.IsHolocene(l2SafeHead.Time) { + // The engine rejects the batch transaction and the block is replaced by its deposits. + require.Equal(t, uint64(1), bigs.Uint64Strict(l2SafeHead.Number)) + safeBlock := env.Engine.L2Chain().GetBlockByHash(l2SafeHead.Hash()) + require.Len(t, safeBlock.Transactions(), 1, "only the L1 info deposit remains") + l1InfoTx := safeBlock.Transactions()[0] + require.Equal(t, uint8(optypes.DepositTxType), l1InfoTx.Type()) + require.Equal(t, predeploys.L1BlockAddr, *l1InfoTx.To()) + sequencerBlock := env.Engine.L2Chain().GetBlockByNumber(1) + require.Equal(t, sequencerBlock.Transactions()[0].Hash(), l1InfoTx.Hash(), "same L1 info deposit as the sequencer's block") + } else { + // The batch is dropped, by the gate or by the engine before Holocene, so the safe head + // only advances once a valid batch is submitted. + require.Equal(t, uint64(0), bigs.Uint64Strict(l2SafeHead.Number)) + env.Batcher.Reset() + require.Equal(t, uint64(1), env.BatchMineAndSync(t).Number) + l2SafeHead = env.Engine.L2Chain().CurrentSafeBlock() + } + + // The crafted deposit was never applied. + balance, err := env.Engine.EthClient().BalanceAt(t.Ctx(), beneficiary, nil) + require.NoError(t, err) + require.Zero(t, balance.Sign()) + + env.RunFaultProofProgramFromGenesis(t, bigs.Uint64Strict(l2SafeHead.Number), testCfg.CheckResult, testCfg.InputParams...) +} + +func TestDepositInBatch(gt *testing.T) { + forks := helpers.NewForkMatrix(helpers.Granite, helpers.Holocene, helpers.Isthmus, helpers.LatestFork) + matrix := helpers.NewMatrix[bool]() + matrix.AddDefaultTestCasesWithName("BareDeposit", bareDeposit, forks, runDepositInBatchTest) + matrix.AddDefaultTestCasesWithName("TaggedDeposit", !bareDeposit, forks, runDepositInBatchTest) + matrix.Run(gt) +}