@@ -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 ) ;
0 commit comments