core/vm: review input

This commit is contained in:
Guillaume Ballet 2018-06-25 04:56:49 -04:00
parent 68a49c5d6b
commit f639948c85
4 changed files with 32 additions and 31 deletions

View file

@ -29,10 +29,10 @@ import (
"github.com/ethereum/go-ethereum/core/types" "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 type Storage map[common.Hash]common.Hash
// Copy duplicates the current storage // 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 {
@ -78,12 +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 // OpName formats the operand name in a human-readable format.
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 // 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()
@ -128,7 +128,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
return logger 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 { func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
return nil return nil
} }
@ -183,12 +183,13 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
return nil 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 { 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 // 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 { 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

View file

@ -29,7 +29,7 @@ type Memory struct {
lastGasCost uint64 lastGasCost uint64
} }
// NewMemory returns a new memory memory model // NewMemory returns a new memory memory model.
func NewMemory() *Memory { func NewMemory() *Memory {
return &Memory{} return &Memory{}
} }
@ -108,7 +108,7 @@ func (m *Memory) Data() []byte {
return m.store return m.store
} }
// Print shows the content of the memory // Print dumps 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 {

View file

@ -23,7 +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 // 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:
@ -32,12 +32,12 @@ func (op OpCode) IsPush() bool {
return false return false
} }
// IsStaticJump specifies if an opcode is JUMP // 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 // 0x0 range - arithmetic ops.
const ( const (
STOP OpCode = iota STOP OpCode = iota
ADD ADD
@ -53,7 +53,7 @@ const (
SIGNEXTEND SIGNEXTEND
) )
// 0x10 range - comparison ops // 0x10 range - comparison ops.
const ( const (
LT OpCode = iota + 0x10 LT OpCode = iota + 0x10
GT GT
@ -73,7 +73,7 @@ const (
SHA3 = 0x20 SHA3 = 0x20
) )
// 0x30 range - closure state // 0x30 range - closure state.
const ( const (
ADDRESS OpCode = 0x30 + iota ADDRESS OpCode = 0x30 + iota
BALANCE BALANCE
@ -92,7 +92,7 @@ const (
RETURNDATACOPY RETURNDATACOPY
) )
// 0x40 range - block operations // 0x40 range - block operations.
const ( const (
BLOCKHASH OpCode = 0x40 + iota BLOCKHASH OpCode = 0x40 + iota
COINBASE COINBASE
@ -102,7 +102,7 @@ const (
GASLIMIT GASLIMIT
) )
// 0x50 range - 'storage' and execution // 0x50 range - 'storage' and execution.
const ( const (
POP OpCode = 0x50 + iota POP OpCode = 0x50 + iota
MLOAD MLOAD
@ -118,7 +118,7 @@ const (
JUMPDEST JUMPDEST
) )
// 0x60 range // 0x60 range.
const ( const (
PUSH1 OpCode = 0x60 + iota PUSH1 OpCode = 0x60 + iota
PUSH2 PUSH2
@ -186,7 +186,7 @@ const (
SWAP16 SWAP16
) )
// 0xa0 range - logging ops // 0xa0 range - logging ops.
const ( const (
LOG0 OpCode = 0xa0 + iota LOG0 OpCode = 0xa0 + iota
LOG1 LOG1
@ -195,14 +195,14 @@ const (
LOG4 LOG4
) )
// unofficial opcodes used for parsing // unofficial opcodes used for parsing.
const ( const (
PUSH OpCode = 0xb0 + iota PUSH OpCode = 0xb0 + iota
DUP DUP
SWAP SWAP
) )
// 0xf0 range - closures // 0xf0 range - closures.
const ( const (
CREATE OpCode = 0xf0 + iota CREATE OpCode = 0xf0 + iota
CALL CALL
@ -215,9 +215,9 @@ const (
SELFDESTRUCT = 0xff 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{ var opCodeToString = map[OpCode]string{
// 0x0 range - arithmetic ops // 0x0 range - arithmetic ops.
STOP: "STOP", STOP: "STOP",
ADD: "ADD", ADD: "ADD",
MUL: "MUL", MUL: "MUL",
@ -236,7 +236,7 @@ var opCodeToString = map[OpCode]string{
ISZERO: "ISZERO", ISZERO: "ISZERO",
SIGNEXTEND: "SIGNEXTEND", SIGNEXTEND: "SIGNEXTEND",
// 0x10 range - bit ops // 0x10 range - bit ops.
AND: "AND", AND: "AND",
OR: "OR", OR: "OR",
XOR: "XOR", XOR: "XOR",
@ -247,10 +247,10 @@ var opCodeToString = map[OpCode]string{
ADDMOD: "ADDMOD", ADDMOD: "ADDMOD",
MULMOD: "MULMOD", MULMOD: "MULMOD",
// 0x20 range - crypto // 0x20 range - crypto.
SHA3: "SHA3", SHA3: "SHA3",
// 0x30 range - closure state // 0x30 range - closure state.
ADDRESS: "ADDRESS", ADDRESS: "ADDRESS",
BALANCE: "BALANCE", BALANCE: "BALANCE",
ORIGIN: "ORIGIN", ORIGIN: "ORIGIN",
@ -267,7 +267,7 @@ var opCodeToString = map[OpCode]string{
RETURNDATASIZE: "RETURNDATASIZE", RETURNDATASIZE: "RETURNDATASIZE",
RETURNDATACOPY: "RETURNDATACOPY", RETURNDATACOPY: "RETURNDATACOPY",
// 0x40 range - block operations // 0x40 range - block operations.
BLOCKHASH: "BLOCKHASH", BLOCKHASH: "BLOCKHASH",
COINBASE: "COINBASE", COINBASE: "COINBASE",
TIMESTAMP: "TIMESTAMP", TIMESTAMP: "TIMESTAMP",
@ -275,7 +275,7 @@ var opCodeToString = map[OpCode]string{
DIFFICULTY: "DIFFICULTY", DIFFICULTY: "DIFFICULTY",
GASLIMIT: "GASLIMIT", GASLIMIT: "GASLIMIT",
// 0x50 range - 'storage' and execution // 0x50 range - 'storage' and execution.
POP: "POP", POP: "POP",
//DUP: "DUP", //DUP: "DUP",
//SWAP: "SWAP", //SWAP: "SWAP",
@ -291,7 +291,7 @@ var opCodeToString = map[OpCode]string{
GAS: "GAS", GAS: "GAS",
JUMPDEST: "JUMPDEST", JUMPDEST: "JUMPDEST",
// 0x60 range - push // 0x60 range - push.
PUSH1: "PUSH1", PUSH1: "PUSH1",
PUSH2: "PUSH2", PUSH2: "PUSH2",
PUSH3: "PUSH3", PUSH3: "PUSH3",
@ -364,7 +364,7 @@ var opCodeToString = map[OpCode]string{
LOG3: "LOG3", LOG3: "LOG3",
LOG4: "LOG4", LOG4: "LOG4",
// 0xf0 range // 0xf0 range.
CREATE: "CREATE", CREATE: "CREATE",
CALL: "CALL", CALL: "CALL",
RETURN: "RETURN", RETURN: "RETURN",

View file

@ -32,7 +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 // 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
} }
@ -81,7 +81,7 @@ func (st *Stack) require(n int) error {
return nil return nil
} }
// Print displays the content of the stack // Print dumps 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 {