Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix(evm): Added Cancun and Shanghai blocks to ChainConfig #1499

Merged
merged 8 commits into from
Nov 25, 2022
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (emv) [#1498](https://github.com/evmos/ethermint/pull/1498) Remove deprecated store migrations
* (evm) [#1499](https://github.com/evmos/ethermint/pull/1499) Add Shanghai and Cancun block
* (ante) [#1455](https://github.com/evmos/ethermint/pull/1455) Refactor `AnteHandler` logic
* (evm) [#1444](https://github.com/evmos/ethermint/pull/1444) Improve performance of `eth_estimateGas`
* (ante) [\#1388](https://github.com/evmos/ethermint/pull/1388) Optimize AnteHandler gas consumption
Expand Down
2 changes: 2 additions & 0 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (suite *AnteTestSuite) SetupTest() {
evmGenesis.Params.ChainConfig.ArrowGlacierBlock = &maxInt
evmGenesis.Params.ChainConfig.GrayGlacierBlock = &maxInt
evmGenesis.Params.ChainConfig.MergeNetsplitBlock = &maxInt
evmGenesis.Params.ChainConfig.ShanghaiBlock = &maxInt
evmGenesis.Params.ChainConfig.CancunBlock = &maxInt
}
if suite.evmParamsOption != nil {
suite.evmParamsOption(&evmGenesis.Params)
Expand Down
13 changes: 12 additions & 1 deletion proto/ethermint/evm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ message ChainConfig {
];
// dao_fork_support defines whether the nodes supports or opposes the DAO hard-fork
bool dao_fork_support = 3
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
// eip150_block: EIP150 implements the Gas price changes
// (https://github.com/ethereum/EIPs/issues/150) EIP150 HF block (nil no fork)
string eip150_block = 4 [
Expand Down Expand Up @@ -117,6 +117,17 @@ message ChainConfig {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"merge_netsplit_block\""
];
// shanghai_block switch block (nil = no fork, 0 = already on shanghai)
string shanghai_block = 22 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"shanghai_block\""
];
// cancun_block switch block (nil = no fork, 0 = already on cancun)
string cancun_block = 23 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"cancun_block\""
];

}

// State represents a single Storage key value pair item.
Expand Down
2 changes: 2 additions & 0 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
evmGenesis.Params.ChainConfig.ArrowGlacierBlock = &maxInt
evmGenesis.Params.ChainConfig.GrayGlacierBlock = &maxInt
evmGenesis.Params.ChainConfig.MergeNetsplitBlock = &maxInt
evmGenesis.Params.ChainConfig.ShanghaiBlock = &maxInt
evmGenesis.Params.ChainConfig.CancunBlock = &maxInt
genesis[types.ModuleName] = app.AppCodec().MustMarshalJSON(evmGenesis)
}
return genesis
Expand Down
15 changes: 12 additions & 3 deletions x/evm/types/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (cc ChainConfig) EthereumConfig(chainID *big.Int) *params.ChainConfig {
ArrowGlacierBlock: getBlockValue(cc.ArrowGlacierBlock),
GrayGlacierBlock: getBlockValue(cc.GrayGlacierBlock),
MergeNetsplitBlock: getBlockValue(cc.MergeNetsplitBlock),
ShanghaiBlock: nil, // TODO: add shanghai block
CancunBlock: nil, // TODO: add cancun block
ShanghaiBlock: getBlockValue(cc.ShanghaiBlock),
CancunBlock: getBlockValue(cc.CancunBlock),
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: nil,
Expand All @@ -60,6 +60,8 @@ func DefaultChainConfig() ChainConfig {
arrowGlacierBlock := sdk.ZeroInt()
grayGlacierBlock := sdk.ZeroInt()
mergeNetsplitBlock := sdk.ZeroInt()
shanghaiBlock := sdk.ZeroInt()
cancunBlock := sdk.ZeroInt()

return ChainConfig{
HomesteadBlock: &homesteadBlock,
Expand All @@ -79,6 +81,8 @@ func DefaultChainConfig() ChainConfig {
ArrowGlacierBlock: &arrowGlacierBlock,
GrayGlacierBlock: &grayGlacierBlock,
MergeNetsplitBlock: &mergeNetsplitBlock,
ShanghaiBlock: &shanghaiBlock,
CancunBlock: &cancunBlock,
}
}

Expand Down Expand Up @@ -141,7 +145,12 @@ func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.MergeNetsplitBlock); err != nil {
return errorsmod.Wrap(err, "MergeNetsplitBlock")
}

if err := validateBlock(cc.ShanghaiBlock); err != nil {
return errorsmod.Wrap(err, "ShanghaiBlock")
}
if err := validateBlock(cc.CancunBlock); err != nil {
return errorsmod.Wrap(err, "CancunBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return errorsmod.Wrap(err, "invalid config fork order")
Expand Down
51 changes: 51 additions & 0 deletions x/evm/types/chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func TestChainConfigValidate(t *testing.T) {
MuirGlacierBlock: newIntPtr(0),
BerlinBlock: newIntPtr(0),
LondonBlock: newIntPtr(0),
CancunBlock: newIntPtr(0),
ShanghaiBlock: newIntPtr(0),
},
false,
},
Expand All @@ -58,6 +60,8 @@ func TestChainConfigValidate(t *testing.T) {
MuirGlacierBlock: nil,
BerlinBlock: nil,
LondonBlock: nil,
CancunBlock: nil,
ShanghaiBlock: nil,
},
false,
},
Expand Down Expand Up @@ -316,6 +320,53 @@ func TestChainConfigValidate(t *testing.T) {
},
true,
},
{
"invalid ShanghaiBlock",
ChainConfig{
HomesteadBlock: newIntPtr(0),
DAOForkBlock: newIntPtr(0),
EIP150Block: newIntPtr(0),
EIP150Hash: defaultEIP150Hash,
EIP155Block: newIntPtr(0),
EIP158Block: newIntPtr(0),
ByzantiumBlock: newIntPtr(0),
ConstantinopleBlock: newIntPtr(0),
PetersburgBlock: newIntPtr(0),
IstanbulBlock: newIntPtr(0),
MuirGlacierBlock: newIntPtr(0),
BerlinBlock: newIntPtr(0),
LondonBlock: newIntPtr(0),
ArrowGlacierBlock: newIntPtr(0),
GrayGlacierBlock: newIntPtr(0),
MergeNetsplitBlock: newIntPtr(0),
ShanghaiBlock: newIntPtr(-1),
},
true,
},
{
"invalid CancunBlock",
ChainConfig{
HomesteadBlock: newIntPtr(0),
DAOForkBlock: newIntPtr(0),
EIP150Block: newIntPtr(0),
EIP150Hash: defaultEIP150Hash,
EIP155Block: newIntPtr(0),
EIP158Block: newIntPtr(0),
ByzantiumBlock: newIntPtr(0),
ConstantinopleBlock: newIntPtr(0),
PetersburgBlock: newIntPtr(0),
IstanbulBlock: newIntPtr(0),
MuirGlacierBlock: newIntPtr(0),
BerlinBlock: newIntPtr(0),
LondonBlock: newIntPtr(0),
ArrowGlacierBlock: newIntPtr(0),
GrayGlacierBlock: newIntPtr(0),
MergeNetsplitBlock: newIntPtr(0),
ShanghaiBlock: newIntPtr(0),
CancunBlock: newIntPtr(-1),
},
true,
},
}

for _, tc := range testCases {
Expand Down
Loading