Skip to content

Commit

Permalink
fix(traces): several tracing fixes (#830)
Browse files Browse the repository at this point in the history
* fix(trace): add `extraData`

* fix(trace): fix `StructLogger`'s `CaptureState`
  • Loading branch information
0xmountaintop authored Jul 8, 2024
1 parent 7257721 commit 5e255cf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
stackLen := len(stackData)
// Copy a snapshot of the current storage to a new container
var storage Storage
if !l.cfg.DisableStorage && (op == vm.SLOAD || op == vm.SSTORE) {
var recordStorageDetail bool
if op == vm.SLOAD || op == vm.SSTORE {
// initialise new changed values storage container for this contract
// if not present.
if l.storage[contract.Address()] == nil {
Expand All @@ -232,15 +233,21 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
value = l.env.StateDB.GetState(contract.Address(), address)
)
l.storage[contract.Address()][address] = value
storage = l.storage[contract.Address()].Copy()
recordStorageDetail = true
if !l.cfg.DisableStorage {
storage = l.storage[contract.Address()].Copy()
}
} else if op == vm.SSTORE && stackLen >= 2 {
// capture SSTORE opcodes and record the written entry in the local storage.
var (
value = common.Hash(stackData[stackLen-2].Bytes32())
address = common.Hash(stackData[stackLen-1].Bytes32())
)
l.storage[contract.Address()][address] = value
storage = l.storage[contract.Address()].Copy()
recordStorageDetail = true
if !l.cfg.DisableStorage {
storage = l.storage[contract.Address()].Copy()
}
}
}
var rdata []byte
Expand All @@ -251,7 +258,7 @@ func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, s
// create a new snapshot of the EVM.
structLog := StructLog{pc, op, gas, cost, mem, memory.Len(), stck, rdata, storage, depth, l.env.StateDB.GetRefund(), err, nil}

if !l.cfg.DisableStorage && (op == vm.SLOAD || op == vm.SSTORE) {
if recordStorageDetail {
if err := traceStorage(l, scope, structLog.getOrInitExtraData()); err != nil {
log.Error("Failed to trace data", "opcode", op.String(), "err", err)
}
Expand Down Expand Up @@ -600,6 +607,7 @@ func FormatLogs(logs []StructLog) []types.StructLogRes {
Depth: trace.Depth,
Error: trace.ErrorString(),
RefundCounter: trace.RefundCounter,
ExtraData: trace.ExtraData,
}
if trace.Stack != nil {
stack := make([]string, len(trace.Stack))
Expand Down

0 comments on commit 5e255cf

Please sign in to comment.