Skip to content

Commit 6383a33

Browse files
holimanTristan-Wilson
authored andcommitted
core/vm, params: ensure order of forks, prevent overflow (#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. (cherry picked from commit ac0ff04) aka ethereum/go-ethereum#29023
1 parent 39c3ff6 commit 6383a33

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
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
@@ -1408,6 +1408,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
14081408
tx *types.Transaction
14091409
err error
14101410
)
1411+
b.SetPoS()
14111412
switch i {
14121413
case 0:
14131414
// transfer 1000wei
@@ -1456,7 +1457,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
14561457
b.AddTx(tx)
14571458
txHashes[i] = tx.Hash()
14581459
}
1459-
b.SetPoS()
14601460
})
14611461
return backend, txHashes
14621462
}

params/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64, curren
881881
if chainID == nil {
882882
chainID = new(big.Int)
883883
}
884+
// disallow setting Merge out of order
885+
isMerge = isMerge && c.IsLondon(num)
884886
return Rules{
885887
IsArbitrum: c.IsArbitrum(),
886888
ChainID: new(big.Int).Set(chainID),
@@ -895,9 +897,9 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64, curren
895897
IsBerlin: c.IsBerlin(num),
896898
IsLondon: c.IsLondon(num),
897899
IsMerge: isMerge,
898-
IsShanghai: c.IsShanghai(num, timestamp, currentArbosVersion),
899-
IsCancun: c.IsCancun(num, timestamp, currentArbosVersion),
900-
IsPrague: c.IsPrague(num, timestamp),
901-
IsVerkle: c.IsVerkle(num, timestamp),
900+
IsShanghai: isMerge && c.IsShanghai(num, timestamp, currentArbosVersion),
901+
IsCancun: isMerge && c.IsCancun(num, timestamp, currentArbosVersion),
902+
IsPrague: isMerge && c.IsPrague(num, timestamp),
903+
IsVerkle: isMerge && c.IsVerkle(num, timestamp),
902904
}
903905
}

0 commit comments

Comments
 (0)