diff --git a/CHANGELOG.md b/CHANGELOG.md index 812d4ad65..f5116f935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ - Fixed an issue with formatting of blocks in Miden Assembly syntax - Fixed the construction of the block hash table (#1506) -- Fixed a bug in the block stack table (#1511) (#1512) +- Fixed a bug in the block stack table (#1511) (#1512) (#1557) - Fixed the construction of the chiplets virtual table (#1514) (#1556) - Fixed the construction of the chiplets bus (#1516) (#1525) - Decorators are now allowed in empty basic blocks (#1466) diff --git a/processor/src/decoder/aux_trace/block_stack_table.rs b/processor/src/decoder/aux_trace/block_stack_table.rs index e3e526018..580095019 100644 --- a/processor/src/decoder/aux_trace/block_stack_table.rs +++ b/processor/src/decoder/aux_trace/block_stack_table.rs @@ -21,10 +21,8 @@ impl> AuxColumnBuilder for BlockStackColumn let op_code = op_code_felt.as_int() as u8; match op_code { - OPCODE_RESPAN => { - get_block_stack_table_removal_multiplicand(main_trace, i, true, alphas) - }, - OPCODE_END => get_block_stack_table_removal_multiplicand(main_trace, i, false, alphas), + OPCODE_RESPAN => get_block_stack_table_respan_multiplicand(main_trace, i, alphas), + OPCODE_END => get_block_stack_table_end_multiplicand(main_trace, i, alphas), _ => E::ONE, } } @@ -48,18 +46,33 @@ impl> AuxColumnBuilder for BlockStackColumn // ================================================================================================ /// Computes the multiplicand representing the removal of a row from the block stack table. -fn get_block_stack_table_removal_multiplicand>( +fn get_block_stack_table_respan_multiplicand>( main_trace: &MainTrace, i: RowIndex, - is_respan: bool, alphas: &[E], ) -> E { let block_id = main_trace.addr(i); - let (parent_id, is_loop) = if is_respan { - (main_trace.decoder_hasher_state_element(1, i + 1), ZERO) - } else { - (main_trace.addr(i + 1), main_trace.is_loop_flag(i)) - }; + let parent_id = main_trace.decoder_hasher_state_element(1, i + 1); + let is_loop = ZERO; + + // Note: the last 8 elements are set to ZERO, so we omit them here. + let elements = [ONE, block_id, parent_id, is_loop]; + + let mut table_row = E::ZERO; + for (&alpha, &element) in alphas.iter().zip(elements.iter()) { + table_row += alpha.mul_base(element); + } + table_row +} + +fn get_block_stack_table_end_multiplicand>( + main_trace: &MainTrace, + i: RowIndex, + alphas: &[E], +) -> E { + let block_id = main_trace.addr(i); + let parent_id = main_trace.addr(i + 1); + let is_loop = main_trace.is_loop_flag(i); let elements = if main_trace.is_call_flag(i) == ONE || main_trace.is_syscall_flag(i) == ONE { let parent_ctx = main_trace.ctx(i + 1); @@ -91,12 +104,11 @@ fn get_block_stack_table_removal_multiplicand> result }; - let mut value = E::ZERO; - + let mut table_row = E::ZERO; for (&alpha, &element) in alphas.iter().zip(elements.iter()) { - value += alpha.mul_base(element); + table_row += alpha.mul_base(element); } - value + table_row } /// Computes the multiplicand representing the inclusion of a new row to the block stack table. diff --git a/processor/src/decoder/aux_trace/mod.rs b/processor/src/decoder/aux_trace/mod.rs index c451c8371..3ee1a8e8b 100644 --- a/processor/src/decoder/aux_trace/mod.rs +++ b/processor/src/decoder/aux_trace/mod.rs @@ -41,6 +41,11 @@ impl AuxTraceBuilder { let p2 = block_hash_column_builder.build_aux_column(main_trace, rand_elements); let p3 = op_group_table_column_builder.build_aux_column(main_trace, rand_elements); + debug_assert_eq!( + *p1.last().unwrap(), + E::ONE, + "block stack table is not empty at the end of program execution" + ); debug_assert_eq!( *p2.last().unwrap(), E::ONE,