Skip to content

Commit 64d32e5

Browse files
committed
core/vm, params: ensure order of forks, prevent overflow
1 parent 034bc46 commit 64d32e5

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
@@ -1818,6 +1818,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
18181818
tx *types.Transaction
18191819
err error
18201820
)
1821+
b.SetPoS()
18211822
switch i {
18221823
case 0:
18231824
// transfer 1000wei
@@ -1866,7 +1867,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha
18661867
b.AddTx(tx)
18671868
txHashes[i] = tx.Hash()
18681869
}
1869-
b.SetPoS()
18701870
})
18711871
return backend, txHashes
18721872
}

params/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
910910
if chainID == nil {
911911
chainID = new(big.Int)
912912
}
913+
// disallow setting Merge out of order
914+
isMerge = isMerge && c.IsLondon(num)
913915
return Rules{
914916
ChainID: new(big.Int).Set(chainID),
915917
IsHomestead: c.IsHomestead(num),
@@ -923,9 +925,9 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
923925
IsBerlin: c.IsBerlin(num),
924926
IsLondon: c.IsLondon(num),
925927
IsMerge: isMerge,
926-
IsShanghai: c.IsShanghai(num, timestamp),
927-
IsCancun: c.IsCancun(num, timestamp),
928-
IsPrague: c.IsPrague(num, timestamp),
929-
IsVerkle: c.IsVerkle(num, timestamp),
928+
IsShanghai: isMerge && c.IsShanghai(num, timestamp),
929+
IsCancun: isMerge && c.IsCancun(num, timestamp),
930+
IsPrague: isMerge && c.IsPrague(num, timestamp),
931+
IsVerkle: isMerge && c.IsVerkle(num, timestamp),
930932
}
931933
}

0 commit comments

Comments
 (0)