Skip to content

Commit

Permalink
Merge pull request #1375 from 0xPolygonHermez/fix-stack-values-and-me…
Browse files Browse the repository at this point in the history
…mory-order

fix: stack values and memory order
  • Loading branch information
MorettiGeorgiev authored Oct 30, 2024
2 parents a4d55d8 + ffff595 commit 620a26e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions eth/tracers/logger/json_stream_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
}
Expand Down

0 comments on commit 620a26e

Please sign in to comment.