Skip to content

Commit 4790c97

Browse files
authored
debug trace alignment: storage encoding (#10117)
* error field type is String not String[] * storage key/value encoding: 0x prefix and zero-padding Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
1 parent e951f90 commit 4790c97

File tree

7 files changed

+108
-84
lines changed

7 files changed

+108
-84
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Upcoming Release
44

5+
### Breaking Changes
6+
- `debug_traceTransaction` and `debug_traceBlockByNumber`: the `error` field in `StructLog` entries is now serialized as a plain string (e.g. `"INVALID_JUMP_DESTINATION"`) instead of an array of strings, aligning with the execution-apis opcode tracer spec. [#10117](https://github.com/besu-eth/besu/pull/10117)
7+
58
### Bug fixes
69
- Upgrade besu-native libraries version to 1.5.0. This fixes the issue of besu-native/secp256r1 exporting OpenSSL
710
symbols in JVM space. [besu-native #308](https://github.com/besu-eth/besu-native/pull/308)

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/StructLog.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,28 @@ public StructLog(final TraceFrame traceFrame) {
6868

6969
private static Map<String, String> formatStorage(final Map<UInt256, UInt256> storage) {
7070
final Map<String, String> formattedStorage = new TreeMap<>();
71-
storage.forEach(
72-
(key, value) -> formattedStorage.put(toCompactHex(key, false), toCompactHex(value, false)));
71+
storage.forEach((key, value) -> formattedStorage.put(toBytes32Hex(key), toBytes32Hex(value)));
7372
return formattedStorage;
7473
}
7574

75+
/**
76+
* Encodes bytes as a 0x-prefixed, zero-padded 32-byte hex string (always 66 chars). Used for
77+
* memory words and storage keys/values per the execution-apis opcode tracer spec.
78+
*/
79+
public static String toBytes32Hex(final Bytes abytes) {
80+
final byte[] raw = abytes.toArrayUnsafe();
81+
final StringBuilder sb = new StringBuilder(66);
82+
sb.append("0x");
83+
for (int i = raw.length; i < 32; i++) {
84+
sb.append("00");
85+
}
86+
for (final byte b : raw) {
87+
sb.append(hexChars[(b >> 4) & 0xF]);
88+
sb.append(hexChars[b & 0xF]);
89+
}
90+
return sb.toString();
91+
}
92+
7693
@JsonGetter("depth")
7794
public int depth() {
7895
return depth;

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/StructLogWithError.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
1616

17+
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
1718
import org.hyperledger.besu.evm.tracing.TraceFrame;
1819

1920
import com.fasterxml.jackson.annotation.JsonGetter;
21+
import com.fasterxml.jackson.annotation.JsonInclude;
2022

2123
public class StructLogWithError extends StructLog {
2224

23-
private final String[] error;
25+
private final String error;
2426

2527
StructLogWithError(final TraceFrame traceFrame) {
2628
super(traceFrame);
27-
error =
28-
traceFrame.getExceptionalHaltReason().map(ehr -> new String[] {ehr.name()}).orElse(null);
29+
error = traceFrame.getExceptionalHaltReason().map(ExceptionalHaltReason::name).orElse(null);
2930
}
3031

3132
@JsonGetter("error")
32-
public String[] getError() {
33+
@JsonInclude(JsonInclude.Include.NON_NULL)
34+
public String getError() {
3335
return error;
3436
}
3537
}

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/StructLogTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public void constructorShouldInitializeFields() throws Exception {
108108
assertThat(structLog.storage())
109109
.isEqualTo(
110110
Map.of(
111-
"1", "2233333",
112-
"2", "4455667"));
111+
"0x0000000000000000000000000000000000000000000000000000000000000001",
112+
"0x0000000000000000000000000000000000000000000000000000000002233333",
113+
"0x0000000000000000000000000000000000000000000000000000000000000002",
114+
"0x0000000000000000000000000000000000000000000000000000000004455667"));
113115
assertThat(structLog.reason()).isEqualTo("0x1");
114116
}
115117

@@ -170,7 +172,7 @@ public void shouldGenerateJsonCorrectly() throws Exception {
170172
+ "\"depth\":1,"
171173
+ "\"stack\":[\"0x0\",\"0x1\",\"0x2\",\"0x3\"],"
172174
+ "\"memory\":[\"0x1\",\"0x2\",\"0x23\",\"0x4\",\"0xe5\",\"0x0\"],"
173-
+ "\"storage\":{\"1\":\"2233333\",\"2\":\"4455667\"},"
175+
+ "\"storage\":{\"0x0000000000000000000000000000000000000000000000000000000000000001\":\"0x0000000000000000000000000000000000000000000000000000000002233333\",\"0x0000000000000000000000000000000000000000000000000000000000000002\":\"0x0000000000000000000000000000000000000000000000000000000004455667\"},"
174176
+ "\"reason\":\"0x53756e696665642066756e6473\""
175177
+ "}";
176178

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/debug/trace-block/debug_traceBlock_default.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"0x1"
7171
],
7272
"storage":{
73-
"1":"1"
73+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"
7474
}
7575
},
7676
{
@@ -83,7 +83,7 @@
8383

8484
],
8585
"storage":{
86-
"1":"1"
86+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"
8787
}
8888
},
8989
{
@@ -96,7 +96,7 @@
9696
"0x60"
9797
],
9898
"storage":{
99-
"1":"1"
99+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"
100100
}
101101
},
102102
{
@@ -109,7 +109,7 @@
109109
"0x2"
110110
],
111111
"storage":{
112-
"1":"1"
112+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"
113113
}
114114
},
115115
{
@@ -123,7 +123,7 @@
123123
"0x40"
124124
],
125125
"storage":{
126-
"1":"1"
126+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001"
127127
}
128128
},
129129
{
@@ -137,8 +137,8 @@
137137
"0x2"
138138
],
139139
"storage":{
140-
"1":"1",
141-
"2":"2"
140+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001",
141+
"0x0000000000000000000000000000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000000000000000000000000000002"
142142
}
143143
},
144144
{
@@ -151,8 +151,8 @@
151151

152152
],
153153
"storage":{
154-
"1":"1",
155-
"2":"2"
154+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001",
155+
"0x0000000000000000000000000000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000000000000000000000000000002"
156156
}
157157
}
158158
]
@@ -217,7 +217,7 @@
217217
"0x1"
218218
],
219219
"storage":{
220-
"1":"3"
220+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
221221
}
222222
},
223223
{
@@ -230,7 +230,7 @@
230230

231231
],
232232
"storage":{
233-
"1":"3"
233+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
234234
}
235235
},
236236
{
@@ -243,7 +243,7 @@
243243
"0x60"
244244
],
245245
"storage":{
246-
"1":"3"
246+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
247247
}
248248
},
249249
{
@@ -256,7 +256,7 @@
256256
"0x4"
257257
],
258258
"storage":{
259-
"1":"3"
259+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
260260
}
261261
},
262262
{
@@ -270,7 +270,7 @@
270270
"0x40"
271271
],
272272
"storage":{
273-
"1":"3"
273+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
274274
}
275275
},
276276
{
@@ -284,8 +284,8 @@
284284
"0x2"
285285
],
286286
"storage":{
287-
"1":"3",
288-
"2":"4"
287+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003",
288+
"0x0000000000000000000000000000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000000000000000000000000000004"
289289
}
290290
},
291291
{
@@ -298,8 +298,8 @@
298298

299299
],
300300
"storage":{
301-
"1":"3",
302-
"2":"4"
301+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003",
302+
"0x0000000000000000000000000000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000000000000000000000000000004"
303303
}
304304
}
305305
]
@@ -364,7 +364,7 @@
364364
"0x1"
365365
],
366366
"storage":{
367-
"1":"3"
367+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
368368
}
369369
},
370370
{
@@ -377,7 +377,7 @@
377377

378378
],
379379
"storage":{
380-
"1":"3"
380+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
381381
}
382382
},
383383
{
@@ -390,7 +390,7 @@
390390
"0x60"
391391
],
392392
"storage":{
393-
"1":"3"
393+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
394394
}
395395
},
396396
{
@@ -403,7 +403,7 @@
403403
"0x0"
404404
],
405405
"storage":{
406-
"1":"3"
406+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
407407
}
408408
},
409409
{
@@ -417,7 +417,7 @@
417417
"0x40"
418418
],
419419
"storage":{
420-
"1":"3"
420+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000003"
421421
}
422422
},
423423
{
@@ -431,7 +431,7 @@
431431
"0x1"
432432
],
433433
"storage":{
434-
"1":"0"
434+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000000"
435435
}
436436
},
437437
{
@@ -444,7 +444,7 @@
444444

445445
],
446446
"storage":{
447-
"1":"0"
447+
"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000000"
448448
}
449449
}
450450
]

0 commit comments

Comments
 (0)