Skip to content

Commit

Permalink
Merge pull request ethereum#293 from ethereum-optimism/jg/backport
Browse files Browse the repository at this point in the history
core/vm, params: ensure order of forks, prevent overflow (ethereum#29023)
  • Loading branch information
trianglesphere authored Apr 8, 2024
2 parents fbf1ff7 + 1c12cf9 commit e9a306b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 6 additions & 1 deletion core/vm/operations_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc {
// outside of this function, as part of the dynamic gas, and that will make it
// also become correctly reported to tracers.
contract.Gas += coldCost
return gas + coldCost, nil

var overflow bool
if gas, overflow = math.SafeAdd(gas, coldCost); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
tx *types.Transaction
err error
)
b.SetPoS()
switch i {
case 0:
// transfer 1000wei
Expand Down Expand Up @@ -1844,7 +1845,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
b.AddTx(tx)
txHashes[i] = tx.Hash()
}
b.SetPoS()
})
return backend, txHashes
}
Expand Down
16 changes: 9 additions & 7 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
if chainID == nil {
chainID = new(big.Int)
}
// disallow setting Merge out of order
isMerge = isMerge && c.IsLondon(num)
return Rules{
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
Expand All @@ -1055,13 +1057,13 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num),
IsMerge: isMerge,
IsShanghai: c.IsShanghai(num, timestamp),
IsCancun: c.IsCancun(num, timestamp),
IsPrague: c.IsPrague(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp),
IsShanghai: isMerge && c.IsShanghai(num, timestamp),
IsCancun: isMerge && c.IsCancun(num, timestamp),
IsPrague: isMerge && c.IsPrague(num, timestamp),
IsVerkle: isMerge && c.IsVerkle(num, timestamp),
// Optimism
IsOptimismBedrock: c.IsOptimismBedrock(num),
IsOptimismRegolith: c.IsOptimismRegolith(timestamp),
IsOptimismCanyon: c.IsOptimismCanyon(timestamp),
IsOptimismBedrock: isMerge && c.IsOptimismBedrock(num),
IsOptimismRegolith: isMerge && c.IsOptimismRegolith(timestamp),
IsOptimismCanyon: isMerge && c.IsOptimismCanyon(timestamp),
}
}
1 change: 1 addition & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestConfigRules(t *testing.T) {

func TestConfigRulesRegolith(t *testing.T) {
c := &ChainConfig{
LondonBlock: new(big.Int),
RegolithTime: newUint64(500),
Optimism: &OptimismConfig{},
}
Expand Down

0 comments on commit e9a306b

Please sign in to comment.