From b55693cd6088ea863f3c926b1b8dba8a61cc0204 Mon Sep 17 00:00:00 2001 From: Moreti Georgiev Date: Tue, 29 Oct 2024 16:28:54 +0200 Subject: [PATCH] fix: return stack values as hex and reverse memory order --- eth/tracers/logger/json_stream_zkevm.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/eth/tracers/logger/json_stream_zkevm.go b/eth/tracers/logger/json_stream_zkevm.go index 3498bd41a5a..98188edc39d 100644 --- a/eth/tracers/logger/json_stream_zkevm.go +++ b/eth/tracers/logger/json_stream_zkevm.go @@ -201,6 +201,7 @@ func (l *JsonStreamLogger_ZkEvm) writeStorage(contract *vm.Contract) { } l.stream.WriteObjectEnd() } + func (l *JsonStreamLogger_ZkEvm) writeMemory(memory *vm.Memory) { if !l.cfg.DisableMemory { memData := memory.Data() @@ -217,11 +218,11 @@ func (l *JsonStreamLogger_ZkEvm) writeMemory(memory *vm.Memory) { l.stream.WriteMore() l.stream.WriteObjectField("memory") l.stream.WriteArrayStart() - for i := len(memData); i-32 >= 0; i -= 32 { - if i != len(memData) { // first 32 bytes, don't add a comma + for i := 0; i+32 <= len(memData); i += 32 { + if i != 0 { // add a comma for all but the first 32 bytes l.stream.WriteMore() } - l.stream.WriteString(string(l.hexEncodeBuf[0:hex.Encode(l.hexEncodeBuf[:], memData[i-32:i])])) + l.stream.WriteString(string(l.hexEncodeBuf[0:hex.Encode(l.hexEncodeBuf[:], memData[i:i+32])])) } l.stream.WriteArrayEnd() @@ -245,7 +246,7 @@ func (l *JsonStreamLogger_ZkEvm) writeStack(stack *stack.Stack) { if i > 0 { l.stream.WriteMore() } - l.stream.WriteString(stackValue.String()) + l.stream.WriteString(stackValue.Hex()) } l.stream.WriteArrayEnd() }