core/vm, params: ensure order of forks, prevent overflow

This commit is contained in:
Martin Holst Swende 2024-02-19 08:55:38 +01:00
parent 034bc4669f
commit 64d32e5a21
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 13 additions and 6 deletions

View file

@ -187,7 +187,12 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc {
// outside of this function, as part of the dynamic gas, and that will make it // outside of this function, as part of the dynamic gas, and that will make it
// also become correctly reported to tracers. // also become correctly reported to tracers.
contract.Gas += coldCost contract.Gas += coldCost
return gas + coldCost, nil
var overflow bool
if gas, overflow = math.SafeAdd(gas, coldCost); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
} }
} }

View file

@ -1818,6 +1818,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
tx *types.Transaction tx *types.Transaction
err error err error
) )
b.SetPoS()
switch i { switch i {
case 0: case 0:
// transfer 1000wei // transfer 1000wei
@ -1866,7 +1867,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
b.AddTx(tx) b.AddTx(tx)
txHashes[i] = tx.Hash() txHashes[i] = tx.Hash()
} }
b.SetPoS()
}) })
return backend, txHashes return backend, txHashes
} }

View file

@ -910,6 +910,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
if chainID == nil { if chainID == nil {
chainID = new(big.Int) chainID = new(big.Int)
} }
// disallow setting Merge out of order
isMerge = isMerge && c.IsLondon(num)
return Rules{ return Rules{
ChainID: new(big.Int).Set(chainID), ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num), IsHomestead: c.IsHomestead(num),
@ -923,9 +925,9 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsBerlin: c.IsBerlin(num), IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num), IsLondon: c.IsLondon(num),
IsMerge: isMerge, IsMerge: isMerge,
IsShanghai: c.IsShanghai(num, timestamp), IsShanghai: isMerge && c.IsShanghai(num, timestamp),
IsCancun: c.IsCancun(num, timestamp), IsCancun: isMerge && c.IsCancun(num, timestamp),
IsPrague: c.IsPrague(num, timestamp), IsPrague: isMerge && c.IsPrague(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp), IsVerkle: isMerge && c.IsVerkle(num, timestamp),
} }
} }