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

Commit 15e4da3

Browse files
fix(evm): Added Cancun and Shanghai blocks to ChainConfig (#1499)
* (refactor): Added Cancun and Shanghai blocks to ChainConfig * (tests): Added test for invalid Shanghai and Cancun block * (fix): ran proto linter * Applied changes from code review * Added CHANGELOG entry Co-authored-by: Federico Kunze Küllmer <[email protected]>
1 parent 8866ae0 commit 15e4da3

File tree

7 files changed

+294
-104
lines changed

7 files changed

+294
-104
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5858

5959
### Improvements
6060

61-
* (emv) [#1498](https://github.com/evmos/ethermint/pull/1498) Remove deprecated store migrations
61+
* (evm) [#1499](https://github.com/evmos/ethermint/pull/1499) Add Shanghai and Cancun block
6262
* (ante) [#1455](https://github.com/evmos/ethermint/pull/1455) Refactor `AnteHandler` logic
6363
* (evm) [#1444](https://github.com/evmos/ethermint/pull/1444) Improve performance of `eth_estimateGas`
6464
* (ante) [\#1388](https://github.com/evmos/ethermint/pull/1388) Optimize AnteHandler gas consumption

app/ante/utils_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func (suite *AnteTestSuite) SetupTest() {
9999
evmGenesis.Params.ChainConfig.ArrowGlacierBlock = &maxInt
100100
evmGenesis.Params.ChainConfig.GrayGlacierBlock = &maxInt
101101
evmGenesis.Params.ChainConfig.MergeNetsplitBlock = &maxInt
102+
evmGenesis.Params.ChainConfig.ShanghaiBlock = &maxInt
103+
evmGenesis.Params.ChainConfig.CancunBlock = &maxInt
102104
}
103105
if suite.evmParamsOption != nil {
104106
suite.evmParamsOption(&evmGenesis.Params)

proto/ethermint/evm/v1/evm.proto

+12-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ message ChainConfig {
3939
];
4040
// dao_fork_support defines whether the nodes supports or opposes the DAO hard-fork
4141
bool dao_fork_support = 3
42-
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
42+
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
4343
// eip150_block: EIP150 implements the Gas price changes
4444
// (https://github.com/ethereum/EIPs/issues/150) EIP150 HF block (nil no fork)
4545
string eip150_block = 4 [
@@ -117,6 +117,17 @@ message ChainConfig {
117117
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
118118
(gogoproto.moretags) = "yaml:\"merge_netsplit_block\""
119119
];
120+
// shanghai_block switch block (nil = no fork, 0 = already on shanghai)
121+
string shanghai_block = 22 [
122+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
123+
(gogoproto.moretags) = "yaml:\"shanghai_block\""
124+
];
125+
// cancun_block switch block (nil = no fork, 0 = already on cancun)
126+
string cancun_block = 23 [
127+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
128+
(gogoproto.moretags) = "yaml:\"cancun_block\""
129+
];
130+
120131
}
121132

122133
// State represents a single Storage key value pair item.

x/evm/keeper/keeper_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
126126
evmGenesis.Params.ChainConfig.ArrowGlacierBlock = &maxInt
127127
evmGenesis.Params.ChainConfig.GrayGlacierBlock = &maxInt
128128
evmGenesis.Params.ChainConfig.MergeNetsplitBlock = &maxInt
129+
evmGenesis.Params.ChainConfig.ShanghaiBlock = &maxInt
130+
evmGenesis.Params.ChainConfig.CancunBlock = &maxInt
129131
genesis[types.ModuleName] = app.AppCodec().MustMarshalJSON(evmGenesis)
130132
}
131133
return genesis

x/evm/types/chain_config.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func (cc ChainConfig) EthereumConfig(chainID *big.Int) *params.ChainConfig {
3535
ArrowGlacierBlock: getBlockValue(cc.ArrowGlacierBlock),
3636
GrayGlacierBlock: getBlockValue(cc.GrayGlacierBlock),
3737
MergeNetsplitBlock: getBlockValue(cc.MergeNetsplitBlock),
38-
ShanghaiBlock: nil, // TODO: add shanghai block
39-
CancunBlock: nil, // TODO: add cancun block
38+
ShanghaiBlock: getBlockValue(cc.ShanghaiBlock),
39+
CancunBlock: getBlockValue(cc.CancunBlock),
4040
TerminalTotalDifficulty: nil,
4141
Ethash: nil,
4242
Clique: nil,
@@ -60,6 +60,8 @@ func DefaultChainConfig() ChainConfig {
6060
arrowGlacierBlock := sdk.ZeroInt()
6161
grayGlacierBlock := sdk.ZeroInt()
6262
mergeNetsplitBlock := sdk.ZeroInt()
63+
shanghaiBlock := sdk.ZeroInt()
64+
cancunBlock := sdk.ZeroInt()
6365

6466
return ChainConfig{
6567
HomesteadBlock: &homesteadBlock,
@@ -79,6 +81,8 @@ func DefaultChainConfig() ChainConfig {
7981
ArrowGlacierBlock: &arrowGlacierBlock,
8082
GrayGlacierBlock: &grayGlacierBlock,
8183
MergeNetsplitBlock: &mergeNetsplitBlock,
84+
ShanghaiBlock: &shanghaiBlock,
85+
CancunBlock: &cancunBlock,
8286
}
8387
}
8488

@@ -141,7 +145,12 @@ func (cc ChainConfig) Validate() error {
141145
if err := validateBlock(cc.MergeNetsplitBlock); err != nil {
142146
return errorsmod.Wrap(err, "MergeNetsplitBlock")
143147
}
144-
148+
if err := validateBlock(cc.ShanghaiBlock); err != nil {
149+
return errorsmod.Wrap(err, "ShanghaiBlock")
150+
}
151+
if err := validateBlock(cc.CancunBlock); err != nil {
152+
return errorsmod.Wrap(err, "CancunBlock")
153+
}
145154
// NOTE: chain ID is not needed to check config order
146155
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
147156
return errorsmod.Wrap(err, "invalid config fork order")

x/evm/types/chain_config_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func TestChainConfigValidate(t *testing.T) {
3939
MuirGlacierBlock: newIntPtr(0),
4040
BerlinBlock: newIntPtr(0),
4141
LondonBlock: newIntPtr(0),
42+
CancunBlock: newIntPtr(0),
43+
ShanghaiBlock: newIntPtr(0),
4244
},
4345
false,
4446
},
@@ -58,6 +60,8 @@ func TestChainConfigValidate(t *testing.T) {
5860
MuirGlacierBlock: nil,
5961
BerlinBlock: nil,
6062
LondonBlock: nil,
63+
CancunBlock: nil,
64+
ShanghaiBlock: nil,
6165
},
6266
false,
6367
},
@@ -316,6 +320,53 @@ func TestChainConfigValidate(t *testing.T) {
316320
},
317321
true,
318322
},
323+
{
324+
"invalid ShanghaiBlock",
325+
ChainConfig{
326+
HomesteadBlock: newIntPtr(0),
327+
DAOForkBlock: newIntPtr(0),
328+
EIP150Block: newIntPtr(0),
329+
EIP150Hash: defaultEIP150Hash,
330+
EIP155Block: newIntPtr(0),
331+
EIP158Block: newIntPtr(0),
332+
ByzantiumBlock: newIntPtr(0),
333+
ConstantinopleBlock: newIntPtr(0),
334+
PetersburgBlock: newIntPtr(0),
335+
IstanbulBlock: newIntPtr(0),
336+
MuirGlacierBlock: newIntPtr(0),
337+
BerlinBlock: newIntPtr(0),
338+
LondonBlock: newIntPtr(0),
339+
ArrowGlacierBlock: newIntPtr(0),
340+
GrayGlacierBlock: newIntPtr(0),
341+
MergeNetsplitBlock: newIntPtr(0),
342+
ShanghaiBlock: newIntPtr(-1),
343+
},
344+
true,
345+
},
346+
{
347+
"invalid CancunBlock",
348+
ChainConfig{
349+
HomesteadBlock: newIntPtr(0),
350+
DAOForkBlock: newIntPtr(0),
351+
EIP150Block: newIntPtr(0),
352+
EIP150Hash: defaultEIP150Hash,
353+
EIP155Block: newIntPtr(0),
354+
EIP158Block: newIntPtr(0),
355+
ByzantiumBlock: newIntPtr(0),
356+
ConstantinopleBlock: newIntPtr(0),
357+
PetersburgBlock: newIntPtr(0),
358+
IstanbulBlock: newIntPtr(0),
359+
MuirGlacierBlock: newIntPtr(0),
360+
BerlinBlock: newIntPtr(0),
361+
LondonBlock: newIntPtr(0),
362+
ArrowGlacierBlock: newIntPtr(0),
363+
GrayGlacierBlock: newIntPtr(0),
364+
MergeNetsplitBlock: newIntPtr(0),
365+
ShanghaiBlock: newIntPtr(0),
366+
CancunBlock: newIntPtr(-1),
367+
},
368+
true,
369+
},
319370
}
320371

321372
for _, tc := range testCases {

0 commit comments

Comments
 (0)