Skip to content

Commit ebd3ea1

Browse files
lmittmannshekhirin
authored andcommitted
core/vm: minor trivial clean up (ethereum#25880)
* dropped `vm.keccakState` for `crypto.KeccakState` * cleaned up `OpCode.IsPush()`
1 parent 837bec5 commit ebd3ea1

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

core/vm/instructions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"github.com/ethereum/go-ethereum/common"
2323
"github.com/ethereum/go-ethereum/core/types"
24+
"github.com/ethereum/go-ethereum/crypto"
2425
"github.com/ethereum/go-ethereum/params"
2526
"github.com/holiman/uint256"
26-
"golang.org/x/crypto/sha3"
2727
)
2828

2929
func opAdd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
@@ -238,7 +238,7 @@ func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
238238
data := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))
239239

240240
if interpreter.hasher == nil {
241-
interpreter.hasher = sha3.NewLegacyKeccak256().(keccakState)
241+
interpreter.hasher = crypto.NewKeccakState()
242242
} else {
243243
interpreter.hasher.Reset()
244244
}

core/vm/interpreter.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
package vm
1818

1919
import (
20-
"hash"
21-
2220
"github.com/ethereum/go-ethereum/common"
2321
"github.com/ethereum/go-ethereum/common/math"
22+
"github.com/ethereum/go-ethereum/crypto"
2423
"github.com/ethereum/go-ethereum/log"
2524
)
2625

@@ -44,21 +43,13 @@ type ScopeContext struct {
4443
Contract *Contract
4544
}
4645

47-
// keccakState wraps sha3.state. In addition to the usual hash methods, it also supports
48-
// Read to get a variable amount of data from the hash state. Read is faster than Sum
49-
// because it doesn't copy the internal state, but also modifies the internal state.
50-
type keccakState interface {
51-
hash.Hash
52-
Read([]byte) (int, error)
53-
}
54-
5546
// EVMInterpreter represents an EVM interpreter
5647
type EVMInterpreter struct {
5748
evm *EVM
5849
cfg Config
5950

60-
hasher keccakState // Keccak256 hasher instance shared across opcodes
61-
hasherBuf common.Hash // Keccak256 hasher result array shared aross opcodes
51+
hasher crypto.KeccakState // Keccak256 hasher instance shared across opcodes
52+
hasherBuf common.Hash // Keccak256 hasher result array shared aross opcodes
6253

6354
readOnly bool // Whether to throw on stateful modifications
6455
returnData []byte // Last CALL's return data for subsequent reuse

core/vm/opcodes.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ type OpCode byte
2525

2626
// IsPush specifies if an opcode is a PUSH opcode.
2727
func (op OpCode) IsPush() bool {
28-
switch op {
29-
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:
30-
return true
31-
}
32-
return false
28+
return PUSH1 <= op && op <= PUSH32
3329
}
3430

3531
// 0x0 range - arithmetic ops.

0 commit comments

Comments
 (0)