Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions core/types/deposit_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package types

import (
"bytes"
"encoding/binary"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -117,3 +118,10 @@ func (tx *Transaction) From() common.Address {
}
return tx.inner.(interface{ from() common.Address }).from()
}

func JovianDepositTx(daFootprintGasScalar uint16) *DepositTx {
data := make([]byte, JovianL1AttributesLen)
copy(data[0:4], JovianL1AttributesSelector)
binary.BigEndian.PutUint16(data[JovianL1AttributesLen-2:JovianL1AttributesLen], daFootprintGasScalar)
return &DepositTx{Data: data}
}
29 changes: 28 additions & 1 deletion internal/ethapi/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ethereum/go-ethereum/internal/ethapi/override"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
)

const (
Expand Down Expand Up @@ -359,12 +360,38 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
reqHash := types.CalcRequestsHash(requests)
header.RequestsHash = &reqHash
}
blockBody := &types.Body{Transactions: txes, Withdrawals: *block.BlockOverrides.Withdrawals}

// For OP Stack Jovian blocks, inject a synthetic deposit transaction at the beginning of the block.
// This is required because CalcDAFootprint (called by FinalizeAndAssemble for Jovian blocks)
// expects the first transaction to be a deposit transaction containing L1 attributes data.
isJovian := sim.chainConfig.IsJovian(parent.Time)
finalTxes := txes
if isJovian {
// Use a reasonable default DA footprint gas scalar (e.g., 1 wei)
depositTx := types.NewTx(types.JovianDepositTx(1))
finalTxes = append([]*types.Transaction{depositTx}, txes...)
}

blockBody := &types.Body{Transactions: finalTxes, Withdrawals: *block.BlockOverrides.Withdrawals}
chainHeadReader := &simChainHeadReader{ctx, sim.b}
b, err := sim.b.Engine().FinalizeAndAssemble(chainHeadReader, header, sim.state, blockBody, receipts)
if err != nil {
return nil, nil, nil, nil, err
}

// For Jovian blocks, reconstruct the block without the synthetic deposit transaction
// to maintain consistent indexing between transactions and receipts.
// We must use types.NewBlock to recompute TxHash correctly for the user transactions only.
if isJovian {
b = types.NewBlock(
b.Header(),
&types.Body{Transactions: txes, Withdrawals: *block.BlockOverrides.Withdrawals},
receipts,
trie.NewStackTrie(nil),
sim.chainConfig,
)
}

repairLogs(callResults, b.Hash())
return b, callResults, senders, receipts, nil
}
Expand Down
10 changes: 1 addition & 9 deletions miner/miner_optimism_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package miner

import (
"encoding/binary"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -114,7 +113,7 @@ func testMineAndExecute(t *testing.T, numTxs uint64, cfg *params.ChainConfig, as
ts := parent.Time + 12
dtx := new(types.DepositTx)
if cfg.IsJovian(parent.Time) {
dtx = jovianDepositTx(testDAFootprintGasScalar)
dtx = types.JovianDepositTx(testDAFootprintGasScalar)
}

genParams := &generateParams{
Expand All @@ -140,13 +139,6 @@ func testMineAndExecute(t *testing.T, numTxs uint64, cfg *params.ChainConfig, as
require.NoError(t, err, "block import/execution failed")
}

func jovianDepositTx(daFootprintGasScalar uint16) *types.DepositTx {
data := make([]byte, types.JovianL1AttributesLen)
copy(data[0:4], types.JovianL1AttributesSelector)
binary.BigEndian.PutUint16(data[types.JovianL1AttributesLen-2:types.JovianL1AttributesLen], daFootprintGasScalar)
return &types.DepositTx{Data: data}
}

func ptr[T any](v T) *T {
return &v
}
2 changes: 1 addition & 1 deletion miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func newPayloadArgs(parentHash common.Hash, cfg *params.ChainConfig) *BuildPaylo
}
dtx := new(types.DepositTx)
if cfg.IsJovian(args.Timestamp) {
dtx = jovianDepositTx(testDAFootprintGasScalar)
dtx = types.JovianDepositTx(testDAFootprintGasScalar)
}
args.Transactions = []*types.Transaction{types.NewTx(dtx)}
if cfg.IsJovian(args.Timestamp) {
Expand Down