Skip to content

Commit

Permalink
core/vm: move constants, address review concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Aug 7, 2019
1 parent 7fd83d0 commit 6d317b1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
19 changes: 12 additions & 7 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 13 additions & 10 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d317b1

Please sign in to comment.