From f639948c85f014f36060ff64187db1dfb046b072 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Mon, 25 Jun 2018 04:56:49 -0400 Subject: [PATCH] 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 9a5754e931..85acb8d6d3 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 dbd27b0e63..722862b1de 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 c2f644d4a8..6c12c50e51 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 ffcbb9ea42..4c1b9e8037 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 {