mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/vm: move constants, address review concerns
This commit is contained in:
parent
7fd83d01f2
commit
6d317b13a4
4 changed files with 28 additions and 19 deletions
|
|
@ -16,11 +16,15 @@
|
||||||
|
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
)
|
||||||
|
|
||||||
// EnableEIP enables the given EIP on the config.
|
// EnableEIP enables the given EIP on the config.
|
||||||
// This operation write in-place, and callers need to ensure that the globally
|
// This operation writes in-place, and callers need to ensure that the globally
|
||||||
// defined jumptables are not polluted
|
// defined jump tables are not polluted.
|
||||||
func EnableEIP(eipNum int, jt *JumpTable) error {
|
func EnableEIP(eipNum int, jt *JumpTable) error {
|
||||||
switch eipNum {
|
switch eipNum {
|
||||||
case 1884:
|
case 1884:
|
||||||
|
|
@ -31,16 +35,17 @@ func EnableEIP(eipNum int, jt *JumpTable) error {
|
||||||
return nil
|
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 BALANCE to 700
|
||||||
// - Increase cost of EXTCODEHASH to 700
|
// - Increase cost of EXTCODEHASH to 700
|
||||||
// - Increase cost of SLOAD to 800
|
// - Increase cost of SLOAD to 800
|
||||||
// - Define SELFBALANCE, with cost GasFastStep (5)
|
// - Define SELFBALANCE, with cost GasFastStep (5)
|
||||||
func enable1884(jt *JumpTable) {
|
func enable1884(jt *JumpTable) {
|
||||||
// Gas cost changes
|
// Gas cost changes
|
||||||
jt[BALANCE].constantGas = 700
|
jt[BALANCE].constantGas = params.BalanceGasEIP1884
|
||||||
jt[EXTCODEHASH].constantGas = 700
|
jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884
|
||||||
jt[SLOAD].constantGas = 800
|
jt[SLOAD].constantGas = params.SloadGasEIP1884
|
||||||
|
|
||||||
// New opcode
|
// New opcode
|
||||||
jt[SELFBALANCE] = operation{
|
jt[SELFBALANCE] = operation{
|
||||||
execute: opSelfBalance,
|
execute: opSelfBalance,
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
|
||||||
if err := EnableEIP(eip, &jt); err != nil {
|
if err := EnableEIP(eip, &jt); err != nil {
|
||||||
// Disable it, so caller can check if it's activated or not
|
// Disable it, so caller can check if it's activated or not
|
||||||
cfg.ExtraEips = append(cfg.ExtraEips[:i], cfg.ExtraEips[i+1:]...)
|
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
|
cfg.JumpTable = jt
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ var (
|
||||||
constantinopleInstructionSet = newConstantinopleInstructionSet()
|
constantinopleInstructionSet = newConstantinopleInstructionSet()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// JumpTable contains the EVM opcodes supported at a given fork.
|
||||||
type JumpTable [256]operation
|
type JumpTable [256]operation
|
||||||
|
|
||||||
// NewConstantinopleInstructionSet returns the frontier, homestead
|
// NewConstantinopleInstructionSet returns the frontier, homestead
|
||||||
|
|
@ -92,7 +93,7 @@ func newConstantinopleInstructionSet() JumpTable {
|
||||||
}
|
}
|
||||||
instructionSet[EXTCODEHASH] = operation{
|
instructionSet[EXTCODEHASH] = operation{
|
||||||
execute: opExtCodeHash,
|
execute: opExtCodeHash,
|
||||||
constantGas: params.ExtcodeHashGas,
|
constantGas: params.ExtcodeHashGasConstantinople,
|
||||||
minStack: minStack(1, 1),
|
minStack: minStack(1, 1),
|
||||||
maxStack: maxStack(1, 1),
|
maxStack: maxStack(1, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,14 @@ const (
|
||||||
CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine)
|
CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine)
|
||||||
BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation
|
BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation
|
||||||
BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine
|
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)
|
ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine)
|
||||||
ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine)
|
ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine)
|
||||||
SloadGasFrontier uint64 = 50
|
SloadGasFrontier uint64 = 50
|
||||||
SloadGasEIP150 uint64 = 200
|
SloadGasEIP150 uint64 = 200
|
||||||
ExtcodeHashGas uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople)
|
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)
|
SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine)
|
||||||
|
|
||||||
// EXP has a dynamic portion depending on the size of the exponent
|
// EXP has a dynamic portion depending on the size of the exponent
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue