x/evm/types: properly split in 32 chunks trace.Memory (#838)

This change fixes an insidious bug that unfortunately
tried to split values in multiples of 32, but unfortunately
due to the loop conditions, if the length of trace.Memory
was less than 32, nothing would be added; if the value wasn't
a multiple of 32, the ends wouldn't be added in.

Fixes #837
This commit is contained in:
Emmanuel T Odeke
2021-12-15 02:29:49 +00:00
committed by GitHub
parent ccc6f5b53d
commit 66292080e4
2 changed files with 8 additions and 2 deletions
+7 -2
View File
@@ -101,8 +101,13 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes {
if trace.Memory != nil {
memory := make([]string, 0, (len(trace.Memory)+31)/32)
for i := 0; i+32 <= len(trace.Memory); i += 32 {
memory = append(memory, fmt.Sprintf("%x", trace.Memory[i:i+32]))
for i, n := 0, len(trace.Memory); i < n; {
end := i + 32
if end >= n {
end = n
}
memory = append(memory, fmt.Sprintf("%x", trace.Memory[i:end]))
i = end
}
formatted[index].Memory = &memory
}