Skip to content

Commit bbad1e9

Browse files
bhobermansjudson
authored andcommitted
Add Fudge Factors to Stack and Heap (#598)
1 parent df3f3dd commit bbad1e9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

vm/src/emulator/memory_stats.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ impl MemoryStats {
9292
// For safety, we just check the stack pointer directly rather than looking for the lowest memory access.
9393
// This ensures we respect the full stack frame that was reserved, even if not all of it is used.
9494
// We could optimize this in the future by tracking actual stack accesses if needed.
95-
self.min_stack_access = min(self.min_stack_access, stack_pointer);
95+
if stack_pointer > 0 {
96+
self.min_stack_access = min(self.min_stack_access, stack_pointer);
97+
}
9698
Ok(())
9799
}
98100

@@ -105,8 +107,8 @@ impl MemoryStats {
105107
output_size: u32,
106108
) -> Result<LinearMemoryLayout> {
107109
LinearMemoryLayout::new(
108-
self.max_heap_access - self.heap_bottom,
109-
self.stack_top - self.min_stack_access,
110+
self.max_heap_access - self.heap_bottom + 0x100,
111+
self.stack_top - self.min_stack_access + 0x100,
110112
input_size,
111113
output_size,
112114
program_size,
@@ -183,9 +185,9 @@ mod tests {
183185
.create_optimized_layout(program_size, ad_size, 0, 0)
184186
.unwrap();
185187

186-
assert_eq!(layout.heap_end(), 5504);
187-
assert_eq!(layout.stack_bottom(), 9600);
188-
assert_eq!(layout.stack_top(), 1006596);
188+
assert_eq!(layout.heap_end(), 5760);
189+
assert_eq!(layout.stack_bottom(), 9856);
190+
assert_eq!(layout.stack_top(), 1007108);
189191
assert_eq!(layout.public_input_end(), 4400);
190192
assert_eq!(layout.ad_end(), 4500);
191193
assert_eq!(layout.public_output_end(), 4504);

vm/src/trace.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ mod tests {
535535
assert!(step
536536
.memory_records
537537
.take(&MemoryRecord::StoreRecord(
538-
(MemAccessSize::Word, 0x80403898, 4128, 0),
538+
(MemAccessSize::Word, 0x3C1C, 4128, 0),
539539
13,
540540
))
541541
.is_some());
@@ -595,7 +595,7 @@ mod tests {
595595
assert!(step
596596
.memory_records
597597
.take(&MemoryRecord::StoreRecord(
598-
(MemAccessSize::Word, 0x80403898, 4128, 0),
598+
(MemAccessSize::Word, 0x3C1C, 4128, 0),
599599
13,
600600
))
601601
.is_some());
@@ -652,10 +652,12 @@ mod tests {
652652
assert_eq!(step.result, None);
653653
assert_eq!(step.memory_records.len(), 1);
654654

655+
println!("{:?}", step.memory_records);
656+
655657
assert!(step
656658
.memory_records
657659
.take(&MemoryRecord::StoreRecord(
658-
(MemAccessSize::Word, 0x80403898, 4128, 0),
660+
(MemAccessSize::Word, 0x3C1C, 4128, 0),
659661
13,
660662
))
661663
.is_some());

0 commit comments

Comments
 (0)