Skip to content

Commit

Permalink
[evm] enable Merge at Redsea height (#3935)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored Oct 14, 2023
1 parent bd7b5e4 commit a2c0285
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 107 deletions.
15 changes: 10 additions & 5 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 IoTeX Foundation
// Copyright (c) 2023 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
Expand Down Expand Up @@ -393,9 +393,13 @@ func getChainConfig(g genesis.Blockchain, height uint64, id uint32) *params.Chai
if g.IsIceland(height) {
chainConfig.ChainID = new(big.Int).SetUint64(uint64(id))
}
// enable Berlin and London
// enable Berlin and London at Okhotsk
chainConfig.BerlinBlock = new(big.Int).SetUint64(g.OkhotskBlockHeight)
chainConfig.LondonBlock = new(big.Int).SetUint64(g.OkhotskBlockHeight)
// enable ArrowGlacier, GrayGlacier, MergeNetsplit at Redsea
chainConfig.ArrowGlacierBlock = new(big.Int).SetUint64(g.RedseaBlockHeight)
chainConfig.GrayGlacierBlock = new(big.Int).SetUint64(g.RedseaBlockHeight)
chainConfig.MergeNetsplitBlock = new(big.Int).SetUint64(g.RedseaBlockHeight)
return &chainConfig
}

Expand Down Expand Up @@ -428,13 +432,14 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte
remainingGas -= intriGas

// Set up the initial access list
if rules := chainConfig.Rules(evm.Context.BlockNumber, false); rules.IsBerlin {
rules := chainConfig.Rules(evm.Context.BlockNumber, g.IsRedsea(blockHeight)) // Merge enabled at Redsea height
if rules.IsBerlin {
stateDB.PrepareAccessList(evmParams.txCtx.Origin, evmParams.contract, vm.ActivePrecompiles(rules), evmParams.accessList)
}

var (
contractRawAddress = action.EmptyAddress
executor = vm.AccountRef(evmParams.txCtx.Origin)
london = evm.ChainConfig().IsLondon(evm.Context.BlockNumber)
ret []byte
evmErr error
refund uint64
Expand Down Expand Up @@ -466,7 +471,7 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte
if stateDB.Error() != nil {
log.L().Debug("statedb error", zap.Error(stateDB.Error()))
}
if !london {
if !rules.IsLondon {
// Before EIP-3529: refunds were capped to gasUsed / 2
refund = (evmParams.gas - remainingGas) / params.RefundQuotient
} else {
Expand Down
25 changes: 21 additions & 4 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 IoTeX Foundation
// Copyright (c) 2023 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
Expand Down Expand Up @@ -219,11 +219,16 @@ func TestConstantinople(t *testing.T) {
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
24838200,
},
// after Quebec
// Quebec - Redsea
{
action.EmptyAddress,
24838201,
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
34838200,
},
// after Redsea
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
math.MaxUint64,
Expand Down Expand Up @@ -268,7 +273,7 @@ func TestConstantinople(t *testing.T) {
require.True(evmChainConfig.IsPetersburg(evm.Context.BlockNumber))

// verify chainRules
chainRules := evmChainConfig.Rules(ps.context.BlockNumber, false)
chainRules := evmChainConfig.Rules(ps.context.BlockNumber, g.IsRedsea(e.height))
require.Equal(g.IsGreenland(e.height), chainRules.IsHomestead)
require.Equal(g.IsGreenland(e.height), chainRules.IsEIP150)
require.Equal(g.IsGreenland(e.height), chainRules.IsEIP158)
Expand Down Expand Up @@ -302,7 +307,19 @@ func TestConstantinople(t *testing.T) {
require.Equal(isOkhotsk, chainRules.IsBerlin)
require.Equal(isOkhotsk, evmChainConfig.IsLondon(evm.Context.BlockNumber))
require.Equal(isOkhotsk, chainRules.IsLondon)
require.False(chainRules.IsMerge)

// Redsea = enable ArrowGlacier, GrayGlacier, MergeNetsplit, and Merge
isRedsea := g.IsRedsea(e.height)
require.Equal(big.NewInt(int64(g.RedseaBlockHeight)), evmChainConfig.ArrowGlacierBlock)
require.Equal(big.NewInt(int64(g.RedseaBlockHeight)), evmChainConfig.GrayGlacierBlock)
require.Equal(big.NewInt(int64(g.RedseaBlockHeight)), evmChainConfig.MergeNetsplitBlock)
require.Equal(isRedsea, evmChainConfig.IsArrowGlacier(evm.Context.BlockNumber))
require.Equal(isRedsea, evmChainConfig.IsGrayGlacier(evm.Context.BlockNumber))
require.Equal(isRedsea, chainRules.IsMerge)

// Shanghai and Cancun not yet enabled
require.False(chainRules.IsShanghai)
require.False(evmChainConfig.IsCancun(evm.Context.BlockNumber))

// test basefee
require.Equal(new(big.Int), evm.Context.BaseFee)
Expand Down
41 changes: 23 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.18

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/ethereum/go-ethereum v1.10.21
github.com/ethereum/go-ethereum v1.10.26
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redis/v8 v8.11.5
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.4
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/vault/api v1.1.0
Expand All @@ -27,23 +27,23 @@ require (
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/multiformats/go-multiaddr v0.3.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/client_golang v1.14.0
github.com/rodaine/table v1.0.1
github.com/schollz/progressbar/v2 v2.15.0
github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.1
github.com/tidwall/gjson v1.11.0
github.com/tyler-smith/go-bip39 v1.0.2
github.com/tyler-smith/go-bip39 v1.1.0
go.elastic.co/ecszap v1.0.0
go.etcd.io/bbolt v1.3.5
go.etcd.io/bbolt v1.3.6
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0
go.opentelemetry.io/otel v1.9.0
go.opentelemetry.io/otel/exporters/jaeger v1.0.1
go.opentelemetry.io/otel/sdk v1.0.1
go.opentelemetry.io/otel/trace v1.9.0
go.uber.org/automaxprocs v1.2.0
go.uber.org/config v1.3.1
go.uber.org/zap v1.16.0
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.1.0
golang.org/x/net v0.7.0
golang.org/x/sync v0.1.0
Expand All @@ -58,8 +58,8 @@ require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/holiman/uint256 v1.2.0
github.com/mackerelio/go-osstat v0.2.4
github.com/prometheus/client_model v0.2.0
github.com/shirou/gopsutil/v3 v3.22.2
github.com/prometheus/client_model v0.3.0
github.com/shirou/gopsutil/v3 v3.22.8
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/text v0.7.0
Expand All @@ -70,7 +70,7 @@ require (
github.com/benbjohnson/clock v1.0.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.1.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
Expand All @@ -79,10 +79,11 @@ require (
github.com/dustinxie/gmsm v1.4.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand All @@ -109,6 +110,7 @@ require (
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/cpuid/v2 v2.0.4 // indirect
github.com/koron/go-ssdp v0.0.0-20191105050749-2e1c40ed0b5d // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/libp2p/go-addr-util v0.0.2 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
Expand Down Expand Up @@ -152,7 +154,9 @@ require (
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magefile/mage v1.9.0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
Expand All @@ -174,17 +178,17 @@ require (
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect
Expand All @@ -193,6 +197,7 @@ require (
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/time v0.1.0 // indirect
Expand All @@ -201,6 +206,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.4.2
replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.4.3

replace golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3
Loading

0 comments on commit a2c0285

Please sign in to comment.