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
This commit is contained in:
Martin Holst Swende 2019-08-05 10:01:02 +02:00 committed by Péter Szilágyi
parent a7de796840
commit aa6005b469
9 changed files with 342 additions and 518 deletions

@ -44,7 +44,7 @@ type (
func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) { func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
if contract.CodeAddr != nil { if contract.CodeAddr != nil {
precompiles := PrecompiledContractsHomestead precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsByzantium(evm.BlockNumber) { if evm.chainRules.IsByzantium {
precompiles = PrecompiledContractsByzantium precompiles = PrecompiledContractsByzantium
} }
if p := precompiles[*contract.CodeAddr]; p != nil { if p := precompiles[*contract.CodeAddr]; p != nil {
@ -203,10 +203,10 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
) )
if !evm.StateDB.Exist(addr) { if !evm.StateDB.Exist(addr) {
precompiles := PrecompiledContractsHomestead precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsByzantium(evm.BlockNumber) { if evm.chainRules.IsByzantium {
precompiles = PrecompiledContractsByzantium precompiles = PrecompiledContractsByzantium
} }
if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 { if precompiles[addr] == nil && evm.chainRules.IsEIP158 && value.Sign() == 0 {
// Calling a non existing account, don't do anything, but ping the tracer // Calling a non existing account, don't do anything, but ping the tracer
if evm.vmConfig.Debug && evm.depth == 0 { if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value) 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,
// Create a new account on the state // Create a new account on the state
snapshot := evm.StateDB.Snapshot() snapshot := evm.StateDB.Snapshot()
evm.StateDB.CreateAccount(address) evm.StateDB.CreateAccount(address)
if evm.ChainConfig().IsEIP158(evm.BlockNumber) { if evm.chainRules.IsEIP158 {
evm.StateDB.SetNonce(address, 1) evm.StateDB.SetNonce(address, 1)
} }
evm.Transfer(evm.StateDB, caller.Address(), address, value) evm.Transfer(evm.StateDB, caller.Address(), address, value)
@ -416,7 +416,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
ret, err := run(evm, contract, nil, false) ret, err := run(evm, contract, nil, false)
// check whether the max code size has been exceeded // check whether the max code size has been exceeded
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize maxCodeSizeExceeded := evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize
// if the contract creation ran successfully and no errors were returned // if the contract creation ran successfully and no errors were returned
// calculate the gas required to store the code. If the code could not // calculate the gas required to store the code. If the code could not
// be stored due to not enough gas set an error and let it be handled // 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,
// When an error was returned by the EVM or when setting the creation code // When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally // above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors. // when we're in homestead this also counts for code storage gas errors.
if maxCodeSizeExceeded || (err != nil && (evm.ChainConfig().IsHomestead(evm.BlockNumber) || err != ErrCodeStoreOutOfGas)) { if maxCodeSizeExceeded || (err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas)) {
evm.StateDB.RevertToSnapshot(snapshot) evm.StateDB.RevertToSnapshot(snapshot)
if err != errExecutionReverted { if err != errExecutionReverted {
contract.UseGas(contract.Gas) contract.UseGas(contract.Gas)

@ -18,8 +18,6 @@ package vm
import ( import (
"math/big" "math/big"
"github.com/ethereum/go-ethereum/params"
) )
// Gas costs // Gas costs
@ -34,10 +32,10 @@ const (
// calcGas returns the actual gas cost of the call. // calcGas returns the actual gas cost of the call.
// //
// The cost of gas was changed during the homestead price change HF. To allow for EIP150 // The cost of gas was changed during the homestead price change HF.
// to be implemented. The returned gas is gas - base * 63 / 64. // As part of EIP 150 (TangerineWhistle), the returned gas is gas - base * 63 / 64.
func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) { func callGas(isEip150 bool, availableGas, base uint64, callCost *big.Int) (uint64, error) {
if gasTable.CreateBySuicide > 0 { if isEip150 {
availableGas = availableGas - base availableGas = availableGas - base
gas := availableGas - availableGas/64 gas := availableGas - availableGas/64
// If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150 // If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150

@ -53,59 +53,45 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) {
return 0, nil return 0, nil
} }
func gasCallDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { // memoryCopierGas creates the gas functions for the following opcodes, and takes
gas, err := memoryGasCost(mem, memorySize) // the stack position of the operand which determines the size of the data to copy
if err != nil { // as argument:
return 0, err // CALLDATACOPY (stack position 2)
} // CODECOPY (stack position 2)
// EXTCODECOPY (stack poition 3)
// RETURNDATACOPY (stack position 2)
func memoryCopierGas(stackpos int) gasFunc {
return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
// Gas for expanding the memory
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
// And gas for copying data, charged per word at param.CopyGas
words, overflow := bigUint64(stack.Back(stackpos))
if overflow {
return 0, errGasUintOverflow
}
var overflow bool if words, overflow = math.SafeMul(toWordSize(words), params.CopyGas); overflow {
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow { return 0, errGasUintOverflow
return 0, errGasUintOverflow }
}
words, overflow := bigUint64(stack.Back(2)) if gas, overflow = math.SafeAdd(gas, words); overflow {
if overflow { return 0, errGasUintOverflow
return 0, errGasUintOverflow }
return gas, nil
} }
if words, overflow = math.SafeMul(toWordSize(words), params.CopyGas); overflow {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, words); overflow {
return 0, errGasUintOverflow
}
return gas, nil
} }
func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { var (
gas, err := memoryGasCost(mem, memorySize) gasCallDataCopy = memoryCopierGas(2)
if err != nil { gasCodeCopy = memoryCopierGas(2)
return 0, err gasExtCodeCopy = memoryCopierGas(3)
} gasReturnDataCopy = memoryCopierGas(2)
)
var overflow bool func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow {
return 0, errGasUintOverflow
}
words, overflow := bigUint64(stack.Back(2))
if overflow {
return 0, errGasUintOverflow
}
if words, overflow = math.SafeMul(toWordSize(words), params.CopyGas); overflow {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, words); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var ( var (
y, x = stack.Back(1), stack.Back(0) y, x = stack.Back(1), stack.Back(0)
current = evm.StateDB.GetState(contract.Address(), common.BigToHash(x)) current = evm.StateDB.GetState(contract.Address(), common.BigToHash(x))
@ -175,7 +161,7 @@ func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m
} }
func makeGasLog(n uint64) gasFunc { func makeGasLog(n uint64) gasFunc {
return func(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
requestedSize, overflow := bigUint64(stack.Back(1)) requestedSize, overflow := bigUint64(stack.Back(1))
if overflow { if overflow {
return 0, errGasUintOverflow return 0, errGasUintOverflow
@ -204,17 +190,11 @@ func makeGasLog(n uint64) gasFunc {
} }
} }
func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasSha3(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize) gas, err := memoryGasCost(mem, memorySize)
if err != nil { if err != nil {
return 0, err return 0, err
} }
if gas, overflow = math.SafeAdd(gas, params.Sha3Gas); overflow {
return 0, errGasUintOverflow
}
wordGas, overflow := bigUint64(stack.Back(1)) wordGas, overflow := bigUint64(stack.Back(1))
if overflow { if overflow {
return 0, errGasUintOverflow return 0, errGasUintOverflow
@ -228,117 +208,27 @@ func gasSha3(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem
return gas, nil return gas, nil
} }
func gasCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { // pureMemoryGascost is used by several operations, which aside from their
// static cost have a dynamic cost which is solely based on the memory
// expansion
func pureMemoryGascost(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return memoryGasCost(mem, memorySize)
}
var (
gasReturn = pureMemoryGascost
gasRevert = pureMemoryGascost
gasMLoad = pureMemoryGascost
gasMStore8 = pureMemoryGascost
gasMStore = pureMemoryGascost
gasCreate = pureMemoryGascost
)
func gasCreate2(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas, err := memoryGasCost(mem, memorySize) gas, err := memoryGasCost(mem, memorySize)
if err != nil { if err != nil {
return 0, err return 0, err
} }
var overflow bool
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow {
return 0, errGasUintOverflow
}
wordGas, overflow := bigUint64(stack.Back(2))
if overflow {
return 0, errGasUintOverflow
}
if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.CopyGas); overflow {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, wordGas); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasExtCodeCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
var overflow bool
if gas, overflow = math.SafeAdd(gas, gt.ExtcodeCopy); overflow {
return 0, errGasUintOverflow
}
wordGas, overflow := bigUint64(stack.Back(3))
if overflow {
return 0, errGasUintOverflow
}
if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.CopyGas); overflow {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, wordGas); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasExtCodeHash(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return gt.ExtcodeHash, nil
}
func gasMLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasMStore8(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasMStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, errGasUintOverflow
}
if gas, overflow = math.SafeAdd(gas, GasFastestStep); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasCreate(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
if gas, overflow = math.SafeAdd(gas, params.CreateGas); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var overflow bool
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
if gas, overflow = math.SafeAdd(gas, params.Create2Gas); overflow {
return 0, errGasUintOverflow
}
wordGas, overflow := bigUint64(stack.Back(2)) wordGas, overflow := bigUint64(stack.Back(2))
if overflow { if overflow {
return 0, errGasUintOverflow return 0, errGasUintOverflow
@ -349,27 +239,14 @@ func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack,
if gas, overflow = math.SafeAdd(gas, wordGas); overflow { if gas, overflow = math.SafeAdd(gas, wordGas); overflow {
return 0, errGasUintOverflow return 0, errGasUintOverflow
} }
return gas, nil return gas, nil
} }
func gasBalance(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return gt.Balance, nil
}
func gasExtCodeSize(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return gt.ExtcodeSize, nil
}
func gasSLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return gt.SLoad, nil
}
func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8) expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8)
var ( var (
gas = expByteLen * gt.ExpByte // no overflow check required. Max is 256 * ExpByte gas gas = expByteLen * params.ExpByteFrontier // no overflow check required. Max is 256 * ExpByte gas
overflow bool overflow bool
) )
if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow { if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow {
@ -378,14 +255,26 @@ func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem
return gas, nil return gas, nil
} }
func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8)
var ( var (
gas = gt.Calls gas = expByteLen * params.ExpByteEIP158 // no overflow check required. Max is 256 * ExpByte gas
overflow bool
)
if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var (
gas uint64
transfersValue = stack.Back(2).Sign() != 0 transfersValue = stack.Back(2).Sign() != 0
address = common.BigToAddress(stack.Back(1)) address = common.BigToAddress(stack.Back(1))
eip158 = evm.ChainConfig().IsEIP158(evm.BlockNumber)
) )
if eip158 { if evm.chainRules.IsEIP158 {
if transfersValue && evm.StateDB.Empty(address) { if transfersValue && evm.StateDB.Empty(address) {
gas += params.CallNewAccountGas gas += params.CallNewAccountGas
} }
@ -404,7 +293,7 @@ func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem
return 0, errGasUintOverflow return 0, errGasUintOverflow
} }
evm.callGasTemp, err = callGas(gt, contract.Gas, gas, stack.Back(0)) evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -414,21 +303,22 @@ func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem
return gas, nil return gas, nil
} }
func gasCallCode(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas := gt.Calls
if stack.Back(2).Sign() != 0 {
gas += params.CallValueTransferGas
}
memoryGas, err := memoryGasCost(mem, memorySize) memoryGas, err := memoryGasCost(mem, memorySize)
if err != nil { if err != nil {
return 0, err return 0, err
} }
var overflow bool var (
gas uint64
overflow bool
)
if stack.Back(2).Sign() != 0 {
gas += params.CallValueTransferGas
}
if gas, overflow = math.SafeAdd(gas, memoryGas); overflow { if gas, overflow = math.SafeAdd(gas, memoryGas); overflow {
return 0, errGasUintOverflow return 0, errGasUintOverflow
} }
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
evm.callGasTemp, err = callGas(gt, contract.Gas, gas, stack.Back(0))
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -438,76 +328,57 @@ func gasCallCode(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack,
return gas, nil return gas, nil
} }
func gasReturn(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasDelegateCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return memoryGasCost(mem, memorySize) gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
if err != nil {
return 0, err
}
var overflow bool
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
return 0, errGasUintOverflow
}
return gas, nil
} }
func gasRevert(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasStaticCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
return memoryGasCost(mem, memorySize) gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
if err != nil {
return 0, err
}
var overflow bool
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
return 0, errGasUintOverflow
}
return gas, nil
} }
func gasSuicide(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var gas uint64 var gas uint64
// EIP150 homestead gas reprice fork: // EIP150 homestead gas reprice fork:
if evm.ChainConfig().IsEIP150(evm.BlockNumber) { if evm.chainRules.IsEIP150 {
gas = gt.Suicide gas = params.SelfdestructGasEIP150
var ( var address = common.BigToAddress(stack.Back(0))
address = common.BigToAddress(stack.Back(0))
eip158 = evm.ChainConfig().IsEIP158(evm.BlockNumber)
)
if eip158 { if evm.chainRules.IsEIP158 {
// if empty and transfers value // if empty and transfers value
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 { if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
gas += gt.CreateBySuicide gas += params.CreateBySelfdestructGas
} }
} else if !evm.StateDB.Exist(address) { } else if !evm.StateDB.Exist(address) {
gas += gt.CreateBySuicide gas += params.CreateBySelfdestructGas
} }
} }
if !evm.StateDB.HasSuicided(contract.Address()) { if !evm.StateDB.HasSuicided(contract.Address()) {
evm.StateDB.AddRefund(params.SuicideRefundGas) evm.StateDB.AddRefund(params.SelfdestructRefundGas)
}
return gas, nil
}
func gasDelegateCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
var overflow bool
if gas, overflow = math.SafeAdd(gas, gt.Calls); overflow {
return 0, errGasUintOverflow
}
evm.callGasTemp, err = callGas(gt, contract.Gas, gas, stack.Back(0))
if err != nil {
return 0, err
}
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
return 0, errGasUintOverflow
}
return gas, nil
}
func gasStaticCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
gas, err := memoryGasCost(mem, memorySize)
if err != nil {
return 0, err
}
var overflow bool
if gas, overflow = math.SafeAdd(gas, gt.Calls); overflow {
return 0, errGasUintOverflow
}
evm.callGasTemp, err = callGas(gt, contract.Gas, gas, stack.Back(0))
if err != nil {
return 0, err
}
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
return 0, errGasUintOverflow
} }
return gas, nil return gas, nil
} }

@ -694,7 +694,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor
input = memory.Get(offset.Int64(), size.Int64()) input = memory.Get(offset.Int64(), size.Int64())
gas = contract.Gas gas = contract.Gas
) )
if interpreter.evm.ChainConfig().IsEIP150(interpreter.evm.BlockNumber) { if interpreter.evm.chainRules.IsEIP150 {
gas -= gas / 64 gas -= gas / 64
} }
@ -704,7 +704,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor
// homestead we must check for CodeStoreOutOfGasError (homestead only // homestead we must check for CodeStoreOutOfGasError (homestead only
// rule) and treat as an error, if the ruleset is frontier we must // rule) and treat as an error, if the ruleset is frontier we must
// ignore this error and pretend the operation was successful. // ignore this error and pretend the operation was successful.
if interpreter.evm.ChainConfig().IsHomestead(interpreter.evm.BlockNumber) && suberr == ErrCodeStoreOutOfGas { if interpreter.evm.chainRules.IsHomestead && suberr == ErrCodeStoreOutOfGas {
stack.push(interpreter.intPool.getZero()) stack.push(interpreter.intPool.getZero())
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas { } else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
stack.push(interpreter.intPool.getZero()) stack.push(interpreter.intPool.getZero())

@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/params"
) )
// Config are the configuration options for the Interpreter // Config are the configuration options for the Interpreter
@ -71,9 +70,8 @@ type keccakState interface {
// EVMInterpreter represents an EVM interpreter // EVMInterpreter represents an EVM interpreter
type EVMInterpreter struct { type EVMInterpreter struct {
evm *EVM evm *EVM
cfg Config cfg Config
gasTable params.GasTable
intPool *intPool intPool *intPool
@ -91,11 +89,15 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
// we'll set the default jump table. // we'll set the default jump table.
if !cfg.JumpTable[STOP].valid { if !cfg.JumpTable[STOP].valid {
switch { switch {
case evm.ChainConfig().IsConstantinople(evm.BlockNumber): case evm.chainRules.IsConstantinople:
cfg.JumpTable = constantinopleInstructionSet cfg.JumpTable = constantinopleInstructionSet
case evm.ChainConfig().IsByzantium(evm.BlockNumber): case evm.chainRules.IsByzantium:
cfg.JumpTable = byzantiumInstructionSet cfg.JumpTable = byzantiumInstructionSet
case evm.ChainConfig().IsHomestead(evm.BlockNumber): case evm.chainRules.IsEIP158:
cfg.JumpTable = spuriousDragonInstructionSet
case evm.chainRules.IsEIP150:
cfg.JumpTable = tangerineWhistleInstructionSet
case evm.chainRules.IsHomestead:
cfg.JumpTable = homesteadInstructionSet cfg.JumpTable = homesteadInstructionSet
default: default:
cfg.JumpTable = frontierInstructionSet cfg.JumpTable = frontierInstructionSet
@ -103,9 +105,8 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
} }
return &EVMInterpreter{ return &EVMInterpreter{
evm: evm, evm: evm,
cfg: cfg, cfg: cfg,
gasTable: evm.ChainConfig().GasTable(evm.BlockNumber),
} }
} }
@ -210,6 +211,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
} }
} }
// Static portion of gas // Static portion of gas
cost = operation.constantGas // For tracing
if !contract.UseGas(operation.constantGas) { if !contract.UseGas(operation.constantGas) {
return nil, ErrOutOfGas return nil, ErrOutOfGas
} }
@ -234,8 +236,10 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// consume the gas and return an error if not enough gas is available. // consume the gas and return an error if not enough gas is available.
// cost is explicitly set so that the capture state defer method can get the proper cost // cost is explicitly set so that the capture state defer method can get the proper cost
if operation.dynamicGas != nil { if operation.dynamicGas != nil {
cost, err = operation.dynamicGas(in.gasTable, in.evm, contract, stack, mem, memorySize) var dynamicCost uint64
if err != nil || !contract.UseGas(cost) { dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
cost += dynamicCost // total cost, for debug tracing
if err != nil || !contract.UseGas(dynamicCost) {
return nil, ErrOutOfGas return nil, ErrOutOfGas
} }
} }

@ -24,7 +24,7 @@ import (
type ( type (
executionFunc func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) executionFunc func(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)
gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 gasFunc func(*EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64
// memorySizeFunc returns the required size, and whether the operation overflowed a uint64 // memorySizeFunc returns the required size, and whether the operation overflowed a uint64
memorySizeFunc func(*Stack) (size uint64, overflow bool) memorySizeFunc func(*Stack) (size uint64, overflow bool)
) )
@ -54,10 +54,12 @@ type operation struct {
} }
var ( var (
frontierInstructionSet = newFrontierInstructionSet() frontierInstructionSet = newFrontierInstructionSet()
homesteadInstructionSet = newHomesteadInstructionSet() homesteadInstructionSet = newHomesteadInstructionSet()
byzantiumInstructionSet = newByzantiumInstructionSet() tangerineWhistleInstructionSet = newTangerineWhistleInstructionSet()
constantinopleInstructionSet = newConstantinopleInstructionSet() spuriousDragonInstructionSet = newSpuriousDragonInstructionSet()
byzantiumInstructionSet = newByzantiumInstructionSet()
constantinopleInstructionSet = newConstantinopleInstructionSet()
) )
// NewConstantinopleInstructionSet returns the frontier, homestead // NewConstantinopleInstructionSet returns the frontier, homestead
@ -87,21 +89,22 @@ func newConstantinopleInstructionSet() [256]operation {
valid: true, valid: true,
} }
instructionSet[EXTCODEHASH] = operation{ instructionSet[EXTCODEHASH] = operation{
execute: opExtCodeHash, execute: opExtCodeHash,
dynamicGas: gasExtCodeHash, constantGas: params.ExtcodeHashGas,
minStack: minStack(1, 1), minStack: minStack(1, 1),
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
valid: true, valid: true,
} }
instructionSet[CREATE2] = operation{ instructionSet[CREATE2] = operation{
execute: opCreate2, execute: opCreate2,
dynamicGas: gasCreate2, constantGas: params.Create2Gas,
minStack: minStack(4, 1), dynamicGas: gasCreate2,
maxStack: maxStack(4, 1), minStack: minStack(4, 1),
memorySize: memoryCreate2, maxStack: maxStack(4, 1),
valid: true, memorySize: memoryCreate2,
writes: true, valid: true,
returns: true, writes: true,
returns: true,
} }
return instructionSet return instructionSet
} }
@ -110,15 +113,16 @@ func newConstantinopleInstructionSet() [256]operation {
// byzantium instructions. // byzantium instructions.
func newByzantiumInstructionSet() [256]operation { func newByzantiumInstructionSet() [256]operation {
// instructions that can be executed during the homestead phase. // instructions that can be executed during the homestead phase.
instructionSet := newHomesteadInstructionSet() instructionSet := newSpuriousDragonInstructionSet()
instructionSet[STATICCALL] = operation{ instructionSet[STATICCALL] = operation{
execute: opStaticCall, execute: opStaticCall,
dynamicGas: gasStaticCall, constantGas: params.CallGasEIP150,
minStack: minStack(6, 1), dynamicGas: gasStaticCall,
maxStack: maxStack(6, 1), minStack: minStack(6, 1),
memorySize: memoryStaticCall, maxStack: maxStack(6, 1),
valid: true, memorySize: memoryStaticCall,
returns: true, valid: true,
returns: true,
} }
instructionSet[RETURNDATASIZE] = operation{ instructionSet[RETURNDATASIZE] = operation{
execute: opReturnDataSize, execute: opReturnDataSize,
@ -128,12 +132,13 @@ func newByzantiumInstructionSet() [256]operation {
valid: true, valid: true,
} }
instructionSet[RETURNDATACOPY] = operation{ instructionSet[RETURNDATACOPY] = operation{
execute: opReturnDataCopy, execute: opReturnDataCopy,
dynamicGas: gasReturnDataCopy, constantGas: GasFastestStep,
minStack: minStack(3, 0), dynamicGas: gasReturnDataCopy,
maxStack: maxStack(3, 0), minStack: minStack(3, 0),
memorySize: memoryReturnDataCopy, maxStack: maxStack(3, 0),
valid: true, memorySize: memoryReturnDataCopy,
valid: true,
} }
instructionSet[REVERT] = operation{ instructionSet[REVERT] = operation{
execute: opRevert, execute: opRevert,
@ -148,18 +153,40 @@ func newByzantiumInstructionSet() [256]operation {
return instructionSet return instructionSet
} }
// EIP 158 a.k.a Spurious Dragon
func newSpuriousDragonInstructionSet() [256]operation {
instructionSet := newTangerineWhistleInstructionSet()
instructionSet[EXP].dynamicGas = gasExpEIP158
return instructionSet
}
// EIP 150 a.k.a Tangerine Whistle
func newTangerineWhistleInstructionSet() [256]operation {
instructionSet := newHomesteadInstructionSet()
instructionSet[BALANCE].constantGas = params.BalanceGasEIP150
instructionSet[EXTCODESIZE].constantGas = params.ExtcodeSizeGasEIP150
instructionSet[SLOAD].constantGas = params.SloadGasEIP150
instructionSet[EXTCODECOPY].constantGas = params.ExtcodeCopyBaseEIP150
instructionSet[CALL].constantGas = params.CallGasEIP150
instructionSet[CALLCODE].constantGas = params.CallGasEIP150
instructionSet[DELEGATECALL].constantGas = params.CallGasEIP150
return instructionSet
}
// NewHomesteadInstructionSet returns the frontier and homestead // NewHomesteadInstructionSet returns the frontier and homestead
// instructions that can be executed during the homestead phase. // instructions that can be executed during the homestead phase.
func newHomesteadInstructionSet() [256]operation { func newHomesteadInstructionSet() [256]operation {
instructionSet := newFrontierInstructionSet() instructionSet := newFrontierInstructionSet()
instructionSet[DELEGATECALL] = operation{ instructionSet[DELEGATECALL] = operation{
execute: opDelegateCall, execute: opDelegateCall,
dynamicGas: gasDelegateCall, dynamicGas: gasDelegateCall,
minStack: minStack(6, 1), constantGas: params.CallGasFrontier,
maxStack: maxStack(6, 1), minStack: minStack(6, 1),
memorySize: memoryDelegateCall, maxStack: maxStack(6, 1),
valid: true, memorySize: memoryDelegateCall,
returns: true, valid: true,
returns: true,
} }
return instructionSet return instructionSet
} }
@ -241,7 +268,7 @@ func newFrontierInstructionSet() [256]operation {
}, },
EXP: { EXP: {
execute: opExp, execute: opExp,
dynamicGas: gasExp, dynamicGas: gasExpFrontier,
minStack: minStack(2, 1), minStack: minStack(2, 1),
maxStack: maxStack(2, 1), maxStack: maxStack(2, 1),
valid: true, valid: true,
@ -331,12 +358,13 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
SHA3: { SHA3: {
execute: opSha3, execute: opSha3,
dynamicGas: gasSha3, constantGas: params.Sha3Gas,
minStack: minStack(2, 1), dynamicGas: gasSha3,
maxStack: maxStack(2, 1), minStack: minStack(2, 1),
memorySize: memorySha3, maxStack: maxStack(2, 1),
valid: true, memorySize: memorySha3,
valid: true,
}, },
ADDRESS: { ADDRESS: {
execute: opAddress, execute: opAddress,
@ -346,11 +374,11 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
BALANCE: { BALANCE: {
execute: opBalance, execute: opBalance,
dynamicGas: gasBalance, constantGas: params.BalanceGasFrontier,
minStack: minStack(1, 1), minStack: minStack(1, 1),
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
valid: true, valid: true,
}, },
ORIGIN: { ORIGIN: {
execute: opOrigin, execute: opOrigin,
@ -388,12 +416,13 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
CALLDATACOPY: { CALLDATACOPY: {
execute: opCallDataCopy, execute: opCallDataCopy,
dynamicGas: gasCallDataCopy, constantGas: GasFastestStep,
minStack: minStack(3, 0), dynamicGas: gasCallDataCopy,
maxStack: maxStack(3, 0), minStack: minStack(3, 0),
memorySize: memoryCallDataCopy, maxStack: maxStack(3, 0),
valid: true, memorySize: memoryCallDataCopy,
valid: true,
}, },
CODESIZE: { CODESIZE: {
execute: opCodeSize, execute: opCodeSize,
@ -403,12 +432,13 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
CODECOPY: { CODECOPY: {
execute: opCodeCopy, execute: opCodeCopy,
dynamicGas: gasCodeCopy, constantGas: GasFastestStep,
minStack: minStack(3, 0), dynamicGas: gasCodeCopy,
maxStack: maxStack(3, 0), minStack: minStack(3, 0),
memorySize: memoryCodeCopy, maxStack: maxStack(3, 0),
valid: true, memorySize: memoryCodeCopy,
valid: true,
}, },
GASPRICE: { GASPRICE: {
execute: opGasprice, execute: opGasprice,
@ -418,19 +448,20 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
EXTCODESIZE: { EXTCODESIZE: {
execute: opExtCodeSize, execute: opExtCodeSize,
dynamicGas: gasExtCodeSize, constantGas: params.ExtcodeSizeGasFrontier,
minStack: minStack(1, 1), minStack: minStack(1, 1),
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
valid: true, valid: true,
}, },
EXTCODECOPY: { EXTCODECOPY: {
execute: opExtCodeCopy, execute: opExtCodeCopy,
dynamicGas: gasExtCodeCopy, constantGas: params.ExtcodeCopyBaseFrontier,
minStack: minStack(4, 0), dynamicGas: gasExtCodeCopy,
maxStack: maxStack(4, 0), minStack: minStack(4, 0),
memorySize: memoryExtCodeCopy, maxStack: maxStack(4, 0),
valid: true, memorySize: memoryExtCodeCopy,
valid: true,
}, },
BLOCKHASH: { BLOCKHASH: {
execute: opBlockhash, execute: opBlockhash,
@ -482,36 +513,39 @@ func newFrontierInstructionSet() [256]operation {
valid: true, valid: true,
}, },
MLOAD: { MLOAD: {
execute: opMload, execute: opMload,
dynamicGas: gasMLoad, constantGas: GasFastestStep,
minStack: minStack(1, 1), dynamicGas: gasMLoad,
maxStack: maxStack(1, 1), minStack: minStack(1, 1),
memorySize: memoryMLoad, maxStack: maxStack(1, 1),
valid: true, memorySize: memoryMLoad,
valid: true,
}, },
MSTORE: { MSTORE: {
execute: opMstore, execute: opMstore,
dynamicGas: gasMStore, constantGas: GasFastestStep,
minStack: minStack(2, 0), dynamicGas: gasMStore,
maxStack: maxStack(2, 0), minStack: minStack(2, 0),
memorySize: memoryMStore, maxStack: maxStack(2, 0),
valid: true, memorySize: memoryMStore,
valid: true,
}, },
MSTORE8: { MSTORE8: {
execute: opMstore8, execute: opMstore8,
dynamicGas: gasMStore8, constantGas: GasFastestStep,
memorySize: memoryMStore8, dynamicGas: gasMStore8,
minStack: minStack(2, 0), memorySize: memoryMStore8,
maxStack: maxStack(2, 0), minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
valid: true, valid: true,
}, },
SLOAD: { SLOAD: {
execute: opSload, execute: opSload,
dynamicGas: gasSLoad, constantGas: params.SloadGasFrontier,
minStack: minStack(1, 1), minStack: minStack(1, 1),
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
valid: true, valid: true,
}, },
SSTORE: { SSTORE: {
execute: opSstore, execute: opSstore,
@ -1059,32 +1093,35 @@ func newFrontierInstructionSet() [256]operation {
writes: true, writes: true,
}, },
CREATE: { CREATE: {
execute: opCreate, execute: opCreate,
dynamicGas: gasCreate, constantGas: params.CreateGas,
minStack: minStack(3, 1), dynamicGas: gasCreate,
maxStack: maxStack(3, 1), minStack: minStack(3, 1),
memorySize: memoryCreate, maxStack: maxStack(3, 1),
valid: true, memorySize: memoryCreate,
writes: true, valid: true,
returns: true, writes: true,
returns: true,
}, },
CALL: { CALL: {
execute: opCall, execute: opCall,
dynamicGas: gasCall, constantGas: params.CallGasFrontier,
minStack: minStack(7, 1), dynamicGas: gasCall,
maxStack: maxStack(7, 1), minStack: minStack(7, 1),
memorySize: memoryCall, maxStack: maxStack(7, 1),
valid: true, memorySize: memoryCall,
returns: true, valid: true,
returns: true,
}, },
CALLCODE: { CALLCODE: {
execute: opCallCode, execute: opCallCode,
dynamicGas: gasCallCode, constantGas: params.CallGasFrontier,
minStack: minStack(7, 1), dynamicGas: gasCallCode,
maxStack: maxStack(7, 1), minStack: minStack(7, 1),
memorySize: memoryCall, maxStack: maxStack(7, 1),
valid: true, memorySize: memoryCall,
returns: true, valid: true,
returns: true,
}, },
RETURN: { RETURN: {
execute: opReturn, execute: opReturn,
@ -1097,7 +1134,7 @@ func newFrontierInstructionSet() [256]operation {
}, },
SELFDESTRUCT: { SELFDESTRUCT: {
execute: opSuicide, execute: opSuicide,
dynamicGas: gasSuicide, dynamicGas: gasSelfdestruct,
minStack: minStack(1, 0), minStack: minStack(1, 0),
maxStack: maxStack(1, 0), maxStack: maxStack(1, 0),
halts: true, halts: true,

@ -386,25 +386,6 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool {
return isForked(c.EWASMBlock, num) return isForked(c.EWASMBlock, num)
} }
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
//
// The returned GasTable's fields shouldn't, under any circumstances, be changed.
func (c *ChainConfig) GasTable(num *big.Int) GasTable {
if num == nil {
return GasTableHomestead
}
switch {
case c.IsConstantinople(num):
return GasTableConstantinople
case c.IsEIP158(num):
return GasTableEIP158
case c.IsEIP150(num):
return GasTableEIP150
default:
return GasTableHomestead
}
}
// CheckCompatible checks whether scheduled fork transitions have been imported // CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration. // with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError { func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {

@ -1,93 +0,0 @@
// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package params
// GasTable organizes gas prices for different ethereum phases.
type GasTable struct {
ExtcodeSize uint64
ExtcodeCopy uint64
ExtcodeHash uint64
Balance uint64
SLoad uint64
Calls uint64
Suicide uint64
ExpByte uint64
// CreateBySuicide occurs when the
// refunded account is one that does
// not exist. This logic is similar
// to call. May be left nil. Nil means
// not charged.
CreateBySuicide uint64
}
// Variables containing gas prices for different ethereum phases.
var (
// GasTableHomestead contain the gas prices for
// the homestead phase.
GasTableHomestead = GasTable{
ExtcodeSize: 20,
ExtcodeCopy: 20,
Balance: 20,
SLoad: 50,
Calls: 40,
Suicide: 0,
ExpByte: 10,
}
// GasTableEIP150 contain the gas re-prices for
// the EIP150 phase.
GasTableEIP150 = GasTable{
ExtcodeSize: 700,
ExtcodeCopy: 700,
Balance: 400,
SLoad: 200,
Calls: 700,
Suicide: 5000,
ExpByte: 10,
CreateBySuicide: 25000,
}
// GasTableEIP158 contain the gas re-prices for
// the EIP155/EIP158 phase.
GasTableEIP158 = GasTable{
ExtcodeSize: 700,
ExtcodeCopy: 700,
Balance: 400,
SLoad: 200,
Calls: 700,
Suicide: 5000,
ExpByte: 50,
CreateBySuicide: 25000,
}
// GasTableConstantinople contain the gas re-prices for
// the constantinople phase.
GasTableConstantinople = GasTable{
ExtcodeSize: 700,
ExtcodeCopy: 700,
ExtcodeHash: 400,
Balance: 400,
SLoad: 200,
Calls: 700,
Suicide: 5000,
ExpByte: 50,
CreateBySuicide: 25000,
}
)

@ -52,22 +52,48 @@ const (
NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value
NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value
JumpdestGas uint64 = 1 // Once per JUMPDEST operation. JumpdestGas uint64 = 1 // Once per JUMPDEST operation.
EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. EpochDuration uint64 = 30000 // Duration between proof-of-work epochs.
CallGas uint64 = 40 // Once per CALL operation & message call transaction.
CreateDataGas uint64 = 200 // CreateDataGas uint64 = 200 //
CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack.
ExpGas uint64 = 10 // Once per EXP instruction ExpGas uint64 = 10 // Once per EXP instruction
LogGas uint64 = 375 // Per LOG* operation. LogGas uint64 = 375 // Per LOG* operation.
CopyGas uint64 = 3 // CopyGas uint64 = 3 //
StackLimit uint64 = 1024 // Maximum size of VM stack allowed. StackLimit uint64 = 1024 // Maximum size of VM stack allowed.
TierStepGas uint64 = 0 // Once per operation, for a selection of them. TierStepGas uint64 = 0 // Once per operation, for a selection of them.
LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas.
CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction.
Create2Gas uint64 = 32000 // Once per CREATE2 operation Create2Gas uint64 = 32000 // Once per CREATE2 operation
SuicideRefundGas uint64 = 24000 // Refunded following a suicide operation. SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation.
MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL.
TxDataNonZeroGas uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. TxDataNonZeroGas uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions.
// These have been changed during the course of the chain
CallGasFrontier uint64 = 40 // Once per CALL operation & message call transaction.
CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine)
BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation
BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine
ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine)
ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine)
SloadGasFrontier uint64 = 50
SloadGasEIP150 uint64 = 200
ExtcodeHashGas uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople)
SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine)
// EXP has a dynamic portion depending on the size of the exponent
ExpByteFrontier uint64 = 10 // was set to 10 in Frontier
ExpByteEIP158 uint64 = 50 // was raised to 50 during Eip158 (Spurious Dragon)
// Extcodecopy has a dynamic AND a static cost. This represents only the
// static portion of the gas. It was changed during EIP 150 (Tangerine)
ExtcodeCopyBaseFrontier uint64 = 20
ExtcodeCopyBaseEIP150 uint64 = 700
// CreateBySelfdestructGas is used when the refunded account is one that does
// not exist. This logic is similar to call.
// Introduced in Tangerine Whistle (Eip 150)
CreateBySelfdestructGas uint64 = 25000
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract MaxCodeSize = 24576 // Maximum bytecode to permit for a contract