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 }