Skip to content

Commit 598f786

Browse files
gballetkaralabe
authored andcommitted
core/vm: clear linter warnings (#17057)
* core/vm: clear linter warnings * core/vm: review input * core/vm.go: revert lint in noop as per request
1 parent 4612918 commit 598f786

File tree

9 files changed

+51
-30
lines changed

9 files changed

+51
-30
lines changed

core/vm/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package vm
1818

1919
import "errors"
2020

21+
// List execution errors
2122
var (
2223
ErrOutOfGas = errors.New("out of gas")
2324
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")

core/vm/evm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import (
3131
var emptyCodeHash = crypto.Keccak256Hash(nil)
3232

3333
type (
34+
// CanTransferFunc is the signature of a transfer guard function
3435
CanTransferFunc func(StateDB, common.Address, *big.Int) bool
35-
TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
36+
// TransferFunc is the signature of a transfer function
37+
TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
3638
// GetHashFunc returns the nth block hash in the blockchain
3739
// and is used by the BLOCKHASH EVM op code.
3840
GetHashFunc func(uint64) common.Hash

core/vm/gas.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/ethereum/go-ethereum/params"
2323
)
2424

25+
// Gas costs
2526
const (
2627
GasQuickStep uint64 = 2
2728
GasFastestStep uint64 = 3

core/vm/instructions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ func makeDup(size int64) executionFunc {
861861
// make swap instruction function
862862
func makeSwap(size int64) executionFunc {
863863
// switch n + 1 otherwise n would be swapped with n
864-
size += 1
864+
size++
865865
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
866866
stack.swap(int(size))
867867
return nil, nil

core/vm/jump_table.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ type operation struct {
5151
}
5252

5353
var (
54-
frontierInstructionSet = NewFrontierInstructionSet()
55-
homesteadInstructionSet = NewHomesteadInstructionSet()
56-
byzantiumInstructionSet = NewByzantiumInstructionSet()
57-
constantinopleInstructionSet = NewConstantinopleInstructionSet()
54+
frontierInstructionSet = newFrontierInstructionSet()
55+
homesteadInstructionSet = newHomesteadInstructionSet()
56+
byzantiumInstructionSet = newByzantiumInstructionSet()
57+
constantinopleInstructionSet = newConstantinopleInstructionSet()
5858
)
5959

6060
// NewConstantinopleInstructionSet returns the frontier, homestead
6161
// byzantium and contantinople instructions.
62-
func NewConstantinopleInstructionSet() [256]operation {
62+
func newConstantinopleInstructionSet() [256]operation {
6363
// instructions that can be executed during the byzantium phase.
64-
instructionSet := NewByzantiumInstructionSet()
64+
instructionSet := newByzantiumInstructionSet()
6565
instructionSet[SHL] = operation{
6666
execute: opSHL,
6767
gasCost: constGasFunc(GasFastestStep),
@@ -85,9 +85,9 @@ func NewConstantinopleInstructionSet() [256]operation {
8585

8686
// NewByzantiumInstructionSet returns the frontier, homestead and
8787
// byzantium instructions.
88-
func NewByzantiumInstructionSet() [256]operation {
88+
func newByzantiumInstructionSet() [256]operation {
8989
// instructions that can be executed during the homestead phase.
90-
instructionSet := NewHomesteadInstructionSet()
90+
instructionSet := newHomesteadInstructionSet()
9191
instructionSet[STATICCALL] = operation{
9292
execute: opStaticCall,
9393
gasCost: gasStaticCall,
@@ -123,8 +123,8 @@ func NewByzantiumInstructionSet() [256]operation {
123123

124124
// NewHomesteadInstructionSet returns the frontier and homestead
125125
// instructions that can be executed during the homestead phase.
126-
func NewHomesteadInstructionSet() [256]operation {
127-
instructionSet := NewFrontierInstructionSet()
126+
func newHomesteadInstructionSet() [256]operation {
127+
instructionSet := newFrontierInstructionSet()
128128
instructionSet[DELEGATECALL] = operation{
129129
execute: opDelegateCall,
130130
gasCost: gasDelegateCall,
@@ -138,7 +138,7 @@ func NewHomesteadInstructionSet() [256]operation {
138138

139139
// NewFrontierInstructionSet returns the frontier instructions
140140
// that can be executed during the frontier phase.
141-
func NewFrontierInstructionSet() [256]operation {
141+
func newFrontierInstructionSet() [256]operation {
142142
return [256]operation{
143143
STOP: {
144144
execute: opStop,

core/vm/logger.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import (
2929
"github.com/ethereum/go-ethereum/core/types"
3030
)
3131

32+
// Storage represents a contract's storage.
3233
type Storage map[common.Hash]common.Hash
3334

35+
// Copy duplicates the current storage.
3436
func (s Storage) Copy() Storage {
3537
cpy := make(Storage)
3638
for key, value := range s {
@@ -76,10 +78,12 @@ type structLogMarshaling struct {
7678
ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON
7779
}
7880

81+
// OpName formats the operand name in a human-readable format.
7982
func (s *StructLog) OpName() string {
8083
return s.Op.String()
8184
}
8285

86+
// ErrorString formats the log's error as a string.
8387
func (s *StructLog) ErrorString() string {
8488
if s.Err != nil {
8589
return s.Err.Error()
@@ -124,6 +128,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
124128
return logger
125129
}
126130

131+
// CaptureStart implements the Tracer interface to initialize the tracing operation.
127132
func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
128133
return nil
129134
}
@@ -178,10 +183,13 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
178183
return nil
179184
}
180185

186+
// CaptureFault implements the Tracer interface to trace an execution fault
187+
// while running an opcode.
181188
func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error {
182189
return nil
183190
}
184191

192+
// CaptureEnd is called after the call finishes to finalize the tracing.
185193
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
186194
l.output = output
187195
l.err = err

core/vm/memory.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Memory struct {
2929
lastGasCost uint64
3030
}
3131

32+
// NewMemory returns a new memory memory model.
3233
func NewMemory() *Memory {
3334
return &Memory{}
3435
}
@@ -107,6 +108,7 @@ func (m *Memory) Data() []byte {
107108
return m.store
108109
}
109110

111+
// Print dumps the content of the memory.
110112
func (m *Memory) Print() {
111113
fmt.Printf("### mem %d bytes ###\n", len(m.store))
112114
if len(m.store) > 0 {

core/vm/opcodes.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
// OpCode is an EVM opcode
2424
type OpCode byte
2525

26+
// IsPush specifies if an opcode is a PUSH opcode.
2627
func (op OpCode) IsPush() bool {
2728
switch op {
2829
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 {
3132
return false
3233
}
3334

35+
// IsStaticJump specifies if an opcode is JUMP.
3436
func (op OpCode) IsStaticJump() bool {
3537
return op == JUMP
3638
}
3739

40+
// 0x0 range - arithmetic ops.
3841
const (
39-
// 0x0 range - arithmetic ops
4042
STOP OpCode = iota
4143
ADD
4244
MUL
@@ -51,6 +53,7 @@ const (
5153
SIGNEXTEND
5254
)
5355

56+
// 0x10 range - comparison ops.
5457
const (
5558
LT OpCode = iota + 0x10
5659
GT
@@ -70,8 +73,8 @@ const (
7073
SHA3 = 0x20
7174
)
7275

76+
// 0x30 range - closure state.
7377
const (
74-
// 0x30 range - closure state
7578
ADDRESS OpCode = 0x30 + iota
7679
BALANCE
7780
ORIGIN
@@ -89,8 +92,8 @@ const (
8992
RETURNDATACOPY
9093
)
9194

95+
// 0x40 range - block operations.
9296
const (
93-
// 0x40 range - block operations
9497
BLOCKHASH OpCode = 0x40 + iota
9598
COINBASE
9699
TIMESTAMP
@@ -99,8 +102,8 @@ const (
99102
GASLIMIT
100103
)
101104

105+
// 0x50 range - 'storage' and execution.
102106
const (
103-
// 0x50 range - 'storage' and execution
104107
POP OpCode = 0x50 + iota
105108
MLOAD
106109
MSTORE
@@ -115,8 +118,8 @@ const (
115118
JUMPDEST
116119
)
117120

121+
// 0x60 range.
118122
const (
119-
// 0x60 range
120123
PUSH1 OpCode = 0x60 + iota
121124
PUSH2
122125
PUSH3
@@ -183,6 +186,7 @@ const (
183186
SWAP16
184187
)
185188

189+
// 0xa0 range - logging ops.
186190
const (
187191
LOG0 OpCode = 0xa0 + iota
188192
LOG1
@@ -191,15 +195,15 @@ const (
191195
LOG4
192196
)
193197

194-
// unofficial opcodes used for parsing
198+
// unofficial opcodes used for parsing.
195199
const (
196200
PUSH OpCode = 0xb0 + iota
197201
DUP
198202
SWAP
199203
)
200204

205+
// 0xf0 range - closures.
201206
const (
202-
// 0xf0 range - closures
203207
CREATE OpCode = 0xf0 + iota
204208
CALL
205209
CALLCODE
@@ -211,9 +215,9 @@ const (
211215
SELFDESTRUCT = 0xff
212216
)
213217

214-
// Since the opcodes aren't all in order we can't use a regular slice
218+
// Since the opcodes aren't all in order we can't use a regular slice.
215219
var opCodeToString = map[OpCode]string{
216-
// 0x0 range - arithmetic ops
220+
// 0x0 range - arithmetic ops.
217221
STOP: "STOP",
218222
ADD: "ADD",
219223
MUL: "MUL",
@@ -232,7 +236,7 @@ var opCodeToString = map[OpCode]string{
232236
ISZERO: "ISZERO",
233237
SIGNEXTEND: "SIGNEXTEND",
234238

235-
// 0x10 range - bit ops
239+
// 0x10 range - bit ops.
236240
AND: "AND",
237241
OR: "OR",
238242
XOR: "XOR",
@@ -243,10 +247,10 @@ var opCodeToString = map[OpCode]string{
243247
ADDMOD: "ADDMOD",
244248
MULMOD: "MULMOD",
245249

246-
// 0x20 range - crypto
250+
// 0x20 range - crypto.
247251
SHA3: "SHA3",
248252

249-
// 0x30 range - closure state
253+
// 0x30 range - closure state.
250254
ADDRESS: "ADDRESS",
251255
BALANCE: "BALANCE",
252256
ORIGIN: "ORIGIN",
@@ -263,15 +267,15 @@ var opCodeToString = map[OpCode]string{
263267
RETURNDATASIZE: "RETURNDATASIZE",
264268
RETURNDATACOPY: "RETURNDATACOPY",
265269

266-
// 0x40 range - block operations
270+
// 0x40 range - block operations.
267271
BLOCKHASH: "BLOCKHASH",
268272
COINBASE: "COINBASE",
269273
TIMESTAMP: "TIMESTAMP",
270274
NUMBER: "NUMBER",
271275
DIFFICULTY: "DIFFICULTY",
272276
GASLIMIT: "GASLIMIT",
273277

274-
// 0x50 range - 'storage' and execution
278+
// 0x50 range - 'storage' and execution.
275279
POP: "POP",
276280
//DUP: "DUP",
277281
//SWAP: "SWAP",
@@ -287,7 +291,7 @@ var opCodeToString = map[OpCode]string{
287291
GAS: "GAS",
288292
JUMPDEST: "JUMPDEST",
289293

290-
// 0x60 range - push
294+
// 0x60 range - push.
291295
PUSH1: "PUSH1",
292296
PUSH2: "PUSH2",
293297
PUSH3: "PUSH3",
@@ -360,7 +364,7 @@ var opCodeToString = map[OpCode]string{
360364
LOG3: "LOG3",
361365
LOG4: "LOG4",
362366

363-
// 0xf0 range
367+
// 0xf0 range.
364368
CREATE: "CREATE",
365369
CALL: "CALL",
366370
RETURN: "RETURN",
@@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{
524528
"SELFDESTRUCT": SELFDESTRUCT,
525529
}
526530

531+
// StringToOp finds the opcode whose name is stored in `str`.
527532
func StringToOp(str string) OpCode {
528533
return stringToOp[str]
529534
}

core/vm/stack.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"math/big"
2222
)
2323

24-
// stack is an object for basic stack operations. Items popped to the stack are
24+
// Stack is an object for basic stack operations. Items popped to the stack are
2525
// expected to be changed and modified. stack does not take care of adding newly
2626
// initialised objects.
2727
type Stack struct {
@@ -32,6 +32,7 @@ func newstack() *Stack {
3232
return &Stack{data: make([]*big.Int, 0, 1024)}
3333
}
3434

35+
// Data returns the underlying big.Int array.
3536
func (st *Stack) Data() []*big.Int {
3637
return st.data
3738
}
@@ -80,6 +81,7 @@ func (st *Stack) require(n int) error {
8081
return nil
8182
}
8283

84+
// Print dumps the content of the stack
8385
func (st *Stack) Print() {
8486
fmt.Println("### stack ###")
8587
if len(st.data) > 0 {

0 commit comments

Comments
 (0)