Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func enable1884(jt *JumpTable) {
jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884

// New opcode
jt[SELFBALANCE] = &operation{
jt[SELFBALANCE] = operation{
execute: opSelfBalance,
constantGas: GasFastStep,
minStack: minStack(0, 1),
Expand All @@ -99,7 +99,7 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
// - Adds an opcode that returns the current chain’s EIP-155 unique identifier
func enable1344(jt *JumpTable) {
// New opcode
jt[CHAINID] = &operation{
jt[CHAINID] = operation{
execute: opChainID,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
Expand Down Expand Up @@ -171,7 +171,7 @@ func enable3529(jt *JumpTable) {
// - Adds an opcode that returns the current block's base fee.
func enable3198(jt *JumpTable) {
// New opcode
jt[BASEFEE] = &operation{
jt[BASEFEE] = operation{
execute: opBaseFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
Expand All @@ -183,14 +183,14 @@ func enable3198(jt *JumpTable) {
// - Adds TLOAD that reads from transient storage
// - Adds TSTORE that writes to transient storage
func enable1153(jt *JumpTable) {
jt[TLOAD] = &operation{
jt[TLOAD] = operation{
execute: opTload,
constantGas: params.WarmStorageReadCostEIP2929,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}

jt[TSTORE] = &operation{
jt[TSTORE] = operation{
execute: opTstore,
constantGas: params.WarmStorageReadCostEIP2929,
minStack: minStack(2, 0),
Expand Down Expand Up @@ -228,7 +228,7 @@ func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
// enable3855 applies EIP-3855 (PUSH0 opcode)
func enable3855(jt *JumpTable) {
// New opcode
jt[PUSH0] = &operation{
jt[PUSH0] = operation{
execute: opPush0,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
Expand All @@ -252,7 +252,7 @@ func enable3860(jt *JumpTable) {
// enable5656 enables EIP-5656 (MCOPY opcode)
// https://eips.ethereum.org/EIPS/eip-5656
func enable5656(jt *JumpTable) {
jt[MCOPY] = &operation{
jt[MCOPY] = operation{
execute: opMcopy,
constantGas: GasFastestStep,
dynamicGas: gasMcopy,
Expand Down Expand Up @@ -303,7 +303,7 @@ func opCLZ(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte

// enable4844 applies EIP-4844 (BLOBHASH opcode)
func enable4844(jt *JumpTable) {
jt[BLOBHASH] = &operation{
jt[BLOBHASH] = operation{
execute: opBlobHash,
constantGas: GasFastestStep,
minStack: minStack(1, 1),
Expand All @@ -313,7 +313,7 @@ func enable4844(jt *JumpTable) {

// enable7939 enables EIP-7939 (CLZ opcode)
func enable7939(jt *JumpTable) {
jt[CLZ] = &operation{
jt[CLZ] = operation{
execute: opCLZ,
constantGas: GasFastStep,
minStack: minStack(1, 1),
Expand All @@ -323,7 +323,7 @@ func enable7939(jt *JumpTable) {

// enable7516 applies EIP-7516 (BLOBBASEFEE opcode)
func enable7516(jt *JumpTable) {
jt[BLOBBASEFEE] = &operation{
jt[BLOBBASEFEE] = operation{
execute: opBlobBaseFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
Expand All @@ -333,7 +333,7 @@ func enable7516(jt *JumpTable) {

// enable6780 applies EIP-6780 (deactivate SELFDESTRUCT)
func enable6780(jt *JumpTable) {
jt[SELFDESTRUCT] = &operation{
jt[SELFDESTRUCT] = operation{
execute: opSelfdestruct6780,
dynamicGas: gasSelfdestructEIP3529,
constantGas: params.SelfdestructGasEIP150,
Expand Down Expand Up @@ -424,49 +424,49 @@ func makePushEIP4762(size uint64, pushByteSize int) executionFunc {
}

func enable4762(jt *JumpTable) {
jt[SSTORE] = &operation{
jt[SSTORE] = operation{
dynamicGas: gasSStore4762,
execute: opSstore,
minStack: minStack(2, 0),
maxStack: maxStack(2, 0),
}
jt[SLOAD] = &operation{
jt[SLOAD] = operation{
dynamicGas: gasSLoad4762,
execute: opSload,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}

jt[BALANCE] = &operation{
jt[BALANCE] = operation{
execute: opBalance,
dynamicGas: gasBalance4762,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}

jt[EXTCODESIZE] = &operation{
jt[EXTCODESIZE] = operation{
execute: opExtCodeSize,
dynamicGas: gasExtCodeSize4762,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}

jt[EXTCODEHASH] = &operation{
jt[EXTCODEHASH] = operation{
execute: opExtCodeHash,
dynamicGas: gasExtCodeHash4762,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}

jt[EXTCODECOPY] = &operation{
jt[EXTCODECOPY] = operation{
execute: opExtCodeCopyEIP4762,
dynamicGas: gasExtCodeCopyEIP4762,
minStack: minStack(4, 0),
maxStack: maxStack(4, 0),
memorySize: memoryExtCodeCopy,
}

jt[CODECOPY] = &operation{
jt[CODECOPY] = operation{
execute: opCodeCopy,
constantGas: GasFastestStep,
dynamicGas: gasCodeCopyEip4762,
Expand All @@ -475,15 +475,15 @@ func enable4762(jt *JumpTable) {
memorySize: memoryCodeCopy,
}

jt[SELFDESTRUCT] = &operation{
jt[SELFDESTRUCT] = operation{
execute: opSelfdestruct6780,
dynamicGas: gasSelfdestructEIP4762,
constantGas: params.SelfdestructGasEIP150,
minStack: minStack(1, 0),
maxStack: maxStack(1, 0),
}

jt[CREATE] = &operation{
jt[CREATE] = operation{
execute: opCreate,
constantGas: params.CreateNGasEip4762,
dynamicGas: gasCreateEip3860,
Expand All @@ -492,7 +492,7 @@ func enable4762(jt *JumpTable) {
memorySize: memoryCreate,
}

jt[CREATE2] = &operation{
jt[CREATE2] = operation{
execute: opCreate2,
constantGas: params.CreateNGasEip4762,
dynamicGas: gasCreate2Eip3860,
Expand All @@ -501,46 +501,46 @@ func enable4762(jt *JumpTable) {
memorySize: memoryCreate2,
}

jt[CALL] = &operation{
jt[CALL] = operation{
execute: opCall,
dynamicGas: gasCallEIP4762,
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
memorySize: memoryCall,
}

jt[CALLCODE] = &operation{
jt[CALLCODE] = operation{
execute: opCallCode,
dynamicGas: gasCallCodeEIP4762,
minStack: minStack(7, 1),
maxStack: maxStack(7, 1),
memorySize: memoryCall,
}

jt[STATICCALL] = &operation{
jt[STATICCALL] = operation{
execute: opStaticCall,
dynamicGas: gasStaticCallEIP4762,
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryStaticCall,
}

jt[DELEGATECALL] = &operation{
jt[DELEGATECALL] = operation{
execute: opDelegateCall,
dynamicGas: gasDelegateCallEIP4762,
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryDelegateCall,
}

jt[PUSH1] = &operation{
jt[PUSH1] = operation{
execute: opPush1EIP4762,
constantGas: GasFastestStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}
for i := 1; i < 32; i++ {
jt[PUSH1+OpCode(i)] = &operation{
jt[PUSH1+OpCode(i)] = operation{
execute: makePushEIP4762(uint64(i+1), i+1),
constantGas: GasFastestStep,
minStack: minStack(0, 1),
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// Get the operation from the jump table and validate the stack to ensure there are
// enough stack items available to perform the operation.
op = contract.GetOp(pc)
operation := jumpTable[op]
operation := &jumpTable[op]
cost = operation.constantGas // For tracing
// Validate stack
if sLen := stack.len(); sLen < operation.minStack {
Expand Down
42 changes: 15 additions & 27 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ type operation struct {

// memorySize returns the memory size required for the operation
memorySize memorySizeFunc

// undefined denotes if the instruction is not officially defined in the jump table
undefined bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in #30418 and Martin wasn't the happiest about it. IIRC it was used for EOF, so should be okay to remove.

}

var (
Expand All @@ -66,13 +63,10 @@ var (
)

// JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]*operation
type JumpTable [256]operation

func validate(jt JumpTable) JumpTable {
for i, op := range jt {
if op == nil {
panic(fmt.Sprintf("op %#x is not set", i))
}
// The interpreter has an assumption that if the memorySize function is
// set, then the dynamicGas function is also set. This is a somewhat
// arbitrary assumption, and can be removed if we need to -- but it
Expand Down Expand Up @@ -124,7 +118,7 @@ func newShanghaiInstructionSet() JumpTable {

func newMergeInstructionSet() JumpTable {
instructionSet := newLondonInstructionSet()
instructionSet[PREVRANDAO] = &operation{
instructionSet[PREVRANDAO] = operation{
execute: opRandom,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
Expand Down Expand Up @@ -166,31 +160,31 @@ func newIstanbulInstructionSet() JumpTable {
// byzantium and constantinople instructions.
func newConstantinopleInstructionSet() JumpTable {
instructionSet := newByzantiumInstructionSet()
instructionSet[SHL] = &operation{
instructionSet[SHL] = operation{
execute: opSHL,
constantGas: GasFastestStep,
minStack: minStack(2, 1),
maxStack: maxStack(2, 1),
}
instructionSet[SHR] = &operation{
instructionSet[SHR] = operation{
execute: opSHR,
constantGas: GasFastestStep,
minStack: minStack(2, 1),
maxStack: maxStack(2, 1),
}
instructionSet[SAR] = &operation{
instructionSet[SAR] = operation{
execute: opSAR,
constantGas: GasFastestStep,
minStack: minStack(2, 1),
maxStack: maxStack(2, 1),
}
instructionSet[EXTCODEHASH] = &operation{
instructionSet[EXTCODEHASH] = operation{
execute: opExtCodeHash,
constantGas: params.ExtcodeHashGasConstantinople,
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}
instructionSet[CREATE2] = &operation{
instructionSet[CREATE2] = operation{
execute: opCreate2,
constantGas: params.Create2Gas,
dynamicGas: gasCreate2,
Expand All @@ -205,29 +199,29 @@ func newConstantinopleInstructionSet() JumpTable {
// byzantium instructions.
func newByzantiumInstructionSet() JumpTable {
instructionSet := newSpuriousDragonInstructionSet()
instructionSet[STATICCALL] = &operation{
instructionSet[STATICCALL] = operation{
execute: opStaticCall,
constantGas: params.CallGasEIP150,
dynamicGas: gasStaticCall,
minStack: minStack(6, 1),
maxStack: maxStack(6, 1),
memorySize: memoryStaticCall,
}
instructionSet[RETURNDATASIZE] = &operation{
instructionSet[RETURNDATASIZE] = operation{
execute: opReturnDataSize,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}
instructionSet[RETURNDATACOPY] = &operation{
instructionSet[RETURNDATACOPY] = operation{
execute: opReturnDataCopy,
constantGas: GasFastestStep,
dynamicGas: gasReturnDataCopy,
minStack: minStack(3, 0),
maxStack: maxStack(3, 0),
memorySize: memoryReturnDataCopy,
}
instructionSet[REVERT] = &operation{
instructionSet[REVERT] = operation{
execute: opRevert,
dynamicGas: gasRevert,
minStack: minStack(2, 0),
Expand Down Expand Up @@ -261,7 +255,7 @@ func newTangerineWhistleInstructionSet() JumpTable {
// instructions that can be executed during the homestead phase.
func newHomesteadInstructionSet() JumpTable {
instructionSet := newFrontierInstructionSet()
instructionSet[DELEGATECALL] = &operation{
instructionSet[DELEGATECALL] = operation{
execute: opDelegateCall,
dynamicGas: gasDelegateCall,
constantGas: params.CallGasFrontier,
Expand Down Expand Up @@ -1084,9 +1078,9 @@ func newFrontierInstructionSet() JumpTable {
}

// Fill all unassigned slots with opUndefined.
for i, entry := range tbl {
if entry == nil {
tbl[i] = &operation{execute: opUndefined, maxStack: maxStack(0, 0), undefined: true}
for i := range tbl {
if tbl[i].execute == nil {
tbl[i] = operation{execute: opUndefined, maxStack: maxStack(0, 0)}
}
}

Expand All @@ -1095,11 +1089,5 @@ func newFrontierInstructionSet() JumpTable {

func copyJumpTable(source *JumpTable) *JumpTable {
dest := *source
for i, op := range source {
if op != nil {
opCopy := *op
dest[i] = &opCopy
}
}
return &dest
}