diff --git a/core/vm/eips.go b/core/vm/eips.go index 0e1cff0c49..89e76c0271 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -16,11 +16,15 @@ package vm -import "fmt" +import ( + "fmt" + + "github.com/ethereum/go-ethereum/params" +) // EnableEIP enables the given EIP on the config. -// This operation write in-place, and callers need to ensure that the globally -// defined jumptables are not polluted +// This operation writes in-place, and callers need to ensure that the globally +// defined jump tables are not polluted. func EnableEIP(eipNum int, jt *JumpTable) error { switch eipNum { case 1884: @@ -31,16 +35,17 @@ func EnableEIP(eipNum int, jt *JumpTable) error { return nil } -// Enable1884 applies EIP-1884 to the given jumptable +// enable1884 applies EIP-1884 to the given jump table: // - Increase cost of BALANCE to 700 // - Increase cost of EXTCODEHASH to 700 // - Increase cost of SLOAD to 800 // - Define SELFBALANCE, with cost GasFastStep (5) func enable1884(jt *JumpTable) { // Gas cost changes - jt[BALANCE].constantGas = 700 - jt[EXTCODEHASH].constantGas = 700 - jt[SLOAD].constantGas = 800 + jt[BALANCE].constantGas = params.BalanceGasEIP1884 + jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884 + jt[SLOAD].constantGas = params.SloadGasEIP1884 + // New opcode jt[SELFBALANCE] = operation{ execute: opSelfBalance, diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index ae4a99539a..4a902dce52 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -110,7 +110,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter { if err := EnableEIP(eip, &jt); err != nil { // Disable it, so caller can check if it's activated or not cfg.ExtraEips = append(cfg.ExtraEips[:i], cfg.ExtraEips[i+1:]...) - log.Error("eip %d failed activation: %v", err) + log.Error("eip activation failed", "eip", eip, "error", err) } } cfg.JumpTable = jt diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index bde9b76078..da532541c6 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -62,6 +62,7 @@ var ( constantinopleInstructionSet = newConstantinopleInstructionSet() ) +// JumpTable contains the EVM opcodes supported at a given fork. type JumpTable [256]operation // NewConstantinopleInstructionSet returns the frontier, homestead @@ -92,7 +93,7 @@ func newConstantinopleInstructionSet() JumpTable { } instructionSet[EXTCODEHASH] = operation{ execute: opExtCodeHash, - constantGas: params.ExtcodeHashGas, + constantGas: params.ExtcodeHashGasConstantinople, minStack: minStack(1, 1), maxStack: maxStack(1, 1), valid: true, diff --git a/params/protocol_params.go b/params/protocol_params.go index 01dc197aff..fe8f18ee21 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -70,16 +70,19 @@ const ( 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) + 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 + BalanceGasEIP1884 uint64 = 700 // The cost of a BALANCE operation after EIP 1884 (part of Istanbul) + 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 + SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul) + ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople) + ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul) + 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