Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sepolia granite #211

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ var (
}
OverrideOptimismFjordFlag = flags.BigFlag{
Name: "override.fjord",
Usage: "Manually specify the Optimism Ecotone fork time, overriding the bundled setting",
Usage: "Manually specify the Optimism Fjord fork time, overriding the bundled setting",
}
OverrideOptimismGraniteFlag = flags.BigFlag{
Name: "override.granite",
Usage: "Manually specify the Optimism Granite fork time, overriding the bundled setting",
}
// Ethash settings
EthashCachesInMemoryFlag = cli.IntFlag{
Expand Down Expand Up @@ -2020,6 +2024,9 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
if ctx.IsSet(OverrideOptimismFjordFlag.Name) {
cfg.OverrideOptimismFjordTime = flags.GlobalBig(ctx, OverrideOptimismFjordFlag.Name)
}
if ctx.IsSet(OverrideOptimismGraniteFlag.Name) {
cfg.OverrideOptimismGraniteTime = flags.GlobalBig(ctx, OverrideOptimismGraniteFlag.Name)
}
if ctx.IsSet(InternalConsensusFlag.Name) && clparams.EmbeddedSupported(cfg.NetworkID) {
cfg.InternalCL = ctx.Bool(InternalConsensusFlag.Name)
}
Expand Down
6 changes: 3 additions & 3 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestGenesisBlockHashes(t *testing.T) {
t.Fatal(err)
}
defer tx.Rollback()
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, "", logger)
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, nil, "", logger)
require.NoError(t, err)
expect := params.GenesisHashByChainName(network)
require.NotNil(t, expect, network)
Expand Down Expand Up @@ -85,13 +85,13 @@ func TestCommitGenesisIdempotency(t *testing.T) {
defer tx.Rollback()

genesis := core.GenesisBlockByChainName(networkname.MainnetChainName)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, "", logger)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, nil, "", logger)
require.NoError(t, err)
seq, err := tx.ReadSequence(kv.EthTx)
require.NoError(t, err)
require.Equal(t, uint64(2), seq)

_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, "", logger)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, nil, nil, nil, nil, nil, nil, "", logger)
require.NoError(t, err)
seq, err = tx.ReadSequence(kv.EthTx)
require.NoError(t, err)
Expand Down
11 changes: 7 additions & 4 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ import (
//
// The returned chain configuration is never nil.
func CommitGenesisBlock(db kv.RwDB, genesis *types.Genesis, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
return CommitGenesisBlockWithOverride(db, genesis, nil, nil, nil, nil, nil, nil, tmpDir, logger)
return CommitGenesisBlockWithOverride(db, genesis, nil, nil, nil, nil, nil, nil, nil, tmpDir, logger)
}

func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overridePragueTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overrideOptimismGraniteTime, overridePragueTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
tx, err := db.BeginRw(context.Background())
if err != nil {
return nil, nil, err
}
defer tx.Rollback()
c, b, err := WriteGenesisBlock(tx, genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overridePragueTime, tmpDir, logger)
c, b, err := WriteGenesisBlock(tx, genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overrideOptimismGraniteTime, overridePragueTime, tmpDir, logger)
if err != nil {
return c, b, err
}
Expand All @@ -88,7 +88,7 @@ func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, override
return c, b, nil
}

func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overridePragueTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideCancunTime, overrideShanghaiTime, overrideOptimismCanyonTime, overrideOptimismEcotoneTime, overrideOptimismFjordTime, overrideOptimismGraniteTime, overridePragueTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
var storedBlock *types.Block
if genesis != nil && genesis.Config == nil {
return params.AllProtocolChanges, nil, types.ErrGenesisNoConfig
Expand Down Expand Up @@ -138,6 +138,9 @@ func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideCancunTime, o
if config.IsOptimism() && overrideOptimismFjordTime != nil {
config.FjordTime = overrideOptimismFjordTime
}
if config.IsOptimism() && overrideOptimismGraniteTime != nil {
config.GraniteTime = overrideOptimismGraniteTime
}
}

if (storedHash == libcommon.Hash{}) {
Expand Down
41 changes: 41 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ var PrecompiledContractsFjord = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}

// PrecompiledContractsGranite contains the default set of pre-compiled Ethereum
// contracts used in the Granite release.
var PrecompiledContractsGranite = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{1}): &ecrecover{},
libcommon.BytesToAddress([]byte{2}): &sha256hash{},
libcommon.BytesToAddress([]byte{3}): &ripemd160hash{},
libcommon.BytesToAddress([]byte{4}): &dataCopy{},
libcommon.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
libcommon.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
libcommon.BytesToAddress([]byte{8}): &bn256PairingGranite{},
libcommon.BytesToAddress([]byte{9}): &blake2F{},
libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
libcommon.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}

var PrecompiledContractsNapoli = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x01}): &ecrecover{},
libcommon.BytesToAddress([]byte{0x02}): &sha256hash{},
Expand Down Expand Up @@ -167,6 +183,7 @@ var PrecompiledContractsPrague = map[libcommon.Address]PrecompiledContract{
}

var (
PrecompiledAddressesGranite []libcommon.Address
PrecompiledAddressesFjord []libcommon.Address
PrecompiledAddressesPrague []libcommon.Address
PrecompiledAddressesNapoli []libcommon.Address
Expand Down Expand Up @@ -196,6 +213,9 @@ func init() {
for k := range PrecompiledContractsFjord {
PrecompiledAddressesFjord = append(PrecompiledAddressesFjord, k)
}
for k := range PrecompiledContractsGranite {
PrecompiledAddressesGranite = append(PrecompiledAddressesGranite, k)
}
for k := range PrecompiledContractsNapoli {
PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k)
}
Expand All @@ -207,6 +227,8 @@ func init() {
// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules *chain.Rules) []libcommon.Address {
switch {
case rules.IsOptimismGranite:
return PrecompiledAddressesGranite
case rules.IsOptimismFjord:
return PrecompiledAddressesFjord
case rules.IsPrague:
Expand Down Expand Up @@ -595,6 +617,9 @@ var (

// errBadPairingInput is returned if the bn256 pairing input is invalid.
errBadPairingInput = errors.New("bad elliptic curve pairing size")

// errBadPairingInputSize is returned if the bn256 pairing input size is invalid.
errBadPairingInputSize = errors.New("bad elliptic curve pairing input size")
)

// runBn256Pairing implements the Bn256Pairing precompile, referenced by both
Expand Down Expand Up @@ -628,6 +653,22 @@ func runBn256Pairing(input []byte) ([]byte, error) {
return false32Byte, nil
}

// bn256PairingGranite implements a pairing pre-compile for the bn256 curve
// conforming to Granite consensus rules.
type bn256PairingGranite struct{}

// RequiredGas returns the gas required to execute the pre-compiled contract.
func (c *bn256PairingGranite) RequiredGas(input []byte) uint64 {
return new(bn256PairingIstanbul).RequiredGas(input)
}

func (c *bn256PairingGranite) Run(input []byte) ([]byte, error) {
if len(input) > int(params.Bn256PairingMaxInputSizeGranite) {
return nil, errBadPairingInputSize
}
return runBn256Pairing(input)
}

// bn256PairingIstanbul implements a pairing pre-compile for the bn256 curve
// conforming to Istanbul consensus rules.
type bn256PairingIstanbul struct{}
Expand Down
12 changes: 11 additions & 1 deletion core/vm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/params"
)

// precompiledTest defines the input/output pairs for precompiled contract tests.
Expand Down Expand Up @@ -56,7 +57,7 @@ var allPrecompiles = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0xf5}): &bigModExp{eip2565: true},
libcommon.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
libcommon.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
libcommon.BytesToAddress([]byte{8}): &bn256PairingGranite{},
libcommon.BytesToAddress([]byte{9}): &blake2F{},
libcommon.BytesToAddress([]byte{10}): &bls12381G1Add{},
libcommon.BytesToAddress([]byte{11}): &bls12381G1Mul{},
Expand Down Expand Up @@ -420,3 +421,12 @@ func TestPrecompiledP256Verify(t *testing.T) {
// test case from OP Stack Fjord geth
testJson("p256Verify2", "100", t)
}

func TestPrecompileBn256PairingTooLargeInput(t *testing.T) {
big := make([]byte, params.Bn256PairingMaxInputSizeGranite+1)
testPrecompiledFailure("08", precompiledFailureTest{
Input: common.Bytes2Hex(big),
ExpectedError: "bad elliptic curve pairing input size",
Name: "bn256Pairing_input_too_big",
}, t)
}
2 changes: 2 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var emptyCodeHash = crypto.Keccak256Hash(nil)
func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) {
var precompiles map[libcommon.Address]PrecompiledContract
switch {
case evm.chainRules.IsOptimismGranite:
precompiles = PrecompiledContractsGranite
case evm.chainRules.IsOptimismFjord:
precompiles = PrecompiledContractsFjord
case evm.chainRules.IsPrague:
Expand Down
14 changes: 13 additions & 1 deletion erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Config struct {
// Delta: the Delta upgrade does not affect the execution-layer, and is thus not configurable in the chain config.
EcotoneTime *big.Int `json:"ecotoneTime,omitempty"` // Ecotone switch time (nil = no fork, 0 = already on optimism ecotone)
FjordTime *big.Int `json:"fjordTime,omitempty"` // Fjord switch time (nil = no fork, 0 = already on optimism fjord)
GraniteTime *big.Int `json:"graniteTime,omitempty"` // Granite switch time (nil = no fork, 0 = already on optimism granite)

// Optional EIP-4844 parameters
MinBlobGasPrice *uint64 `json:"minBlobGasPrice,omitempty"`
Expand Down Expand Up @@ -149,12 +150,13 @@ func (c *Config) String() string {
c.NoPruneContracts,
)
if c.IsOptimism() {
configString += fmt.Sprintf("{Bedrock: %v, Regolith: %v, Canyon: %v, Ecotone: %v, Fjord: %v}",
configString += fmt.Sprintf("{Bedrock: %v, Regolith: %v, Canyon: %v, Ecotone: %v, Fjord: %v, Granite: %v}",
c.BedrockBlock,
c.RegolithTime,
c.CanyonTime,
c.EcotoneTime,
c.FjordTime,
c.GraniteTime,
)
}
return configString
Expand Down Expand Up @@ -336,6 +338,10 @@ func (c *Config) IsFjord(time uint64) bool {
return isForked(c.FjordTime, time)
}

func (c *Config) IsGranite(time uint64) bool {
return isForked(c.GraniteTime, time)
}

// IsOptimism returns whether the node is an optimism node or not.
func (c *Config) IsOptimism() bool {
return c.Optimism != nil
Expand All @@ -362,6 +368,10 @@ func (c *Config) IsOptimismFjord(time uint64) bool {
return c.IsOptimism() && c.IsFjord(time)
}

func (c *Config) IsOptimismGranite(time uint64) bool {
return c.IsOptimism() && c.IsGranite(time)
}

// IsOptimismPreBedrock returns true iff this is an optimism node & bedrock is not yet active
func (c *Config) IsOptimismPreBedrock(num uint64) bool {
return c.IsOptimism() && !c.IsBedrock(num)
Expand Down Expand Up @@ -615,6 +625,7 @@ type Rules struct {
IsAura bool
IsOptimismBedrock, IsOptimismRegolith bool
IsOptimismCanyon, IsOptimismEcotone, IsOptimismFjord bool
IsOptimismGranite bool
}

// Rules ensures c's ChainID is not nil and returns a new Rules instance
Expand Down Expand Up @@ -646,6 +657,7 @@ func (c *Config) Rules(num uint64, time uint64) *Rules {
IsOptimismCanyon: c.IsOptimismCanyon(time),
IsOptimismEcotone: c.IsOptimismEcotone(time),
IsOptimismFjord: c.IsOptimismFjord(time),
IsOptimismGranite: c.IsOptimismGranite(time),
}
}

Expand Down
5 changes: 4 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
genesisSpec = nil
}
var genesisErr error
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideCancunTime, config.OverrideShanghaiTime, config.OverrideOptimismCanyonTime, config.OverrideOptimismEcotoneTime, config.OverrideOptimismFjordTime, config.OverridePragueTime, tmpdir, logger)
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideCancunTime, config.OverrideShanghaiTime, config.OverrideOptimismCanyonTime, config.OverrideOptimismEcotoneTime, config.OverrideOptimismFjordTime, config.OverrideOptimismGraniteTime, config.OverridePragueTime, tmpdir, logger)
if _, ok := genesisErr.(*chain.ConfigCompatError); genesisErr != nil && !ok {
return genesisErr
}
Expand All @@ -330,6 +330,9 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
if chainConfig.FjordTime == nil {
log.Warn("Optimism FjordTime has not been set")
}
if chainConfig.GraniteTime == nil {
log.Warn("Optimism GraniteTime has not been set")
}
}

setBorDefaultMinerGasPrice(chainConfig, config, logger)
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ type Config struct {
OverrideOptimismCanyonTime *big.Int `toml:",omitempty"`
OverrideOptimismEcotoneTime *big.Int `toml:",omitempty"`
OverrideOptimismFjordTime *big.Int `toml:",omitempty"`
OverrideOptimismGraniteTime *big.Int `toml:",omitempty"`

OverridePragueTime *big.Int `toml:",omitempty"`

Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ require (
github.com/consensys/gnark-crypto v0.12.1
github.com/crate-crypto/go-ipa v0.0.0-20221111143132-9aa5d42120bc
github.com/crate-crypto/go-kzg-4844 v0.7.0
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckarep/golang-set v1.8.0
github.com/deckarep/golang-set/v2 v2.3.1
github.com/docker/docker v26.1.0+incompatible
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf
github.com/edsrzf/mmap-go v1.1.0
github.com/emicklei/dot v1.6.1
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240603085035-9c8f6081266e
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240803025447-c92ef420eec2
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c
github.com/gballet/go-verkle v0.0.0-20221121182333-31427a1f2d35
github.com/gfx-labs/sse v0.0.0-20231226060816-f747e26a9baa
Expand Down Expand Up @@ -97,11 +97,11 @@ require (
github.com/xsleonard/go-merkle v1.1.0
go.uber.org/mock v0.4.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.22.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use same version of these libraries as op-geth?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not the critical change for Granite. I think we should follow upstream erigon other than op-geth for library versions

golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
golang.org/x/net v0.24.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0
golang.org/x/sys v0.20.0
golang.org/x/time v0.5.0
google.golang.org/grpc v1.63.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
Expand All @@ -123,6 +123,7 @@ require (
)

require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
Expand Down Expand Up @@ -245,7 +246,7 @@ require (
github.com/pion/turn/v2 v2.0.8 // indirect
github.com/pion/udp v0.1.4 // indirect
github.com/pion/webrtc/v3 v3.1.42 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down Expand Up @@ -279,7 +280,7 @@ require (
go.uber.org/fx v1.20.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
Expand Down
Loading
Loading