From 68a49c5d6b0eba7892cc66ff40b95309172521d4 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Fri, 22 Jun 2018 10:50:50 -0400 Subject: [PATCH 1/3] core/vm: clear linter warnings --- core/vm/errors.go | 1 + core/vm/evm.go | 4 +- core/vm/gas.go | 1 + core/vm/instructions.go | 2 +- core/vm/jump_table.go | 22 ++++----- core/vm/logger.go | 7 +++ core/vm/memory.go | 2 + core/vm/noop.go | 101 +++++++++++++++++++++++++++++++--------- core/vm/opcodes.go | 17 ++++--- core/vm/stack.go | 4 +- 10 files changed, 119 insertions(+), 42 deletions(-) diff --git a/core/vm/errors.go b/core/vm/errors.go index b19366be0e6e..ea33f13f3357 100644 --- a/core/vm/errors.go +++ b/core/vm/errors.go @@ -18,6 +18,7 @@ package vm import "errors" +// List execution errors var ( ErrOutOfGas = errors.New("out of gas") ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas") diff --git a/core/vm/evm.go b/core/vm/evm.go index ea4620974233..69c8ec47871c 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -31,8 +31,10 @@ import ( var emptyCodeHash = crypto.Keccak256Hash(nil) type ( + // CanTransferFunc is the signature of a transfer guard function CanTransferFunc func(StateDB, common.Address, *big.Int) bool - TransferFunc func(StateDB, common.Address, common.Address, *big.Int) + // TransferFunc is the signature of a transfer function + TransferFunc func(StateDB, common.Address, common.Address, *big.Int) // GetHashFunc returns the nth block hash in the blockchain // and is used by the BLOCKHASH EVM op code. GetHashFunc func(uint64) common.Hash diff --git a/core/vm/gas.go b/core/vm/gas.go index dd64d5f178d2..bba7058c7e23 100644 --- a/core/vm/gas.go +++ b/core/vm/gas.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/params" ) +// Gas costs const ( GasQuickStep uint64 = 2 GasFastestStep uint64 = 3 diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 9475322cdf89..1ec13ba35fd0 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -861,7 +861,7 @@ func makeDup(size int64) executionFunc { // make swap instruction function func makeSwap(size int64) executionFunc { // 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) { stack.swap(int(size)) return nil, nil diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 49a94d964621..111a9b798178 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -51,17 +51,17 @@ type operation struct { } var ( - frontierInstructionSet = NewFrontierInstructionSet() - homesteadInstructionSet = NewHomesteadInstructionSet() - byzantiumInstructionSet = NewByzantiumInstructionSet() - constantinopleInstructionSet = NewConstantinopleInstructionSet() + frontierInstructionSet = newFrontierInstructionSet() + homesteadInstructionSet = newHomesteadInstructionSet() + byzantiumInstructionSet = newByzantiumInstructionSet() + constantinopleInstructionSet = newConstantinopleInstructionSet() ) // NewConstantinopleInstructionSet returns the frontier, homestead // byzantium and contantinople instructions. -func NewConstantinopleInstructionSet() [256]operation { +func newConstantinopleInstructionSet() [256]operation { // instructions that can be executed during the byzantium phase. - instructionSet := NewByzantiumInstructionSet() + instructionSet := newByzantiumInstructionSet() instructionSet[SHL] = operation{ execute: opSHL, gasCost: constGasFunc(GasFastestStep), @@ -85,9 +85,9 @@ func NewConstantinopleInstructionSet() [256]operation { // NewByzantiumInstructionSet returns the frontier, homestead and // byzantium instructions. -func NewByzantiumInstructionSet() [256]operation { +func newByzantiumInstructionSet() [256]operation { // instructions that can be executed during the homestead phase. - instructionSet := NewHomesteadInstructionSet() + instructionSet := newHomesteadInstructionSet() instructionSet[STATICCALL] = operation{ execute: opStaticCall, gasCost: gasStaticCall, @@ -123,8 +123,8 @@ func NewByzantiumInstructionSet() [256]operation { // NewHomesteadInstructionSet returns the frontier and homestead // instructions that can be executed during the homestead phase. -func NewHomesteadInstructionSet() [256]operation { - instructionSet := NewFrontierInstructionSet() +func newHomesteadInstructionSet() [256]operation { + instructionSet := newFrontierInstructionSet() instructionSet[DELEGATECALL] = operation{ execute: opDelegateCall, gasCost: gasDelegateCall, @@ -138,7 +138,7 @@ func NewHomesteadInstructionSet() [256]operation { // NewFrontierInstructionSet returns the frontier instructions // that can be executed during the frontier phase. -func NewFrontierInstructionSet() [256]operation { +func newFrontierInstructionSet() [256]operation { return [256]operation{ STOP: { execute: opStop, diff --git a/core/vm/logger.go b/core/vm/logger.go index c32a7b4044e8..9a5754e931b2 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -29,8 +29,10 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) +// Storage represents a contract's storage type Storage map[common.Hash]common.Hash +// Copy duplicates the current storage func (s Storage) Copy() Storage { cpy := make(Storage) for key, value := range s { @@ -76,10 +78,12 @@ type structLogMarshaling struct { ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON } +// OpName formats the func (s *StructLog) OpName() string { return s.Op.String() } +// ErrorString formats the log's error as a string func (s *StructLog) ErrorString() string { if s.Err != nil { return s.Err.Error() @@ -124,6 +128,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger { 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 { return nil } @@ -178,10 +183,12 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui 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 { return nil } +// CaptureEnd logs the end of a contract func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error { l.output = output l.err = err diff --git a/core/vm/memory.go b/core/vm/memory.go index 43f6ff5bffa5..dbd27b0e63ff 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -29,6 +29,7 @@ type Memory struct { lastGasCost uint64 } +// NewMemory returns a new memory memory model func NewMemory() *Memory { return &Memory{} } @@ -107,6 +108,7 @@ func (m *Memory) Data() []byte { return m.store } +// Print shows the content of the memory func (m *Memory) Print() { fmt.Printf("### mem %d bytes ###\n", len(m.store)) if len(m.store) > 0 { diff --git a/core/vm/noop.go b/core/vm/noop.go index b71ead0d777d..9e95352686dd 100644 --- a/core/vm/noop.go +++ b/core/vm/noop.go @@ -23,48 +23,105 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) +// NoopCanTransfer dummy function func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool { return true } + +// NoopTransfer dummy function func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int) {} +// NoopEVMCallContext represents the EVM's call context type NoopEVMCallContext struct{} +// Call dummy function func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) { return nil, nil } + +// CallCode dummy function func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) { return nil, nil } + +// Create dummy function func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) { return nil, common.Address{}, nil } + +// DelegateCall dummy function func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) { return nil, nil } +// NoopStateDB is an dummy state database type NoopStateDB struct{} -func (NoopStateDB) CreateAccount(common.Address) {} -func (NoopStateDB) SubBalance(common.Address, *big.Int) {} -func (NoopStateDB) AddBalance(common.Address, *big.Int) {} -func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } -func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } -func (NoopStateDB) SetNonce(common.Address, uint64) {} -func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } -func (NoopStateDB) GetCode(common.Address) []byte { return nil } -func (NoopStateDB) SetCode(common.Address, []byte) {} -func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } -func (NoopStateDB) AddRefund(uint64) {} -func (NoopStateDB) GetRefund() uint64 { return 0 } -func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } -func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} -func (NoopStateDB) Suicide(common.Address) bool { return false } -func (NoopStateDB) HasSuicided(common.Address) bool { return false } -func (NoopStateDB) Exist(common.Address) bool { return false } -func (NoopStateDB) Empty(common.Address) bool { return false } -func (NoopStateDB) RevertToSnapshot(int) {} -func (NoopStateDB) Snapshot() int { return 0 } -func (NoopStateDB) AddLog(*types.Log) {} -func (NoopStateDB) AddPreimage(common.Hash, []byte) {} +// CreateAccount dummy method +func (NoopStateDB) CreateAccount(common.Address) {} + +// SubBalance dummy method +func (NoopStateDB) SubBalance(common.Address, *big.Int) {} + +// AddBalance dummy method +func (NoopStateDB) AddBalance(common.Address, *big.Int) {} + +// GetBalance dummy method +func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } + +// GetNonce dummy method +func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } + +// SetNonce dummy method +func (NoopStateDB) SetNonce(common.Address, uint64) {} + +// GetCodeHash dummy method +func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } + +// GetCode dummy method +func (NoopStateDB) GetCode(common.Address) []byte { return nil } + +// SetCode dummy method +func (NoopStateDB) SetCode(common.Address, []byte) {} + +// GetCodeSize dummy method +func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } + +// AddRefund dummy method +func (NoopStateDB) AddRefund(uint64) {} + +// GetRefund dummy method +func (NoopStateDB) GetRefund() uint64 { return 0 } + +// GetState dummy method +func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } + +// SetState dummy method +func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} + +// Suicide dummy method +func (NoopStateDB) Suicide(common.Address) bool { return false } + +// HasSuicided dummy method +func (NoopStateDB) HasSuicided(common.Address) bool { return false } + +// Exist dummy method +func (NoopStateDB) Exist(common.Address) bool { return false } + +// Empty dummy method +func (NoopStateDB) Empty(common.Address) bool { return false } + +// RevertToSnapshot dummy method +func (NoopStateDB) RevertToSnapshot(int) {} + +// Snapshot dummy method +func (NoopStateDB) Snapshot() int { return 0 } + +// AddLog dummy method +func (NoopStateDB) AddLog(*types.Log) {} + +// AddPreimage dummy method +func (NoopStateDB) AddPreimage(common.Hash, []byte) {} + +// ForEachStorage dummy method func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {} diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index e3568eb000a3..c2f644d4a866 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -23,6 +23,7 @@ import ( // OpCode is an EVM opcode type OpCode byte +// IsPush specifies if an opcode is a PUSH opcode func (op OpCode) IsPush() bool { 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: @@ -31,12 +32,13 @@ func (op OpCode) IsPush() bool { return false } +// IsStaticJump specifies if an opcode is JUMP func (op OpCode) IsStaticJump() bool { return op == JUMP } +// 0x0 range - arithmetic ops const ( - // 0x0 range - arithmetic ops STOP OpCode = iota ADD MUL @@ -51,6 +53,7 @@ const ( SIGNEXTEND ) +// 0x10 range - comparison ops const ( LT OpCode = iota + 0x10 GT @@ -70,8 +73,8 @@ const ( SHA3 = 0x20 ) +// 0x30 range - closure state const ( - // 0x30 range - closure state ADDRESS OpCode = 0x30 + iota BALANCE ORIGIN @@ -89,8 +92,8 @@ const ( RETURNDATACOPY ) +// 0x40 range - block operations const ( - // 0x40 range - block operations BLOCKHASH OpCode = 0x40 + iota COINBASE TIMESTAMP @@ -99,8 +102,8 @@ const ( GASLIMIT ) +// 0x50 range - 'storage' and execution const ( - // 0x50 range - 'storage' and execution POP OpCode = 0x50 + iota MLOAD MSTORE @@ -115,8 +118,8 @@ const ( JUMPDEST ) +// 0x60 range const ( - // 0x60 range PUSH1 OpCode = 0x60 + iota PUSH2 PUSH3 @@ -183,6 +186,7 @@ const ( SWAP16 ) +// 0xa0 range - logging ops const ( LOG0 OpCode = 0xa0 + iota LOG1 @@ -198,8 +202,8 @@ const ( SWAP ) +// 0xf0 range - closures const ( - // 0xf0 range - closures CREATE OpCode = 0xf0 + iota CALL CALLCODE @@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{ "SELFDESTRUCT": SELFDESTRUCT, } +// StringToOp finds the opcode whose name is stored in `str`. func StringToOp(str string) OpCode { return stringToOp[str] } diff --git a/core/vm/stack.go b/core/vm/stack.go index 9c10d50ad15d..ffcbb9ea424b 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -21,7 +21,7 @@ import ( "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 // initialised objects. type Stack struct { @@ -32,6 +32,7 @@ func newstack() *Stack { return &Stack{data: make([]*big.Int, 0, 1024)} } +// Data returns the underlying big.Int array func (st *Stack) Data() []*big.Int { return st.data } @@ -80,6 +81,7 @@ func (st *Stack) require(n int) error { return nil } +// Print displays the content of the stack func (st *Stack) Print() { fmt.Println("### stack ###") if len(st.data) > 0 { From f639948c85f014f36060ff64187db1dfb046b072 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Mon, 25 Jun 2018 04:56:49 -0400 Subject: [PATCH 2/3] core/vm: review input --- core/vm/logger.go | 15 ++++++++------- core/vm/memory.go | 4 ++-- core/vm/opcodes.go | 40 ++++++++++++++++++++-------------------- core/vm/stack.go | 4 ++-- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/core/vm/logger.go b/core/vm/logger.go index 9a5754e931b2..85acb8d6d395 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -29,10 +29,10 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) -// Storage represents a contract's storage +// Storage represents a contract's storage. type Storage map[common.Hash]common.Hash -// Copy duplicates the current storage +// Copy duplicates the current storage. func (s Storage) Copy() Storage { cpy := make(Storage) for key, value := range s { @@ -78,12 +78,12 @@ type structLogMarshaling struct { ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON } -// OpName formats the +// OpName formats the operand name in a human-readable format. func (s *StructLog) OpName() string { return s.Op.String() } -// ErrorString formats the log's error as a string +// ErrorString formats the log's error as a string. func (s *StructLog) ErrorString() string { if s.Err != nil { return s.Err.Error() @@ -128,7 +128,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger { return logger } -// CaptureStart logs the start of a contract +// CaptureStart implements the Tracer interface to initialize the tracing operation. func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error { return nil } @@ -183,12 +183,13 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui return nil } -// CaptureFault logs a fault in the execution +// CaptureFault implements the Tracer interface to trace an execution fault +// while running an opcode. 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 } -// CaptureEnd logs the end of a contract +// CaptureEnd is called after the call finishes to finalize the tracing. func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error { l.output = output l.err = err diff --git a/core/vm/memory.go b/core/vm/memory.go index dbd27b0e63ff..722862b1de37 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -29,7 +29,7 @@ type Memory struct { lastGasCost uint64 } -// NewMemory returns a new memory memory model +// NewMemory returns a new memory memory model. func NewMemory() *Memory { return &Memory{} } @@ -108,7 +108,7 @@ func (m *Memory) Data() []byte { return m.store } -// Print shows the content of the memory +// Print dumps the content of the memory. func (m *Memory) Print() { fmt.Printf("### mem %d bytes ###\n", len(m.store)) if len(m.store) > 0 { diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index c2f644d4a866..6c12c50e5111 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -23,7 +23,7 @@ import ( // OpCode is an EVM opcode type OpCode byte -// IsPush specifies if an opcode is a PUSH opcode +// IsPush specifies if an opcode is a PUSH opcode. func (op OpCode) IsPush() bool { 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: @@ -32,12 +32,12 @@ func (op OpCode) IsPush() bool { return false } -// IsStaticJump specifies if an opcode is JUMP +// IsStaticJump specifies if an opcode is JUMP. func (op OpCode) IsStaticJump() bool { return op == JUMP } -// 0x0 range - arithmetic ops +// 0x0 range - arithmetic ops. const ( STOP OpCode = iota ADD @@ -53,7 +53,7 @@ const ( SIGNEXTEND ) -// 0x10 range - comparison ops +// 0x10 range - comparison ops. const ( LT OpCode = iota + 0x10 GT @@ -73,7 +73,7 @@ const ( SHA3 = 0x20 ) -// 0x30 range - closure state +// 0x30 range - closure state. const ( ADDRESS OpCode = 0x30 + iota BALANCE @@ -92,7 +92,7 @@ const ( RETURNDATACOPY ) -// 0x40 range - block operations +// 0x40 range - block operations. const ( BLOCKHASH OpCode = 0x40 + iota COINBASE @@ -102,7 +102,7 @@ const ( GASLIMIT ) -// 0x50 range - 'storage' and execution +// 0x50 range - 'storage' and execution. const ( POP OpCode = 0x50 + iota MLOAD @@ -118,7 +118,7 @@ const ( JUMPDEST ) -// 0x60 range +// 0x60 range. const ( PUSH1 OpCode = 0x60 + iota PUSH2 @@ -186,7 +186,7 @@ const ( SWAP16 ) -// 0xa0 range - logging ops +// 0xa0 range - logging ops. const ( LOG0 OpCode = 0xa0 + iota LOG1 @@ -195,14 +195,14 @@ const ( LOG4 ) -// unofficial opcodes used for parsing +// unofficial opcodes used for parsing. const ( PUSH OpCode = 0xb0 + iota DUP SWAP ) -// 0xf0 range - closures +// 0xf0 range - closures. const ( CREATE OpCode = 0xf0 + iota CALL @@ -215,9 +215,9 @@ const ( SELFDESTRUCT = 0xff ) -// Since the opcodes aren't all in order we can't use a regular slice +// Since the opcodes aren't all in order we can't use a regular slice. var opCodeToString = map[OpCode]string{ - // 0x0 range - arithmetic ops + // 0x0 range - arithmetic ops. STOP: "STOP", ADD: "ADD", MUL: "MUL", @@ -236,7 +236,7 @@ var opCodeToString = map[OpCode]string{ ISZERO: "ISZERO", SIGNEXTEND: "SIGNEXTEND", - // 0x10 range - bit ops + // 0x10 range - bit ops. AND: "AND", OR: "OR", XOR: "XOR", @@ -247,10 +247,10 @@ var opCodeToString = map[OpCode]string{ ADDMOD: "ADDMOD", MULMOD: "MULMOD", - // 0x20 range - crypto + // 0x20 range - crypto. SHA3: "SHA3", - // 0x30 range - closure state + // 0x30 range - closure state. ADDRESS: "ADDRESS", BALANCE: "BALANCE", ORIGIN: "ORIGIN", @@ -267,7 +267,7 @@ var opCodeToString = map[OpCode]string{ RETURNDATASIZE: "RETURNDATASIZE", RETURNDATACOPY: "RETURNDATACOPY", - // 0x40 range - block operations + // 0x40 range - block operations. BLOCKHASH: "BLOCKHASH", COINBASE: "COINBASE", TIMESTAMP: "TIMESTAMP", @@ -275,7 +275,7 @@ var opCodeToString = map[OpCode]string{ DIFFICULTY: "DIFFICULTY", GASLIMIT: "GASLIMIT", - // 0x50 range - 'storage' and execution + // 0x50 range - 'storage' and execution. POP: "POP", //DUP: "DUP", //SWAP: "SWAP", @@ -291,7 +291,7 @@ var opCodeToString = map[OpCode]string{ GAS: "GAS", JUMPDEST: "JUMPDEST", - // 0x60 range - push + // 0x60 range - push. PUSH1: "PUSH1", PUSH2: "PUSH2", PUSH3: "PUSH3", @@ -364,7 +364,7 @@ var opCodeToString = map[OpCode]string{ LOG3: "LOG3", LOG4: "LOG4", - // 0xf0 range + // 0xf0 range. CREATE: "CREATE", CALL: "CALL", RETURN: "RETURN", diff --git a/core/vm/stack.go b/core/vm/stack.go index ffcbb9ea424b..4c1b9e803707 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -32,7 +32,7 @@ func newstack() *Stack { return &Stack{data: make([]*big.Int, 0, 1024)} } -// Data returns the underlying big.Int array +// Data returns the underlying big.Int array. func (st *Stack) Data() []*big.Int { return st.data } @@ -81,7 +81,7 @@ func (st *Stack) require(n int) error { return nil } -// Print displays the content of the stack +// Print dumps the content of the stack func (st *Stack) Print() { fmt.Println("### stack ###") if len(st.data) > 0 { From 325cb515318c59176395abb902d69b71c304901b Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Mon, 25 Jun 2018 14:41:36 -0400 Subject: [PATCH 3/3] core/vm.go: revert lint in noop as per request --- core/vm/noop.go | 101 +++++++++++------------------------------------- 1 file changed, 22 insertions(+), 79 deletions(-) diff --git a/core/vm/noop.go b/core/vm/noop.go index 9e95352686dd..b71ead0d777d 100644 --- a/core/vm/noop.go +++ b/core/vm/noop.go @@ -23,105 +23,48 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) -// NoopCanTransfer dummy function func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool { return true } - -// NoopTransfer dummy function func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int) {} -// NoopEVMCallContext represents the EVM's call context type NoopEVMCallContext struct{} -// Call dummy function func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) { return nil, nil } - -// CallCode dummy function func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) { return nil, nil } - -// Create dummy function func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) { return nil, common.Address{}, nil } - -// DelegateCall dummy function func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) { return nil, nil } -// NoopStateDB is an dummy state database type NoopStateDB struct{} -// CreateAccount dummy method -func (NoopStateDB) CreateAccount(common.Address) {} - -// SubBalance dummy method -func (NoopStateDB) SubBalance(common.Address, *big.Int) {} - -// AddBalance dummy method -func (NoopStateDB) AddBalance(common.Address, *big.Int) {} - -// GetBalance dummy method -func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } - -// GetNonce dummy method -func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } - -// SetNonce dummy method -func (NoopStateDB) SetNonce(common.Address, uint64) {} - -// GetCodeHash dummy method -func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } - -// GetCode dummy method -func (NoopStateDB) GetCode(common.Address) []byte { return nil } - -// SetCode dummy method -func (NoopStateDB) SetCode(common.Address, []byte) {} - -// GetCodeSize dummy method -func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } - -// AddRefund dummy method -func (NoopStateDB) AddRefund(uint64) {} - -// GetRefund dummy method -func (NoopStateDB) GetRefund() uint64 { return 0 } - -// GetState dummy method -func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } - -// SetState dummy method -func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} - -// Suicide dummy method -func (NoopStateDB) Suicide(common.Address) bool { return false } - -// HasSuicided dummy method -func (NoopStateDB) HasSuicided(common.Address) bool { return false } - -// Exist dummy method -func (NoopStateDB) Exist(common.Address) bool { return false } - -// Empty dummy method -func (NoopStateDB) Empty(common.Address) bool { return false } - -// RevertToSnapshot dummy method -func (NoopStateDB) RevertToSnapshot(int) {} - -// Snapshot dummy method -func (NoopStateDB) Snapshot() int { return 0 } - -// AddLog dummy method -func (NoopStateDB) AddLog(*types.Log) {} - -// AddPreimage dummy method -func (NoopStateDB) AddPreimage(common.Hash, []byte) {} - -// ForEachStorage dummy method +func (NoopStateDB) CreateAccount(common.Address) {} +func (NoopStateDB) SubBalance(common.Address, *big.Int) {} +func (NoopStateDB) AddBalance(common.Address, *big.Int) {} +func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil } +func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 } +func (NoopStateDB) SetNonce(common.Address, uint64) {} +func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} } +func (NoopStateDB) GetCode(common.Address) []byte { return nil } +func (NoopStateDB) SetCode(common.Address, []byte) {} +func (NoopStateDB) GetCodeSize(common.Address) int { return 0 } +func (NoopStateDB) AddRefund(uint64) {} +func (NoopStateDB) GetRefund() uint64 { return 0 } +func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} } +func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {} +func (NoopStateDB) Suicide(common.Address) bool { return false } +func (NoopStateDB) HasSuicided(common.Address) bool { return false } +func (NoopStateDB) Exist(common.Address) bool { return false } +func (NoopStateDB) Empty(common.Address) bool { return false } +func (NoopStateDB) RevertToSnapshot(int) {} +func (NoopStateDB) Snapshot() int { return 0 } +func (NoopStateDB) AddLog(*types.Log) {} +func (NoopStateDB) AddPreimage(common.Hash, []byte) {} func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {}