Skip to content

Commit

Permalink
Merge branch 'boba-develop' into upstream-v2.60.2
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuan-chen committed Jul 9, 2024
2 parents c6feab8 + a956b9b commit 2e9bf15
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 88 deletions.
2 changes: 0 additions & 2 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,6 @@ func loadOPStackGenesisByChainName(name string) (*types.Genesis, error) {
switch opStackChainCfg.ChainID {
case params.OPMainnetChainID:
expectedHash = params.OPMainnetGenesisHash
case params.OPGoerliChainID:
expectedHash = params.OPGoerliGenesisHash
case params.BobaMainnetChainID:
expectedHash = params.BobaMainnetGenesisHash
case params.BobaSepoliaChainID:
Expand Down
10 changes: 0 additions & 10 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/params"

"github.com/ledgerwatch/log/v3"
)

var emptyCodeHash = crypto.Keccak256Hash(nil)
Expand Down Expand Up @@ -264,9 +262,6 @@ func (st *StateTransition) buyGas(gasBailout bool) error {
}
var subBalance = false
have, want := st.state.GetBalance(st.msg.From()), balanceCheck
if !gasBailout {
log.Info("Validating balance requirements in buyGas", "from", st.msg.From(), "nonce", st.msg.Nonce(), "have", have, "want", want)
}
if have.Cmp(want) < 0 {
if !gasBailout {
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
Expand Down Expand Up @@ -310,17 +305,12 @@ func (st *StateTransition) preCheck(gasBailout bool) error {
// If not check it here, it will trigger evm internal error and break consensus.

have, want := st.state.GetBalance(st.msg.From()), st.msg.Value()
if !want.IsZero() {
log.Info("Validating balance requirements for depositTx in preCheck", "from", st.msg.From(), "nonce", st.msg.Nonce(), "have", have, "want", want)
}
if have.Cmp(want) < 0 {
if !gasBailout {
return fmt.Errorf("%w: precheck address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
}
}

log.Debug("preCheck for Deposit txn", "from", st.msg.From(), "to", st.msg.To(), "mint", st.msg.Mint(), "value", st.msg.Mint())

// Following section copied from Optimism patchset

// No fee fields to check, no nonce to check, and no need to check if EOA (L1 already verified it for us)
Expand Down
5 changes: 0 additions & 5 deletions erigon-lib/chain/networkname/network_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ const (
ChiadoChainName = "chiado"

OPMainnetChainName = "op-mainnet"
OPGoerliChainName = "op-goerli"
OPSepoliaChainName = "op-sepolia"

BobaMainnetChainName = "boba-mainnet"
BobaSepoliaChainName = "boba-sepolia"

LegacyOPMainnetChainName = "optimism-mainnet"
LegacyOPGoerliChainName = "optimism-goerli"
LegacyOPSepoliaChainName = "optimism-sepolia"
)

Expand All @@ -40,16 +38,13 @@ var All = []string{

OPMainnetChainName,
OPSepoliaChainName,
OPGoerliChainName,

BobaMainnetChainName,
BobaSepoliaChainName,
}

func HandleLegacyName(name string) string {
switch name {
case LegacyOPGoerliChainName:
return OPGoerliChainName
case LegacyOPSepoliaChainName:
return OPSepoliaChainName
case LegacyOPMainnetChainName:
Expand Down
15 changes: 4 additions & 11 deletions erigon-lib/opstack/rollup_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func NewL1CostFunc(config *chain.Config, statedb StateGetter) L1CostFunc {
l1BlobBaseFeeScalar := new(uint256.Int).SetBytes(l1FeeScalars[offset+4 : offset+8])

if config.IsFjord(blockTime) {
cachedFunc = newL1CostFuncFjord(blockTime, &l1BaseFee, &l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar)
cachedFunc = newL1CostFuncFjord(&l1BaseFee, &l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar)
} else {
cachedFunc = newL1CostFuncEcotone(blockTime, &l1BaseFee, &l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar)
cachedFunc = newL1CostFuncEcotone(&l1BaseFee, &l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar)
}
}
}
Expand All @@ -170,7 +170,6 @@ func newL1CostFuncBedrock(config *chain.Config, statedb StateGetter, blockTime u
statedb.GetState(L1BlockAddr, &OverheadSlot, &overhead)
statedb.GetState(L1BlockAddr, &ScalarSlot, &scalar)
isRegolith := config.IsRegolith(blockTime)
log.Info("Caching l1cost parameters for bedrock", "isRegolith", isRegolith, "blockTime", blockTime, "l1BaseFee", l1BaseFee, "overhead", overhead, "l1BaseFeeScalar", scalar)
return newL1CostFuncBedrockHelper(&l1BaseFee, &overhead, &scalar, isRegolith)
}

Expand All @@ -196,8 +195,7 @@ func newL1CostFuncBedrockHelper(l1BaseFee, overhead, scalar *uint256.Int, isRego

// newL1CostFuncEcotone returns an l1 cost function suitable for the Ecotone upgrade except for the
// very first block of the upgrade.
func newL1CostFuncEcotone(blockTime uint64, l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar *uint256.Int) l1CostFunc {
log.Info("Caching l1cost parameters for ecotone", "blockTime", blockTime, "l1BaseFee", l1BaseFee, "l1BlobBaseFee", l1BlobBaseFee, "l1BaseFeeScalar", l1BaseFeeScalar, "l1BlobBaseFeeScalar", l1BlobBaseFeeScalar)
func newL1CostFuncEcotone(l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar *uint256.Int) l1CostFunc {
return func(costData types.RollupCostData) (fee, calldataGasUsed *uint256.Int) {
calldataGas := (costData.Zeroes * fixedgas.TxDataZeroGas) + (costData.Ones * fixedgas.TxDataNonZeroGasEIP2028)
calldataGasUsed = new(uint256.Int).SetUint64(calldataGas)
Expand Down Expand Up @@ -237,8 +235,7 @@ type gasParams struct {
L1BlobBaseFeeScalar *uint256.Int // post-ecotone
}

func newL1CostFuncFjord(blockTime uint64, l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar *uint256.Int) l1CostFunc {
log.Info("Caching l1cost parameters for fjord", "blockTime", blockTime, "l1BaseFee", l1BaseFee, "l1BlobBaseFee", l1BlobBaseFee, "l1BaseFeeScalar", l1BaseFeeScalar, "l1BlobBaseFeeScalar", l1BlobBaseFeeScalar)
func newL1CostFuncFjord(l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar *uint256.Int) l1CostFunc {
return func(costData types.RollupCostData) (fee, calldataGasUsed *uint256.Int) {
// Fjord L1 cost function:
//l1FeeScaled = baseFeeScalar*l1BaseFee*16 + blobFeeScalar*l1BlobBaseFee
Expand Down Expand Up @@ -287,15 +284,13 @@ func ExtractL1GasParams(config *chain.Config, time uint64, data []byte) (gasPara

if config.IsFjord(time) {
p.CostFunc = newL1CostFuncFjord(
time,
p.L1BaseFee,
p.L1BlobBaseFee,
p.L1BaseFeeScalar,
p.L1BlobBaseFeeScalar,
)
} else {
p.CostFunc = newL1CostFuncEcotone(
time,
p.L1BaseFee,
p.L1BlobBaseFee,
p.L1BaseFeeScalar,
Expand Down Expand Up @@ -382,15 +377,13 @@ func L1CostFnForTxPool(time uint64, data []byte, isFjord bool) (types.L1CostFn,
return nil, err
}
p.CostFunc = newL1CostFuncEcotone(
time,
p.L1BaseFee,
p.L1BlobBaseFee,
p.L1BaseFeeScalar,
p.L1BlobBaseFeeScalar,
)
if isFjord {
p.CostFunc = newL1CostFuncFjord(
time,
p.L1BaseFee,
p.L1BlobBaseFee,
p.L1BaseFeeScalar,
Expand Down
4 changes: 1 addition & 3 deletions erigon-lib/opstack/rollup_cost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ func TestBedrockL1CostFunc(t *testing.T) {
}

func TestEcotoneL1CostFunc(t *testing.T) {
costFunc := newL1CostFuncEcotone(0, basefee, blobBasefee, basefeeScalar, blobBasefeeScalar)
costFunc := newL1CostFuncEcotone(basefee, blobBasefee, basefeeScalar, blobBasefeeScalar)
c, g := costFunc(emptyTxRollupCostData)
require.Equal(t, ecotoneGas, g)
require.Equal(t, ecotoneFee, c)
}

func TestFjordL1CostFuncMinimumBounds(t *testing.T) {
costFunc := newL1CostFuncFjord(
0,
basefee,
blobBasefee,
basefeeScalar,
Expand Down Expand Up @@ -106,7 +105,6 @@ func TestFjordL1CostFuncMinimumBounds(t *testing.T) {
// test to ensure the outputs are the same.
func TestFjordL1CostSolidityParity(t *testing.T) {
costFunc := newL1CostFuncFjord(
0,
uint256.NewInt(2*1e6),
uint256.NewInt(3*1e6),
uint256.NewInt(20),
Expand Down
1 change: 0 additions & 1 deletion eth/stagedsync/stage_mining_create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
return err
}

log.Info("cfg.blockBuilderParamters", "params", cfg.blockBuilderParameters)
if cfg.blockBuilderParameters != nil {
header.MixDigest = cfg.blockBuilderParameters.PrevRandao
header.ParentBeaconBlockRoot = cfg.blockBuilderParameters.ParentBeaconBlockRoot
Expand Down
1 change: 0 additions & 1 deletion eth/stagedsync/stage_mining_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func SpawnMiningExecStage(s *StageState, tx kv.RwTx, cfg MiningExecCfg, quit <-c
var txs []types.Transaction
for i := range current.Deposits {
transaction, err := types.UnmarshalTransactionFromBinary(current.Deposits[i], false)
log.Debug("Decoded Deposit transaction", "i", i, "err", err, "tx", transaction)
if err == io.EOF {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,4 @@ replace github.com/anacrolix/torrent => github.com/erigontech/torrent v1.54.2-al

replace github.com/ledgerwatch/erigon-lib => ./erigon-lib

replace github.com/ethereum-optimism/superchain-registry/superchain => github.com/bobanetwork/superchain-registry/superchain v0.0.0-20240621015329-5215351945d3
replace github.com/ethereum-optimism/superchain-registry/superchain => github.com/bobanetwork/superchain-registry/superchain v0.0.0-20240709155336-a98d1dc97fa3
4 changes: 0 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ var (
ChiadoGenesisHash = libcommon.HexToHash("0xada44fd8d2ecab8b08f256af07ad3e777f17fb434f8f8e678b312f576212ba9a")

OPMainnetGenesisHash = libcommon.HexToHash("0x7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b")
OPGoerliGenesisHash = libcommon.HexToHash("0xc1fc15cd51159b1f1e5cbc4b82e85c1447ddfa33c52cf1d98d14fba0d6354be1")
OPSepoliaGenesisHash = libcommon.HexToHash("0x102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d")

BobaMainnetGenesisHash = libcommon.HexToHash("0xdcd9e6a8f9973eaa62da2874959cb152faeb4fd6929177bd6335a1a16074ef9c")
Expand Down Expand Up @@ -299,9 +298,6 @@ func GenesisHashByChainName(chain string) *libcommon.Hash {
case networkname.OPMainnetChainName:
// cannot use genesis hash from superchain registry because of pre-bedrock blocks
return &OPMainnetGenesisHash
case networkname.OPGoerliChainName:
// cannot use genesis has from superchain registry because of pre-bedrock blocks
return &OPGoerliGenesisHash
case networkname.OPSepoliaChainName:
return &OPSepoliaGenesisHash
case networkname.BobaMainnetChainName:
Expand Down
62 changes: 14 additions & 48 deletions params/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@ import (
)

const (
OPMainnetChainID = 10
OPGoerliChainID = 420
OPSepoliaChainID = 11155420
BaseMainnetChainID = 8453
BaseGoerliChainID = 84531
baseSepoliaChainID = 84532
baseGoerliDevnetChainID = 11763071
pgnSepoliaChainID = 58008
devnetChainID = 997
chaosnetChainID = 888
BobaMainnetChainID = 288
BobaSepoliaChainID = 28882
BobaBnbTestnetChainID = 9728
OPMainnetChainID = 10
OPSepoliaChainID = 11155420
BaseMainnetChainID = 8453
baseSepoliaChainID = 84532
pgnSepoliaChainID = 58008
devnetChainID = 997
chaosnetChainID = 888
BobaMainnetChainID = 288
BobaSepoliaChainID = 28882
BobaBnbTestnetChainID = 9728
)

// OP Stack chain config
var (
// March 17, 2023 @ 7:00:00 pm UTC
OptimismGoerliRegolithTime = big.NewInt(1679079600)
// May 4, 2023 @ 5:00:00 pm UTC
BaseGoerliRegolithTime = big.NewInt(1683219600)
// Apr 21, 2023 @ 6:30:00 pm UTC
baseGoerliDevnetRegolithTime = big.NewInt(1682101800)
// March 5, 2023 @ 2:48:00 am UTC
devnetRegolithTime = big.NewInt(1677984480)
// August 16, 2023 @ 3:34:22 am UTC
Expand Down Expand Up @@ -68,6 +61,10 @@ func OPStackChainConfigByGenesisHash(genesisHash common.Hash) *superchain.ChainC
return superchain.OPChains[OPSepoliaChainID]
} else if bytes.Equal(genesisHash.Bytes(), BobaSepoliaGenesisHash.Bytes()) {
return superchain.OPChains[BobaSepoliaChainID]
} else if bytes.Equal(genesisHash.Bytes(), BobaMainnetGenesisHash.Bytes()) {
return superchain.OPChains[BobaMainnetChainID]
} else if bytes.Equal(genesisHash.Bytes(), BobaBnbTestnetGenesisHash.Bytes()) {
return superchain.OPChains[BobaBnbTestnetChainID]
}
for _, chainCfg := range superchain.OPChains {
if bytes.Equal(chainCfg.Genesis.L2.Hash[:], genesisHash.Bytes()) {
Expand Down Expand Up @@ -156,28 +153,15 @@ func LoadSuperChainConfig(opStackChainCfg *superchain.ChainConfig) *chain.Config

// special overrides for OP-Stack chains with pre-Regolith upgrade history
switch opStackChainCfg.ChainID {
case OPGoerliChainID:
out.LondonBlock = big.NewInt(4061224)
out.ArrowGlacierBlock = big.NewInt(4061224)
out.GrayGlacierBlock = big.NewInt(4061224)
out.MergeNetsplitBlock = big.NewInt(4061224)
out.BedrockBlock = big.NewInt(4061224)
out.RegolithTime = OptimismGoerliRegolithTime
out.Optimism.EIP1559Elasticity = 10
case OPMainnetChainID:
out.BerlinBlock = big.NewInt(3950000)
out.LondonBlock = big.NewInt(105235063)
out.ArrowGlacierBlock = big.NewInt(105235063)
out.GrayGlacierBlock = big.NewInt(105235063)
out.MergeNetsplitBlock = big.NewInt(105235063)
out.BedrockBlock = big.NewInt(105235063)
case BaseGoerliChainID:
out.RegolithTime = BaseGoerliRegolithTime
out.Optimism.EIP1559Elasticity = 10
case baseSepoliaChainID:
out.Optimism.EIP1559Elasticity = 10
case baseGoerliDevnetChainID:
out.RegolithTime = baseGoerliDevnetRegolithTime
case pgnSepoliaChainID:
out.Optimism.EIP1559Elasticity = 2
out.Optimism.EIP1559Denominator = 8
Expand All @@ -195,12 +179,6 @@ func LoadSuperChainConfig(opStackChainCfg *superchain.ChainConfig) *chain.Config
out.MergeNetsplitBlock = big.NewInt(511)
out.BedrockBlock = big.NewInt(511)
out.RegolithTime = BobaSepoliaRegolithTime
out.ShanghaiTime = BobaSepoliaRegolithTime
out.CanyonTime = BobaSepoliaRegolithTime
out.Optimism.EIP1559Elasticity = 6
out.Optimism.EIP1559Denominator = 50
out.Optimism.EIP1559DenominatorCanyon = 250
out.FjordTime = nil
case BobaMainnetChainID:
out.BerlinBlock = big.NewInt(1149019)
out.LondonBlock = big.NewInt(1149019)
Expand All @@ -209,12 +187,6 @@ func LoadSuperChainConfig(opStackChainCfg *superchain.ChainConfig) *chain.Config
out.MergeNetsplitBlock = big.NewInt(1149019)
out.BedrockBlock = big.NewInt(1149019)
out.RegolithTime = BobaMainnetRegolithTime
out.ShanghaiTime = BobaMainnetRegolithTime
out.CanyonTime = BobaMainnetRegolithTime
out.Optimism.EIP1559Elasticity = 6
out.Optimism.EIP1559Denominator = 50
out.Optimism.EIP1559DenominatorCanyon = 250
out.FjordTime = nil
case BobaBnbTestnetChainID:
out.BerlinBlock = big.NewInt(675077)
out.LondonBlock = big.NewInt(675077)
Expand All @@ -223,12 +195,6 @@ func LoadSuperChainConfig(opStackChainCfg *superchain.ChainConfig) *chain.Config
out.MergeNetsplitBlock = big.NewInt(675077)
out.BedrockBlock = big.NewInt(675077)
out.RegolithTime = BobaBnbTestnetRegoTime
out.ShanghaiTime = BobaBnbTestnetRegoTime
out.CanyonTime = BobaBnbTestnetRegoTime
out.Optimism.EIP1559Elasticity = 6
out.Optimism.EIP1559Denominator = 50
out.Optimism.EIP1559DenominatorCanyon = 250
out.FjordTime = nil
}

return out
Expand Down
Loading

0 comments on commit 2e9bf15

Please sign in to comment.