Skip to content

Commit aa6005b

Browse files
holimankaralabe
authored andcommitted
core/vm, params: refactor chain configuration (#19735)
* params, core/vm: deprecating gastable, part 1 * core/vm, params: deprecate gastable, use both constant and dynamic gas * core/vm, params: remove gastable, remove copypaste * core/vm: make use of the chainrules * interpreter: make tracing count constant+dynamic gas * core/vm: review concerns (param/method name changes) * core/vm: make use of chainrules more
1 parent a7de796 commit aa6005b

File tree

9 files changed

+329
-505
lines changed

9 files changed

+329
-505
lines changed

core/vm/evm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type (
4444
func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
4545
if contract.CodeAddr != nil {
4646
precompiles := PrecompiledContractsHomestead
47-
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
47+
if evm.chainRules.IsByzantium {
4848
precompiles = PrecompiledContractsByzantium
4949
}
5050
if p := precompiles[*contract.CodeAddr]; p != nil {
@@ -203,10 +203,10 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
203203
)
204204
if !evm.StateDB.Exist(addr) {
205205
precompiles := PrecompiledContractsHomestead
206-
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
206+
if evm.chainRules.IsByzantium {
207207
precompiles = PrecompiledContractsByzantium
208208
}
209-
if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 {
209+
if precompiles[addr] == nil && evm.chainRules.IsEIP158 && value.Sign() == 0 {
210210
// Calling a non existing account, don't do anything, but ping the tracer
211211
if evm.vmConfig.Debug && evm.depth == 0 {
212212
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
@@ -394,7 +394,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
394394
// Create a new account on the state
395395
snapshot := evm.StateDB.Snapshot()
396396
evm.StateDB.CreateAccount(address)
397-
if evm.ChainConfig().IsEIP158(evm.BlockNumber) {
397+
if evm.chainRules.IsEIP158 {
398398
evm.StateDB.SetNonce(address, 1)
399399
}
400400
evm.Transfer(evm.StateDB, caller.Address(), address, value)
@@ -416,7 +416,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
416416
ret, err := run(evm, contract, nil, false)
417417

418418
// check whether the max code size has been exceeded
419-
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
419+
maxCodeSizeExceeded := evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize
420420
// if the contract creation ran successfully and no errors were returned
421421
// calculate the gas required to store the code. If the code could not
422422
// be stored due to not enough gas set an error and let it be handled
@@ -433,7 +433,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
433433
// When an error was returned by the EVM or when setting the creation code
434434
// above we revert to the snapshot and consume any gas remaining. Additionally
435435
// when we're in homestead this also counts for code storage gas errors.
436-
if maxCodeSizeExceeded || (err != nil && (evm.ChainConfig().IsHomestead(evm.BlockNumber) || err != ErrCodeStoreOutOfGas)) {
436+
if maxCodeSizeExceeded || (err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas)) {
437437
evm.StateDB.RevertToSnapshot(snapshot)
438438
if err != errExecutionReverted {
439439
contract.UseGas(contract.Gas)

core/vm/gas.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package vm
1818

1919
import (
2020
"math/big"
21-
22-
"github.com/ethereum/go-ethereum/params"
2321
)
2422

2523
// Gas costs
@@ -34,10 +32,10 @@ const (
3432

3533
// calcGas returns the actual gas cost of the call.
3634
//
37-
// The cost of gas was changed during the homestead price change HF. To allow for EIP150
38-
// to be implemented. The returned gas is gas - base * 63 / 64.
39-
func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) {
40-
if gasTable.CreateBySuicide > 0 {
35+
// The cost of gas was changed during the homestead price change HF.
36+
// As part of EIP 150 (TangerineWhistle), the returned gas is gas - base * 63 / 64.
37+
func callGas(isEip150 bool, availableGas, base uint64, callCost *big.Int) (uint64, error) {
38+
if isEip150 {
4139
availableGas = availableGas - base
4240
gas := availableGas - availableGas/64
4341
// If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150

0 commit comments

Comments
 (0)