Skip to content
Merged
10 changes: 9 additions & 1 deletion cannon/mipsevm/testutil/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func NewEVMEnv(contracts *ContractMetadata) (*vm.EVM, *state.StateDB) {
cancunActivation := *chainCfg.ShanghaiTime + 10
chainCfg.CancunTime = &cancunActivation
offsetBlocks := uint64(1000) // blocks after cancun fork
bc := &testChain{startTime: *chainCfg.CancunTime + offsetBlocks*12}
bc := &testChain{
config: chainCfg,
startTime: *chainCfg.CancunTime + offsetBlocks*12,
}
header := bc.GetHeader(common.Hash{}, 17034870+offsetBlocks)
db := rawdb.NewMemoryDatabase()
statedb := state.NewDatabase(triedb.NewDatabase(db, nil), nil)
Expand Down Expand Up @@ -129,13 +132,18 @@ func NewEVMEnv(contracts *ContractMetadata) (*vm.EVM, *state.StateDB) {
}

type testChain struct {
config *params.ChainConfig
startTime uint64
}

func (d *testChain) Engine() consensus.Engine {
return ethash.NewFullFaker()
}

func (d *testChain) Config() *params.ChainConfig {
return d.config
}

func (d *testChain) GetHeader(h common.Hash, n uint64) *types.Header {
parentHash := common.Hash{0: 0xff}
binary.BigEndian.PutUint64(parentHash[1:], n-1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101500.1-rc.1
replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101500.2-rc.1

//replace github.com/ethereum/go-ethereum => ../op-geth

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ github.com/elastic/gosigar v0.14.3 h1:xwkKwPia+hSfg9GqrCUKYdId102m9qTJIIr7egmK/u
github.com/elastic/gosigar v0.14.3/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/op-geth v1.101500.1-rc.1 h1:nvfeMbZdXgrNI5EZtIUVZqql9Jms3F2Q5CWHz3Catr4=
github.com/ethereum-optimism/op-geth v1.101500.1-rc.1/go.mod h1:OMpyVMMy5zpAAHlR5s/aGbXRk+7cIKczUEIJj54APbY=
github.com/ethereum-optimism/op-geth v1.101500.2-rc.1 h1:CCQtyKKobjMbK9jYd676YbH6Xcvntdn6jIOxFTCb5B8=
github.com/ethereum-optimism/op-geth v1.101500.2-rc.1/go.mod h1:OMpyVMMy5zpAAHlR5s/aGbXRk+7cIKczUEIJj54APbY=
github.com/ethereum-optimism/superchain-registry/validation v0.0.0-20250205201532-8ff62ada16e1 h1:OqRYDcjiOx5QCLn5krpd3BK1CW+VfSZx7YIa6zY9ePE=
github.com/ethereum-optimism/superchain-registry/validation v0.0.0-20250205201532-8ff62ada16e1/go.mod h1:NZ816PzLU1TLv1RdAvYAb6KWOj4Zm5aInT0YpDVml2Y=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestChannel_NextTxData_singleFrameTx(t *testing.T) {

func TestChannel_NextTxData_multiFrameTx(t *testing.T) {
require := require.New(t)
const n = eth.MaxBlobsPerBlobTx
const n = 6
lgr := testlog.Logger(t, log.LevelWarn)
ch, err := newChannelWithChannelOut(lgr, metrics.NoopMetrics, ChannelConfig{
UseBlobs: true,
Expand Down
14 changes: 10 additions & 4 deletions op-batcher/batcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ import (
"strings"
"time"

"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"

altda "github.com/ethereum-optimism/optimism/op-alt-da"
"github.com/ethereum-optimism/optimism/op-batcher/compressor"
"github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-service/eth"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/oppprof"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
)

// Current max blobs const, irrespective of active fork, is that of the Prague
// blob config.
var maxBlobsPerBlock = params.DefaultPragueBlobConfig.Max

type CLIConfig struct {
// L1EthRpc is the HTTP provider URL for L1.
L1EthRpc string
Expand Down Expand Up @@ -155,9 +159,11 @@ func (c *CLIConfig) Check() error {
if !flags.ValidDataAvailabilityType(c.DataAvailabilityType) {
return fmt.Errorf("unknown data availability type: %q", c.DataAvailabilityType)
}
// we want to enforce it for both blobs and auto
if c.DataAvailabilityType != flags.CalldataType && c.TargetNumFrames > eth.MaxBlobsPerBlobTx {
return fmt.Errorf("too many frames for blob transactions, max %d", eth.MaxBlobsPerBlobTx)
// Most chains' L1s still have only Cancun active, but we don't want to
// overcomplicate this check with a dynamic L1 query, so we just use maxBlobsPerBlock.
// We want to check for both, blobs and auto da-type.
if c.DataAvailabilityType != flags.CalldataType && c.TargetNumFrames > maxBlobsPerBlock {
return fmt.Errorf("too many frames for blob transactions, max %d", maxBlobsPerBlock)
}
if err := c.MetricsConfig.Check(); err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions op-batcher/batcher/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/ethereum-optimism/optimism/op-batcher/compressor"
"github.com/ethereum-optimism/optimism/op-batcher/flags"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/oppprof"
"github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -50,6 +50,9 @@ func TestValidBatcherConfig(t *testing.T) {
require.NoError(t, cfg.Check(), "valid config should pass the check function")
}

// Set current
var maxBlobsPerBlock = params.DefaultPragueBlobConfig.Max

func TestBatcherConfig(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -102,12 +105,12 @@ func TestBatcherConfig(t *testing.T) {
errString: "TargetNumFrames must be at least 1",
},
{
name: fmt.Sprintf("larger %d TargetNumFrames for blobs", eth.MaxBlobsPerBlobTx),
name: fmt.Sprintf("larger %d TargetNumFrames for blobs", maxBlobsPerBlock),
override: func(c *batcher.CLIConfig) {
c.TargetNumFrames = eth.MaxBlobsPerBlobTx + 1
c.TargetNumFrames = maxBlobsPerBlock + 1
c.DataAvailabilityType = flags.BlobsType
},
errString: fmt.Sprintf("too many frames for blob transactions, max %d", eth.MaxBlobsPerBlobTx),
errString: fmt.Sprintf("too many frames for blob transactions, max %d", maxBlobsPerBlock),
},
{
name: "invalid compr ratio for ratio compressor",
Expand Down
36 changes: 3 additions & 33 deletions op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package batcher

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"math"
"math/big"
_ "net/http/pprof"
"sync"
Expand Down Expand Up @@ -892,45 +890,17 @@ type TxSender[T any] interface {
// sendTx uses the txmgr queue to send the given transaction candidate after setting its
// gaslimit. It will block if the txmgr queue has reached its MaxPendingTransactions limit.
func (l *BatchSubmitter) sendTx(txdata txData, isCancel bool, candidate *txmgr.TxCandidate, queue TxSender[txRef], receiptsCh chan txmgr.TxReceipt[txRef]) {
intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, nil, false, true, true, false)
floorDataGas, err := core.FloorDataGas(candidate.TxData)
if err != nil {
// we log instead of return an error here because txmgr can do its own gas estimation
l.Log.Error("Failed to calculate intrinsic gas", "err", err)
// We log instead of return an error here because the txmgr will do its own gas estimation.
l.Log.Warn("Failed to calculate floor data gas", "err", err)
} else {
candidate.GasLimit = intrinsicGas
}

floorDataGas, err := floorDataGas(candidate.TxData)
if err != nil {
l.Log.Warn("Failed to compute FloorDataGas: %v, continuing with intrinsic gas.")
} else if floorDataGas > candidate.GasLimit {
l.Log.Debug("Bumping gas limit to floor data gas", "intrinsic_gas", intrinsicGas, "floor_data_gas", floorDataGas)
candidate.GasLimit = floorDataGas
}

queue.Send(txRef{id: txdata.ID(), isCancel: isCancel, isBlob: txdata.asBlob}, *candidate, receiptsCh)
}

// Copypaste from upstream geth
// TODO remove in #14500
func floorDataGas(data []byte) (uint64, error) {
TxTokenPerNonZeroByte := uint64(4)
TxGas := uint64(21000)
TxCostFloorPerToken := uint64(10)

var (
z = uint64(bytes.Count(data, []byte{0}))
nz = uint64(len(data)) - z
tokens = nz*TxTokenPerNonZeroByte + z
)
// Check for overflow
if (math.MaxUint64-TxGas)/TxCostFloorPerToken < tokens {
return 0, core.ErrGasUintOverflow
}
// Minimum gas required for a transaction based on its data tokens (EIP-7623).
return TxGas + tokens*TxCostFloorPerToken, nil
}

func (l *BatchSubmitter) blobTxCandidate(data txData) (*txmgr.TxCandidate, error) {
blobs, err := data.Blobs()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/test_batch_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (l *TestBatchSubmitter) JamTxPool(ctx context.Context) error {
} else if candidate, err = l.blobTxCandidate(emptyTxData); err != nil {
return err
}
if candidate.GasLimit, err = core.IntrinsicGas(candidate.TxData, nil, nil, false, true, true, false); err != nil {
if candidate.GasLimit, err = core.FloorDataGas(candidate.TxData); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions op-chain-ops/cmd/check-derivation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client
var txData types.TxData
switch txType {
case types.LegacyTxType:
gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false)
gasLimit, err := core.FloorDataGas(data)
if err != nil {
return nil, fmt.Errorf("failed to get intrinsicGas: %w", err)
}
Expand All @@ -242,7 +242,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client
Address: randomAddress,
StorageKeys: []common.Hash{common.HexToHash("0x1234")},
}}
gasLimit, err := core.IntrinsicGas(data, accessList, nil, false, true, true, false)
gasLimit, err := core.FloorDataGas(data)
if err != nil {
return nil, fmt.Errorf("failed to get intrinsicGas: %w", err)
}
Expand All @@ -257,7 +257,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client
Data: data,
}
case types.DynamicFeeTxType:
gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, true, false)
gasLimit, err := core.FloorDataGas(data)
if err != nil {
return nil, fmt.Errorf("failed to get intrinsicGas: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions op-chain-ops/cmd/check-ecotone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -512,7 +511,8 @@ func checkBlobTxDenial(ctx context.Context, env *actionEnv) error {
if latestHeader.ExcessBlobGas == nil {
return fmt.Errorf("the L1 block %s (time %d) is not ecotone yet", latestHeader.Hash(), latestHeader.Time)
}
blobBaseFee := eip4844.CalcBlobFee(*latestHeader.ExcessBlobGas)

blobBaseFee := eth.CalcBlobFeeDefault(latestHeader)
blobFeeCap := new(uint256.Int).Mul(uint256.NewInt(2), uint256.MustFromBig(blobBaseFee))
if blobFeeCap.Lt(uint256.NewInt(params.GWei)) { // ensure we meet 1 gwei geth tx-pool minimum
blobFeeCap = uint256.NewInt(params.GWei)
Expand Down
12 changes: 9 additions & 3 deletions op-chain-ops/cmd/op-simulate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
gstate "github.com/ethereum/go-ethereum/core/state"
Expand Down Expand Up @@ -190,7 +191,7 @@ func fetchChainConfig(ctx context.Context, cl *rpc.Client) (*params.ChainConfig,
}
// if not already recognized, then fetch the chain config manually
var config params.ChainConfig
if err := cl.CallContext(ctx, &config, "eth_chainConfig"); err != nil {
if err := cl.CallContext(ctx, &config, "debug_chainConfig"); err != nil {
return nil, fmt.Errorf("failed to retrieve chain config: %w", err)
}
return &config, nil
Expand Down Expand Up @@ -234,6 +235,7 @@ func readDump(prestatePath string) (map[common.Address]DumpAccount, error) {
type simChainContext struct {
eng consensus.Engine
head *types.Header
cfg *params.ChainConfig
}

func (d *simChainContext) Engine() consensus.Engine {
Expand All @@ -247,6 +249,10 @@ func (d *simChainContext) GetHeader(h common.Hash, n uint64) *types.Header {
panic(fmt.Errorf("header retrieval not supported, cannot fetch %s %d", h, n))
}

func (d *simChainContext) Config() *params.ChainConfig {
return d.cfg
}

func simulate(ctx context.Context, logger log.Logger, conf *params.ChainConfig,
prestatePath string, tx *types.Transaction, header *types.Header, doProfile bool) error {
memDB := rawdb.NewMemoryDatabase()
Expand All @@ -262,7 +268,7 @@ func simulate(ctx context.Context, logger log.Logger, conf *params.ChainConfig,
for addr, acc := range dump {
state.CreateAccount(addr)
state.SetBalance(addr, uint256.MustFromBig((*big.Int)(&acc.Balance)), tracing.BalanceChangeUnspecified)
state.SetNonce(addr, acc.Nonce)
state.SetNonce(addr, acc.Nonce, tracing.NonceChangeUnspecified)
state.SetCode(addr, acc.Code)
state.SetStorage(addr, acc.Storage)
}
Expand All @@ -284,7 +290,7 @@ func simulate(ctx context.Context, logger log.Logger, conf *params.ChainConfig,
state.Prepare(rules, sender, header.Coinbase, tx.To(), precompiles, tx.AccessList())
state.SetTxContext(tx.Hash(), 0)

cCtx := &simChainContext{eng: beacon.NewFaker(), head: header}
cCtx := &simChainContext{eng: beacon.New(ethash.NewFaker()), head: header, cfg: conf}
gp := core.GasPool(tx.Gas())
usedGas := uint64(0)
vmConfig := vm.Config{}
Expand Down
6 changes: 3 additions & 3 deletions op-chain-ops/foundry/allocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ func TestForgeAllocs_FromState(t *testing.T) {
alice := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
st.CreateAccount(alice)
st.SetBalance(alice, uint256.NewInt(123), tracing.BalanceChangeUnspecified)
st.SetNonce(alice, 42)
st.SetNonce(alice, 42, tracing.NonceChangeUnspecified)

bob := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
st.CreateAccount(bob)
st.CreateContract(bob)
st.SetBalance(bob, uint256.NewInt(100), tracing.BalanceChangeUnspecified)
st.SetNonce(bob, 1)
st.SetNonce(bob, 1, tracing.NonceChangeUnspecified)
st.SetState(bob, common.Hash{0: 0x42}, common.Hash{0: 7})

contract := common.HexToAddress("0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC")
st.CreateAccount(contract)
st.CreateContract(contract)
st.SetNonce(contract, 30)
st.SetNonce(contract, 30, tracing.NonceChangeUnspecified)
st.SetBalance(contract, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
st.SetCode(contract, []byte{10, 11, 12, 13, 14})

Expand Down
2 changes: 2 additions & 0 deletions op-chain-ops/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) {
// To enable post-Merge consensus at genesis
MergeNetsplitBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
// use default Ethereum prod blob schedules
BlobScheduleConfig: params.DefaultBlobSchedule,
}

gasLimit := config.L1GenesisBlockGasLimit
Expand Down
6 changes: 3 additions & 3 deletions op-chain-ops/script/cheatcodes_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type Log struct {

// SetNonce implements https://book.getfoundry.sh/cheatcodes/set-nonce
func (c *CheatCodesPrecompile) SetNonce(account common.Address, nonce uint64) {
c.h.state.SetNonce(account, nonce)
c.h.state.SetNonce(account, nonce, tracing.NonceChangeUnspecified)
}

// GetNonce implements https://book.getfoundry.sh/cheatcodes/get-nonce
Expand All @@ -149,9 +149,9 @@ func (c *CheatCodesPrecompile) ResetNonce(addr common.Address) {
// Resets nonce to 0 if EOA, or 1 if contract.
// In scripts often set code to empty first when using it, it then becomes 0.
if c.h.state.GetCodeHash(addr) == types.EmptyCodeHash {
c.h.state.SetNonce(addr, 0)
c.h.state.SetNonce(addr, 0, tracing.NonceChangeUnspecified)
} else {
c.h.state.SetNonce(addr, 1)
c.h.state.SetNonce(addr, 1, tracing.NonceChangeUnspecified)
}
}

Expand Down
Loading