-
Notifications
You must be signed in to change notification settings - Fork 20k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core/vm: clear linter warnings #17057
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather emphasize that it's a deep copy. also period |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the end is missing, period |
||
func (s *StructLog) OpName() string { | ||
return s.Op.String() | ||
} | ||
|
||
// ErrorString formats the log's error as a string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. period |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // 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 | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // CaptureFault implements the Tracer interface to trace an execution fault |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ type Memory struct { | |
lastGasCost uint64 | ||
} | ||
|
||
// NewMemory returns a new memory memory model | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. period |
||
func NewMemory() *Memory { | ||
return &Memory{} | ||
} | ||
|
@@ -107,6 +108,7 @@ func (m *Memory) Data() []byte { | |
return m.store | ||
} | ||
|
||
// Print shows the content of the memory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
func (m *Memory) Print() { | ||
fmt.Printf("### mem %d bytes ###\n", len(m.store)) | ||
if len(m.store) > 0 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert these changes. These don't add any meaningful information to the code. On the other hand, the many lines bloat up the code and make it harder to see that this is a noop mock construct. |
||
func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
// OpCode is an EVM opcode | ||
type OpCode byte | ||
|
||
// IsPush specifies if an opcode is a PUSH opcode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. period |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. period |
||
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] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
period