diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-10-08 19:14:29 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-10-08 19:14:29 +0800 |
commit | 1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b (patch) | |
tree | 00ce13af5e001692be11412e2e8e372bd9c0bbc5 /core/vm/instructions.go | |
parent | c5cb214f689e5c34bf487daa8eb4234d6e3237a7 (diff) | |
download | dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar.gz dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar.bz2 dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar.lz dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar.xz dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.tar.zst dexon-1d3d4a4d578825b040a3cac9eb163e7f3c16ce4b.zip |
core/vm: reuse Keccak-256 hashes across opcode executions (#17863)
Diffstat (limited to 'core/vm/instructions.go')
-rw-r--r-- | core/vm/instructions.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 9623fb8de..e94a2777b 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -24,7 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/params" ) @@ -373,13 +373,20 @@ func opSAR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory * func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { offset, size := stack.pop(), stack.pop() data := memory.Get(offset.Int64(), size.Int64()) - hash := crypto.Keccak256(data) - evm := interpreter.evm + if interpreter.hasher == nil { + interpreter.hasher = sha3.NewKeccak256().(keccakState) + } else { + interpreter.hasher.Reset() + } + interpreter.hasher.Write(data) + interpreter.hasher.Read(interpreter.hasherBuf[:]) + + evm := interpreter.evm if evm.vmConfig.EnablePreimageRecording { - evm.StateDB.AddPreimage(common.BytesToHash(hash), data) + evm.StateDB.AddPreimage(interpreter.hasherBuf, data) } - stack.push(interpreter.intPool.get().SetBytes(hash)) + stack.push(interpreter.intPool.get().SetBytes(interpreter.hasherBuf[:])) interpreter.intPool.put(offset, size) return nil, nil |