aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm')
-rw-r--r--core/vm/instructions.go7
-rw-r--r--core/vm/interface.go1
-rw-r--r--core/vm/noop.go1
-rw-r--r--core/vm/vm.go2
4 files changed, 10 insertions, 1 deletions
diff --git a/core/vm/instructions.go b/core/vm/instructions.go
index 5bfa73a30..3b1b06cca 100644
--- a/core/vm/instructions.go
+++ b/core/vm/instructions.go
@@ -247,7 +247,12 @@ func opMulmod(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *S
func opSha3(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
offset, size := stack.pop(), stack.pop()
- hash := crypto.Keccak256(memory.Get(offset.Int64(), size.Int64()))
+ data := memory.Get(offset.Int64(), size.Int64())
+ hash := crypto.Keccak256(data)
+
+ if env.vmConfig.EnablePreimageRecording {
+ env.StateDB.AddPreimage(common.BytesToHash(hash), data)
+ }
stack.push(common.BytesToBig(hash))
return nil, nil
diff --git a/core/vm/interface.go b/core/vm/interface.go
index 8617b2d0f..6f15112ee 100644
--- a/core/vm/interface.go
+++ b/core/vm/interface.go
@@ -60,6 +60,7 @@ type StateDB interface {
Snapshot() int
AddLog(*types.Log)
+ AddPreimage(common.Hash, []byte)
}
// Account represents a contract or basic ethereum account.
diff --git a/core/vm/noop.go b/core/vm/noop.go
index ef6837273..7835eeaf3 100644
--- a/core/vm/noop.go
+++ b/core/vm/noop.go
@@ -67,3 +67,4 @@ func (NoopStateDB) Empty(common.Address) bool { return f
func (NoopStateDB) RevertToSnapshot(int) {}
func (NoopStateDB) Snapshot() int { return 0 }
func (NoopStateDB) AddLog(*types.Log) {}
+func (NoopStateDB) AddPreimage(common.Hash, []byte) {}
diff --git a/core/vm/vm.go b/core/vm/vm.go
index 56081f12c..a5f48750d 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -44,6 +44,8 @@ type Config struct {
NoRecursion bool
// Disable gas metering
DisableGasMetering bool
+ // Enable recording of SHA3/keccak preimages
+ EnablePreimageRecording bool
// JumpTable contains the EVM instruction table. This
// may me left uninitialised and will be set the default
// table.