mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/vm: review concerns (param/method name changes)
This commit is contained in:
parent
326b20e123
commit
0648c43247
3 changed files with 43 additions and 45 deletions
|
|
@ -255,11 +255,11 @@ func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
|
|||
return gas, nil
|
||||
}
|
||||
|
||||
func gasExpEip158(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 (
|
||||
gas = expByteLen * params.ExpByteEip158 // no overflow check required. Max is 256 * ExpByte gas
|
||||
gas = expByteLen * params.ExpByteEIP158 // no overflow check required. Max is 256 * ExpByte gas
|
||||
overflow bool
|
||||
)
|
||||
if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow {
|
||||
|
|
@ -273,10 +273,8 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
|
|||
gas uint64
|
||||
transfersValue = stack.Back(2).Sign() != 0
|
||||
address = common.BigToAddress(stack.Back(1))
|
||||
eip158 = evm.chainRules.IsEIP158
|
||||
eip150 = evm.chainRules.IsEIP150
|
||||
)
|
||||
if eip158 {
|
||||
if evm.chainRules.IsEIP158 {
|
||||
if transfersValue && evm.StateDB.Empty(address) {
|
||||
gas += params.CallNewAccountGas
|
||||
}
|
||||
|
|
@ -295,7 +293,7 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
|
|||
return 0, errGasUintOverflow
|
||||
}
|
||||
|
||||
evm.callGasTemp, err = callGas(eip150, contract.Gas, gas, stack.Back(0))
|
||||
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -362,25 +360,25 @@ func gasStaticCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo
|
|||
return gas, nil
|
||||
}
|
||||
|
||||
func gasSuicide(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
|
||||
// EIP150 homestead gas reprice fork:
|
||||
if evm.chainRules.IsEIP150 {
|
||||
gas = params.SuicideGasEip150
|
||||
gas = params.SelfdestructGasEIP150
|
||||
var address = common.BigToAddress(stack.Back(0))
|
||||
|
||||
if evm.chainRules.IsEIP158 {
|
||||
// if empty and transfers value
|
||||
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
|
||||
gas += params.CreateBySuicideGas
|
||||
gas += params.CreateBySelfdestructGas
|
||||
}
|
||||
} else if !evm.StateDB.Exist(address) {
|
||||
gas += params.CreateBySuicideGas
|
||||
gas += params.CreateBySelfdestructGas
|
||||
}
|
||||
}
|
||||
|
||||
if !evm.StateDB.HasSuicided(contract.Address()) {
|
||||
evm.StateDB.AddRefund(params.SuicideRefundGas)
|
||||
evm.StateDB.AddRefund(params.SelfdestructRefundGas)
|
||||
}
|
||||
return gas, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ func newByzantiumInstructionSet() [256]operation {
|
|||
instructionSet := newSpuriousDragonInstructionSet()
|
||||
instructionSet[STATICCALL] = operation{
|
||||
execute: opStaticCall,
|
||||
constantGas: params.CallGasEip150,
|
||||
constantGas: params.CallGasEIP150,
|
||||
dynamicGas: gasStaticCall,
|
||||
minStack: minStack(6, 1),
|
||||
maxStack: maxStack(6, 1),
|
||||
|
|
@ -156,7 +156,7 @@ func newByzantiumInstructionSet() [256]operation {
|
|||
// EIP 158 a.k.a Spurious Dragon
|
||||
func newSpuriousDragonInstructionSet() [256]operation {
|
||||
instructionSet := newTangerineWhistleInstructionSet()
|
||||
instructionSet[EXP].dynamicGas = gasExpEip158
|
||||
instructionSet[EXP].dynamicGas = gasExpEIP158
|
||||
return instructionSet
|
||||
|
||||
}
|
||||
|
|
@ -164,13 +164,13 @@ func newSpuriousDragonInstructionSet() [256]operation {
|
|||
// 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
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -1134,7 +1134,7 @@ func newFrontierInstructionSet() [256]operation {
|
|||
},
|
||||
SELFDESTRUCT: {
|
||||
execute: opSuicide,
|
||||
dynamicGas: gasSuicide,
|
||||
dynamicGas: gasSelfdestruct,
|
||||
minStack: minStack(1, 0),
|
||||
maxStack: maxStack(1, 0),
|
||||
halts: true,
|
||||
|
|
|
|||
|
|
@ -65,35 +65,35 @@ const (
|
|||
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.
|
||||
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.
|
||||
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 (T.W)
|
||||
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 Whistle
|
||||
ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (T.W)
|
||||
ExtcodeSizeGasEip150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (T.W)
|
||||
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
|
||||
SloadGasEIP150 uint64 = 200
|
||||
ExtcodeHashGas uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople)
|
||||
SuicideGasEip150 uint64 = 5000 // Cost of SELFDESTRUCT post T.W
|
||||
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)
|
||||
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 Whistle)
|
||||
// static portion of the gas. It was changed during EIP 150 (Tangerine)
|
||||
ExtcodeCopyBaseFrontier uint64 = 20
|
||||
ExtcodeCopyBaseEip150 uint64 = 700
|
||||
ExtcodeCopyBaseEIP150 uint64 = 700
|
||||
|
||||
// CreateBySuicide occurs when the refunded account is one that does
|
||||
// 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)
|
||||
CreateBySuicideGas uint64 = 25000
|
||||
CreateBySelfdestructGas uint64 = 25000
|
||||
|
||||
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue