From 5d400f14a1c571441027de6d4fd0749956f16172 Mon Sep 17 00:00:00 2001 From: Francesco4203 Date: Fri, 21 Jun 2024 13:22:00 +0700 Subject: [PATCH 1/2] core/vm: add wrapper functions for all opcodes, all versions - for each opcode and each version, assign corresponding wrapper based on the version and opcodeName - vm/jump_table/ExportInstructionSet: export instruction set attributes based on input version for generating codes, including unsupported instructions of different versions for dummy wrappers - vm/interpreter: if not debug mode, call wrapper instead of execute opcodes directly --- core/vm/eips.go | 3 + core/vm/instruction_wrapper_Berlin.go | 2249 ++++++++++++++++ core/vm/instruction_wrapper_Byzantium.go | 2063 +++++++++++++++ core/vm/instruction_wrapper_Constantinople.go | 2181 ++++++++++++++++ core/vm/instruction_wrapper_Frontier.go | 1905 ++++++++++++++ core/vm/instruction_wrapper_Homestead.go | 1940 ++++++++++++++ core/vm/instruction_wrapper_Istanbul.go | 2221 ++++++++++++++++ core/vm/instruction_wrapper_London.go | 2269 +++++++++++++++++ core/vm/instruction_wrapper_SpuriousDragon.go | 1940 ++++++++++++++ .../instruction_wrapper_TangerineWhistle.go | 1940 ++++++++++++++ core/vm/interpreter.go | 10 + core/vm/jump_table.go | 1520 ++++++----- 12 files changed, 19621 insertions(+), 620 deletions(-) create mode 100644 core/vm/instruction_wrapper_Berlin.go create mode 100644 core/vm/instruction_wrapper_Byzantium.go create mode 100644 core/vm/instruction_wrapper_Constantinople.go create mode 100644 core/vm/instruction_wrapper_Frontier.go create mode 100644 core/vm/instruction_wrapper_Homestead.go create mode 100644 core/vm/instruction_wrapper_Istanbul.go create mode 100644 core/vm/instruction_wrapper_London.go create mode 100644 core/vm/instruction_wrapper_SpuriousDragon.go create mode 100644 core/vm/instruction_wrapper_TangerineWhistle.go diff --git a/core/vm/eips.go b/core/vm/eips.go index 4070a2db53..5b7aea4c65 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -71,6 +71,7 @@ func enable1884(jt *JumpTable) { // New opcode jt[SELFBALANCE] = &operation{ + opcodeName: "opSelfBalance", execute: opSelfBalance, constantGas: GasFastStep, minStack: minStack(0, 1), @@ -89,6 +90,7 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) func enable1344(jt *JumpTable) { // New opcode jt[CHAINID] = &operation{ + opcodeName: "opChainID", execute: opChainID, constantGas: GasQuickStep, minStack: minStack(0, 1), @@ -161,6 +163,7 @@ func enable3529(jt *JumpTable) { func enable3198(jt *JumpTable) { // New opcode jt[BASEFEE] = &operation{ + opcodeName: "opBaseFee", execute: opBaseFee, constantGas: GasQuickStep, minStack: minStack(0, 1), diff --git a/core/vm/instruction_wrapper_Berlin.go b/core/vm/instruction_wrapper_Berlin.go new file mode 100644 index 0000000000..5b5d3f0ff3 --- /dev/null +++ b/core/vm/instruction_wrapper_Berlin.go @@ -0,0 +1,2249 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHRWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSARWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataSizeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataCopyWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeHashWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opChainIDWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSelfBalanceWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreate2WrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opStaticCallWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opRevertWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + return res, ErrExecutionReverted +} + +func opSuicideWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(5000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBaseFeeWrapperBerlin(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperBerlin = map[string]executionWrapperFunc{ + "opStop": opStopWrapperBerlin, + "opAdd": opAddWrapperBerlin, + "opMul": opMulWrapperBerlin, + "opSub": opSubWrapperBerlin, + "opDiv": opDivWrapperBerlin, + "opSdiv": opSdivWrapperBerlin, + "opMod": opModWrapperBerlin, + "opSmod": opSmodWrapperBerlin, + "opAddmod": opAddmodWrapperBerlin, + "opMulmod": opMulmodWrapperBerlin, + "opExp": opExpWrapperBerlin, + "opSignExtend": opSignExtendWrapperBerlin, + "opLt": opLtWrapperBerlin, + "opGt": opGtWrapperBerlin, + "opSlt": opSltWrapperBerlin, + "opSgt": opSgtWrapperBerlin, + "opEq": opEqWrapperBerlin, + "opIszero": opIszeroWrapperBerlin, + "opAnd": opAndWrapperBerlin, + "opOr": opOrWrapperBerlin, + "opXor": opXorWrapperBerlin, + "opNot": opNotWrapperBerlin, + "opByte": opByteWrapperBerlin, + "opSHL": opSHLWrapperBerlin, + "opSHR": opSHRWrapperBerlin, + "opSAR": opSARWrapperBerlin, + "opSha3": opSha3WrapperBerlin, + "opAddress": opAddressWrapperBerlin, + "opBalance": opBalanceWrapperBerlin, + "opOrigin": opOriginWrapperBerlin, + "opCaller": opCallerWrapperBerlin, + "opCallValue": opCallValueWrapperBerlin, + "opCallDataLoad": opCallDataLoadWrapperBerlin, + "opCallDataSize": opCallDataSizeWrapperBerlin, + "opCallDataCopy": opCallDataCopyWrapperBerlin, + "opCodeSize": opCodeSizeWrapperBerlin, + "opCodeCopy": opCodeCopyWrapperBerlin, + "opGasprice": opGaspriceWrapperBerlin, + "opExtCodeSize": opExtCodeSizeWrapperBerlin, + "opExtCodeCopy": opExtCodeCopyWrapperBerlin, + "opReturnDataSize": opReturnDataSizeWrapperBerlin, + "opReturnDataCopy": opReturnDataCopyWrapperBerlin, + "opExtCodeHash": opExtCodeHashWrapperBerlin, + "opBlockhash": opBlockhashWrapperBerlin, + "opCoinbase": opCoinbaseWrapperBerlin, + "opTimestamp": opTimestampWrapperBerlin, + "opNumber": opNumberWrapperBerlin, + "opDifficulty": opDifficultyWrapperBerlin, + "opGasLimit": opGasLimitWrapperBerlin, + "opChainID": opChainIDWrapperBerlin, + "opSelfBalance": opSelfBalanceWrapperBerlin, + "opPop": opPopWrapperBerlin, + "opMload": opMloadWrapperBerlin, + "opMstore": opMstoreWrapperBerlin, + "opMstore8": opMstore8WrapperBerlin, + "opSload": opSloadWrapperBerlin, + "opSstore": opSstoreWrapperBerlin, + "opJump": opJumpWrapperBerlin, + "opJumpi": opJumpiWrapperBerlin, + "opPc": opPcWrapperBerlin, + "opMsize": opMsizeWrapperBerlin, + "opGas": opGasWrapperBerlin, + "opJumpdest": opJumpdestWrapperBerlin, + "opPush1": opPush1WrapperBerlin, + "opPush": opPushWrapperBerlin, + "opDup": opDupWrapperBerlin, + "opSwap": opSwapWrapperBerlin, + "opLog": opLogWrapperBerlin, + "opCreate": opCreateWrapperBerlin, + "opCall": opCallWrapperBerlin, + "opCallCode": opCallCodeWrapperBerlin, + "opReturn": opReturnWrapperBerlin, + "opDelegateCall": opDelegateCallWrapperBerlin, + "opCreate2": opCreate2WrapperBerlin, + "opStaticCall": opStaticCallWrapperBerlin, + "opRevert": opRevertWrapperBerlin, + "opSuicide": opSuicideWrapperBerlin, + "opBaseFee": opBaseFeeWrapperBerlin, +} diff --git a/core/vm/instruction_wrapper_Byzantium.go b/core/vm/instruction_wrapper_Byzantium.go new file mode 100644 index 0000000000..45fa5577b2 --- /dev/null +++ b/core/vm/instruction_wrapper_Byzantium.go @@ -0,0 +1,2063 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(400) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataSizeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataCopyWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(200) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opStaticCallWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opRevertWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + return res, ErrExecutionReverted +} + +func opSuicideWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSHRWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSARWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opExtCodeHashWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opChainIDWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opCreate2WrapperByzantium(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperByzantium = map[string]executionWrapperFunc{ + "opStop": opStopWrapperByzantium, + "opAdd": opAddWrapperByzantium, + "opMul": opMulWrapperByzantium, + "opSub": opSubWrapperByzantium, + "opDiv": opDivWrapperByzantium, + "opSdiv": opSdivWrapperByzantium, + "opMod": opModWrapperByzantium, + "opSmod": opSmodWrapperByzantium, + "opAddmod": opAddmodWrapperByzantium, + "opMulmod": opMulmodWrapperByzantium, + "opExp": opExpWrapperByzantium, + "opSignExtend": opSignExtendWrapperByzantium, + "opLt": opLtWrapperByzantium, + "opGt": opGtWrapperByzantium, + "opSlt": opSltWrapperByzantium, + "opSgt": opSgtWrapperByzantium, + "opEq": opEqWrapperByzantium, + "opIszero": opIszeroWrapperByzantium, + "opAnd": opAndWrapperByzantium, + "opOr": opOrWrapperByzantium, + "opXor": opXorWrapperByzantium, + "opNot": opNotWrapperByzantium, + "opByte": opByteWrapperByzantium, + "opSha3": opSha3WrapperByzantium, + "opAddress": opAddressWrapperByzantium, + "opBalance": opBalanceWrapperByzantium, + "opOrigin": opOriginWrapperByzantium, + "opCaller": opCallerWrapperByzantium, + "opCallValue": opCallValueWrapperByzantium, + "opCallDataLoad": opCallDataLoadWrapperByzantium, + "opCallDataSize": opCallDataSizeWrapperByzantium, + "opCallDataCopy": opCallDataCopyWrapperByzantium, + "opCodeSize": opCodeSizeWrapperByzantium, + "opCodeCopy": opCodeCopyWrapperByzantium, + "opGasprice": opGaspriceWrapperByzantium, + "opExtCodeSize": opExtCodeSizeWrapperByzantium, + "opExtCodeCopy": opExtCodeCopyWrapperByzantium, + "opReturnDataSize": opReturnDataSizeWrapperByzantium, + "opReturnDataCopy": opReturnDataCopyWrapperByzantium, + "opBlockhash": opBlockhashWrapperByzantium, + "opCoinbase": opCoinbaseWrapperByzantium, + "opTimestamp": opTimestampWrapperByzantium, + "opNumber": opNumberWrapperByzantium, + "opDifficulty": opDifficultyWrapperByzantium, + "opGasLimit": opGasLimitWrapperByzantium, + "opPop": opPopWrapperByzantium, + "opMload": opMloadWrapperByzantium, + "opMstore": opMstoreWrapperByzantium, + "opMstore8": opMstore8WrapperByzantium, + "opSload": opSloadWrapperByzantium, + "opSstore": opSstoreWrapperByzantium, + "opJump": opJumpWrapperByzantium, + "opJumpi": opJumpiWrapperByzantium, + "opPc": opPcWrapperByzantium, + "opMsize": opMsizeWrapperByzantium, + "opGas": opGasWrapperByzantium, + "opJumpdest": opJumpdestWrapperByzantium, + "opPush1": opPush1WrapperByzantium, + "opPush": opPushWrapperByzantium, + "opDup": opDupWrapperByzantium, + "opSwap": opSwapWrapperByzantium, + "opLog": opLogWrapperByzantium, + "opCreate": opCreateWrapperByzantium, + "opCall": opCallWrapperByzantium, + "opCallCode": opCallCodeWrapperByzantium, + "opReturn": opReturnWrapperByzantium, + "opDelegateCall": opDelegateCallWrapperByzantium, + "opStaticCall": opStaticCallWrapperByzantium, + "opRevert": opRevertWrapperByzantium, + "opSuicide": opSuicideWrapperByzantium, + "opSHL": opSHLWrapperByzantium, + "opSHR": opSHRWrapperByzantium, + "opSAR": opSARWrapperByzantium, + "opExtCodeHash": opExtCodeHashWrapperByzantium, + "opChainID": opChainIDWrapperByzantium, + "opSelfBalance": opSelfBalanceWrapperByzantium, + "opBaseFee": opBaseFeeWrapperByzantium, + "opCreate2": opCreate2WrapperByzantium, +} diff --git a/core/vm/instruction_wrapper_Constantinople.go b/core/vm/instruction_wrapper_Constantinople.go new file mode 100644 index 0000000000..b4fddc630a --- /dev/null +++ b/core/vm/instruction_wrapper_Constantinople.go @@ -0,0 +1,2181 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHRWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSARWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(400) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataSizeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataCopyWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeHashWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(400) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(200) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreate2WrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opStaticCallWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opRevertWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + return res, ErrExecutionReverted +} + +func opSuicideWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opChainIDWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperConstantinople(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperConstantinople = map[string]executionWrapperFunc{ + "opStop": opStopWrapperConstantinople, + "opAdd": opAddWrapperConstantinople, + "opMul": opMulWrapperConstantinople, + "opSub": opSubWrapperConstantinople, + "opDiv": opDivWrapperConstantinople, + "opSdiv": opSdivWrapperConstantinople, + "opMod": opModWrapperConstantinople, + "opSmod": opSmodWrapperConstantinople, + "opAddmod": opAddmodWrapperConstantinople, + "opMulmod": opMulmodWrapperConstantinople, + "opExp": opExpWrapperConstantinople, + "opSignExtend": opSignExtendWrapperConstantinople, + "opLt": opLtWrapperConstantinople, + "opGt": opGtWrapperConstantinople, + "opSlt": opSltWrapperConstantinople, + "opSgt": opSgtWrapperConstantinople, + "opEq": opEqWrapperConstantinople, + "opIszero": opIszeroWrapperConstantinople, + "opAnd": opAndWrapperConstantinople, + "opOr": opOrWrapperConstantinople, + "opXor": opXorWrapperConstantinople, + "opNot": opNotWrapperConstantinople, + "opByte": opByteWrapperConstantinople, + "opSHL": opSHLWrapperConstantinople, + "opSHR": opSHRWrapperConstantinople, + "opSAR": opSARWrapperConstantinople, + "opSha3": opSha3WrapperConstantinople, + "opAddress": opAddressWrapperConstantinople, + "opBalance": opBalanceWrapperConstantinople, + "opOrigin": opOriginWrapperConstantinople, + "opCaller": opCallerWrapperConstantinople, + "opCallValue": opCallValueWrapperConstantinople, + "opCallDataLoad": opCallDataLoadWrapperConstantinople, + "opCallDataSize": opCallDataSizeWrapperConstantinople, + "opCallDataCopy": opCallDataCopyWrapperConstantinople, + "opCodeSize": opCodeSizeWrapperConstantinople, + "opCodeCopy": opCodeCopyWrapperConstantinople, + "opGasprice": opGaspriceWrapperConstantinople, + "opExtCodeSize": opExtCodeSizeWrapperConstantinople, + "opExtCodeCopy": opExtCodeCopyWrapperConstantinople, + "opReturnDataSize": opReturnDataSizeWrapperConstantinople, + "opReturnDataCopy": opReturnDataCopyWrapperConstantinople, + "opExtCodeHash": opExtCodeHashWrapperConstantinople, + "opBlockhash": opBlockhashWrapperConstantinople, + "opCoinbase": opCoinbaseWrapperConstantinople, + "opTimestamp": opTimestampWrapperConstantinople, + "opNumber": opNumberWrapperConstantinople, + "opDifficulty": opDifficultyWrapperConstantinople, + "opGasLimit": opGasLimitWrapperConstantinople, + "opPop": opPopWrapperConstantinople, + "opMload": opMloadWrapperConstantinople, + "opMstore": opMstoreWrapperConstantinople, + "opMstore8": opMstore8WrapperConstantinople, + "opSload": opSloadWrapperConstantinople, + "opSstore": opSstoreWrapperConstantinople, + "opJump": opJumpWrapperConstantinople, + "opJumpi": opJumpiWrapperConstantinople, + "opPc": opPcWrapperConstantinople, + "opMsize": opMsizeWrapperConstantinople, + "opGas": opGasWrapperConstantinople, + "opJumpdest": opJumpdestWrapperConstantinople, + "opPush1": opPush1WrapperConstantinople, + "opPush": opPushWrapperConstantinople, + "opDup": opDupWrapperConstantinople, + "opSwap": opSwapWrapperConstantinople, + "opLog": opLogWrapperConstantinople, + "opCreate": opCreateWrapperConstantinople, + "opCall": opCallWrapperConstantinople, + "opCallCode": opCallCodeWrapperConstantinople, + "opReturn": opReturnWrapperConstantinople, + "opDelegateCall": opDelegateCallWrapperConstantinople, + "opCreate2": opCreate2WrapperConstantinople, + "opStaticCall": opStaticCallWrapperConstantinople, + "opRevert": opRevertWrapperConstantinople, + "opSuicide": opSuicideWrapperConstantinople, + "opChainID": opChainIDWrapperConstantinople, + "opSelfBalance": opSelfBalanceWrapperConstantinople, + "opBaseFee": opBaseFeeWrapperConstantinople, +} diff --git a/core/vm/instruction_wrapper_Frontier.go b/core/vm/instruction_wrapper_Frontier.go new file mode 100644 index 0000000000..edb0252664 --- /dev/null +++ b/core/vm/instruction_wrapper_Frontier.go @@ -0,0 +1,1905 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(20 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(50) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(40 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(40 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSuicideWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSHRWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSARWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataSizeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataCopyWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opExtCodeHashWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opChainIDWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opDelegateCallWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opCreate2WrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opStaticCallWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opRevertWrapperFrontier(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperFrontier = map[string]executionWrapperFunc{ + "opStop": opStopWrapperFrontier, + "opAdd": opAddWrapperFrontier, + "opMul": opMulWrapperFrontier, + "opSub": opSubWrapperFrontier, + "opDiv": opDivWrapperFrontier, + "opSdiv": opSdivWrapperFrontier, + "opMod": opModWrapperFrontier, + "opSmod": opSmodWrapperFrontier, + "opAddmod": opAddmodWrapperFrontier, + "opMulmod": opMulmodWrapperFrontier, + "opExp": opExpWrapperFrontier, + "opSignExtend": opSignExtendWrapperFrontier, + "opLt": opLtWrapperFrontier, + "opGt": opGtWrapperFrontier, + "opSlt": opSltWrapperFrontier, + "opSgt": opSgtWrapperFrontier, + "opEq": opEqWrapperFrontier, + "opIszero": opIszeroWrapperFrontier, + "opAnd": opAndWrapperFrontier, + "opOr": opOrWrapperFrontier, + "opXor": opXorWrapperFrontier, + "opNot": opNotWrapperFrontier, + "opByte": opByteWrapperFrontier, + "opSha3": opSha3WrapperFrontier, + "opAddress": opAddressWrapperFrontier, + "opBalance": opBalanceWrapperFrontier, + "opOrigin": opOriginWrapperFrontier, + "opCaller": opCallerWrapperFrontier, + "opCallValue": opCallValueWrapperFrontier, + "opCallDataLoad": opCallDataLoadWrapperFrontier, + "opCallDataSize": opCallDataSizeWrapperFrontier, + "opCallDataCopy": opCallDataCopyWrapperFrontier, + "opCodeSize": opCodeSizeWrapperFrontier, + "opCodeCopy": opCodeCopyWrapperFrontier, + "opGasprice": opGaspriceWrapperFrontier, + "opExtCodeSize": opExtCodeSizeWrapperFrontier, + "opExtCodeCopy": opExtCodeCopyWrapperFrontier, + "opBlockhash": opBlockhashWrapperFrontier, + "opCoinbase": opCoinbaseWrapperFrontier, + "opTimestamp": opTimestampWrapperFrontier, + "opNumber": opNumberWrapperFrontier, + "opDifficulty": opDifficultyWrapperFrontier, + "opGasLimit": opGasLimitWrapperFrontier, + "opPop": opPopWrapperFrontier, + "opMload": opMloadWrapperFrontier, + "opMstore": opMstoreWrapperFrontier, + "opMstore8": opMstore8WrapperFrontier, + "opSload": opSloadWrapperFrontier, + "opSstore": opSstoreWrapperFrontier, + "opJump": opJumpWrapperFrontier, + "opJumpi": opJumpiWrapperFrontier, + "opPc": opPcWrapperFrontier, + "opMsize": opMsizeWrapperFrontier, + "opGas": opGasWrapperFrontier, + "opJumpdest": opJumpdestWrapperFrontier, + "opPush1": opPush1WrapperFrontier, + "opPush": opPushWrapperFrontier, + "opDup": opDupWrapperFrontier, + "opSwap": opSwapWrapperFrontier, + "opLog": opLogWrapperFrontier, + "opCreate": opCreateWrapperFrontier, + "opCall": opCallWrapperFrontier, + "opCallCode": opCallCodeWrapperFrontier, + "opReturn": opReturnWrapperFrontier, + "opSuicide": opSuicideWrapperFrontier, + "opSHL": opSHLWrapperFrontier, + "opSHR": opSHRWrapperFrontier, + "opSAR": opSARWrapperFrontier, + "opReturnDataSize": opReturnDataSizeWrapperFrontier, + "opReturnDataCopy": opReturnDataCopyWrapperFrontier, + "opExtCodeHash": opExtCodeHashWrapperFrontier, + "opChainID": opChainIDWrapperFrontier, + "opSelfBalance": opSelfBalanceWrapperFrontier, + "opBaseFee": opBaseFeeWrapperFrontier, + "opDelegateCall": opDelegateCallWrapperFrontier, + "opCreate2": opCreate2WrapperFrontier, + "opStaticCall": opStaticCallWrapperFrontier, + "opRevert": opRevertWrapperFrontier, +} diff --git a/core/vm/instruction_wrapper_Homestead.go b/core/vm/instruction_wrapper_Homestead.go new file mode 100644 index 0000000000..14fe4a279d --- /dev/null +++ b/core/vm/instruction_wrapper_Homestead.go @@ -0,0 +1,1940 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(20 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(50) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(40 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(40 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(40 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSuicideWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSHRWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSARWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataSizeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataCopyWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opExtCodeHashWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opChainIDWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opCreate2WrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opStaticCallWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opRevertWrapperHomestead(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperHomestead = map[string]executionWrapperFunc{ + "opStop": opStopWrapperHomestead, + "opAdd": opAddWrapperHomestead, + "opMul": opMulWrapperHomestead, + "opSub": opSubWrapperHomestead, + "opDiv": opDivWrapperHomestead, + "opSdiv": opSdivWrapperHomestead, + "opMod": opModWrapperHomestead, + "opSmod": opSmodWrapperHomestead, + "opAddmod": opAddmodWrapperHomestead, + "opMulmod": opMulmodWrapperHomestead, + "opExp": opExpWrapperHomestead, + "opSignExtend": opSignExtendWrapperHomestead, + "opLt": opLtWrapperHomestead, + "opGt": opGtWrapperHomestead, + "opSlt": opSltWrapperHomestead, + "opSgt": opSgtWrapperHomestead, + "opEq": opEqWrapperHomestead, + "opIszero": opIszeroWrapperHomestead, + "opAnd": opAndWrapperHomestead, + "opOr": opOrWrapperHomestead, + "opXor": opXorWrapperHomestead, + "opNot": opNotWrapperHomestead, + "opByte": opByteWrapperHomestead, + "opSha3": opSha3WrapperHomestead, + "opAddress": opAddressWrapperHomestead, + "opBalance": opBalanceWrapperHomestead, + "opOrigin": opOriginWrapperHomestead, + "opCaller": opCallerWrapperHomestead, + "opCallValue": opCallValueWrapperHomestead, + "opCallDataLoad": opCallDataLoadWrapperHomestead, + "opCallDataSize": opCallDataSizeWrapperHomestead, + "opCallDataCopy": opCallDataCopyWrapperHomestead, + "opCodeSize": opCodeSizeWrapperHomestead, + "opCodeCopy": opCodeCopyWrapperHomestead, + "opGasprice": opGaspriceWrapperHomestead, + "opExtCodeSize": opExtCodeSizeWrapperHomestead, + "opExtCodeCopy": opExtCodeCopyWrapperHomestead, + "opBlockhash": opBlockhashWrapperHomestead, + "opCoinbase": opCoinbaseWrapperHomestead, + "opTimestamp": opTimestampWrapperHomestead, + "opNumber": opNumberWrapperHomestead, + "opDifficulty": opDifficultyWrapperHomestead, + "opGasLimit": opGasLimitWrapperHomestead, + "opPop": opPopWrapperHomestead, + "opMload": opMloadWrapperHomestead, + "opMstore": opMstoreWrapperHomestead, + "opMstore8": opMstore8WrapperHomestead, + "opSload": opSloadWrapperHomestead, + "opSstore": opSstoreWrapperHomestead, + "opJump": opJumpWrapperHomestead, + "opJumpi": opJumpiWrapperHomestead, + "opPc": opPcWrapperHomestead, + "opMsize": opMsizeWrapperHomestead, + "opGas": opGasWrapperHomestead, + "opJumpdest": opJumpdestWrapperHomestead, + "opPush1": opPush1WrapperHomestead, + "opPush": opPushWrapperHomestead, + "opDup": opDupWrapperHomestead, + "opSwap": opSwapWrapperHomestead, + "opLog": opLogWrapperHomestead, + "opCreate": opCreateWrapperHomestead, + "opCall": opCallWrapperHomestead, + "opCallCode": opCallCodeWrapperHomestead, + "opReturn": opReturnWrapperHomestead, + "opDelegateCall": opDelegateCallWrapperHomestead, + "opSuicide": opSuicideWrapperHomestead, + "opSHL": opSHLWrapperHomestead, + "opSHR": opSHRWrapperHomestead, + "opSAR": opSARWrapperHomestead, + "opReturnDataSize": opReturnDataSizeWrapperHomestead, + "opReturnDataCopy": opReturnDataCopyWrapperHomestead, + "opExtCodeHash": opExtCodeHashWrapperHomestead, + "opChainID": opChainIDWrapperHomestead, + "opSelfBalance": opSelfBalanceWrapperHomestead, + "opBaseFee": opBaseFeeWrapperHomestead, + "opCreate2": opCreate2WrapperHomestead, + "opStaticCall": opStaticCallWrapperHomestead, + "opRevert": opRevertWrapperHomestead, +} diff --git a/core/vm/instruction_wrapper_Istanbul.go b/core/vm/instruction_wrapper_Istanbul.go new file mode 100644 index 0000000000..4b368d6246 --- /dev/null +++ b/core/vm/instruction_wrapper_Istanbul.go @@ -0,0 +1,2221 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHRWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSARWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataSizeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataCopyWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeHashWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opChainIDWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSelfBalanceWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(800) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreate2WrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opStaticCallWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opRevertWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + return res, ErrExecutionReverted +} + +func opSuicideWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBaseFeeWrapperIstanbul(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperIstanbul = map[string]executionWrapperFunc{ + "opStop": opStopWrapperIstanbul, + "opAdd": opAddWrapperIstanbul, + "opMul": opMulWrapperIstanbul, + "opSub": opSubWrapperIstanbul, + "opDiv": opDivWrapperIstanbul, + "opSdiv": opSdivWrapperIstanbul, + "opMod": opModWrapperIstanbul, + "opSmod": opSmodWrapperIstanbul, + "opAddmod": opAddmodWrapperIstanbul, + "opMulmod": opMulmodWrapperIstanbul, + "opExp": opExpWrapperIstanbul, + "opSignExtend": opSignExtendWrapperIstanbul, + "opLt": opLtWrapperIstanbul, + "opGt": opGtWrapperIstanbul, + "opSlt": opSltWrapperIstanbul, + "opSgt": opSgtWrapperIstanbul, + "opEq": opEqWrapperIstanbul, + "opIszero": opIszeroWrapperIstanbul, + "opAnd": opAndWrapperIstanbul, + "opOr": opOrWrapperIstanbul, + "opXor": opXorWrapperIstanbul, + "opNot": opNotWrapperIstanbul, + "opByte": opByteWrapperIstanbul, + "opSHL": opSHLWrapperIstanbul, + "opSHR": opSHRWrapperIstanbul, + "opSAR": opSARWrapperIstanbul, + "opSha3": opSha3WrapperIstanbul, + "opAddress": opAddressWrapperIstanbul, + "opBalance": opBalanceWrapperIstanbul, + "opOrigin": opOriginWrapperIstanbul, + "opCaller": opCallerWrapperIstanbul, + "opCallValue": opCallValueWrapperIstanbul, + "opCallDataLoad": opCallDataLoadWrapperIstanbul, + "opCallDataSize": opCallDataSizeWrapperIstanbul, + "opCallDataCopy": opCallDataCopyWrapperIstanbul, + "opCodeSize": opCodeSizeWrapperIstanbul, + "opCodeCopy": opCodeCopyWrapperIstanbul, + "opGasprice": opGaspriceWrapperIstanbul, + "opExtCodeSize": opExtCodeSizeWrapperIstanbul, + "opExtCodeCopy": opExtCodeCopyWrapperIstanbul, + "opReturnDataSize": opReturnDataSizeWrapperIstanbul, + "opReturnDataCopy": opReturnDataCopyWrapperIstanbul, + "opExtCodeHash": opExtCodeHashWrapperIstanbul, + "opBlockhash": opBlockhashWrapperIstanbul, + "opCoinbase": opCoinbaseWrapperIstanbul, + "opTimestamp": opTimestampWrapperIstanbul, + "opNumber": opNumberWrapperIstanbul, + "opDifficulty": opDifficultyWrapperIstanbul, + "opGasLimit": opGasLimitWrapperIstanbul, + "opChainID": opChainIDWrapperIstanbul, + "opSelfBalance": opSelfBalanceWrapperIstanbul, + "opPop": opPopWrapperIstanbul, + "opMload": opMloadWrapperIstanbul, + "opMstore": opMstoreWrapperIstanbul, + "opMstore8": opMstore8WrapperIstanbul, + "opSload": opSloadWrapperIstanbul, + "opSstore": opSstoreWrapperIstanbul, + "opJump": opJumpWrapperIstanbul, + "opJumpi": opJumpiWrapperIstanbul, + "opPc": opPcWrapperIstanbul, + "opMsize": opMsizeWrapperIstanbul, + "opGas": opGasWrapperIstanbul, + "opJumpdest": opJumpdestWrapperIstanbul, + "opPush1": opPush1WrapperIstanbul, + "opPush": opPushWrapperIstanbul, + "opDup": opDupWrapperIstanbul, + "opSwap": opSwapWrapperIstanbul, + "opLog": opLogWrapperIstanbul, + "opCreate": opCreateWrapperIstanbul, + "opCall": opCallWrapperIstanbul, + "opCallCode": opCallCodeWrapperIstanbul, + "opReturn": opReturnWrapperIstanbul, + "opDelegateCall": opDelegateCallWrapperIstanbul, + "opCreate2": opCreate2WrapperIstanbul, + "opStaticCall": opStaticCallWrapperIstanbul, + "opRevert": opRevertWrapperIstanbul, + "opSuicide": opSuicideWrapperIstanbul, + "opBaseFee": opBaseFeeWrapperIstanbul, +} diff --git a/core/vm/instruction_wrapper_London.go b/core/vm/instruction_wrapper_London.go new file mode 100644 index 0000000000..0a35723d4d --- /dev/null +++ b/core/vm/instruction_wrapper_London.go @@ -0,0 +1,2269 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHRWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSARWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataSizeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnDataCopyWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeHashWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opChainIDWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSelfBalanceWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBaseFeeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreate2WrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opStaticCallWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(100 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opRevertWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + return res, ErrExecutionReverted +} + +func opSuicideWrapperLondon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(5000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +var stringToWrapperLondon = map[string]executionWrapperFunc{ + "opStop": opStopWrapperLondon, + "opAdd": opAddWrapperLondon, + "opMul": opMulWrapperLondon, + "opSub": opSubWrapperLondon, + "opDiv": opDivWrapperLondon, + "opSdiv": opSdivWrapperLondon, + "opMod": opModWrapperLondon, + "opSmod": opSmodWrapperLondon, + "opAddmod": opAddmodWrapperLondon, + "opMulmod": opMulmodWrapperLondon, + "opExp": opExpWrapperLondon, + "opSignExtend": opSignExtendWrapperLondon, + "opLt": opLtWrapperLondon, + "opGt": opGtWrapperLondon, + "opSlt": opSltWrapperLondon, + "opSgt": opSgtWrapperLondon, + "opEq": opEqWrapperLondon, + "opIszero": opIszeroWrapperLondon, + "opAnd": opAndWrapperLondon, + "opOr": opOrWrapperLondon, + "opXor": opXorWrapperLondon, + "opNot": opNotWrapperLondon, + "opByte": opByteWrapperLondon, + "opSHL": opSHLWrapperLondon, + "opSHR": opSHRWrapperLondon, + "opSAR": opSARWrapperLondon, + "opSha3": opSha3WrapperLondon, + "opAddress": opAddressWrapperLondon, + "opBalance": opBalanceWrapperLondon, + "opOrigin": opOriginWrapperLondon, + "opCaller": opCallerWrapperLondon, + "opCallValue": opCallValueWrapperLondon, + "opCallDataLoad": opCallDataLoadWrapperLondon, + "opCallDataSize": opCallDataSizeWrapperLondon, + "opCallDataCopy": opCallDataCopyWrapperLondon, + "opCodeSize": opCodeSizeWrapperLondon, + "opCodeCopy": opCodeCopyWrapperLondon, + "opGasprice": opGaspriceWrapperLondon, + "opExtCodeSize": opExtCodeSizeWrapperLondon, + "opExtCodeCopy": opExtCodeCopyWrapperLondon, + "opReturnDataSize": opReturnDataSizeWrapperLondon, + "opReturnDataCopy": opReturnDataCopyWrapperLondon, + "opExtCodeHash": opExtCodeHashWrapperLondon, + "opBlockhash": opBlockhashWrapperLondon, + "opCoinbase": opCoinbaseWrapperLondon, + "opTimestamp": opTimestampWrapperLondon, + "opNumber": opNumberWrapperLondon, + "opDifficulty": opDifficultyWrapperLondon, + "opGasLimit": opGasLimitWrapperLondon, + "opChainID": opChainIDWrapperLondon, + "opSelfBalance": opSelfBalanceWrapperLondon, + "opBaseFee": opBaseFeeWrapperLondon, + "opPop": opPopWrapperLondon, + "opMload": opMloadWrapperLondon, + "opMstore": opMstoreWrapperLondon, + "opMstore8": opMstore8WrapperLondon, + "opSload": opSloadWrapperLondon, + "opSstore": opSstoreWrapperLondon, + "opJump": opJumpWrapperLondon, + "opJumpi": opJumpiWrapperLondon, + "opPc": opPcWrapperLondon, + "opMsize": opMsizeWrapperLondon, + "opGas": opGasWrapperLondon, + "opJumpdest": opJumpdestWrapperLondon, + "opPush1": opPush1WrapperLondon, + "opPush": opPushWrapperLondon, + "opDup": opDupWrapperLondon, + "opSwap": opSwapWrapperLondon, + "opLog": opLogWrapperLondon, + "opCreate": opCreateWrapperLondon, + "opCall": opCallWrapperLondon, + "opCallCode": opCallCodeWrapperLondon, + "opReturn": opReturnWrapperLondon, + "opDelegateCall": opDelegateCallWrapperLondon, + "opCreate2": opCreate2WrapperLondon, + "opStaticCall": opStaticCallWrapperLondon, + "opRevert": opRevertWrapperLondon, + "opSuicide": opSuicideWrapperLondon, +} diff --git a/core/vm/instruction_wrapper_SpuriousDragon.go b/core/vm/instruction_wrapper_SpuriousDragon.go new file mode 100644 index 0000000000..70b7635ddd --- /dev/null +++ b/core/vm/instruction_wrapper_SpuriousDragon.go @@ -0,0 +1,1940 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(400) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(200) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSuicideWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSHRWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSARWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataSizeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataCopyWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opExtCodeHashWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opChainIDWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opCreate2WrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opStaticCallWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opRevertWrapperSpuriousDragon(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperSpuriousDragon = map[string]executionWrapperFunc{ + "opStop": opStopWrapperSpuriousDragon, + "opAdd": opAddWrapperSpuriousDragon, + "opMul": opMulWrapperSpuriousDragon, + "opSub": opSubWrapperSpuriousDragon, + "opDiv": opDivWrapperSpuriousDragon, + "opSdiv": opSdivWrapperSpuriousDragon, + "opMod": opModWrapperSpuriousDragon, + "opSmod": opSmodWrapperSpuriousDragon, + "opAddmod": opAddmodWrapperSpuriousDragon, + "opMulmod": opMulmodWrapperSpuriousDragon, + "opExp": opExpWrapperSpuriousDragon, + "opSignExtend": opSignExtendWrapperSpuriousDragon, + "opLt": opLtWrapperSpuriousDragon, + "opGt": opGtWrapperSpuriousDragon, + "opSlt": opSltWrapperSpuriousDragon, + "opSgt": opSgtWrapperSpuriousDragon, + "opEq": opEqWrapperSpuriousDragon, + "opIszero": opIszeroWrapperSpuriousDragon, + "opAnd": opAndWrapperSpuriousDragon, + "opOr": opOrWrapperSpuriousDragon, + "opXor": opXorWrapperSpuriousDragon, + "opNot": opNotWrapperSpuriousDragon, + "opByte": opByteWrapperSpuriousDragon, + "opSha3": opSha3WrapperSpuriousDragon, + "opAddress": opAddressWrapperSpuriousDragon, + "opBalance": opBalanceWrapperSpuriousDragon, + "opOrigin": opOriginWrapperSpuriousDragon, + "opCaller": opCallerWrapperSpuriousDragon, + "opCallValue": opCallValueWrapperSpuriousDragon, + "opCallDataLoad": opCallDataLoadWrapperSpuriousDragon, + "opCallDataSize": opCallDataSizeWrapperSpuriousDragon, + "opCallDataCopy": opCallDataCopyWrapperSpuriousDragon, + "opCodeSize": opCodeSizeWrapperSpuriousDragon, + "opCodeCopy": opCodeCopyWrapperSpuriousDragon, + "opGasprice": opGaspriceWrapperSpuriousDragon, + "opExtCodeSize": opExtCodeSizeWrapperSpuriousDragon, + "opExtCodeCopy": opExtCodeCopyWrapperSpuriousDragon, + "opBlockhash": opBlockhashWrapperSpuriousDragon, + "opCoinbase": opCoinbaseWrapperSpuriousDragon, + "opTimestamp": opTimestampWrapperSpuriousDragon, + "opNumber": opNumberWrapperSpuriousDragon, + "opDifficulty": opDifficultyWrapperSpuriousDragon, + "opGasLimit": opGasLimitWrapperSpuriousDragon, + "opPop": opPopWrapperSpuriousDragon, + "opMload": opMloadWrapperSpuriousDragon, + "opMstore": opMstoreWrapperSpuriousDragon, + "opMstore8": opMstore8WrapperSpuriousDragon, + "opSload": opSloadWrapperSpuriousDragon, + "opSstore": opSstoreWrapperSpuriousDragon, + "opJump": opJumpWrapperSpuriousDragon, + "opJumpi": opJumpiWrapperSpuriousDragon, + "opPc": opPcWrapperSpuriousDragon, + "opMsize": opMsizeWrapperSpuriousDragon, + "opGas": opGasWrapperSpuriousDragon, + "opJumpdest": opJumpdestWrapperSpuriousDragon, + "opPush1": opPush1WrapperSpuriousDragon, + "opPush": opPushWrapperSpuriousDragon, + "opDup": opDupWrapperSpuriousDragon, + "opSwap": opSwapWrapperSpuriousDragon, + "opLog": opLogWrapperSpuriousDragon, + "opCreate": opCreateWrapperSpuriousDragon, + "opCall": opCallWrapperSpuriousDragon, + "opCallCode": opCallCodeWrapperSpuriousDragon, + "opReturn": opReturnWrapperSpuriousDragon, + "opDelegateCall": opDelegateCallWrapperSpuriousDragon, + "opSuicide": opSuicideWrapperSpuriousDragon, + "opSHL": opSHLWrapperSpuriousDragon, + "opSHR": opSHRWrapperSpuriousDragon, + "opSAR": opSARWrapperSpuriousDragon, + "opReturnDataSize": opReturnDataSizeWrapperSpuriousDragon, + "opReturnDataCopy": opReturnDataCopyWrapperSpuriousDragon, + "opExtCodeHash": opExtCodeHashWrapperSpuriousDragon, + "opChainID": opChainIDWrapperSpuriousDragon, + "opSelfBalance": opSelfBalanceWrapperSpuriousDragon, + "opBaseFee": opBaseFeeWrapperSpuriousDragon, + "opCreate2": opCreate2WrapperSpuriousDragon, + "opStaticCall": opStaticCallWrapperSpuriousDragon, + "opRevert": opRevertWrapperSpuriousDragon, +} diff --git a/core/vm/instruction_wrapper_TangerineWhistle.go b/core/vm/instruction_wrapper_TangerineWhistle.go new file mode 100644 index 0000000000..ae0dac3745 --- /dev/null +++ b/core/vm/instruction_wrapper_TangerineWhistle.go @@ -0,0 +1,1940 @@ + +package vm + +import "github.com/ethereum/go-ethereum/common/math" + + +func opStopWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(0) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSubWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDivWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSdivWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opModWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSmodWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddmodWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMulmodWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExpWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSignExtendWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(5) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLtWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGtWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSltWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSgtWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opEqWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opIszeroWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAndWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOrWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opXorWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNotWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opByteWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSha3WrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(30 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opAddressWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBalanceWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(400) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opOriginWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallerWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallValueWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataLoadWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataSizeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallDataCopyWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeSizeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCodeCopyWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGaspriceWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeSizeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(700) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opExtCodeCopyWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 4 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 4} + } else if sLen > 1028 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1028} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opBlockhashWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(20) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCoinbaseWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opTimestampWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opNumberWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDifficultyWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasLimitWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPopWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMloadWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstoreWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMstore8WrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(3 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSloadWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(200) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSstoreWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if !contract.UseGas(8) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opJumpiWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if !contract.UseGas(10) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + return res, nil +} + +func opPcWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opMsizeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opGasWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(2) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opJumpdestWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(1) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPush1WrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opPushWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 0 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 0} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDupWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1023 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1023} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSwapWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1024 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1024} + } + if !contract.UseGas(3) { + return nil, ErrOutOfGas + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opLogWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1027 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1027} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCreateWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 3 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 3} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(32000 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opCallCodeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 7 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 7} + } else if sLen > 1030 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1030} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opReturnWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 2 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 2} + } else if sLen > 1026 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1026} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opDelegateCallWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 6 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 6} + } else if sLen > 1029 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1029} + } + var memorySize uint64 + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(700 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + in.returnData = res + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSuicideWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + mem := callContext.Memory + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < 1 { + return nil, &ErrStackUnderflow{stackLen: sLen, required: 1} + } else if sLen > 1025 { + return nil, &ErrStackOverflow{stackLen: sLen, limit: 1025} + } + if in.readOnly && in.evm.chainRules.IsByzantium { + return nil, ErrWriteProtection + } + var memorySize uint64 + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas(0 + dynamicCost) { + return nil, ErrOutOfGas + } + if memorySize > 0 { + mem.Resize(memorySize) + } + res, err = operation.execute(pc, in, callContext) + if err != nil { + return nil, err + } + *pc++ + return res, nil +} + +func opSHLWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSHRWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSARWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataSizeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opReturnDataCopyWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opExtCodeHashWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opChainIDWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opSelfBalanceWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opBaseFeeWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opCreate2WrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opStaticCallWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +func opRevertWrapperTangerineWhistle(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { + return nil, nil +} + +var stringToWrapperTangerineWhistle = map[string]executionWrapperFunc{ + "opStop": opStopWrapperTangerineWhistle, + "opAdd": opAddWrapperTangerineWhistle, + "opMul": opMulWrapperTangerineWhistle, + "opSub": opSubWrapperTangerineWhistle, + "opDiv": opDivWrapperTangerineWhistle, + "opSdiv": opSdivWrapperTangerineWhistle, + "opMod": opModWrapperTangerineWhistle, + "opSmod": opSmodWrapperTangerineWhistle, + "opAddmod": opAddmodWrapperTangerineWhistle, + "opMulmod": opMulmodWrapperTangerineWhistle, + "opExp": opExpWrapperTangerineWhistle, + "opSignExtend": opSignExtendWrapperTangerineWhistle, + "opLt": opLtWrapperTangerineWhistle, + "opGt": opGtWrapperTangerineWhistle, + "opSlt": opSltWrapperTangerineWhistle, + "opSgt": opSgtWrapperTangerineWhistle, + "opEq": opEqWrapperTangerineWhistle, + "opIszero": opIszeroWrapperTangerineWhistle, + "opAnd": opAndWrapperTangerineWhistle, + "opOr": opOrWrapperTangerineWhistle, + "opXor": opXorWrapperTangerineWhistle, + "opNot": opNotWrapperTangerineWhistle, + "opByte": opByteWrapperTangerineWhistle, + "opSha3": opSha3WrapperTangerineWhistle, + "opAddress": opAddressWrapperTangerineWhistle, + "opBalance": opBalanceWrapperTangerineWhistle, + "opOrigin": opOriginWrapperTangerineWhistle, + "opCaller": opCallerWrapperTangerineWhistle, + "opCallValue": opCallValueWrapperTangerineWhistle, + "opCallDataLoad": opCallDataLoadWrapperTangerineWhistle, + "opCallDataSize": opCallDataSizeWrapperTangerineWhistle, + "opCallDataCopy": opCallDataCopyWrapperTangerineWhistle, + "opCodeSize": opCodeSizeWrapperTangerineWhistle, + "opCodeCopy": opCodeCopyWrapperTangerineWhistle, + "opGasprice": opGaspriceWrapperTangerineWhistle, + "opExtCodeSize": opExtCodeSizeWrapperTangerineWhistle, + "opExtCodeCopy": opExtCodeCopyWrapperTangerineWhistle, + "opBlockhash": opBlockhashWrapperTangerineWhistle, + "opCoinbase": opCoinbaseWrapperTangerineWhistle, + "opTimestamp": opTimestampWrapperTangerineWhistle, + "opNumber": opNumberWrapperTangerineWhistle, + "opDifficulty": opDifficultyWrapperTangerineWhistle, + "opGasLimit": opGasLimitWrapperTangerineWhistle, + "opPop": opPopWrapperTangerineWhistle, + "opMload": opMloadWrapperTangerineWhistle, + "opMstore": opMstoreWrapperTangerineWhistle, + "opMstore8": opMstore8WrapperTangerineWhistle, + "opSload": opSloadWrapperTangerineWhistle, + "opSstore": opSstoreWrapperTangerineWhistle, + "opJump": opJumpWrapperTangerineWhistle, + "opJumpi": opJumpiWrapperTangerineWhistle, + "opPc": opPcWrapperTangerineWhistle, + "opMsize": opMsizeWrapperTangerineWhistle, + "opGas": opGasWrapperTangerineWhistle, + "opJumpdest": opJumpdestWrapperTangerineWhistle, + "opPush1": opPush1WrapperTangerineWhistle, + "opPush": opPushWrapperTangerineWhistle, + "opDup": opDupWrapperTangerineWhistle, + "opSwap": opSwapWrapperTangerineWhistle, + "opLog": opLogWrapperTangerineWhistle, + "opCreate": opCreateWrapperTangerineWhistle, + "opCall": opCallWrapperTangerineWhistle, + "opCallCode": opCallCodeWrapperTangerineWhistle, + "opReturn": opReturnWrapperTangerineWhistle, + "opDelegateCall": opDelegateCallWrapperTangerineWhistle, + "opSuicide": opSuicideWrapperTangerineWhistle, + "opSHL": opSHLWrapperTangerineWhistle, + "opSHR": opSHRWrapperTangerineWhistle, + "opSAR": opSARWrapperTangerineWhistle, + "opReturnDataSize": opReturnDataSizeWrapperTangerineWhistle, + "opReturnDataCopy": opReturnDataCopyWrapperTangerineWhistle, + "opExtCodeHash": opExtCodeHashWrapperTangerineWhistle, + "opChainID": opChainIDWrapperTangerineWhistle, + "opSelfBalance": opSelfBalanceWrapperTangerineWhistle, + "opBaseFee": opBaseFeeWrapperTangerineWhistle, + "opCreate2": opCreate2WrapperTangerineWhistle, + "opStaticCall": opStaticCallWrapperTangerineWhistle, + "opRevert": opRevertWrapperTangerineWhistle, +} diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index f988757897..7d91c1c3ac 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -202,6 +202,16 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( if operation == nil { return nil, &ErrInvalidOpCode{opcode: op} } + + // If not debug, execute the wrapper of each operation instead of run all the checks + if !debug { + res, err = operation.executeWrapper(operation, &pc, in, callContext) + if operation.halts || err != nil { + return res, err + } + continue + } + // increase context's counter in.evm.Context.Counter++ // Validate stack diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 329ad77cbf..10e75ff9a1 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -21,17 +21,21 @@ import ( ) type ( - executionFunc func(pc *uint64, interpreter *EVMInterpreter, callContext *ScopeContext) ([]byte, error) - gasFunc func(*EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 + executionWrapperFunc func(operation *operation, pc *uint64, interpreter *EVMInterpreter, callContext *ScopeContext) ([]byte, error) + executionFunc func(pc *uint64, interpreter *EVMInterpreter, callContext *ScopeContext) ([]byte, error) + gasFunc func(*EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 // memorySizeFunc returns the required size, and whether the operation overflowed a uint64 memorySizeFunc func(*Stack) (size uint64, overflow bool) ) type operation struct { + // opcode name to get wrapper function + opcodeName string // execute is the operation function - execute executionFunc - constantGas uint64 - dynamicGas gasFunc + executeWrapper executionWrapperFunc + execute executionFunc + constantGas uint64 + dynamicGas gasFunc // minStack tells how many stack items are required minStack int // maxStack specifies the max length the stack can have for this operation @@ -69,6 +73,11 @@ func newLondonInstructionSet() JumpTable { instructionSet := newBerlinInstructionSet() enable3529(&instructionSet) // EIP-3529: Reduction in refunds https://eips.ethereum.org/EIPS/eip-3529 enable3198(&instructionSet) // Base fee opcode https://eips.ethereum.org/EIPS/eip-3198 + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperLondon[instruction.opcodeName] + } + } return instructionSet } @@ -77,6 +86,11 @@ func newLondonInstructionSet() JumpTable { func newBerlinInstructionSet() JumpTable { instructionSet := newIstanbulInstructionSet() enable2929(&instructionSet) // Access lists for trie accesses https://eips.ethereum.org/EIPS/eip-2929 + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperBerlin[instruction.opcodeName] + } + } return instructionSet } @@ -88,7 +102,11 @@ func newIstanbulInstructionSet() JumpTable { enable1344(&instructionSet) // ChainID opcode - https://eips.ethereum.org/EIPS/eip-1344 enable1884(&instructionSet) // Reprice reader opcodes - https://eips.ethereum.org/EIPS/eip-1884 enable2200(&instructionSet) // Net metered SSTORE - https://eips.ethereum.org/EIPS/eip-2200 - + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperIstanbul[instruction.opcodeName] + } + } return instructionSet } @@ -97,38 +115,48 @@ func newIstanbulInstructionSet() JumpTable { func newConstantinopleInstructionSet() JumpTable { instructionSet := newByzantiumInstructionSet() instructionSet[SHL] = &operation{ - execute: opSHL, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSHL", + execute: opSHL, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), } instructionSet[SHR] = &operation{ - execute: opSHR, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSHR", + execute: opSHR, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), } instructionSet[SAR] = &operation{ - execute: opSAR, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSAR", + execute: opSAR, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), } instructionSet[EXTCODEHASH] = &operation{ - execute: opExtCodeHash, - constantGas: params.ExtcodeHashGasConstantinople, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opExtCodeHash", + execute: opExtCodeHash, + constantGas: params.ExtcodeHashGasConstantinople, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), } instructionSet[CREATE2] = &operation{ - execute: opCreate2, - constantGas: params.Create2Gas, - dynamicGas: gasCreate2, - minStack: minStack(4, 1), - maxStack: maxStack(4, 1), - memorySize: memoryCreate2, - writes: true, - returns: true, + opcodeName: "opCreate2", + execute: opCreate2, + constantGas: params.Create2Gas, + dynamicGas: gasCreate2, + minStack: minStack(4, 1), + maxStack: maxStack(4, 1), + memorySize: memoryCreate2, + writes: true, + returns: true, + } + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperConstantinople[instruction.opcodeName] + } } return instructionSet } @@ -138,36 +166,45 @@ func newConstantinopleInstructionSet() JumpTable { func newByzantiumInstructionSet() JumpTable { instructionSet := newSpuriousDragonInstructionSet() instructionSet[STATICCALL] = &operation{ - execute: opStaticCall, - constantGas: params.CallGasEIP150, - dynamicGas: gasStaticCall, - minStack: minStack(6, 1), - maxStack: maxStack(6, 1), - memorySize: memoryStaticCall, - returns: true, + opcodeName: "opStaticCall", + execute: opStaticCall, + constantGas: params.CallGasEIP150, + dynamicGas: gasStaticCall, + minStack: minStack(6, 1), + maxStack: maxStack(6, 1), + memorySize: memoryStaticCall, + returns: true, } instructionSet[RETURNDATASIZE] = &operation{ - execute: opReturnDataSize, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opReturnDataSize", + execute: opReturnDataSize, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), } instructionSet[RETURNDATACOPY] = &operation{ - execute: opReturnDataCopy, - constantGas: GasFastestStep, - dynamicGas: gasReturnDataCopy, - minStack: minStack(3, 0), - maxStack: maxStack(3, 0), - memorySize: memoryReturnDataCopy, + opcodeName: "opReturnDataCopy", + execute: opReturnDataCopy, + constantGas: GasFastestStep, + dynamicGas: gasReturnDataCopy, + minStack: minStack(3, 0), + maxStack: maxStack(3, 0), + memorySize: memoryReturnDataCopy, } instructionSet[REVERT] = &operation{ - execute: opRevert, - dynamicGas: gasRevert, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - memorySize: memoryRevert, - reverts: true, - returns: true, + opcodeName: "opRevert", + execute: opRevert, + dynamicGas: gasRevert, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + memorySize: memoryRevert, + reverts: true, + returns: true, + } + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperByzantium[instruction.opcodeName] + } } return instructionSet } @@ -176,6 +213,11 @@ func newByzantiumInstructionSet() JumpTable { func newSpuriousDragonInstructionSet() JumpTable { instructionSet := newTangerineWhistleInstructionSet() instructionSet[EXP].dynamicGas = gasExpEIP158 + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperSpuriousDragon[instruction.opcodeName] + } + } return instructionSet } @@ -190,6 +232,11 @@ func newTangerineWhistleInstructionSet() JumpTable { instructionSet[CALL].constantGas = params.CallGasEIP150 instructionSet[CALLCODE].constantGas = params.CallGasEIP150 instructionSet[DELEGATECALL].constantGas = params.CallGasEIP150 + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperTangerineWhistle[instruction.opcodeName] + } + } return instructionSet } @@ -198,13 +245,19 @@ func newTangerineWhistleInstructionSet() JumpTable { func newHomesteadInstructionSet() JumpTable { instructionSet := newFrontierInstructionSet() instructionSet[DELEGATECALL] = &operation{ - execute: opDelegateCall, - dynamicGas: gasDelegateCall, - constantGas: params.CallGasFrontier, - minStack: minStack(6, 1), - maxStack: maxStack(6, 1), - memorySize: memoryDelegateCall, - returns: true, + opcodeName: "opDelegateCall", + execute: opDelegateCall, + dynamicGas: gasDelegateCall, + constantGas: params.CallGasFrontier, + minStack: minStack(6, 1), + maxStack: maxStack(6, 1), + memorySize: memoryDelegateCall, + returns: true, + } + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperHomestead[instruction.opcodeName] + } } return instructionSet } @@ -212,822 +265,1049 @@ func newHomesteadInstructionSet() JumpTable { // newFrontierInstructionSet returns the frontier instructions // that can be executed during the frontier phase. func newFrontierInstructionSet() JumpTable { - return JumpTable{ + instructionSet := JumpTable{ STOP: { - execute: opStop, - constantGas: 0, - minStack: minStack(0, 0), - maxStack: maxStack(0, 0), - halts: true, + opcodeName: "opStop", + execute: opStop, + constantGas: 0, + minStack: minStack(0, 0), + maxStack: maxStack(0, 0), + halts: true, }, ADD: { - execute: opAdd, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opAdd", + execute: opAdd, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, MUL: { - execute: opMul, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opMul", + execute: opMul, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SUB: { - execute: opSub, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSub", + execute: opSub, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, DIV: { - execute: opDiv, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opDiv", + execute: opDiv, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SDIV: { - execute: opSdiv, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSdiv", + execute: opSdiv, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, MOD: { - execute: opMod, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opMod", + execute: opMod, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SMOD: { - execute: opSmod, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSmod", + execute: opSmod, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, ADDMOD: { - execute: opAddmod, - constantGas: GasMidStep, - minStack: minStack(3, 1), - maxStack: maxStack(3, 1), + opcodeName: "opAddmod", + execute: opAddmod, + constantGas: GasMidStep, + minStack: minStack(3, 1), + maxStack: maxStack(3, 1), }, MULMOD: { - execute: opMulmod, - constantGas: GasMidStep, - minStack: minStack(3, 1), - maxStack: maxStack(3, 1), + opcodeName: "opMulmod", + execute: opMulmod, + constantGas: GasMidStep, + minStack: minStack(3, 1), + maxStack: maxStack(3, 1), }, EXP: { - execute: opExp, - dynamicGas: gasExpFrontier, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opExp", + execute: opExp, + dynamicGas: gasExpFrontier, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SIGNEXTEND: { - execute: opSignExtend, - constantGas: GasFastStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSignExtend", + execute: opSignExtend, + constantGas: GasFastStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, LT: { - execute: opLt, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opLt", + execute: opLt, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, GT: { - execute: opGt, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opGt", + execute: opGt, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SLT: { - execute: opSlt, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSlt", + execute: opSlt, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SGT: { - execute: opSgt, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opSgt", + execute: opSgt, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, EQ: { - execute: opEq, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opEq", + execute: opEq, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, ISZERO: { - execute: opIszero, - constantGas: GasFastestStep, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opIszero", + execute: opIszero, + constantGas: GasFastestStep, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, AND: { - execute: opAnd, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opAnd", + execute: opAnd, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, XOR: { - execute: opXor, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opXor", + execute: opXor, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, OR: { - execute: opOr, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opOr", + execute: opOr, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, NOT: { - execute: opNot, - constantGas: GasFastestStep, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opNot", + execute: opNot, + constantGas: GasFastestStep, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, BYTE: { - execute: opByte, - constantGas: GasFastestStep, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), + opcodeName: "opByte", + execute: opByte, + constantGas: GasFastestStep, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), }, SHA3: { - execute: opSha3, - constantGas: params.Sha3Gas, - dynamicGas: gasSha3, - minStack: minStack(2, 1), - maxStack: maxStack(2, 1), - memorySize: memorySha3, + opcodeName: "opSha3", + execute: opSha3, + constantGas: params.Sha3Gas, + dynamicGas: gasSha3, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), + memorySize: memorySha3, }, ADDRESS: { - execute: opAddress, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opAddress", + execute: opAddress, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, BALANCE: { - execute: opBalance, - constantGas: params.BalanceGasFrontier, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opBalance", + execute: opBalance, + constantGas: params.BalanceGasFrontier, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, ORIGIN: { - execute: opOrigin, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opOrigin", + execute: opOrigin, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, CALLER: { - execute: opCaller, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opCaller", + execute: opCaller, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, CALLVALUE: { - execute: opCallValue, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opCallValue", + execute: opCallValue, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, CALLDATALOAD: { - execute: opCallDataLoad, - constantGas: GasFastestStep, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opCallDataLoad", + execute: opCallDataLoad, + constantGas: GasFastestStep, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, CALLDATASIZE: { - execute: opCallDataSize, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opCallDataSize", + execute: opCallDataSize, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, CALLDATACOPY: { - execute: opCallDataCopy, - constantGas: GasFastestStep, - dynamicGas: gasCallDataCopy, - minStack: minStack(3, 0), - maxStack: maxStack(3, 0), - memorySize: memoryCallDataCopy, + opcodeName: "opCallDataCopy", + execute: opCallDataCopy, + constantGas: GasFastestStep, + dynamicGas: gasCallDataCopy, + minStack: minStack(3, 0), + maxStack: maxStack(3, 0), + memorySize: memoryCallDataCopy, }, CODESIZE: { - execute: opCodeSize, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opCodeSize", + execute: opCodeSize, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, CODECOPY: { - execute: opCodeCopy, - constantGas: GasFastestStep, - dynamicGas: gasCodeCopy, - minStack: minStack(3, 0), - maxStack: maxStack(3, 0), - memorySize: memoryCodeCopy, + opcodeName: "opCodeCopy", + execute: opCodeCopy, + constantGas: GasFastestStep, + dynamicGas: gasCodeCopy, + minStack: minStack(3, 0), + maxStack: maxStack(3, 0), + memorySize: memoryCodeCopy, }, GASPRICE: { - execute: opGasprice, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opGasprice", + execute: opGasprice, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, EXTCODESIZE: { - execute: opExtCodeSize, - constantGas: params.ExtcodeSizeGasFrontier, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opExtCodeSize", + execute: opExtCodeSize, + constantGas: params.ExtcodeSizeGasFrontier, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, EXTCODECOPY: { - execute: opExtCodeCopy, - constantGas: params.ExtcodeCopyBaseFrontier, - dynamicGas: gasExtCodeCopy, - minStack: minStack(4, 0), - maxStack: maxStack(4, 0), - memorySize: memoryExtCodeCopy, + opcodeName: "opExtCodeCopy", + execute: opExtCodeCopy, + constantGas: params.ExtcodeCopyBaseFrontier, + dynamicGas: gasExtCodeCopy, + minStack: minStack(4, 0), + maxStack: maxStack(4, 0), + memorySize: memoryExtCodeCopy, }, BLOCKHASH: { - execute: opBlockhash, - constantGas: GasExtStep, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opBlockhash", + execute: opBlockhash, + constantGas: GasExtStep, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, COINBASE: { - execute: opCoinbase, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opCoinbase", + execute: opCoinbase, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, TIMESTAMP: { - execute: opTimestamp, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opTimestamp", + execute: opTimestamp, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, NUMBER: { - execute: opNumber, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opNumber", + execute: opNumber, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, DIFFICULTY: { - execute: opDifficulty, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opDifficulty", + execute: opDifficulty, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, GASLIMIT: { - execute: opGasLimit, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opGasLimit", + execute: opGasLimit, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, POP: { - execute: opPop, - constantGas: GasQuickStep, - minStack: minStack(1, 0), - maxStack: maxStack(1, 0), + opcodeName: "opPop", + execute: opPop, + constantGas: GasQuickStep, + minStack: minStack(1, 0), + maxStack: maxStack(1, 0), }, MLOAD: { - execute: opMload, - constantGas: GasFastestStep, - dynamicGas: gasMLoad, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), - memorySize: memoryMLoad, + opcodeName: "opMload", + execute: opMload, + constantGas: GasFastestStep, + dynamicGas: gasMLoad, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), + memorySize: memoryMLoad, }, MSTORE: { - execute: opMstore, - constantGas: GasFastestStep, - dynamicGas: gasMStore, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - memorySize: memoryMStore, + opcodeName: "opMstore", + execute: opMstore, + constantGas: GasFastestStep, + dynamicGas: gasMStore, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + memorySize: memoryMStore, }, MSTORE8: { - execute: opMstore8, - constantGas: GasFastestStep, - dynamicGas: gasMStore8, - memorySize: memoryMStore8, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), + opcodeName: "opMstore8", + execute: opMstore8, + constantGas: GasFastestStep, + dynamicGas: gasMStore8, + memorySize: memoryMStore8, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), }, SLOAD: { - execute: opSload, - constantGas: params.SloadGasFrontier, - minStack: minStack(1, 1), - maxStack: maxStack(1, 1), + opcodeName: "opSload", + execute: opSload, + constantGas: params.SloadGasFrontier, + minStack: minStack(1, 1), + maxStack: maxStack(1, 1), }, SSTORE: { - execute: opSstore, - dynamicGas: gasSStore, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - writes: true, + opcodeName: "opSstore", + execute: opSstore, + dynamicGas: gasSStore, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + writes: true, }, JUMP: { - execute: opJump, - constantGas: GasMidStep, - minStack: minStack(1, 0), - maxStack: maxStack(1, 0), - jumps: true, + opcodeName: "opJump", + execute: opJump, + constantGas: GasMidStep, + minStack: minStack(1, 0), + maxStack: maxStack(1, 0), + jumps: true, }, JUMPI: { - execute: opJumpi, - constantGas: GasSlowStep, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - jumps: true, + opcodeName: "opJumpi", + execute: opJumpi, + constantGas: GasSlowStep, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + jumps: true, }, PC: { - execute: opPc, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPc", + execute: opPc, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, MSIZE: { - execute: opMsize, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opMsize", + execute: opMsize, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, GAS: { - execute: opGas, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opGas", + execute: opGas, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, JUMPDEST: { - execute: opJumpdest, - constantGas: params.JumpdestGas, - minStack: minStack(0, 0), - maxStack: maxStack(0, 0), + opcodeName: "opJumpdest", + execute: opJumpdest, + constantGas: params.JumpdestGas, + minStack: minStack(0, 0), + maxStack: maxStack(0, 0), }, PUSH1: { - execute: opPush1, - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush1", + execute: opPush1, + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH2: { - execute: makePush(2, 2), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(2, 2), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH3: { - execute: makePush(3, 3), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(3, 3), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH4: { - execute: makePush(4, 4), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(4, 4), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH5: { - execute: makePush(5, 5), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(5, 5), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH6: { - execute: makePush(6, 6), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(6, 6), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH7: { - execute: makePush(7, 7), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(7, 7), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH8: { - execute: makePush(8, 8), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(8, 8), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH9: { - execute: makePush(9, 9), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(9, 9), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH10: { - execute: makePush(10, 10), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(10, 10), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH11: { - execute: makePush(11, 11), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(11, 11), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH12: { - execute: makePush(12, 12), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(12, 12), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH13: { - execute: makePush(13, 13), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(13, 13), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH14: { - execute: makePush(14, 14), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(14, 14), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH15: { - execute: makePush(15, 15), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(15, 15), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH16: { - execute: makePush(16, 16), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(16, 16), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH17: { - execute: makePush(17, 17), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(17, 17), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH18: { - execute: makePush(18, 18), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(18, 18), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH19: { - execute: makePush(19, 19), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(19, 19), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH20: { - execute: makePush(20, 20), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(20, 20), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH21: { - execute: makePush(21, 21), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(21, 21), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH22: { - execute: makePush(22, 22), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(22, 22), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH23: { - execute: makePush(23, 23), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(23, 23), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH24: { - execute: makePush(24, 24), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(24, 24), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH25: { - execute: makePush(25, 25), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(25, 25), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH26: { - execute: makePush(26, 26), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(26, 26), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH27: { - execute: makePush(27, 27), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(27, 27), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH28: { - execute: makePush(28, 28), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(28, 28), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH29: { - execute: makePush(29, 29), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(29, 29), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH30: { - execute: makePush(30, 30), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(30, 30), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH31: { - execute: makePush(31, 31), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(31, 31), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, PUSH32: { - execute: makePush(32, 32), - constantGas: GasFastestStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), + opcodeName: "opPush", + execute: makePush(32, 32), + constantGas: GasFastestStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), }, DUP1: { - execute: makeDup(1), - constantGas: GasFastestStep, - minStack: minDupStack(1), - maxStack: maxDupStack(1), + opcodeName: "opDup", + execute: makeDup(1), + constantGas: GasFastestStep, + minStack: minDupStack(1), + maxStack: maxDupStack(1), }, DUP2: { - execute: makeDup(2), - constantGas: GasFastestStep, - minStack: minDupStack(2), - maxStack: maxDupStack(2), + opcodeName: "opDup", + execute: makeDup(2), + constantGas: GasFastestStep, + minStack: minDupStack(2), + maxStack: maxDupStack(2), }, DUP3: { - execute: makeDup(3), - constantGas: GasFastestStep, - minStack: minDupStack(3), - maxStack: maxDupStack(3), + opcodeName: "opDup", + execute: makeDup(3), + constantGas: GasFastestStep, + minStack: minDupStack(3), + maxStack: maxDupStack(3), }, DUP4: { - execute: makeDup(4), - constantGas: GasFastestStep, - minStack: minDupStack(4), - maxStack: maxDupStack(4), + opcodeName: "opDup", + execute: makeDup(4), + constantGas: GasFastestStep, + minStack: minDupStack(4), + maxStack: maxDupStack(4), }, DUP5: { - execute: makeDup(5), - constantGas: GasFastestStep, - minStack: minDupStack(5), - maxStack: maxDupStack(5), + opcodeName: "opDup", + execute: makeDup(5), + constantGas: GasFastestStep, + minStack: minDupStack(5), + maxStack: maxDupStack(5), }, DUP6: { - execute: makeDup(6), - constantGas: GasFastestStep, - minStack: minDupStack(6), - maxStack: maxDupStack(6), + opcodeName: "opDup", + execute: makeDup(6), + constantGas: GasFastestStep, + minStack: minDupStack(6), + maxStack: maxDupStack(6), }, DUP7: { - execute: makeDup(7), - constantGas: GasFastestStep, - minStack: minDupStack(7), - maxStack: maxDupStack(7), + opcodeName: "opDup", + execute: makeDup(7), + constantGas: GasFastestStep, + minStack: minDupStack(7), + maxStack: maxDupStack(7), }, DUP8: { - execute: makeDup(8), - constantGas: GasFastestStep, - minStack: minDupStack(8), - maxStack: maxDupStack(8), + opcodeName: "opDup", + execute: makeDup(8), + constantGas: GasFastestStep, + minStack: minDupStack(8), + maxStack: maxDupStack(8), }, DUP9: { - execute: makeDup(9), - constantGas: GasFastestStep, - minStack: minDupStack(9), - maxStack: maxDupStack(9), + opcodeName: "opDup", + execute: makeDup(9), + constantGas: GasFastestStep, + minStack: minDupStack(9), + maxStack: maxDupStack(9), }, DUP10: { - execute: makeDup(10), - constantGas: GasFastestStep, - minStack: minDupStack(10), - maxStack: maxDupStack(10), + opcodeName: "opDup", + execute: makeDup(10), + constantGas: GasFastestStep, + minStack: minDupStack(10), + maxStack: maxDupStack(10), }, DUP11: { - execute: makeDup(11), - constantGas: GasFastestStep, - minStack: minDupStack(11), - maxStack: maxDupStack(11), + opcodeName: "opDup", + execute: makeDup(11), + constantGas: GasFastestStep, + minStack: minDupStack(11), + maxStack: maxDupStack(11), }, DUP12: { - execute: makeDup(12), - constantGas: GasFastestStep, - minStack: minDupStack(12), - maxStack: maxDupStack(12), + opcodeName: "opDup", + execute: makeDup(12), + constantGas: GasFastestStep, + minStack: minDupStack(12), + maxStack: maxDupStack(12), }, DUP13: { - execute: makeDup(13), - constantGas: GasFastestStep, - minStack: minDupStack(13), - maxStack: maxDupStack(13), + opcodeName: "opDup", + execute: makeDup(13), + constantGas: GasFastestStep, + minStack: minDupStack(13), + maxStack: maxDupStack(13), }, DUP14: { - execute: makeDup(14), - constantGas: GasFastestStep, - minStack: minDupStack(14), - maxStack: maxDupStack(14), + opcodeName: "opDup", + execute: makeDup(14), + constantGas: GasFastestStep, + minStack: minDupStack(14), + maxStack: maxDupStack(14), }, DUP15: { - execute: makeDup(15), - constantGas: GasFastestStep, - minStack: minDupStack(15), - maxStack: maxDupStack(15), + opcodeName: "opDup", + execute: makeDup(15), + constantGas: GasFastestStep, + minStack: minDupStack(15), + maxStack: maxDupStack(15), }, DUP16: { - execute: makeDup(16), - constantGas: GasFastestStep, - minStack: minDupStack(16), - maxStack: maxDupStack(16), + opcodeName: "opDup", + execute: makeDup(16), + constantGas: GasFastestStep, + minStack: minDupStack(16), + maxStack: maxDupStack(16), }, SWAP1: { - execute: makeSwap(1), - constantGas: GasFastestStep, - minStack: minSwapStack(2), - maxStack: maxSwapStack(2), + opcodeName: "opSwap", + execute: makeSwap(1), + constantGas: GasFastestStep, + minStack: minSwapStack(2), + maxStack: maxSwapStack(2), }, SWAP2: { - execute: makeSwap(2), - constantGas: GasFastestStep, - minStack: minSwapStack(3), - maxStack: maxSwapStack(3), + opcodeName: "opSwap", + execute: makeSwap(2), + constantGas: GasFastestStep, + minStack: minSwapStack(3), + maxStack: maxSwapStack(3), }, SWAP3: { - execute: makeSwap(3), - constantGas: GasFastestStep, - minStack: minSwapStack(4), - maxStack: maxSwapStack(4), + opcodeName: "opSwap", + execute: makeSwap(3), + constantGas: GasFastestStep, + minStack: minSwapStack(4), + maxStack: maxSwapStack(4), }, SWAP4: { - execute: makeSwap(4), - constantGas: GasFastestStep, - minStack: minSwapStack(5), - maxStack: maxSwapStack(5), + opcodeName: "opSwap", + execute: makeSwap(4), + constantGas: GasFastestStep, + minStack: minSwapStack(5), + maxStack: maxSwapStack(5), }, SWAP5: { - execute: makeSwap(5), - constantGas: GasFastestStep, - minStack: minSwapStack(6), - maxStack: maxSwapStack(6), + opcodeName: "opSwap", + execute: makeSwap(5), + constantGas: GasFastestStep, + minStack: minSwapStack(6), + maxStack: maxSwapStack(6), }, SWAP6: { - execute: makeSwap(6), - constantGas: GasFastestStep, - minStack: minSwapStack(7), - maxStack: maxSwapStack(7), + opcodeName: "opSwap", + execute: makeSwap(6), + constantGas: GasFastestStep, + minStack: minSwapStack(7), + maxStack: maxSwapStack(7), }, SWAP7: { - execute: makeSwap(7), - constantGas: GasFastestStep, - minStack: minSwapStack(8), - maxStack: maxSwapStack(8), + opcodeName: "opSwap", + execute: makeSwap(7), + constantGas: GasFastestStep, + minStack: minSwapStack(8), + maxStack: maxSwapStack(8), }, SWAP8: { - execute: makeSwap(8), - constantGas: GasFastestStep, - minStack: minSwapStack(9), - maxStack: maxSwapStack(9), + opcodeName: "opSwap", + execute: makeSwap(8), + constantGas: GasFastestStep, + minStack: minSwapStack(9), + maxStack: maxSwapStack(9), }, SWAP9: { - execute: makeSwap(9), - constantGas: GasFastestStep, - minStack: minSwapStack(10), - maxStack: maxSwapStack(10), + opcodeName: "opSwap", + execute: makeSwap(9), + constantGas: GasFastestStep, + minStack: minSwapStack(10), + maxStack: maxSwapStack(10), }, SWAP10: { - execute: makeSwap(10), - constantGas: GasFastestStep, - minStack: minSwapStack(11), - maxStack: maxSwapStack(11), + opcodeName: "opSwap", + execute: makeSwap(10), + constantGas: GasFastestStep, + minStack: minSwapStack(11), + maxStack: maxSwapStack(11), }, SWAP11: { - execute: makeSwap(11), - constantGas: GasFastestStep, - minStack: minSwapStack(12), - maxStack: maxSwapStack(12), + opcodeName: "opSwap", + execute: makeSwap(11), + constantGas: GasFastestStep, + minStack: minSwapStack(12), + maxStack: maxSwapStack(12), }, SWAP12: { - execute: makeSwap(12), - constantGas: GasFastestStep, - minStack: minSwapStack(13), - maxStack: maxSwapStack(13), + opcodeName: "opSwap", + execute: makeSwap(12), + constantGas: GasFastestStep, + minStack: minSwapStack(13), + maxStack: maxSwapStack(13), }, SWAP13: { - execute: makeSwap(13), - constantGas: GasFastestStep, - minStack: minSwapStack(14), - maxStack: maxSwapStack(14), + opcodeName: "opSwap", + execute: makeSwap(13), + constantGas: GasFastestStep, + minStack: minSwapStack(14), + maxStack: maxSwapStack(14), }, SWAP14: { - execute: makeSwap(14), - constantGas: GasFastestStep, - minStack: minSwapStack(15), - maxStack: maxSwapStack(15), + opcodeName: "opSwap", + execute: makeSwap(14), + constantGas: GasFastestStep, + minStack: minSwapStack(15), + maxStack: maxSwapStack(15), }, SWAP15: { - execute: makeSwap(15), - constantGas: GasFastestStep, - minStack: minSwapStack(16), - maxStack: maxSwapStack(16), + opcodeName: "opSwap", + execute: makeSwap(15), + constantGas: GasFastestStep, + minStack: minSwapStack(16), + maxStack: maxSwapStack(16), }, SWAP16: { - execute: makeSwap(16), - constantGas: GasFastestStep, - minStack: minSwapStack(17), - maxStack: maxSwapStack(17), + opcodeName: "opSwap", + execute: makeSwap(16), + constantGas: GasFastestStep, + minStack: minSwapStack(17), + maxStack: maxSwapStack(17), }, LOG0: { - execute: makeLog(0), - dynamicGas: makeGasLog(0), - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - memorySize: memoryLog, - writes: true, + opcodeName: "opSwap", + execute: makeLog(0), + dynamicGas: makeGasLog(0), + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + memorySize: memoryLog, + writes: true, }, LOG1: { - execute: makeLog(1), - dynamicGas: makeGasLog(1), - minStack: minStack(3, 0), - maxStack: maxStack(3, 0), - memorySize: memoryLog, - writes: true, + opcodeName: "opLog", + execute: makeLog(1), + dynamicGas: makeGasLog(1), + minStack: minStack(3, 0), + maxStack: maxStack(3, 0), + memorySize: memoryLog, + writes: true, }, LOG2: { - execute: makeLog(2), - dynamicGas: makeGasLog(2), - minStack: minStack(4, 0), - maxStack: maxStack(4, 0), - memorySize: memoryLog, - writes: true, + opcodeName: "opLog", + execute: makeLog(2), + dynamicGas: makeGasLog(2), + minStack: minStack(4, 0), + maxStack: maxStack(4, 0), + memorySize: memoryLog, + writes: true, }, LOG3: { - execute: makeLog(3), - dynamicGas: makeGasLog(3), - minStack: minStack(5, 0), - maxStack: maxStack(5, 0), - memorySize: memoryLog, - writes: true, + opcodeName: "opLog", + execute: makeLog(3), + dynamicGas: makeGasLog(3), + minStack: minStack(5, 0), + maxStack: maxStack(5, 0), + memorySize: memoryLog, + writes: true, }, LOG4: { - execute: makeLog(4), - dynamicGas: makeGasLog(4), - minStack: minStack(6, 0), - maxStack: maxStack(6, 0), - memorySize: memoryLog, - writes: true, + opcodeName: "opLog", + execute: makeLog(4), + dynamicGas: makeGasLog(4), + minStack: minStack(6, 0), + maxStack: maxStack(6, 0), + memorySize: memoryLog, + writes: true, }, CREATE: { - execute: opCreate, - constantGas: params.CreateGas, - dynamicGas: gasCreate, - minStack: minStack(3, 1), - maxStack: maxStack(3, 1), - memorySize: memoryCreate, - writes: true, - returns: true, + opcodeName: "opCreate", + execute: opCreate, + constantGas: params.CreateGas, + dynamicGas: gasCreate, + minStack: minStack(3, 1), + maxStack: maxStack(3, 1), + memorySize: memoryCreate, + writes: true, + returns: true, }, CALL: { - execute: opCall, - constantGas: params.CallGasFrontier, - dynamicGas: gasCall, - minStack: minStack(7, 1), - maxStack: maxStack(7, 1), - memorySize: memoryCall, - returns: true, + opcodeName: "opCall", + execute: opCall, + constantGas: params.CallGasFrontier, + dynamicGas: gasCall, + minStack: minStack(7, 1), + maxStack: maxStack(7, 1), + memorySize: memoryCall, + returns: true, }, CALLCODE: { - execute: opCallCode, - constantGas: params.CallGasFrontier, - dynamicGas: gasCallCode, - minStack: minStack(7, 1), - maxStack: maxStack(7, 1), - memorySize: memoryCall, - returns: true, + opcodeName: "opCallCode", + execute: opCallCode, + constantGas: params.CallGasFrontier, + dynamicGas: gasCallCode, + minStack: minStack(7, 1), + maxStack: maxStack(7, 1), + memorySize: memoryCall, + returns: true, }, RETURN: { - execute: opReturn, - dynamicGas: gasReturn, - minStack: minStack(2, 0), - maxStack: maxStack(2, 0), - memorySize: memoryReturn, - halts: true, + opcodeName: "opReturn", + execute: opReturn, + dynamicGas: gasReturn, + minStack: minStack(2, 0), + maxStack: maxStack(2, 0), + memorySize: memoryReturn, + halts: true, }, SELFDESTRUCT: { - execute: opSuicide, - dynamicGas: gasSelfdestruct, - minStack: minStack(1, 0), - maxStack: maxStack(1, 0), - halts: true, - writes: true, + opcodeName: "opSuicide", + execute: opSuicide, + dynamicGas: gasSelfdestruct, + minStack: minStack(1, 0), + maxStack: maxStack(1, 0), + halts: true, + writes: true, }, } + for _, instruction := range instructionSet { + if instruction != nil { + instruction.executeWrapper = stringToWrapperFrontier[instruction.opcodeName] + } + } + return instructionSet +} + +// Export instruction set attributes + +type OperationAttribute struct { + Supported bool + Name string + MinStack int + MaxStack int + ConstantGas uint64 + DynamicCost bool + MemorySize bool + Halts bool + Jumps bool + Writes bool + Reverts bool + Returns bool +} + +func ExportInstructionSet(rules params.Rules) []OperationAttribute{ + var instructionSet JumpTable + switch { + case rules.IsLondon: + instructionSet = londonInstructionSet + case rules.IsBerlin: + instructionSet = berlinInstructionSet + case rules.IsIstanbul: + instructionSet = istanbulInstructionSet + case rules.IsConstantinople: + instructionSet = constantinopleInstructionSet + case rules.IsByzantium: + instructionSet = byzantiumInstructionSet + case rules.IsEIP158: + instructionSet = spuriousDragonInstructionSet + case rules.IsEIP150: + instructionSet = tangerineWhistleInstructionSet + case rules.IsHomestead: + instructionSet = homesteadInstructionSet + default: + instructionSet = frontierInstructionSet + } + // Eliminate duplicate operations (like PUSH, DUP,...), and to add unsupported operations + existOperations := make(map[string]bool) + var operations []OperationAttribute + for _, op := range instructionSet { + if op != nil { + functionName := op.opcodeName + if !existOperations[functionName] { + existOperations[functionName] = true + attribute := OperationAttribute{ + Supported: true, + Name: functionName, + MinStack: op.minStack, + MaxStack: op.maxStack, + ConstantGas: op.constantGas, + DynamicCost: op.dynamicGas != nil, + MemorySize: op.memorySize != nil, + Halts: op.halts, + Jumps: op.jumps, + Writes: op.writes, + Reverts: op.reverts, + Returns: op.returns, + } + operations = append(operations, attribute) + } + } + } + // Also add unsupported operations for generating dummy wrappers + for _, op := range londonInstructionSet { + if op != nil { + functionName := op.opcodeName + if !existOperations[functionName] { + existOperations[functionName] = true + attribute := OperationAttribute{ + Supported: false, + Name: functionName, + MinStack: op.minStack, + MaxStack: op.maxStack, + ConstantGas: op.constantGas, + DynamicCost: op.dynamicGas != nil, + MemorySize: op.memorySize != nil, + Halts: op.halts, + Jumps: op.jumps, + Writes: op.writes, + Reverts: op.reverts, + Returns: op.returns, + } + operations = append(operations, attribute) + } + } + } + return operations } From ec0f76fefca8fe7f18ba0bb136be028fdafc233a Mon Sep 17 00:00:00 2001 From: Francesco4203 Date: Fri, 21 Jun 2024 13:22:50 +0700 Subject: [PATCH 2/2] WrapperCodeGenerator: add script for generating wrappers - ExportInstructionSet: export instruction set based on input version to json - ImportInstructionSet: import instruction set from json - OpCodeWrapperGenerator: generate wrappers for an instruction set --- WrapperCodeGenerator/main.go | 219 +++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 WrapperCodeGenerator/main.go diff --git a/WrapperCodeGenerator/main.go b/WrapperCodeGenerator/main.go new file mode 100644 index 0000000000..645d6b79b2 --- /dev/null +++ b/WrapperCodeGenerator/main.go @@ -0,0 +1,219 @@ +package main + +import ( + "encoding/json" + "os" + "text/template" + + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/params" +) + +type InstructionSetJSON struct { + Version string `json:"version"` + InstructionSet []vm.OperationAttribute `json:"instruction_set"` +} +func ExportInstructionSet(version string) { + // Get the instruction set + var rules params.Rules + switch { + case version == "Homestead": + rules = params.Rules{ + IsHomestead: true, + } + case version == "TangerineWhistle": + rules = params.Rules{ + IsEIP150: true, + } + case version == "SpuriousDragon": + rules = params.Rules{ + IsEIP158: true, + } + case version == "Byzantium": + rules = params.Rules{ + IsByzantium: true, + } + case version == "Constantinople": + rules = params.Rules{ + IsConstantinople: true, + } + case version == "Istanbul": + rules = params.Rules{ + IsIstanbul: true, + } + case version == "Berlin": + rules = params.Rules{ + IsBerlin: true, + } + case version == "London": + rules = params.Rules{ + IsLondon: true, + } + default: + // frontier by default + rules = params.Rules{ + + } + } + instructionSet := vm.ExportInstructionSet(rules) + + // Export the instruction set to json + file, err := os.Create("instruction_set.json") + if err != nil { + panic(err) + } + defer file.Close() + + encoder := json.NewEncoder(file) + encoder.SetIndent("", " ") + err = encoder.Encode( + InstructionSetJSON{ + Version: version, + InstructionSet: instructionSet, + }, + ) + if err != nil { + panic(err) + } +} + +func ImportInstructionSet() InstructionSetJSON { + // Import the instruction set from json + file, err := os.Open("instruction_set.json") + if err != nil { + panic(err) + } + defer file.Close() + + decoder := json.NewDecoder(file) + var instructionSetJSON InstructionSetJSON + err = decoder.Decode(&instructionSetJSON) + if err != nil { + panic(err) + } + return instructionSetJSON +} + +func OpCodeWrapperGenerator() { + // Get instruction set + instructionSetJSON := ImportInstructionSet() + + // Define the template + tmpl := template.Must(template.New("opcode").Parse(` +package vm + +import "github.com/ethereum/go-ethereum/common/math" +{{$parent := .}} +{{range .InstructionSet}} +func {{.Name}}Wrapper{{$parent.Version}}(operation *operation, pc *uint64, in *EVMInterpreter, callContext *ScopeContext) ([]byte, error) { +{{- if .Supported}} + {{- if or .MemorySize .DynamicCost}} + mem := callContext.Memory + {{- end}} + stack := callContext.Stack + contract := callContext.Contract + var err error + var res []byte + + in.evm.Context.Counter++ + + if sLen := stack.len(); sLen < {{.MinStack}} { + return nil, &ErrStackUnderflow{stackLen: sLen, required: {{.MinStack}}} + } else if sLen > {{.MaxStack}} { + return nil, &ErrStackOverflow{stackLen: sLen, limit: {{.MaxStack}}} + } + {{- if or .Writes (eq .Name "opCall")}} + if in.readOnly && in.evm.chainRules.IsByzantium { + {{- if .Writes}} + return nil, ErrWriteProtection + {{- else if (eq .Name "opCall")}} + if stack.Back(2).Sign() != 0 { + return nil, ErrWriteProtection + } + {{- end}} + } + {{- end}} + {{- if not .DynamicCost}} + if !contract.UseGas({{.ConstantGas}}) { + return nil, ErrOutOfGas + } + {{- end}} + {{- if or .MemorySize .DynamicCost}} + var memorySize uint64 + {{- end}} + {{- if .MemorySize}} + memSize, overflow := operation.memorySize(stack) + if overflow { + return nil, ErrGasUintOverflow + } + if memorySize, overflow = math.SafeMul(toWordSize(memSize), 32); overflow { + return nil, ErrGasUintOverflow + } + {{- end}} + {{- if .DynamicCost}} + var dynamicCost uint64 + dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) + if err != nil || !contract.UseGas({{.ConstantGas}} + dynamicCost) { + return nil, ErrOutOfGas + } + {{- end}} + {{- if or .MemorySize .DynamicCost}} + if memorySize > 0 { + mem.Resize(memorySize) + } + {{- end}} + res, err = operation.execute(pc, in, callContext) + {{- if .Returns}} + in.returnData = res + {{- end}} + if err != nil { + return nil, err + } + {{- if .Reverts}} + return res, ErrExecutionReverted + {{- end}} + {{- if and (not .Jumps) (not .Reverts)}} + *pc++ + {{- end}} + {{- if not .Reverts}} + return res, nil + {{- end}} +{{- else}} + return nil, nil +{{- end}} +} +{{end}} +var stringToWrapper{{$parent.Version}} = map[string]executionWrapperFunc{ +{{- range .InstructionSet}} + "{{.Name}}": {{.Name}}Wrapper{{$parent.Version}},{{end}} +} +`)) + + // Create the source file + file, err := os.Create("instruction_wrapper_" + instructionSetJSON.Version + ".go") + if err != nil { + panic(err) + } + defer file.Close() + + // Execute the template and write to the source file + err = tmpl.Execute(file, instructionSetJSON) + if err != nil { + panic(err) + } +} + +func main() { + if len(os.Args) > 1 { + version := os.Args[1] + ExportInstructionSet(version) + OpCodeWrapperGenerator() + } else { + // export all by default + versions := []string{"Homestead", "TangerineWhistle", "SpuriousDragon", "Byzantium", "Constantinople", "Istanbul", "Berlin", "London", "Frontier"} + for _, version := range versions { + ExportInstructionSet(version) + OpCodeWrapperGenerator() + } + } +}