From 368d1da9606334be3175fec6196445b49d51ceed Mon Sep 17 00:00:00 2001 From: SharovBot Date: Wed, 22 Apr 2026 16:47:28 +0200 Subject: [PATCH] fix: add 0x prefix to structLog storage keys and values debug_traceBlockByNumber and debug_traceCall were returning storage keys/values in structLogs without the 0x prefix, e.g.: "2fa8c5322c...": "0000..." go-ethereum returns them with the 0x prefix: "0x2fa8c5322c...": "0x0000..." This caused two RPC integration test failures on release/3.4 (debug_traceBlockByNumber/test_42 and debug_traceCall/test_43) across all commits. Fix the three code paths that format storage in structLogs: - execution/tracing/tracers/logger/json_stream.go (streaming path used by debug_traceCall and debug_traceBlockByNumber) - execution/tracing/tracers/logger/logger.go (StructLogger format path) - rpc/ethapi/api.go (ethapi format path) Co-authored-by: Giulio Rebuffo --- execution/tracing/tracers/logger/json_stream.go | 9 +++++++-- execution/tracing/tracers/logger/logger.go | 3 ++- rpc/ethapi/api.go | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/execution/tracing/tracers/logger/json_stream.go b/execution/tracing/tracers/logger/json_stream.go index 93cbf4061a4..9725d01413c 100644 --- a/execution/tracing/tracers/logger/json_stream.go +++ b/execution/tracing/tracers/logger/json_stream.go @@ -214,8 +214,13 @@ func (l *JsonStreamLogger) OnOpcode(pc uint64, typ byte, gas, cost uint64, scope } else { l.stream.WriteMore() } - l.stream.WriteObjectField(string(l.hexEncodeBuf[0:hex.Encode(l.hexEncodeBuf[:], loc[:])])) - l.stream.WriteString(string(l.hexEncodeBuf[0:hex.Encode(l.hexEncodeBuf[:], value[:])])) + // Storage keys and values must be 0x-prefixed to match go-ethereum output. + n := hex.Encode(l.hexEncodeBuf[2:], loc[:]) + l.hexEncodeBuf[0], l.hexEncodeBuf[1] = '0', 'x' + l.stream.WriteObjectField(string(l.hexEncodeBuf[0 : 2+n])) + n = hex.Encode(l.hexEncodeBuf[2:], value[:]) + l.hexEncodeBuf[0], l.hexEncodeBuf[1] = '0', 'x' + l.stream.WriteString(string(l.hexEncodeBuf[0 : 2+n])) } l.stream.WriteObjectEnd() } diff --git a/execution/tracing/tracers/logger/logger.go b/execution/tracing/tracers/logger/logger.go index 894bb545e53..013f440ce4a 100644 --- a/execution/tracing/tracers/logger/logger.go +++ b/execution/tracing/tracers/logger/logger.go @@ -322,7 +322,8 @@ func FormatLogs(logs []StructLog) []StructLogRes { if trace.Storage != nil { storage := make(map[string]string) for i, storageValue := range trace.Storage { - storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue) + // Use 0x-prefixed hex to match go-ethereum output + storage[fmt.Sprintf("0x%x", i)] = fmt.Sprintf("0x%x", storageValue) } formatted[index].Storage = &storage } diff --git a/rpc/ethapi/api.go b/rpc/ethapi/api.go index bfc5ca54727..310d564d8c9 100644 --- a/rpc/ethapi/api.go +++ b/rpc/ethapi/api.go @@ -415,7 +415,8 @@ func FormatLogs(logs []logger.StructLog) []StructLogRes { if trace.Storage != nil { storage := make(map[string]string) for i, storageValue := range trace.Storage { - storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue) + // Use 0x-prefixed hex to match go-ethereum output + storage[fmt.Sprintf("0x%x", i)] = fmt.Sprintf("0x%x", storageValue) } formatted[index].Storage = &storage }