mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core/vm: clear linter warnings
This commit is contained in:
parent
61a5976368
commit
68a49c5d6b
10 changed files with 119 additions and 42 deletions
|
|
@ -18,6 +18,7 @@ package vm
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
|
// List execution errors
|
||||||
var (
|
var (
|
||||||
ErrOutOfGas = errors.New("out of gas")
|
ErrOutOfGas = errors.New("out of gas")
|
||||||
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")
|
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,9 @@ import (
|
||||||
var emptyCodeHash = crypto.Keccak256Hash(nil)
|
var emptyCodeHash = crypto.Keccak256Hash(nil)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// CanTransferFunc is the signature of a transfer guard function
|
||||||
CanTransferFunc func(StateDB, common.Address, *big.Int) bool
|
CanTransferFunc func(StateDB, common.Address, *big.Int) bool
|
||||||
|
// TransferFunc is the signature of a transfer function
|
||||||
TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
|
TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
|
||||||
// GetHashFunc returns the nth block hash in the blockchain
|
// GetHashFunc returns the nth block hash in the blockchain
|
||||||
// and is used by the BLOCKHASH EVM op code.
|
// and is used by the BLOCKHASH EVM op code.
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Gas costs
|
||||||
const (
|
const (
|
||||||
GasQuickStep uint64 = 2
|
GasQuickStep uint64 = 2
|
||||||
GasFastestStep uint64 = 3
|
GasFastestStep uint64 = 3
|
||||||
|
|
|
||||||
|
|
@ -861,7 +861,7 @@ func makeDup(size int64) executionFunc {
|
||||||
// make swap instruction function
|
// make swap instruction function
|
||||||
func makeSwap(size int64) executionFunc {
|
func makeSwap(size int64) executionFunc {
|
||||||
// switch n + 1 otherwise n would be swapped with n
|
// switch n + 1 otherwise n would be swapped with n
|
||||||
size += 1
|
size++
|
||||||
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||||
stack.swap(int(size))
|
stack.swap(int(size))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
||||||
|
|
@ -51,17 +51,17 @@ type operation struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
frontierInstructionSet = NewFrontierInstructionSet()
|
frontierInstructionSet = newFrontierInstructionSet()
|
||||||
homesteadInstructionSet = NewHomesteadInstructionSet()
|
homesteadInstructionSet = newHomesteadInstructionSet()
|
||||||
byzantiumInstructionSet = NewByzantiumInstructionSet()
|
byzantiumInstructionSet = newByzantiumInstructionSet()
|
||||||
constantinopleInstructionSet = NewConstantinopleInstructionSet()
|
constantinopleInstructionSet = newConstantinopleInstructionSet()
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewConstantinopleInstructionSet returns the frontier, homestead
|
// NewConstantinopleInstructionSet returns the frontier, homestead
|
||||||
// byzantium and contantinople instructions.
|
// byzantium and contantinople instructions.
|
||||||
func NewConstantinopleInstructionSet() [256]operation {
|
func newConstantinopleInstructionSet() [256]operation {
|
||||||
// instructions that can be executed during the byzantium phase.
|
// instructions that can be executed during the byzantium phase.
|
||||||
instructionSet := NewByzantiumInstructionSet()
|
instructionSet := newByzantiumInstructionSet()
|
||||||
instructionSet[SHL] = operation{
|
instructionSet[SHL] = operation{
|
||||||
execute: opSHL,
|
execute: opSHL,
|
||||||
gasCost: constGasFunc(GasFastestStep),
|
gasCost: constGasFunc(GasFastestStep),
|
||||||
|
|
@ -85,9 +85,9 @@ func NewConstantinopleInstructionSet() [256]operation {
|
||||||
|
|
||||||
// NewByzantiumInstructionSet returns the frontier, homestead and
|
// NewByzantiumInstructionSet returns the frontier, homestead and
|
||||||
// byzantium instructions.
|
// byzantium instructions.
|
||||||
func NewByzantiumInstructionSet() [256]operation {
|
func newByzantiumInstructionSet() [256]operation {
|
||||||
// instructions that can be executed during the homestead phase.
|
// instructions that can be executed during the homestead phase.
|
||||||
instructionSet := NewHomesteadInstructionSet()
|
instructionSet := newHomesteadInstructionSet()
|
||||||
instructionSet[STATICCALL] = operation{
|
instructionSet[STATICCALL] = operation{
|
||||||
execute: opStaticCall,
|
execute: opStaticCall,
|
||||||
gasCost: gasStaticCall,
|
gasCost: gasStaticCall,
|
||||||
|
|
@ -123,8 +123,8 @@ func NewByzantiumInstructionSet() [256]operation {
|
||||||
|
|
||||||
// NewHomesteadInstructionSet returns the frontier and homestead
|
// NewHomesteadInstructionSet returns the frontier and homestead
|
||||||
// instructions that can be executed during the homestead phase.
|
// instructions that can be executed during the homestead phase.
|
||||||
func NewHomesteadInstructionSet() [256]operation {
|
func newHomesteadInstructionSet() [256]operation {
|
||||||
instructionSet := NewFrontierInstructionSet()
|
instructionSet := newFrontierInstructionSet()
|
||||||
instructionSet[DELEGATECALL] = operation{
|
instructionSet[DELEGATECALL] = operation{
|
||||||
execute: opDelegateCall,
|
execute: opDelegateCall,
|
||||||
gasCost: gasDelegateCall,
|
gasCost: gasDelegateCall,
|
||||||
|
|
@ -138,7 +138,7 @@ func NewHomesteadInstructionSet() [256]operation {
|
||||||
|
|
||||||
// NewFrontierInstructionSet returns the frontier instructions
|
// NewFrontierInstructionSet returns the frontier instructions
|
||||||
// that can be executed during the frontier phase.
|
// that can be executed during the frontier phase.
|
||||||
func NewFrontierInstructionSet() [256]operation {
|
func newFrontierInstructionSet() [256]operation {
|
||||||
return [256]operation{
|
return [256]operation{
|
||||||
STOP: {
|
STOP: {
|
||||||
execute: opStop,
|
execute: opStop,
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Storage represents a contract's storage
|
||||||
type Storage map[common.Hash]common.Hash
|
type Storage map[common.Hash]common.Hash
|
||||||
|
|
||||||
|
// Copy duplicates the current storage
|
||||||
func (s Storage) Copy() Storage {
|
func (s Storage) Copy() Storage {
|
||||||
cpy := make(Storage)
|
cpy := make(Storage)
|
||||||
for key, value := range s {
|
for key, value := range s {
|
||||||
|
|
@ -76,10 +78,12 @@ type structLogMarshaling struct {
|
||||||
ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON
|
ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpName formats the
|
||||||
func (s *StructLog) OpName() string {
|
func (s *StructLog) OpName() string {
|
||||||
return s.Op.String()
|
return s.Op.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrorString formats the log's error as a string
|
||||||
func (s *StructLog) ErrorString() string {
|
func (s *StructLog) ErrorString() string {
|
||||||
if s.Err != nil {
|
if s.Err != nil {
|
||||||
return s.Err.Error()
|
return s.Err.Error()
|
||||||
|
|
@ -124,6 +128,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
|
||||||
return logger
|
return logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CaptureStart logs the start of a contract
|
||||||
func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
|
func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -178,10 +183,12 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CaptureFault logs a fault in the execution
|
||||||
func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error {
|
func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CaptureEnd logs the end of a contract
|
||||||
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
|
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
|
||||||
l.output = output
|
l.output = output
|
||||||
l.err = err
|
l.err = err
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ type Memory struct {
|
||||||
lastGasCost uint64
|
lastGasCost uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMemory returns a new memory memory model
|
||||||
func NewMemory() *Memory {
|
func NewMemory() *Memory {
|
||||||
return &Memory{}
|
return &Memory{}
|
||||||
}
|
}
|
||||||
|
|
@ -107,6 +108,7 @@ func (m *Memory) Data() []byte {
|
||||||
return m.store
|
return m.store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print shows the content of the memory
|
||||||
func (m *Memory) Print() {
|
func (m *Memory) Print() {
|
||||||
fmt.Printf("### mem %d bytes ###\n", len(m.store))
|
fmt.Printf("### mem %d bytes ###\n", len(m.store))
|
||||||
if len(m.store) > 0 {
|
if len(m.store) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -23,48 +23,105 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NoopCanTransfer dummy function
|
||||||
func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool {
|
func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoopTransfer dummy function
|
||||||
func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int) {}
|
func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int) {}
|
||||||
|
|
||||||
|
// NoopEVMCallContext represents the EVM's call context
|
||||||
type NoopEVMCallContext struct{}
|
type NoopEVMCallContext struct{}
|
||||||
|
|
||||||
|
// Call dummy function
|
||||||
func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CallCode dummy function
|
||||||
func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create dummy function
|
||||||
func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) {
|
func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) {
|
||||||
return nil, common.Address{}, nil
|
return nil, common.Address{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DelegateCall dummy function
|
||||||
func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) {
|
func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoopStateDB is an dummy state database
|
||||||
type NoopStateDB struct{}
|
type NoopStateDB struct{}
|
||||||
|
|
||||||
|
// CreateAccount dummy method
|
||||||
func (NoopStateDB) CreateAccount(common.Address) {}
|
func (NoopStateDB) CreateAccount(common.Address) {}
|
||||||
|
|
||||||
|
// SubBalance dummy method
|
||||||
func (NoopStateDB) SubBalance(common.Address, *big.Int) {}
|
func (NoopStateDB) SubBalance(common.Address, *big.Int) {}
|
||||||
|
|
||||||
|
// AddBalance dummy method
|
||||||
func (NoopStateDB) AddBalance(common.Address, *big.Int) {}
|
func (NoopStateDB) AddBalance(common.Address, *big.Int) {}
|
||||||
|
|
||||||
|
// GetBalance dummy method
|
||||||
func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil }
|
func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil }
|
||||||
|
|
||||||
|
// GetNonce dummy method
|
||||||
func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 }
|
func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||||
|
|
||||||
|
// SetNonce dummy method
|
||||||
func (NoopStateDB) SetNonce(common.Address, uint64) {}
|
func (NoopStateDB) SetNonce(common.Address, uint64) {}
|
||||||
|
|
||||||
|
// GetCodeHash dummy method
|
||||||
func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} }
|
func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} }
|
||||||
|
|
||||||
|
// GetCode dummy method
|
||||||
func (NoopStateDB) GetCode(common.Address) []byte { return nil }
|
func (NoopStateDB) GetCode(common.Address) []byte { return nil }
|
||||||
|
|
||||||
|
// SetCode dummy method
|
||||||
func (NoopStateDB) SetCode(common.Address, []byte) {}
|
func (NoopStateDB) SetCode(common.Address, []byte) {}
|
||||||
|
|
||||||
|
// GetCodeSize dummy method
|
||||||
func (NoopStateDB) GetCodeSize(common.Address) int { return 0 }
|
func (NoopStateDB) GetCodeSize(common.Address) int { return 0 }
|
||||||
|
|
||||||
|
// AddRefund dummy method
|
||||||
func (NoopStateDB) AddRefund(uint64) {}
|
func (NoopStateDB) AddRefund(uint64) {}
|
||||||
|
|
||||||
|
// GetRefund dummy method
|
||||||
func (NoopStateDB) GetRefund() uint64 { return 0 }
|
func (NoopStateDB) GetRefund() uint64 { return 0 }
|
||||||
|
|
||||||
|
// GetState dummy method
|
||||||
func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} }
|
func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} }
|
||||||
|
|
||||||
|
// SetState dummy method
|
||||||
func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {}
|
func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {}
|
||||||
|
|
||||||
|
// Suicide dummy method
|
||||||
func (NoopStateDB) Suicide(common.Address) bool { return false }
|
func (NoopStateDB) Suicide(common.Address) bool { return false }
|
||||||
|
|
||||||
|
// HasSuicided dummy method
|
||||||
func (NoopStateDB) HasSuicided(common.Address) bool { return false }
|
func (NoopStateDB) HasSuicided(common.Address) bool { return false }
|
||||||
|
|
||||||
|
// Exist dummy method
|
||||||
func (NoopStateDB) Exist(common.Address) bool { return false }
|
func (NoopStateDB) Exist(common.Address) bool { return false }
|
||||||
|
|
||||||
|
// Empty dummy method
|
||||||
func (NoopStateDB) Empty(common.Address) bool { return false }
|
func (NoopStateDB) Empty(common.Address) bool { return false }
|
||||||
|
|
||||||
|
// RevertToSnapshot dummy method
|
||||||
func (NoopStateDB) RevertToSnapshot(int) {}
|
func (NoopStateDB) RevertToSnapshot(int) {}
|
||||||
|
|
||||||
|
// Snapshot dummy method
|
||||||
func (NoopStateDB) Snapshot() int { return 0 }
|
func (NoopStateDB) Snapshot() int { return 0 }
|
||||||
|
|
||||||
|
// AddLog dummy method
|
||||||
func (NoopStateDB) AddLog(*types.Log) {}
|
func (NoopStateDB) AddLog(*types.Log) {}
|
||||||
|
|
||||||
|
// AddPreimage dummy method
|
||||||
func (NoopStateDB) AddPreimage(common.Hash, []byte) {}
|
func (NoopStateDB) AddPreimage(common.Hash, []byte) {}
|
||||||
|
|
||||||
|
// ForEachStorage dummy method
|
||||||
func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {}
|
func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
// OpCode is an EVM opcode
|
// OpCode is an EVM opcode
|
||||||
type OpCode byte
|
type OpCode byte
|
||||||
|
|
||||||
|
// IsPush specifies if an opcode is a PUSH opcode
|
||||||
func (op OpCode) IsPush() bool {
|
func (op OpCode) IsPush() bool {
|
||||||
switch op {
|
switch op {
|
||||||
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
|
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
|
||||||
|
|
@ -31,12 +32,13 @@ func (op OpCode) IsPush() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsStaticJump specifies if an opcode is JUMP
|
||||||
func (op OpCode) IsStaticJump() bool {
|
func (op OpCode) IsStaticJump() bool {
|
||||||
return op == JUMP
|
return op == JUMP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0x0 range - arithmetic ops
|
||||||
const (
|
const (
|
||||||
// 0x0 range - arithmetic ops
|
|
||||||
STOP OpCode = iota
|
STOP OpCode = iota
|
||||||
ADD
|
ADD
|
||||||
MUL
|
MUL
|
||||||
|
|
@ -51,6 +53,7 @@ const (
|
||||||
SIGNEXTEND
|
SIGNEXTEND
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0x10 range - comparison ops
|
||||||
const (
|
const (
|
||||||
LT OpCode = iota + 0x10
|
LT OpCode = iota + 0x10
|
||||||
GT
|
GT
|
||||||
|
|
@ -70,8 +73,8 @@ const (
|
||||||
SHA3 = 0x20
|
SHA3 = 0x20
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0x30 range - closure state
|
||||||
const (
|
const (
|
||||||
// 0x30 range - closure state
|
|
||||||
ADDRESS OpCode = 0x30 + iota
|
ADDRESS OpCode = 0x30 + iota
|
||||||
BALANCE
|
BALANCE
|
||||||
ORIGIN
|
ORIGIN
|
||||||
|
|
@ -89,8 +92,8 @@ const (
|
||||||
RETURNDATACOPY
|
RETURNDATACOPY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0x40 range - block operations
|
||||||
const (
|
const (
|
||||||
// 0x40 range - block operations
|
|
||||||
BLOCKHASH OpCode = 0x40 + iota
|
BLOCKHASH OpCode = 0x40 + iota
|
||||||
COINBASE
|
COINBASE
|
||||||
TIMESTAMP
|
TIMESTAMP
|
||||||
|
|
@ -99,8 +102,8 @@ const (
|
||||||
GASLIMIT
|
GASLIMIT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0x50 range - 'storage' and execution
|
||||||
const (
|
const (
|
||||||
// 0x50 range - 'storage' and execution
|
|
||||||
POP OpCode = 0x50 + iota
|
POP OpCode = 0x50 + iota
|
||||||
MLOAD
|
MLOAD
|
||||||
MSTORE
|
MSTORE
|
||||||
|
|
@ -115,8 +118,8 @@ const (
|
||||||
JUMPDEST
|
JUMPDEST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0x60 range
|
||||||
const (
|
const (
|
||||||
// 0x60 range
|
|
||||||
PUSH1 OpCode = 0x60 + iota
|
PUSH1 OpCode = 0x60 + iota
|
||||||
PUSH2
|
PUSH2
|
||||||
PUSH3
|
PUSH3
|
||||||
|
|
@ -183,6 +186,7 @@ const (
|
||||||
SWAP16
|
SWAP16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0xa0 range - logging ops
|
||||||
const (
|
const (
|
||||||
LOG0 OpCode = 0xa0 + iota
|
LOG0 OpCode = 0xa0 + iota
|
||||||
LOG1
|
LOG1
|
||||||
|
|
@ -198,8 +202,8 @@ const (
|
||||||
SWAP
|
SWAP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 0xf0 range - closures
|
||||||
const (
|
const (
|
||||||
// 0xf0 range - closures
|
|
||||||
CREATE OpCode = 0xf0 + iota
|
CREATE OpCode = 0xf0 + iota
|
||||||
CALL
|
CALL
|
||||||
CALLCODE
|
CALLCODE
|
||||||
|
|
@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{
|
||||||
"SELFDESTRUCT": SELFDESTRUCT,
|
"SELFDESTRUCT": SELFDESTRUCT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StringToOp finds the opcode whose name is stored in `str`.
|
||||||
func StringToOp(str string) OpCode {
|
func StringToOp(str string) OpCode {
|
||||||
return stringToOp[str]
|
return stringToOp[str]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
// stack is an object for basic stack operations. Items popped to the stack are
|
// Stack is an object for basic stack operations. Items popped to the stack are
|
||||||
// expected to be changed and modified. stack does not take care of adding newly
|
// expected to be changed and modified. stack does not take care of adding newly
|
||||||
// initialised objects.
|
// initialised objects.
|
||||||
type Stack struct {
|
type Stack struct {
|
||||||
|
|
@ -32,6 +32,7 @@ func newstack() *Stack {
|
||||||
return &Stack{data: make([]*big.Int, 0, 1024)}
|
return &Stack{data: make([]*big.Int, 0, 1024)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Data returns the underlying big.Int array
|
||||||
func (st *Stack) Data() []*big.Int {
|
func (st *Stack) Data() []*big.Int {
|
||||||
return st.data
|
return st.data
|
||||||
}
|
}
|
||||||
|
|
@ -80,6 +81,7 @@ func (st *Stack) require(n int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print displays the content of the stack
|
||||||
func (st *Stack) Print() {
|
func (st *Stack) Print() {
|
||||||
fmt.Println("### stack ###")
|
fmt.Println("### stack ###")
|
||||||
if len(st.data) > 0 {
|
if len(st.data) > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue