Skip to content

Commit 1c12cf9

Browse files
holimantrianglesphere
authored andcommitted
core/vm, params: ensure order of forks, prevent overflow (ethereum#29023)
This PR fixes an overflow which can could happen if inconsistent blockchain rules were configured. Additionally, it tries to prevent such inconsistencies from occurring by making sure that merge cannot be enabled unless previous fork(s) are also enabled.
1 parent fbf1ff7 commit 1c12cf9

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

core/vm/operations_acl.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc {
187187
// outside of this function, as part of the dynamic gas, and that will make it
188188
// also become correctly reported to tracers.
189189
contract.Gas += coldCost
190-
return gas + coldCost, nil
190+
191+
var overflow bool
192+
if gas, overflow = math.SafeAdd(gas, coldCost); overflow {
193+
return 0, ErrGasUintOverflow
194+
}
195+
return gas, nil
191196
}
192197
}
193198

internal/ethapi/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
17961796
tx *types.Transaction
17971797
err error
17981798
)
1799+
b.SetPoS()
17991800
switch i {
18001801
case 0:
18011802
// transfer 1000wei
@@ -1844,7 +1845,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
18441845
b.AddTx(tx)
18451846
txHashes[i] = tx.Hash()
18461847
}
1847-
b.SetPoS()
18481848
})
18491849
return backend, txHashes
18501850
}

params/config.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
10421042
if chainID == nil {
10431043
chainID = new(big.Int)
10441044
}
1045+
// disallow setting Merge out of order
1046+
isMerge = isMerge && c.IsLondon(num)
10451047
return Rules{
10461048
ChainID: new(big.Int).Set(chainID),
10471049
IsHomestead: c.IsHomestead(num),
@@ -1055,13 +1057,13 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
10551057
IsBerlin: c.IsBerlin(num),
10561058
IsLondon: c.IsLondon(num),
10571059
IsMerge: isMerge,
1058-
IsShanghai: c.IsShanghai(num, timestamp),
1059-
IsCancun: c.IsCancun(num, timestamp),
1060-
IsPrague: c.IsPrague(num, timestamp),
1061-
IsVerkle: c.IsVerkle(num, timestamp),
1060+
IsShanghai: isMerge && c.IsShanghai(num, timestamp),
1061+
IsCancun: isMerge && c.IsCancun(num, timestamp),
1062+
IsPrague: isMerge && c.IsPrague(num, timestamp),
1063+
IsVerkle: isMerge && c.IsVerkle(num, timestamp),
10621064
// Optimism
1063-
IsOptimismBedrock: c.IsOptimismBedrock(num),
1064-
IsOptimismRegolith: c.IsOptimismRegolith(timestamp),
1065-
IsOptimismCanyon: c.IsOptimismCanyon(timestamp),
1065+
IsOptimismBedrock: isMerge && c.IsOptimismBedrock(num),
1066+
IsOptimismRegolith: isMerge && c.IsOptimismRegolith(timestamp),
1067+
IsOptimismCanyon: isMerge && c.IsOptimismCanyon(timestamp),
10661068
}
10671069
}

params/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func TestConfigRules(t *testing.T) {
140140

141141
func TestConfigRulesRegolith(t *testing.T) {
142142
c := &ChainConfig{
143+
LondonBlock: new(big.Int),
143144
RegolithTime: newUint64(500),
144145
Optimism: &OptimismConfig{},
145146
}

0 commit comments

Comments
 (0)