Skip to content

Commit b4d9ce1

Browse files
committed
tracers
1 parent 478d678 commit b4d9ce1

28 files changed

+214
-106
lines changed

src/Nethermind/Nethermind.State/StorageValue.cs renamed to src/Nethermind/Nethermind.Core/StorageValue.cs

+24-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Nethermind.Core.Extensions;
1010
using Nethermind.Int256;
1111

12-
namespace Nethermind.State;
12+
namespace Nethermind.Core;
1313

1414
/// <summary>
1515
/// Represents a storage value.
@@ -125,9 +125,31 @@ ref Unsafe.Add(ref Unsafe.As<Vector256<byte>, byte>(ref Unsafe.AsRef(in _bytes))
125125
public bool IsZero => _bytes == Vector256<byte>.Zero;
126126

127127
[MethodImpl(MethodImplOptions.AggressiveInlining)]
128-
public string ToHexString(bool withZeroX) => Bytes.WithoutLeadingZeros().ToHexString(withZeroX);
128+
public string ToHexString(bool withZeroX) => BytesWithNoLeadingZeroes.ToHexString(withZeroX);
129129

130130
public override string ToString() => ToHexString(false);
131131

132132
public byte[] ToArray() => BytesWithNoLeadingZeroes.ToArray();
133+
134+
public static StorageValue FromHexString(ReadOnlySpan<byte> hex)
135+
{
136+
const int maxChars = MemorySize * 2;
137+
138+
StorageValue result = default;
139+
140+
if (hex.Length < maxChars)
141+
{
142+
Span<byte> hex32 = stackalloc byte[maxChars];
143+
hex32.Fill((byte)'0');
144+
hex.CopyTo(hex32[(64 - hex.Length)..]);
145+
146+
Nethermind.Core.Extensions.Bytes.FromUtf8HexString(hex32, result.BytesAsSpan);
147+
}
148+
else
149+
{
150+
Nethermind.Core.Extensions.Bytes.FromUtf8HexString(hex, result.BytesAsSpan);
151+
}
152+
153+
return result;
154+
}
133155
}

src/Nethermind/Nethermind.Evm.Test/EvmPooledMemoryTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@ public void ReportMemoryChange(long offset, in ReadOnlySpan<byte> data)
275275
{
276276
}
277277

278-
public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte> value)
278+
public void ReportStorageChange(in ReadOnlySpan<byte> key, in StorageValue value)
279279
{
280280
}
281281

282-
public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> newValue, ReadOnlySpan<byte> currentValue)
282+
public void SetOperationStorage(Address address, UInt256 storageIndex, in StorageValue newValue, in StorageValue currentValue)
283283
{
284284
}
285285

286-
public void LoadOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> value)
286+
public void LoadOperationStorage(Address address, UInt256 storageIndex, in StorageValue value)
287287
{
288288
}
289289

@@ -312,7 +312,7 @@ public void ReportAccountRead(Address address)
312312
throw new NotImplementedException();
313313
}
314314

315-
public void ReportStorageChange(in StorageCell storageAddress, byte[] before, byte[] after)
315+
public void ReportStorageChange(in StorageCell storageAddress, in StorageValue before, in StorageValue after)
316316
{
317317
throw new NotSupportedException();
318318
}

src/Nethermind/Nethermind.Evm.Test/Tracing/ParityLikeTxTracerTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,10 @@ public void Can_trace_storage_changes()
687687
Assert.That(trace.StateChanges.ContainsKey(Recipient), Is.True, "recipient");
688688
Assert.That(trace.StateChanges.ContainsKey(TestItem.AddressC), Is.True, "address c");
689689
Assert.That(trace.StateChanges[Recipient].Storage.Count, Is.EqualTo(2), "recipient storage count");
690-
Assert.That(trace.StateChanges[Recipient].Storage[2].Before, Is.EqualTo(new byte[] { 0 }), "recipient storage[2]");
691-
Assert.That(trace.StateChanges[Recipient].Storage[2].After, Is.EqualTo(Bytes.FromHexString(SampleHexData1)), "recipient storage[2] after");
692-
Assert.That(trace.StateChanges[Recipient].Storage[3].Before, Is.EqualTo(new byte[] { 0 }), "recipient storage[3]");
693-
Assert.That(trace.StateChanges[Recipient].Storage[3].After, Is.EqualTo(Bytes.FromHexString(SampleHexData2)), "recipient storage[3] after");
690+
Assert.That(trace.StateChanges[Recipient].Storage[2].Before.ToArray(), Is.EqualTo(new byte[] { 0 }), "recipient storage[2]");
691+
Assert.That(trace.StateChanges[Recipient].Storage[2].After.ToArray(), Is.EqualTo(Bytes.FromHexString(SampleHexData1)), "recipient storage[2] after");
692+
Assert.That(trace.StateChanges[Recipient].Storage[3].Before.ToArray(), Is.EqualTo(new byte[] { 0 }), "recipient storage[3]");
693+
Assert.That(trace.StateChanges[Recipient].Storage[3].After.ToArray(), Is.EqualTo(Bytes.FromHexString(SampleHexData2)), "recipient storage[3] after");
694694
}
695695

696696
[Test]

src/Nethermind/Nethermind.Evm/Tracing/AlwaysCancelTxTracer.cs

+49-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Nethermind.Core.Crypto;
99
using Nethermind.Evm.TransactionProcessing;
1010
using Nethermind.Int256;
11+
using Nethermind.State;
1112

1213
namespace Nethermind.Evm.Tracing;
1314

@@ -44,11 +45,14 @@ public static AlwaysCancelTxTracer Instance
4445
public bool IsTracingFees => true;
4546
public bool IsTracingLogs => true;
4647

47-
public void MarkAsSuccess(Address recipient, GasConsumed gasSpent, byte[] output, LogEntry[] logs, Hash256? stateRoot = null) => throw new OperationCanceledException(ErrorMessage);
48+
public void MarkAsSuccess(Address recipient, GasConsumed gasSpent, byte[] output, LogEntry[] logs,
49+
Hash256? stateRoot = null) => throw new OperationCanceledException(ErrorMessage);
4850

49-
public void MarkAsFailed(Address recipient, GasConsumed gasSpent, byte[] output, string? error, Hash256? stateRoot = null) => throw new OperationCanceledException(ErrorMessage);
51+
public void MarkAsFailed(Address recipient, GasConsumed gasSpent, byte[] output, string? error,
52+
Hash256? stateRoot = null) => throw new OperationCanceledException(ErrorMessage);
5053

51-
public void StartOperation(int pc, Instruction opcode, long gas, in ExecutionEnvironment env) => throw new OperationCanceledException(ErrorMessage);
54+
public void StartOperation(int pc, Instruction opcode, long gas, in ExecutionEnvironment env) =>
55+
throw new OperationCanceledException(ErrorMessage);
5256

5357
public void ReportOperationError(EvmExceptionType error) => throw new OperationCanceledException(ErrorMessage);
5458

@@ -58,47 +62,73 @@ public static AlwaysCancelTxTracer Instance
5862

5963
public void SetOperationMemorySize(ulong newSize) => throw new OperationCanceledException(ErrorMessage);
6064

61-
public void ReportMemoryChange(long offset, in ReadOnlySpan<byte> data) => throw new OperationCanceledException(ErrorMessage);
62-
public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte> value) => throw new OperationCanceledException(ErrorMessage);
65+
public void ReportMemoryChange(long offset, in ReadOnlySpan<byte> data) =>
66+
throw new OperationCanceledException(ErrorMessage);
67+
68+
public void ReportStorageChange(in ReadOnlySpan<byte> key, in StorageValue value) =>
69+
throw new OperationCanceledException(ErrorMessage);
6370

6471
public void SetOperationStack(TraceStack stack) => throw new OperationCanceledException(ErrorMessage);
6572

6673
public void ReportStackPush(in ReadOnlySpan<byte> stackItem) => throw new OperationCanceledException(ErrorMessage);
6774

6875
public void SetOperationMemory(TraceMemory memoryTrace) => throw new OperationCanceledException(ErrorMessage);
6976

70-
public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> newValue, ReadOnlySpan<byte> currentValue) => throw new OperationCanceledException(ErrorMessage);
77+
public void SetOperationStorage(Address address, UInt256 storageIndex, in StorageValue newValue,
78+
in StorageValue currentValue) => throw new OperationCanceledException(ErrorMessage);
7179

72-
public void LoadOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> value) => throw new OperationCanceledException(ErrorMessage);
80+
public void LoadOperationStorage(Address address, UInt256 storageIndex, in StorageValue value) =>
81+
throw new OperationCanceledException(ErrorMessage);
7382

74-
public void ReportSelfDestruct(Address address, UInt256 balance, Address refundAddress) => throw new OperationCanceledException(ErrorMessage);
83+
public void ReportSelfDestruct(Address address, UInt256 balance, Address refundAddress) =>
84+
throw new OperationCanceledException(ErrorMessage);
7585

76-
public void ReportBalanceChange(Address address, UInt256? before, UInt256? after) => throw new OperationCanceledException(ErrorMessage);
86+
public void ReportBalanceChange(Address address, UInt256? before, UInt256? after) =>
87+
throw new OperationCanceledException(ErrorMessage);
7788

78-
public void ReportCodeChange(Address address, byte[] before, byte[] after) => throw new OperationCanceledException(ErrorMessage);
89+
public void ReportCodeChange(Address address, byte[] before, byte[] after) =>
90+
throw new OperationCanceledException(ErrorMessage);
7991

80-
public void ReportNonceChange(Address address, UInt256? before, UInt256? after) => throw new OperationCanceledException(ErrorMessage);
92+
public void ReportNonceChange(Address address, UInt256? before, UInt256? after) =>
93+
throw new OperationCanceledException(ErrorMessage);
8194

8295
public void ReportAccountRead(Address address) => throw new OperationCanceledException(ErrorMessage);
8396

84-
public void ReportStorageChange(in StorageCell storageCell, byte[] before, byte[] after) => throw new OperationCanceledException(ErrorMessage);
97+
public void ReportStorageChange(in StorageCell storageCell, in StorageValue before, in StorageValue after) =>
98+
throw new OperationCanceledException(ErrorMessage);
8599

86100
public void ReportStorageRead(in StorageCell storageCell) => throw new OperationCanceledException(ErrorMessage);
87101

88-
public void ReportAction(long gas, UInt256 value, Address from, Address to, ReadOnlyMemory<byte> input, ExecutionType callType, bool isPrecompileCall = false) => throw new OperationCanceledException(ErrorMessage);
102+
public void ReportAction(long gas, UInt256 value, Address from, Address to, ReadOnlyMemory<byte> input,
103+
ExecutionType callType, bool isPrecompileCall = false) => throw new OperationCanceledException(ErrorMessage);
104+
105+
public void ReportActionEnd(long gas, ReadOnlyMemory<byte> output) =>
106+
throw new OperationCanceledException(ErrorMessage);
89107

90-
public void ReportActionEnd(long gas, ReadOnlyMemory<byte> output) => throw new OperationCanceledException(ErrorMessage);
91108
public void ReportActionError(EvmExceptionType exceptionType) => throw new OperationCanceledException(ErrorMessage);
92-
public void ReportActionRevert(long gas, ReadOnlyMemory<byte> output) => throw new OperationCanceledException(ErrorMessage);
93109

94-
public void ReportActionEnd(long gas, Address deploymentAddress, ReadOnlyMemory<byte> deployedCode) => throw new OperationCanceledException(ErrorMessage);
110+
public void ReportActionRevert(long gas, ReadOnlyMemory<byte> output) =>
111+
throw new OperationCanceledException(ErrorMessage);
112+
113+
public void ReportActionEnd(long gas, Address deploymentAddress, ReadOnlyMemory<byte> deployedCode) =>
114+
throw new OperationCanceledException(ErrorMessage);
115+
95116
public void ReportBlockHash(Hash256 blockHash) => throw new OperationCanceledException(ErrorMessage);
96117

97118
public void ReportByteCode(ReadOnlyMemory<byte> byteCode) => throw new OperationCanceledException(ErrorMessage);
98-
public void ReportGasUpdateForVmTrace(long refund, long gasAvailable) => throw new OperationCanceledException(ErrorMessage);
119+
120+
public void ReportGasUpdateForVmTrace(long refund, long gasAvailable) =>
121+
throw new OperationCanceledException(ErrorMessage);
122+
99123
public void ReportRefund(long refund) => throw new OperationCanceledException(ErrorMessage);
100124
public void ReportExtraGasPressure(long extraGasPressure) => throw new OperationCanceledException(ErrorMessage);
101-
public void ReportAccess(IReadOnlySet<Address> accessedAddresses, IReadOnlySet<StorageCell> accessedStorageCells) => throw new OperationCanceledException(ErrorMessage);
125+
126+
public void ReportAccess(IReadOnlySet<Address> accessedAddresses, IReadOnlySet<StorageCell> accessedStorageCells) =>
127+
throw new OperationCanceledException(ErrorMessage);
128+
102129
public void ReportFees(UInt256 fees, UInt256 burntFees) => throw new OperationCanceledException(ErrorMessage);
103-
public void Dispose() { }
130+
131+
public void Dispose()
132+
{
133+
}
104134
}

src/Nethermind/Nethermind.Evm/Tracing/BlockReceiptsTracer.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Nethermind.Core.Crypto;
99
using Nethermind.Evm.TransactionProcessing;
1010
using Nethermind.Int256;
11+
using Nethermind.State;
1112

1213
namespace Nethermind.Evm.Tracing;
1314

@@ -115,13 +116,13 @@ public void SetOperationMemorySize(ulong newSize) =>
115116
public void ReportMemoryChange(long offset, in ReadOnlySpan<byte> data) =>
116117
_currentTxTracer.ReportMemoryChange(offset, data);
117118

118-
public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte> value) =>
119+
public void ReportStorageChange(in ReadOnlySpan<byte> key, in StorageValue value) =>
119120
_currentTxTracer.ReportStorageChange(key, value);
120121

121-
public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> newValue, ReadOnlySpan<byte> currentValue) =>
122+
public void SetOperationStorage(Address address, UInt256 storageIndex, in StorageValue newValue, in StorageValue currentValue) =>
122123
_currentTxTracer.SetOperationStorage(address, storageIndex, newValue, currentValue);
123124

124-
public void LoadOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> value) =>
125+
public void LoadOperationStorage(Address address, UInt256 storageIndex, in StorageValue value) =>
125126
_currentTxTracer.LoadOperationStorage(address, storageIndex, value);
126127

127128
public void ReportSelfDestruct(Address address, UInt256 balance, Address refundAddress) =>
@@ -139,7 +140,7 @@ public void ReportNonceChange(Address address, UInt256? before, UInt256? after)
139140
public void ReportAccountRead(Address address) =>
140141
_currentTxTracer.ReportAccountRead(address);
141142

142-
public void ReportStorageChange(in StorageCell storageCell, byte[] before, byte[] after) =>
143+
public void ReportStorageChange(in StorageCell storageCell, in StorageValue before, in StorageValue after) =>
143144
_currentTxTracer.ReportStorageChange(storageCell, before, after);
144145

145146
public void ReportStorageRead(in StorageCell storageCell) =>

src/Nethermind/Nethermind.Evm/Tracing/CancellationTxTracer.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Nethermind.Core.Crypto;
99
using Nethermind.Evm.TransactionProcessing;
1010
using Nethermind.Int256;
11+
using Nethermind.State;
1112

1213
namespace Nethermind.Evm.Tracing;
1314

@@ -154,7 +155,7 @@ public void ReportAccountRead(Address address)
154155
}
155156
}
156157

157-
public void ReportStorageChange(in StorageCell storageCell, byte[] before, byte[] after)
158+
public void ReportStorageChange(in StorageCell storageCell, in StorageValue before, in StorageValue after)
158159
{
159160
token.ThrowIfCancellationRequested();
160161
if (innerTracer.IsTracingStorage)
@@ -307,7 +308,7 @@ public void ReportMemoryChange(UInt256 offset, byte data)
307308
}
308309
}
309310

310-
public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte> value)
311+
public void ReportStorageChange(in ReadOnlySpan<byte> key, in StorageValue value)
311312
{
312313
token.ThrowIfCancellationRequested();
313314
if (innerTracer.IsTracingInstructions)
@@ -316,7 +317,7 @@ public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte>
316317
}
317318
}
318319

319-
public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> newValue, ReadOnlySpan<byte> currentValue)
320+
public void SetOperationStorage(Address address, UInt256 storageIndex, in StorageValue newValue, in StorageValue currentValue)
320321
{
321322
token.ThrowIfCancellationRequested();
322323
if (innerTracer.IsTracingOpLevelStorage)
@@ -325,7 +326,7 @@ public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlyS
325326
}
326327
}
327328

328-
public void LoadOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> value)
329+
public void LoadOperationStorage(Address address, UInt256 storageIndex, in StorageValue value)
329330
{
330331
token.ThrowIfCancellationRequested();
331332
if (innerTracer.IsTracingOpLevelStorage)

src/Nethermind/Nethermind.Evm/Tracing/CompositeTxTracer.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void ReportAccountRead(Address address)
103103
}
104104
}
105105

106-
public void ReportStorageChange(in StorageCell storageCell, byte[] before, byte[] after)
106+
public void ReportStorageChange(in StorageCell storageCell, in StorageValue before, in StorageValue after)
107107
{
108108
for (int index = 0; index < _txTracers.Count; index++)
109109
{
@@ -127,7 +127,8 @@ public void ReportStorageRead(in StorageCell storageCell)
127127
}
128128
}
129129

130-
public void MarkAsSuccess(Address recipient, GasConsumed gasSpent, byte[] output, LogEntry[] logs, Hash256? stateRoot = null)
130+
public void MarkAsSuccess(Address recipient, GasConsumed gasSpent, byte[] output, LogEntry[] logs,
131+
Hash256? stateRoot = null)
131132
{
132133
for (int index = 0; index < _txTracers.Count; index++)
133134
{
@@ -139,7 +140,8 @@ public void MarkAsSuccess(Address recipient, GasConsumed gasSpent, byte[] output
139140
}
140141
}
141142

142-
public void MarkAsFailed(Address recipient, GasConsumed gasSpent, byte[] output, string? error, Hash256? stateRoot = null)
143+
public void MarkAsFailed(Address recipient, GasConsumed gasSpent, byte[] output, string? error,
144+
Hash256? stateRoot = null)
143145
{
144146
for (int index = 0; index < _txTracers.Count; index++)
145147
{
@@ -319,7 +321,7 @@ public void ReportMemoryChange(UInt256 offset, byte data)
319321
}
320322
}
321323

322-
public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte> value)
324+
public void ReportStorageChange(in ReadOnlySpan<byte> key, in StorageValue value)
323325
{
324326
for (int index = 0; index < _txTracers.Count; index++)
325327
{
@@ -331,7 +333,8 @@ public void ReportStorageChange(in ReadOnlySpan<byte> key, in ReadOnlySpan<byte>
331333
}
332334
}
333335

334-
public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> newValue, ReadOnlySpan<byte> currentValue)
336+
public void SetOperationStorage(Address address, UInt256 storageIndex, in StorageValue newValue,
337+
in StorageValue currentValue)
335338
{
336339
for (int index = 0; index < _txTracers.Count; index++)
337340
{
@@ -343,7 +346,7 @@ public void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlyS
343346
}
344347
}
345348

346-
public void LoadOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan<byte> value)
349+
public void LoadOperationStorage(Address address, UInt256 storageIndex, in StorageValue value)
347350
{
348351
for (int index = 0; index < _txTracers.Count; index++)
349352
{
@@ -367,7 +370,8 @@ public void ReportSelfDestruct(Address address, UInt256 balance, Address refundA
367370
}
368371
}
369372

370-
public void ReportAction(long gas, UInt256 value, Address from, Address to, ReadOnlyMemory<byte> input, ExecutionType callType, bool isPrecompileCall = false)
373+
public void ReportAction(long gas, UInt256 value, Address from, Address to, ReadOnlyMemory<byte> input,
374+
ExecutionType callType, bool isPrecompileCall = false)
371375
{
372376
for (int index = 0; index < _txTracers.Count; index++)
373377
{

0 commit comments

Comments
 (0)