Skip to content

Commit c8a1c0a

Browse files
authored
Merge pull request #19993 from karalabe/istanbul-eip-integration
core/vm: enable istanbul EIPs in the jump table
2 parents 961aa05 + 4aeeddc commit c8a1c0a

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

cmd/geth/retesteth.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type CParamsParams struct {
132132
ByzantiumForkBlock *math.HexOrDecimal64 `json:"byzantiumForkBlock"`
133133
ConstantinopleForkBlock *math.HexOrDecimal64 `json:"constantinopleForkBlock"`
134134
ConstantinopleFixForkBlock *math.HexOrDecimal64 `json:"constantinopleFixForkBlock"`
135+
IstanbulBlock *math.HexOrDecimal64 `json:"istanbulForkBlock"`
135136
ChainID *math.HexOrDecimal256 `json:"chainID"`
136137
MaximumExtraDataSize math.HexOrDecimal64 `json:"maximumExtraDataSize"`
137138
TieBreakingGas bool `json:"tieBreakingGas"`
@@ -319,6 +320,7 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
319320
byzantiumBlock *big.Int
320321
constantinopleBlock *big.Int
321322
petersburgBlock *big.Int
323+
istanbulBlock *big.Int
322324
)
323325
if chainParams.Params.HomesteadForkBlock != nil {
324326
homesteadBlock = big.NewInt(int64(*chainParams.Params.HomesteadForkBlock))
@@ -345,6 +347,10 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
345347
if constantinopleBlock != nil && petersburgBlock == nil {
346348
petersburgBlock = big.NewInt(100000000000)
347349
}
350+
if chainParams.Params.IstanbulBlock != nil {
351+
istanbulBlock = big.NewInt(int64(*chainParams.Params.IstanbulBlock))
352+
}
353+
348354
genesis := &core.Genesis{
349355
Config: &params.ChainConfig{
350356
ChainID: chainId,
@@ -357,6 +363,7 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
357363
ByzantiumBlock: byzantiumBlock,
358364
ConstantinopleBlock: constantinopleBlock,
359365
PetersburgBlock: petersburgBlock,
366+
IstanbulBlock: istanbulBlock,
360367
},
361368
Nonce: uint64(chainParams.Genesis.Nonce),
362369
Timestamp: uint64(chainParams.Genesis.Timestamp),

core/vm/interpreter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
9393
if !cfg.JumpTable[STOP].valid {
9494
var jt JumpTable
9595
switch {
96+
case evm.chainRules.IsIstanbul:
97+
jt = istanbulInstructionSet
9698
case evm.chainRules.IsConstantinople:
9799
jt = constantinopleInstructionSet
98100
case evm.chainRules.IsByzantium:

core/vm/jump_table.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,27 @@ var (
6060
spuriousDragonInstructionSet = newSpuriousDragonInstructionSet()
6161
byzantiumInstructionSet = newByzantiumInstructionSet()
6262
constantinopleInstructionSet = newConstantinopleInstructionSet()
63+
istanbulInstructionSet = newIstanbulInstructionSet()
6364
)
6465

6566
// JumpTable contains the EVM opcodes supported at a given fork.
6667
type JumpTable [256]operation
6768

68-
// NewConstantinopleInstructionSet returns the frontier, homestead
69+
// newIstanbulInstructionSet returns the frontier, homestead
70+
// byzantium, contantinople and petersburg instructions.
71+
func newIstanbulInstructionSet() JumpTable {
72+
instructionSet := newConstantinopleInstructionSet()
73+
74+
enable1344(&instructionSet) // ChainID opcode - https://eips.ethereum.org/EIPS/eip-1344
75+
enable1884(&instructionSet) // Reprice reader opcodes - https://eips.ethereum.org/EIPS/eip-1884
76+
enable2200(&instructionSet) // Net metered SSTORE - https://eips.ethereum.org/EIPS/eip-2200
77+
78+
return instructionSet
79+
}
80+
81+
// newConstantinopleInstructionSet returns the frontier, homestead
6982
// byzantium and contantinople instructions.
7083
func newConstantinopleInstructionSet() JumpTable {
71-
// instructions that can be executed during the byzantium phase.
7284
instructionSet := newByzantiumInstructionSet()
7385
instructionSet[SHL] = operation{
7486
execute: opSHL,
@@ -112,10 +124,9 @@ func newConstantinopleInstructionSet() JumpTable {
112124
return instructionSet
113125
}
114126

115-
// NewByzantiumInstructionSet returns the frontier, homestead and
127+
// newByzantiumInstructionSet returns the frontier, homestead and
116128
// byzantium instructions.
117129
func newByzantiumInstructionSet() JumpTable {
118-
// instructions that can be executed during the homestead phase.
119130
instructionSet := newSpuriousDragonInstructionSet()
120131
instructionSet[STATICCALL] = operation{
121132
execute: opStaticCall,
@@ -177,7 +188,7 @@ func newTangerineWhistleInstructionSet() JumpTable {
177188
return instructionSet
178189
}
179190

180-
// NewHomesteadInstructionSet returns the frontier and homestead
191+
// newHomesteadInstructionSet returns the frontier and homestead
181192
// instructions that can be executed during the homestead phase.
182193
func newHomesteadInstructionSet() JumpTable {
183194
instructionSet := newFrontierInstructionSet()
@@ -194,7 +205,7 @@ func newHomesteadInstructionSet() JumpTable {
194205
return instructionSet
195206
}
196207

197-
// NewFrontierInstructionSet returns the frontier instructions
208+
// newFrontierInstructionSet returns the frontier instructions
198209
// that can be executed during the frontier phase.
199210
func newFrontierInstructionSet() JumpTable {
200211
return JumpTable{

tests/init.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ var Forks = map[string]*params.ChainConfig{
7575
ConstantinopleBlock: big.NewInt(0),
7676
PetersburgBlock: big.NewInt(0),
7777
},
78+
"Istanbul": {
79+
ChainID: big.NewInt(1),
80+
HomesteadBlock: big.NewInt(0),
81+
EIP150Block: big.NewInt(0),
82+
EIP155Block: big.NewInt(0),
83+
EIP158Block: big.NewInt(0),
84+
DAOForkBlock: big.NewInt(0),
85+
ByzantiumBlock: big.NewInt(0),
86+
ConstantinopleBlock: big.NewInt(0),
87+
PetersburgBlock: big.NewInt(0),
88+
IstanbulBlock: big.NewInt(0),
89+
},
7890
"FrontierToHomesteadAt5": {
7991
ChainID: big.NewInt(1),
8092
HomesteadBlock: big.NewInt(5),
@@ -117,6 +129,17 @@ var Forks = map[string]*params.ChainConfig{
117129
ConstantinopleBlock: big.NewInt(5),
118130
PetersburgBlock: big.NewInt(5),
119131
},
132+
"ConstantinopleFixToIstanbulAt5": {
133+
ChainID: big.NewInt(1),
134+
HomesteadBlock: big.NewInt(0),
135+
EIP150Block: big.NewInt(0),
136+
EIP155Block: big.NewInt(0),
137+
EIP158Block: big.NewInt(0),
138+
ByzantiumBlock: big.NewInt(0),
139+
ConstantinopleBlock: big.NewInt(0),
140+
PetersburgBlock: big.NewInt(0),
141+
IstanbulBlock: big.NewInt(5),
142+
},
120143
}
121144

122145
// UnsupportedForkError is returned when a test requests a fork that isn't implemented.

0 commit comments

Comments
 (0)