mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
fixes storage tracer
This commit is contained in:
parent
67c38b0275
commit
9efef3829f
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
json, strutils, sets,
|
json, strutils, sets, hashes,
|
||||||
chronicles, nimcrypto, eth/common, stint,
|
chronicles, nimcrypto, eth/common, stint,
|
||||||
../vm_types, memory, stack, ../db/[db_chain, state_db],
|
../vm_types, memory, stack, ../db/[db_chain, state_db],
|
||||||
eth/trie/hexary, ./message, ranges/typedranges,
|
eth/trie/hexary, ./message, ranges/typedranges,
|
||||||
@ -8,6 +8,9 @@ import
|
|||||||
logScope:
|
logScope:
|
||||||
topics = "vm opcode"
|
topics = "vm opcode"
|
||||||
|
|
||||||
|
proc hash*(x: Uint256): Hash =
|
||||||
|
result = hash(x.toByteArrayBE)
|
||||||
|
|
||||||
proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
|
proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
|
||||||
tracer.trace = newJObject()
|
tracer.trace = newJObject()
|
||||||
|
|
||||||
@ -19,6 +22,7 @@ proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
|
|||||||
tracer.trace["structLogs"] = newJArray()
|
tracer.trace["structLogs"] = newJArray()
|
||||||
tracer.flags = flags
|
tracer.flags = flags
|
||||||
tracer.accounts = initSet[EthAddress]()
|
tracer.accounts = initSet[EthAddress]()
|
||||||
|
tracer.storageKeys = initSet[Uint256]()
|
||||||
|
|
||||||
proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
|
proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
|
||||||
if unlikely tracer.trace.isNil:
|
if unlikely tracer.trace.isNil:
|
||||||
@ -60,6 +64,11 @@ proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op:
|
|||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
if TracerFlags.DisableStorage notin tracer.flags:
|
||||||
|
if op == Sstore:
|
||||||
|
assert(c.stack.values.len > 1)
|
||||||
|
tracer.storageKeys.incl c.stack[^1, Uint256]
|
||||||
|
|
||||||
proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
|
proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation, op: Op) =
|
||||||
let j = tracer.trace["structLogs"].elems[^1]
|
let j = tracer.trace["structLogs"].elems[^1]
|
||||||
|
|
||||||
@ -68,7 +77,8 @@ proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation, op: Op
|
|||||||
if TracerFlags.DisableStorage notin tracer.flags:
|
if TracerFlags.DisableStorage notin tracer.flags:
|
||||||
var storage = newJObject()
|
var storage = newJObject()
|
||||||
var stateDB = c.vmState.accountDb
|
var stateDB = c.vmState.accountDb
|
||||||
for key, value in stateDB.storage(c.msg.storageAddress):
|
for key in tracer.storageKeys:
|
||||||
|
let (value, _) = stateDB.getStorage(c.msg.storageAddress, key)
|
||||||
storage[key.dumpHex] = %(value.dumpHex)
|
storage[key.dumpHex] = %(value.dumpHex)
|
||||||
j["storage"] = storage
|
j["storage"] = storage
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ type
|
|||||||
gasRemaining*: GasInt
|
gasRemaining*: GasInt
|
||||||
flags*: set[TracerFlags]
|
flags*: set[TracerFlags]
|
||||||
accounts*: HashSet[EthAddress]
|
accounts*: HashSet[EthAddress]
|
||||||
|
storageKeys*: HashSet[Uint256]
|
||||||
|
|
||||||
OpcodeExecutor* = proc(computation: var BaseComputation)
|
OpcodeExecutor* = proc(computation: var BaseComputation)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user