From dc3a5951989d3d86f854dc12573e94a0b0229de9 Mon Sep 17 00:00:00 2001 From: Ohad Agadi Date: Thu, 19 Dec 2024 10:43:00 +0200 Subject: [PATCH] batched logup in opcodes --- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 91 +- .../component.rs | 4 +- .../add_opcode_is_small_f_is_imm_f/prover.rs | 155 ++- .../component.rs | 4 +- .../add_opcode_is_small_f_is_imm_t/prover.rs | 157 ++- .../component.rs | 4 +- .../add_opcode_is_small_t_is_imm_f/prover.rs | 155 ++- .../component.rs | 4 +- .../add_opcode_is_small_t_is_imm_t/prover.rs | 157 ++- .../component.rs | 4 +- .../prover.rs | 85 +- .../component.rs | 4 +- .../prover.rs | 87 +- .../component.rs | 4 +- .../prover.rs | 122 +- .../component.rs | 4 +- .../prover.rs | 158 ++- .../component.rs | 4 +- .../prover.rs | 158 ++- .../component.rs | 4 +- .../prover.rs | 159 ++- .../components/generic_opcode/component.rs | 4 +- .../src/components/generic_opcode/prover.rs | 1022 +++++++---------- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 119 +- .../component.rs | 4 +- .../prover.rs | 119 +- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 118 +- .../component.rs | 4 +- .../prover.rs | 89 +- .../component.rs | 4 +- .../prover.rs | 90 +- .../component.rs | 4 +- .../mul_opcode_is_small_f_is_imm_f/prover.rs | 650 ++++++----- .../component.rs | 4 +- .../mul_opcode_is_small_f_is_imm_t/prover.rs | 652 ++++++----- .../src/components/ret_opcode/component.rs | 4 +- .../src/components/ret_opcode/prover.rs | 120 +- 50 files changed, 2439 insertions(+), 2569 deletions(-) diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/component.rs index 26aa232f..43dbefb7 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 10]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -206,7 +206,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/prover.rs index 30806183..e012c313 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -198,7 +200,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -231,7 +233,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_ap_col1) + ((offset2_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_ap_col1) + ((offset2_col3) - (M31_32768))), op1_id_col4, ]); @@ -254,7 +256,7 @@ pub fn write_trace_simd( trace[9].data[row_index] = op1_limb_2_col9; sub_components_inputs.memory_id_to_big_inputs[0].extend(op1_id_col4.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ op1_id_col4, op1_limb_0_col7, op1_limb_1_col8, @@ -286,8 +288,10 @@ pub fn write_trace_simd( ((msb_col5) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (((((op1_limb_0_col7) + ((op1_limb_1_col8) * (M31_512))) @@ -303,19 +307,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -328,10 +334,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -340,42 +346,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/component.rs index 84dd1276..32ecd314 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 10]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -206,7 +206,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/prover.rs index 79e89653..83d8ae8d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_f_op_1_base_fp_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -198,7 +200,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -231,7 +233,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_fp_col2) + ((offset2_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_fp_col2) + ((offset2_col3) - (M31_32768))), op1_id_col4, ]); @@ -254,7 +256,7 @@ pub fn write_trace_simd( trace[9].data[row_index] = op1_limb_2_col9; sub_components_inputs.memory_id_to_big_inputs[0].extend(op1_id_col4.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ op1_id_col4, op1_limb_0_col7, op1_limb_1_col8, @@ -286,8 +288,10 @@ pub fn write_trace_simd( ((msb_col5) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (((((op1_limb_0_col7) + ((op1_limb_1_col8) * (M31_512))) @@ -303,19 +307,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -328,10 +334,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -340,42 +346,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/component.rs index 7fcf3d98..aaf45e9f 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 9]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -203,7 +203,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/prover.rs index 03467b7b..c9951311 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_ap_opcode_is_imm_t_op_1_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -185,7 +187,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -218,7 +220,9 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[0].push([((input_pc_col0) + (M31_1)), op1_id_col3]); + lookup_data + .memory_address_to_id_0 + .push([((input_pc_col0) + (M31_1)), op1_id_col3]); // Cond Decode Small Sign. @@ -238,7 +242,7 @@ pub fn write_trace_simd( trace[8].data[row_index] = op1_limb_2_col8; sub_components_inputs.memory_id_to_big_inputs[0].extend(op1_id_col3.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ op1_id_col3, op1_limb_0_col6, op1_limb_1_col7, @@ -270,8 +274,10 @@ pub fn write_trace_simd( ((msb_col4) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (((((op1_limb_0_col6) + ((op1_limb_1_col7) * (M31_512))) @@ -287,19 +293,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -312,10 +320,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -324,42 +332,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs index e3112364..4d786e84 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 99]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -689,7 +689,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs index 5c636283..531b7d7e 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -277,7 +279,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -317,7 +319,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col6)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -381,7 +383,7 @@ pub fn write_trace_simd( trace[39].data[row_index] = dst_limb_27_col39; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col11.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col11, dst_limb_0_col12, dst_limb_1_col13, @@ -431,7 +433,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col7) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col7)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -495,7 +497,7 @@ pub fn write_trace_simd( trace[68].data[row_index] = op0_limb_27_col68; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col40.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col40, op0_limb_0_col41, op0_limb_1_col42, @@ -543,7 +545,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((((op1_base_fp_col8) * (input_fp_col2)) + ((op1_base_ap_col9) * (input_ap_col1))) + ((offset2_col5) - (M31_32768))), op1_id_col69, @@ -606,7 +608,7 @@ pub fn write_trace_simd( trace[97].data[row_index] = op1_limb_27_col97; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col69.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col69, op1_limb_0_col70, op1_limb_1_col71, @@ -647,8 +649,10 @@ pub fn write_trace_simd( let sub_p_bit_col98 = sub_p_bit_tmp_f459_17.as_m31(); trace[98].data[row_index] = sub_p_bit_col98; - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (ap_update_add_1_col10)), input_fp_col2, @@ -659,27 +663,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -692,10 +698,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -704,74 +710,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs index 96801ee2..f100c7a0 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 96]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -681,7 +681,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs index 06ee319c..ffdd0998 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_f_is_imm_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -248,7 +250,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -288,7 +290,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col5) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col5)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -352,7 +354,7 @@ pub fn write_trace_simd( trace[36].data[row_index] = dst_limb_27_col36; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col8.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col8, dst_limb_0_col9, dst_limb_1_col10, @@ -402,7 +404,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col6)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -466,7 +468,7 @@ pub fn write_trace_simd( trace[65].data[row_index] = op0_limb_27_col65; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col37.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col37, op0_limb_0_col38, op0_limb_1_col39, @@ -509,7 +511,9 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[2].push([((input_pc_col0) + (M31_1)), op1_id_col66]); + lookup_data + .memory_address_to_id_2 + .push([((input_pc_col0) + (M31_1)), op1_id_col66]); let op1_limb_0_col67 = memory_id_to_big_value_tmp_f0ae_13.get_m31(0); trace[67].data[row_index] = op1_limb_0_col67; let op1_limb_1_col68 = memory_id_to_big_value_tmp_f0ae_13.get_m31(1); @@ -568,7 +572,7 @@ pub fn write_trace_simd( trace[94].data[row_index] = op1_limb_27_col94; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col66.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col66, op1_limb_0_col67, op1_limb_1_col68, @@ -609,8 +613,10 @@ pub fn write_trace_simd( let sub_p_bit_col95 = sub_p_bit_tmp_f0ae_14.as_m31(); trace[95].data[row_index] = sub_p_bit_col95; - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col7)), input_fp_col2, @@ -621,27 +627,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -654,10 +662,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -666,74 +674,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs index 567615a6..1bf18e3a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 29]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -371,7 +371,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs index cb8ee32b..e08415be 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -280,7 +282,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -320,7 +322,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col6)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -345,7 +347,7 @@ pub fn write_trace_simd( trace[16].data[row_index] = dst_limb_2_col16; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col11.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col11, dst_limb_0_col14, dst_limb_1_col15, @@ -395,7 +397,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col7) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col7)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -420,7 +422,7 @@ pub fn write_trace_simd( trace[22].data[row_index] = op0_limb_2_col22; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col17.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col17, op0_limb_0_col20, op0_limb_1_col21, @@ -468,7 +470,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((((op1_base_fp_col8) * (input_fp_col2)) + ((op1_base_ap_col9) * (input_ap_col1))) + ((offset2_col5) - (M31_32768))), op1_id_col23, @@ -492,7 +494,7 @@ pub fn write_trace_simd( trace[28].data[row_index] = op1_limb_2_col28; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col23.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col23, op1_limb_0_col26, op1_limb_1_col27, @@ -524,8 +526,10 @@ pub fn write_trace_simd( ((msb_col24) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (ap_update_add_1_col10)), input_fp_col2, @@ -536,27 +540,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -569,10 +575,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -581,74 +587,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs index 4cd63dbb..24d75b22 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 26]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -363,7 +363,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs index 9354184a..623fbf55 100644 --- a/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/add_opcode_is_small_t_is_imm_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -251,7 +253,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -291,7 +293,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col5) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col5)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -316,7 +318,7 @@ pub fn write_trace_simd( trace[13].data[row_index] = dst_limb_2_col13; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col8.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col8, dst_limb_0_col11, dst_limb_1_col12, @@ -366,7 +368,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col6)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -391,7 +393,7 @@ pub fn write_trace_simd( trace[19].data[row_index] = op0_limb_2_col19; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col14.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col14, op0_limb_0_col17, op0_limb_1_col18, @@ -434,7 +436,9 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[2].push([((input_pc_col0) + (M31_1)), op1_id_col20]); + lookup_data + .memory_address_to_id_2 + .push([((input_pc_col0) + (M31_1)), op1_id_col20]); // Cond Decode Small Sign. @@ -454,7 +458,7 @@ pub fn write_trace_simd( trace[25].data[row_index] = op1_limb_2_col25; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col20.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col20, op1_limb_0_col23, op1_limb_1_col24, @@ -486,8 +490,10 @@ pub fn write_trace_simd( ((msb_col21) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col7)), input_fp_col2, @@ -498,27 +504,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -531,10 +539,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -543,74 +551,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs index 4b619a03..e1186422 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/component.rs @@ -31,7 +31,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 10]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -167,7 +167,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs index 8108e781..8e9e9332 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -248,7 +250,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -286,7 +288,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col5) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col5)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -298,14 +300,16 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op1_base_fp_col6) * (input_fp_col2)) + ((op1_base_ap_col7) * (input_ap_col1))) + ((offset2_col4) - (M31_32768))), dst_id_col9, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (ap_update_add_1_col8)), input_fp_col2, @@ -317,17 +321,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -340,9 +348,9 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -351,42 +359,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_address_to_id_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_address_to_id.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs index 95b1354e..2a9f1655 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/component.rs @@ -31,7 +31,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 7]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -156,7 +156,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs index 8be89524..50efd705 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_f_is_imm_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -218,7 +220,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -256,7 +258,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col4) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col4)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -265,10 +267,14 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1].push([((input_pc_col0) + (M31_1)), dst_id_col6]); + lookup_data + .memory_address_to_id_1 + .push([((input_pc_col0) + (M31_1)), dst_id_col6]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col5)), input_fp_col2, @@ -280,17 +286,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -303,9 +313,9 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -314,42 +324,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_address_to_id_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_address_to_id.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs index 679ee75b..f3d266e7 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 14]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 7]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 4]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -193,7 +193,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs index b3eb041e..5b68e2d4 100644 --- a/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/assert_eq_opcode_is_double_deref_t_is_imm_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -259,7 +261,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -299,7 +301,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((op0_base_fp_col7) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col7)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -313,7 +315,7 @@ pub fn write_trace_simd( trace[12].data[row_index] = mem1_base_limb_2_col12; sub_components_inputs.memory_id_to_big_inputs[0].extend(mem1_base_id_col9.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ mem1_base_id_col9, mem1_base_limb_0_col10, mem1_base_limb_1_col11, @@ -361,7 +363,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((dst_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col6)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -374,15 +376,17 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((((mem1_base_limb_0_col10) + ((mem1_base_limb_1_col11) * (M31_512))) + ((mem1_base_limb_2_col12) * (M31_262144))) + ((offset2_col5) - (M31_32768))), dst_id_col13, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (ap_update_add_1_col8)), input_fp_col2, @@ -394,23 +398,25 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -423,10 +429,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -435,58 +441,48 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_address_to_id_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_address_to_id.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/component.rs index 62faa0ea..9fd121cf 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 16]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -225,7 +225,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/prover.rs index d44ce127..5b61add6 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -195,7 +197,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32768, M31_32769, @@ -227,7 +229,9 @@ pub fn write_trace_simd( trace[4].data[row_index] = stored_fp_id_col4; sub_components_inputs.memory_address_to_id_inputs[0].extend(input_ap_col1.unpack()); - lookup_data.memory_address_to_id[0].push([input_ap_col1, stored_fp_id_col4]); + lookup_data + .memory_address_to_id_0 + .push([input_ap_col1, stored_fp_id_col4]); let stored_fp_limb_0_col5 = memory_id_to_big_value_tmp_eefa_5.get_m31(0); trace[5].data[row_index] = stored_fp_limb_0_col5; let stored_fp_limb_1_col6 = memory_id_to_big_value_tmp_eefa_5.get_m31(1); @@ -236,7 +240,7 @@ pub fn write_trace_simd( trace[7].data[row_index] = stored_fp_limb_2_col7; sub_components_inputs.memory_id_to_big_inputs[0].extend(stored_fp_id_col4.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ stored_fp_id_col4, stored_fp_limb_0_col5, stored_fp_limb_1_col6, @@ -279,7 +283,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_ap_col1) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_ap_col1) + (M31_1)), stored_ret_pc_id_col8]); let stored_ret_pc_limb_0_col9 = memory_id_to_big_value_tmp_eefa_7.get_m31(0); trace[9].data[row_index] = stored_ret_pc_limb_0_col9; @@ -289,7 +294,7 @@ pub fn write_trace_simd( trace[11].data[row_index] = stored_ret_pc_limb_2_col11; sub_components_inputs.memory_id_to_big_inputs[1].extend(stored_ret_pc_id_col8.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ stored_ret_pc_id_col8, stored_ret_pc_limb_0_col9, stored_ret_pc_limb_1_col10, @@ -332,7 +337,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_ap_col1) + ((offset2_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((input_ap_col1) + ((offset2_col3) - (M31_32768))), next_pc_id_col12, ]); @@ -344,7 +349,7 @@ pub fn write_trace_simd( trace[15].data[row_index] = next_pc_limb_2_col15; sub_components_inputs.memory_id_to_big_inputs[2].extend(next_pc_id_col12.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ next_pc_id_col12, next_pc_limb_0_col13, next_pc_limb_1_col14, @@ -376,8 +381,10 @@ pub fn write_trace_simd( M31_0, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ (((next_pc_limb_0_col13) + ((next_pc_limb_1_col14) * (M31_512))) + ((next_pc_limb_2_col15) * (M31_262144))), ((input_ap_col1) + (M31_2)), @@ -390,27 +397,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -423,10 +432,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -435,74 +444,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/component.rs index 5625dfdf..b2ebe801 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 16]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -225,7 +225,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/prover.rs index 4f8c19cc..8914f525 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_f_op_1_base_fp_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -195,7 +197,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32768, M31_32769, @@ -227,7 +229,9 @@ pub fn write_trace_simd( trace[4].data[row_index] = stored_fp_id_col4; sub_components_inputs.memory_address_to_id_inputs[0].extend(input_ap_col1.unpack()); - lookup_data.memory_address_to_id[0].push([input_ap_col1, stored_fp_id_col4]); + lookup_data + .memory_address_to_id_0 + .push([input_ap_col1, stored_fp_id_col4]); let stored_fp_limb_0_col5 = memory_id_to_big_value_tmp_d5fd_5.get_m31(0); trace[5].data[row_index] = stored_fp_limb_0_col5; let stored_fp_limb_1_col6 = memory_id_to_big_value_tmp_d5fd_5.get_m31(1); @@ -236,7 +240,7 @@ pub fn write_trace_simd( trace[7].data[row_index] = stored_fp_limb_2_col7; sub_components_inputs.memory_id_to_big_inputs[0].extend(stored_fp_id_col4.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ stored_fp_id_col4, stored_fp_limb_0_col5, stored_fp_limb_1_col6, @@ -279,7 +283,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_ap_col1) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_ap_col1) + (M31_1)), stored_ret_pc_id_col8]); let stored_ret_pc_limb_0_col9 = memory_id_to_big_value_tmp_d5fd_7.get_m31(0); trace[9].data[row_index] = stored_ret_pc_limb_0_col9; @@ -289,7 +294,7 @@ pub fn write_trace_simd( trace[11].data[row_index] = stored_ret_pc_limb_2_col11; sub_components_inputs.memory_id_to_big_inputs[1].extend(stored_ret_pc_id_col8.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ stored_ret_pc_id_col8, stored_ret_pc_limb_0_col9, stored_ret_pc_limb_1_col10, @@ -332,7 +337,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_fp_col2) + ((offset2_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((input_fp_col2) + ((offset2_col3) - (M31_32768))), next_pc_id_col12, ]); @@ -344,7 +349,7 @@ pub fn write_trace_simd( trace[15].data[row_index] = next_pc_limb_2_col15; sub_components_inputs.memory_id_to_big_inputs[2].extend(next_pc_id_col12.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ next_pc_id_col12, next_pc_limb_0_col13, next_pc_limb_1_col14, @@ -376,8 +381,10 @@ pub fn write_trace_simd( M31_0, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ (((next_pc_limb_0_col13) + ((next_pc_limb_1_col14) * (M31_512))) + ((next_pc_limb_2_col15) * (M31_262144))), ((input_ap_col1) + (M31_2)), @@ -390,27 +397,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -423,10 +432,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -435,74 +444,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/component.rs index 12e3655a..ed5fecf5 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 17]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 9]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -272,7 +272,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/prover.rs index 78e76995..19d64d28 100644 --- a/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/call_opcode_is_rel_t_op_1_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -185,7 +187,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32768, M31_32769, @@ -217,7 +219,9 @@ pub fn write_trace_simd( trace[3].data[row_index] = stored_fp_id_col3; sub_components_inputs.memory_address_to_id_inputs[0].extend(input_ap_col1.unpack()); - lookup_data.memory_address_to_id[0].push([input_ap_col1, stored_fp_id_col3]); + lookup_data + .memory_address_to_id_0 + .push([input_ap_col1, stored_fp_id_col3]); let stored_fp_limb_0_col4 = memory_id_to_big_value_tmp_4f8b_4.get_m31(0); trace[4].data[row_index] = stored_fp_limb_0_col4; let stored_fp_limb_1_col5 = memory_id_to_big_value_tmp_4f8b_4.get_m31(1); @@ -226,7 +230,7 @@ pub fn write_trace_simd( trace[6].data[row_index] = stored_fp_limb_2_col6; sub_components_inputs.memory_id_to_big_inputs[0].extend(stored_fp_id_col3.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ stored_fp_id_col3, stored_fp_limb_0_col4, stored_fp_limb_1_col5, @@ -269,7 +273,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_ap_col1) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_ap_col1) + (M31_1)), stored_ret_pc_id_col7]); let stored_ret_pc_limb_0_col8 = memory_id_to_big_value_tmp_4f8b_6.get_m31(0); trace[8].data[row_index] = stored_ret_pc_limb_0_col8; @@ -279,7 +284,7 @@ pub fn write_trace_simd( trace[10].data[row_index] = stored_ret_pc_limb_2_col10; sub_components_inputs.memory_id_to_big_inputs[1].extend(stored_ret_pc_id_col7.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ stored_ret_pc_id_col7, stored_ret_pc_limb_0_col8, stored_ret_pc_limb_1_col9, @@ -322,7 +327,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[2] + lookup_data + .memory_address_to_id_2 .push([((input_pc_col0) + (M31_1)), distance_to_next_pc_id_col11]); // Cond Decode Small Sign. @@ -344,7 +350,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_id_to_big_inputs[2] .extend(distance_to_next_pc_id_col11.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ distance_to_next_pc_id_col11, distance_to_next_pc_limb_0_col14, distance_to_next_pc_limb_1_col15, @@ -376,8 +382,10 @@ pub fn write_trace_simd( ((msb_col12) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (((((distance_to_next_pc_limb_0_col14) + ((distance_to_next_pc_limb_1_col15) * (M31_512))) @@ -394,27 +402,29 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -427,10 +437,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -439,74 +449,61 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs index 6608b763..b07decda 100644 --- a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/component.rs @@ -34,7 +34,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 229]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 65]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 33]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -3656,7 +3656,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs index 72a791df..afd7422a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/generic_opcode/prover.rs @@ -1,6 +1,7 @@ #![cfg_attr(rustfmt, rustfmt_skip)]#![allow(unused_parens)] #![allow(unused_imports)] use air_structs_derive::SubComponentInputs; +use std::iter::zip; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; use prover_types::cpu::*; @@ -219,7 +220,7 @@ sub_components_inputs .verify_instruction_inputs[0] .extend((input_pc_col0, [offset0_col3, offset1_col4, offset2_col5], [dst_base_fp_col6, op0_base_fp_col7, op1_imm_col8, op1_base_fp_col9, op1_base_ap_col10, res_add_col11, res_mul_col12, pc_update_jump_col13, pc_update_jump_rel_col14, pc_update_jnz_col15, ap_update_add_col16, ap_update_add_1_col17, opcode_call_col18, opcode_ret_col19, opcode_assert_eq_col20]).unpack()); -lookup_data.verify_instruction[0].push([input_pc_col0, offset0_col3, offset1_col4, offset2_col5, dst_base_fp_col6, op0_base_fp_col7, op1_imm_col8, op1_base_fp_col9, op1_base_ap_col10, res_add_col11, res_mul_col12, pc_update_jump_col13, pc_update_jump_rel_col14, pc_update_jnz_col15, ap_update_add_col16, ap_update_add_1_col17, opcode_call_col18, opcode_ret_col19, opcode_assert_eq_col20]); +lookup_data.verify_instruction_0.push([input_pc_col0, offset0_col3, offset1_col4, offset2_col5, dst_base_fp_col6, op0_base_fp_col7, op1_imm_col8, op1_base_fp_col9, op1_base_ap_col10, res_add_col11, res_mul_col12, pc_update_jump_col13, pc_update_jump_rel_col14, pc_update_jnz_col15, ap_update_add_col16, ap_update_add_1_col17, opcode_call_col18, opcode_ret_col19, opcode_assert_eq_col20]); @@ -253,7 +254,7 @@ sub_components_inputs .memory_address_to_id_inputs[0] .extend(((((((dst_base_fp_col6) * (input_fp_col2))) + (((((M31_1) - (dst_base_fp_col6))) * (input_ap_col1))))) + (((offset0_col3) - (M31_32768)))).unpack()); -lookup_data.memory_address_to_id[0].push([((((((dst_base_fp_col6) * (input_fp_col2))) + (((((M31_1) - (dst_base_fp_col6))) * (input_ap_col1))))) + (((offset0_col3) - (M31_32768)))), dst_id_col21]); +lookup_data.memory_address_to_id_0.push([((((((dst_base_fp_col6) * (input_fp_col2))) + (((((M31_1) - (dst_base_fp_col6))) * (input_ap_col1))))) + (((offset0_col3) - (M31_32768)))), dst_id_col21]); let dst_limb_0_col22 = memory_id_to_big_value_tmp_5745_27.get_m31(0); trace[22].data[row_index] = dst_limb_0_col22; let dst_limb_1_col23 = memory_id_to_big_value_tmp_5745_27.get_m31(1); @@ -314,7 +315,7 @@ sub_components_inputs .memory_id_to_big_inputs[0] .extend(dst_id_col21.unpack()); -lookup_data.memory_id_to_big[0].push([dst_id_col21, dst_limb_0_col22, dst_limb_1_col23, dst_limb_2_col24, dst_limb_3_col25, dst_limb_4_col26, dst_limb_5_col27, dst_limb_6_col28, dst_limb_7_col29, dst_limb_8_col30, dst_limb_9_col31, dst_limb_10_col32, dst_limb_11_col33, dst_limb_12_col34, dst_limb_13_col35, dst_limb_14_col36, dst_limb_15_col37, dst_limb_16_col38, dst_limb_17_col39, dst_limb_18_col40, dst_limb_19_col41, dst_limb_20_col42, dst_limb_21_col43, dst_limb_22_col44, dst_limb_23_col45, dst_limb_24_col46, dst_limb_25_col47, dst_limb_26_col48, dst_limb_27_col49]); +lookup_data.memory_id_to_big_0.push([dst_id_col21, dst_limb_0_col22, dst_limb_1_col23, dst_limb_2_col24, dst_limb_3_col25, dst_limb_4_col26, dst_limb_5_col27, dst_limb_6_col28, dst_limb_7_col29, dst_limb_8_col30, dst_limb_9_col31, dst_limb_10_col32, dst_limb_11_col33, dst_limb_12_col34, dst_limb_13_col35, dst_limb_14_col36, dst_limb_15_col37, dst_limb_16_col38, dst_limb_17_col39, dst_limb_18_col40, dst_limb_19_col41, dst_limb_20_col42, dst_limb_21_col43, dst_limb_22_col44, dst_limb_23_col45, dst_limb_24_col46, dst_limb_25_col47, dst_limb_26_col48, dst_limb_27_col49]); @@ -335,7 +336,7 @@ sub_components_inputs .memory_address_to_id_inputs[1] .extend(((((((op0_base_fp_col7) * (input_fp_col2))) + (((((M31_1) - (op0_base_fp_col7))) * (input_ap_col1))))) + (((offset1_col4) - (M31_32768)))).unpack()); -lookup_data.memory_address_to_id[1].push([((((((op0_base_fp_col7) * (input_fp_col2))) + (((((M31_1) - (op0_base_fp_col7))) * (input_ap_col1))))) + (((offset1_col4) - (M31_32768)))), op0_id_col50]); +lookup_data.memory_address_to_id_1.push([((((((op0_base_fp_col7) * (input_fp_col2))) + (((((M31_1) - (op0_base_fp_col7))) * (input_ap_col1))))) + (((offset1_col4) - (M31_32768)))), op0_id_col50]); let op0_limb_0_col51 = memory_id_to_big_value_tmp_5745_29.get_m31(0); trace[51].data[row_index] = op0_limb_0_col51; let op0_limb_1_col52 = memory_id_to_big_value_tmp_5745_29.get_m31(1); @@ -396,7 +397,7 @@ sub_components_inputs .memory_id_to_big_inputs[1] .extend(op0_id_col50.unpack()); -lookup_data.memory_id_to_big[1].push([op0_id_col50, op0_limb_0_col51, op0_limb_1_col52, op0_limb_2_col53, op0_limb_3_col54, op0_limb_4_col55, op0_limb_5_col56, op0_limb_6_col57, op0_limb_7_col58, op0_limb_8_col59, op0_limb_9_col60, op0_limb_10_col61, op0_limb_11_col62, op0_limb_12_col63, op0_limb_13_col64, op0_limb_14_col65, op0_limb_15_col66, op0_limb_16_col67, op0_limb_17_col68, op0_limb_18_col69, op0_limb_19_col70, op0_limb_20_col71, op0_limb_21_col72, op0_limb_22_col73, op0_limb_23_col74, op0_limb_24_col75, op0_limb_25_col76, op0_limb_26_col77, op0_limb_27_col78]); +lookup_data.memory_id_to_big_1.push([op0_id_col50, op0_limb_0_col51, op0_limb_1_col52, op0_limb_2_col53, op0_limb_3_col54, op0_limb_4_col55, op0_limb_5_col56, op0_limb_6_col57, op0_limb_7_col58, op0_limb_8_col59, op0_limb_9_col60, op0_limb_10_col61, op0_limb_11_col62, op0_limb_12_col63, op0_limb_13_col64, op0_limb_14_col65, op0_limb_15_col66, op0_limb_16_col67, op0_limb_17_col68, op0_limb_18_col69, op0_limb_19_col70, op0_limb_20_col71, op0_limb_21_col72, op0_limb_22_col73, op0_limb_23_col74, op0_limb_24_col75, op0_limb_25_col76, op0_limb_26_col77, op0_limb_27_col78]); @@ -417,7 +418,7 @@ sub_components_inputs .memory_address_to_id_inputs[2] .extend(((((((((((op1_base_fp_col9) * (input_fp_col2))) + (((op1_base_ap_col10) * (input_ap_col1))))) + (((op1_imm_col8) * (input_pc_col0))))) + (((op1_base_op0_tmp_5745_21) * (((((op0_limb_0_col51) + (((op0_limb_1_col52) * (M31_512))))) + (((op0_limb_2_col53) * (M31_262144))))))))) + (((offset2_col5) - (M31_32768)))).unpack()); -lookup_data.memory_address_to_id[2].push([((((((((((op1_base_fp_col9) * (input_fp_col2))) + (((op1_base_ap_col10) * (input_ap_col1))))) + (((op1_imm_col8) * (input_pc_col0))))) + (((op1_base_op0_tmp_5745_21) * (((((op0_limb_0_col51) + (((op0_limb_1_col52) * (M31_512))))) + (((op0_limb_2_col53) * (M31_262144))))))))) + (((offset2_col5) - (M31_32768)))), op1_id_col79]); +lookup_data.memory_address_to_id_2.push([((((((((((op1_base_fp_col9) * (input_fp_col2))) + (((op1_base_ap_col10) * (input_ap_col1))))) + (((op1_imm_col8) * (input_pc_col0))))) + (((op1_base_op0_tmp_5745_21) * (((((op0_limb_0_col51) + (((op0_limb_1_col52) * (M31_512))))) + (((op0_limb_2_col53) * (M31_262144))))))))) + (((offset2_col5) - (M31_32768)))), op1_id_col79]); let op1_limb_0_col80 = memory_id_to_big_value_tmp_5745_31.get_m31(0); trace[80].data[row_index] = op1_limb_0_col80; let op1_limb_1_col81 = memory_id_to_big_value_tmp_5745_31.get_m31(1); @@ -478,7 +479,7 @@ sub_components_inputs .memory_id_to_big_inputs[2] .extend(op1_id_col79.unpack()); -lookup_data.memory_id_to_big[2].push([op1_id_col79, op1_limb_0_col80, op1_limb_1_col81, op1_limb_2_col82, op1_limb_3_col83, op1_limb_4_col84, op1_limb_5_col85, op1_limb_6_col86, op1_limb_7_col87, op1_limb_8_col88, op1_limb_9_col89, op1_limb_10_col90, op1_limb_11_col91, op1_limb_12_col92, op1_limb_13_col93, op1_limb_14_col94, op1_limb_15_col95, op1_limb_16_col96, op1_limb_17_col97, op1_limb_18_col98, op1_limb_19_col99, op1_limb_20_col100, op1_limb_21_col101, op1_limb_22_col102, op1_limb_23_col103, op1_limb_24_col104, op1_limb_25_col105, op1_limb_26_col106, op1_limb_27_col107]); +lookup_data.memory_id_to_big_2.push([op1_id_col79, op1_limb_0_col80, op1_limb_1_col81, op1_limb_2_col82, op1_limb_3_col83, op1_limb_4_col84, op1_limb_5_col85, op1_limb_6_col86, op1_limb_7_col87, op1_limb_8_col88, op1_limb_9_col89, op1_limb_10_col90, op1_limb_11_col91, op1_limb_12_col92, op1_limb_13_col93, op1_limb_14_col94, op1_limb_15_col95, op1_limb_16_col96, op1_limb_17_col97, op1_limb_18_col98, op1_limb_19_col99, op1_limb_20_col100, op1_limb_21_col101, op1_limb_22_col102, op1_limb_23_col103, op1_limb_24_col104, op1_limb_25_col105, op1_limb_26_col106, op1_limb_27_col107]); @@ -554,85 +555,85 @@ sub_components_inputs .range_check_9_9_inputs[0] .extend([add_res_limb_0_col108, add_res_limb_1_col109].unpack()); -lookup_data.range_check_9_9[0].push([add_res_limb_0_col108, add_res_limb_1_col109]); +lookup_data.range_check_9_9_0.push([add_res_limb_0_col108, add_res_limb_1_col109]); sub_components_inputs .range_check_9_9_inputs[1] .extend([add_res_limb_2_col110, add_res_limb_3_col111].unpack()); -lookup_data.range_check_9_9[1].push([add_res_limb_2_col110, add_res_limb_3_col111]); +lookup_data.range_check_9_9_1.push([add_res_limb_2_col110, add_res_limb_3_col111]); sub_components_inputs .range_check_9_9_inputs[2] .extend([add_res_limb_4_col112, add_res_limb_5_col113].unpack()); -lookup_data.range_check_9_9[2].push([add_res_limb_4_col112, add_res_limb_5_col113]); +lookup_data.range_check_9_9_2.push([add_res_limb_4_col112, add_res_limb_5_col113]); sub_components_inputs .range_check_9_9_inputs[3] .extend([add_res_limb_6_col114, add_res_limb_7_col115].unpack()); -lookup_data.range_check_9_9[3].push([add_res_limb_6_col114, add_res_limb_7_col115]); +lookup_data.range_check_9_9_3.push([add_res_limb_6_col114, add_res_limb_7_col115]); sub_components_inputs .range_check_9_9_inputs[4] .extend([add_res_limb_8_col116, add_res_limb_9_col117].unpack()); -lookup_data.range_check_9_9[4].push([add_res_limb_8_col116, add_res_limb_9_col117]); +lookup_data.range_check_9_9_4.push([add_res_limb_8_col116, add_res_limb_9_col117]); sub_components_inputs .range_check_9_9_inputs[5] .extend([add_res_limb_10_col118, add_res_limb_11_col119].unpack()); -lookup_data.range_check_9_9[5].push([add_res_limb_10_col118, add_res_limb_11_col119]); +lookup_data.range_check_9_9_5.push([add_res_limb_10_col118, add_res_limb_11_col119]); sub_components_inputs .range_check_9_9_inputs[6] .extend([add_res_limb_12_col120, add_res_limb_13_col121].unpack()); -lookup_data.range_check_9_9[6].push([add_res_limb_12_col120, add_res_limb_13_col121]); +lookup_data.range_check_9_9_6.push([add_res_limb_12_col120, add_res_limb_13_col121]); sub_components_inputs .range_check_9_9_inputs[7] .extend([add_res_limb_14_col122, add_res_limb_15_col123].unpack()); -lookup_data.range_check_9_9[7].push([add_res_limb_14_col122, add_res_limb_15_col123]); +lookup_data.range_check_9_9_7.push([add_res_limb_14_col122, add_res_limb_15_col123]); sub_components_inputs .range_check_9_9_inputs[8] .extend([add_res_limb_16_col124, add_res_limb_17_col125].unpack()); -lookup_data.range_check_9_9[8].push([add_res_limb_16_col124, add_res_limb_17_col125]); +lookup_data.range_check_9_9_8.push([add_res_limb_16_col124, add_res_limb_17_col125]); sub_components_inputs .range_check_9_9_inputs[9] .extend([add_res_limb_18_col126, add_res_limb_19_col127].unpack()); -lookup_data.range_check_9_9[9].push([add_res_limb_18_col126, add_res_limb_19_col127]); +lookup_data.range_check_9_9_9.push([add_res_limb_18_col126, add_res_limb_19_col127]); sub_components_inputs .range_check_9_9_inputs[10] .extend([add_res_limb_20_col128, add_res_limb_21_col129].unpack()); -lookup_data.range_check_9_9[10].push([add_res_limb_20_col128, add_res_limb_21_col129]); +lookup_data.range_check_9_9_10.push([add_res_limb_20_col128, add_res_limb_21_col129]); sub_components_inputs .range_check_9_9_inputs[11] .extend([add_res_limb_22_col130, add_res_limb_23_col131].unpack()); -lookup_data.range_check_9_9[11].push([add_res_limb_22_col130, add_res_limb_23_col131]); +lookup_data.range_check_9_9_11.push([add_res_limb_22_col130, add_res_limb_23_col131]); sub_components_inputs .range_check_9_9_inputs[12] .extend([add_res_limb_24_col132, add_res_limb_25_col133].unpack()); -lookup_data.range_check_9_9[12].push([add_res_limb_24_col132, add_res_limb_25_col133]); +lookup_data.range_check_9_9_12.push([add_res_limb_24_col132, add_res_limb_25_col133]); sub_components_inputs .range_check_9_9_inputs[13] .extend([add_res_limb_26_col134, add_res_limb_27_col135].unpack()); -lookup_data.range_check_9_9[13].push([add_res_limb_26_col134, add_res_limb_27_col135]); +lookup_data.range_check_9_9_13.push([add_res_limb_26_col134, add_res_limb_27_col135]); @@ -722,85 +723,85 @@ sub_components_inputs .range_check_9_9_inputs[14] .extend([mul_res_limb_0_col137, mul_res_limb_1_col138].unpack()); -lookup_data.range_check_9_9[14].push([mul_res_limb_0_col137, mul_res_limb_1_col138]); +lookup_data.range_check_9_9_14.push([mul_res_limb_0_col137, mul_res_limb_1_col138]); sub_components_inputs .range_check_9_9_inputs[15] .extend([mul_res_limb_2_col139, mul_res_limb_3_col140].unpack()); -lookup_data.range_check_9_9[15].push([mul_res_limb_2_col139, mul_res_limb_3_col140]); +lookup_data.range_check_9_9_15.push([mul_res_limb_2_col139, mul_res_limb_3_col140]); sub_components_inputs .range_check_9_9_inputs[16] .extend([mul_res_limb_4_col141, mul_res_limb_5_col142].unpack()); -lookup_data.range_check_9_9[16].push([mul_res_limb_4_col141, mul_res_limb_5_col142]); +lookup_data.range_check_9_9_16.push([mul_res_limb_4_col141, mul_res_limb_5_col142]); sub_components_inputs .range_check_9_9_inputs[17] .extend([mul_res_limb_6_col143, mul_res_limb_7_col144].unpack()); -lookup_data.range_check_9_9[17].push([mul_res_limb_6_col143, mul_res_limb_7_col144]); +lookup_data.range_check_9_9_17.push([mul_res_limb_6_col143, mul_res_limb_7_col144]); sub_components_inputs .range_check_9_9_inputs[18] .extend([mul_res_limb_8_col145, mul_res_limb_9_col146].unpack()); -lookup_data.range_check_9_9[18].push([mul_res_limb_8_col145, mul_res_limb_9_col146]); +lookup_data.range_check_9_9_18.push([mul_res_limb_8_col145, mul_res_limb_9_col146]); sub_components_inputs .range_check_9_9_inputs[19] .extend([mul_res_limb_10_col147, mul_res_limb_11_col148].unpack()); -lookup_data.range_check_9_9[19].push([mul_res_limb_10_col147, mul_res_limb_11_col148]); +lookup_data.range_check_9_9_19.push([mul_res_limb_10_col147, mul_res_limb_11_col148]); sub_components_inputs .range_check_9_9_inputs[20] .extend([mul_res_limb_12_col149, mul_res_limb_13_col150].unpack()); -lookup_data.range_check_9_9[20].push([mul_res_limb_12_col149, mul_res_limb_13_col150]); +lookup_data.range_check_9_9_20.push([mul_res_limb_12_col149, mul_res_limb_13_col150]); sub_components_inputs .range_check_9_9_inputs[21] .extend([mul_res_limb_14_col151, mul_res_limb_15_col152].unpack()); -lookup_data.range_check_9_9[21].push([mul_res_limb_14_col151, mul_res_limb_15_col152]); +lookup_data.range_check_9_9_21.push([mul_res_limb_14_col151, mul_res_limb_15_col152]); sub_components_inputs .range_check_9_9_inputs[22] .extend([mul_res_limb_16_col153, mul_res_limb_17_col154].unpack()); -lookup_data.range_check_9_9[22].push([mul_res_limb_16_col153, mul_res_limb_17_col154]); +lookup_data.range_check_9_9_22.push([mul_res_limb_16_col153, mul_res_limb_17_col154]); sub_components_inputs .range_check_9_9_inputs[23] .extend([mul_res_limb_18_col155, mul_res_limb_19_col156].unpack()); -lookup_data.range_check_9_9[23].push([mul_res_limb_18_col155, mul_res_limb_19_col156]); +lookup_data.range_check_9_9_23.push([mul_res_limb_18_col155, mul_res_limb_19_col156]); sub_components_inputs .range_check_9_9_inputs[24] .extend([mul_res_limb_20_col157, mul_res_limb_21_col158].unpack()); -lookup_data.range_check_9_9[24].push([mul_res_limb_20_col157, mul_res_limb_21_col158]); +lookup_data.range_check_9_9_24.push([mul_res_limb_20_col157, mul_res_limb_21_col158]); sub_components_inputs .range_check_9_9_inputs[25] .extend([mul_res_limb_22_col159, mul_res_limb_23_col160].unpack()); -lookup_data.range_check_9_9[25].push([mul_res_limb_22_col159, mul_res_limb_23_col160]); +lookup_data.range_check_9_9_25.push([mul_res_limb_22_col159, mul_res_limb_23_col160]); sub_components_inputs .range_check_9_9_inputs[26] .extend([mul_res_limb_24_col161, mul_res_limb_25_col162].unpack()); -lookup_data.range_check_9_9[26].push([mul_res_limb_24_col161, mul_res_limb_25_col162]); +lookup_data.range_check_9_9_26.push([mul_res_limb_24_col161, mul_res_limb_25_col162]); sub_components_inputs .range_check_9_9_inputs[27] .extend([mul_res_limb_26_col163, mul_res_limb_27_col164].unpack()); -lookup_data.range_check_9_9[27].push([mul_res_limb_26_col163, mul_res_limb_27_col164]); +lookup_data.range_check_9_9_27.push([mul_res_limb_26_col163, mul_res_limb_27_col164]); @@ -900,7 +901,7 @@ sub_components_inputs .range_check_19_inputs[0] .extend([((k_col165) + (M31_262144))].unpack()); -lookup_data.range_check_19[0].push([((k_col165) + (M31_262144))]); +lookup_data.range_check_19_0.push([((k_col165) + (M31_262144))]); let carry_0_col166 = ((((((conv_mod_tmp_5745_117) - (((M31_1) * (k_col165))))) + (M31_0))) * (M31_4194304)); trace[166].data[row_index] = carry_0_col166; @@ -908,7 +909,7 @@ sub_components_inputs .range_check_19_inputs[1] .extend([((carry_0_col166) + (M31_131072))].unpack()); -lookup_data.range_check_19[1].push([((carry_0_col166) + (M31_131072))]); +lookup_data.range_check_19_1.push([((carry_0_col166) + (M31_131072))]); let carry_1_col167 = ((((conv_mod_tmp_5745_118) + (carry_0_col166))) * (M31_4194304)); trace[167].data[row_index] = carry_1_col167; @@ -916,7 +917,7 @@ sub_components_inputs .range_check_19_inputs[2] .extend([((carry_1_col167) + (M31_131072))].unpack()); -lookup_data.range_check_19[2].push([((carry_1_col167) + (M31_131072))]); +lookup_data.range_check_19_2.push([((carry_1_col167) + (M31_131072))]); let carry_2_col168 = ((((conv_mod_tmp_5745_119) + (carry_1_col167))) * (M31_4194304)); trace[168].data[row_index] = carry_2_col168; @@ -924,7 +925,7 @@ sub_components_inputs .range_check_19_inputs[3] .extend([((carry_2_col168) + (M31_131072))].unpack()); -lookup_data.range_check_19[3].push([((carry_2_col168) + (M31_131072))]); +lookup_data.range_check_19_3.push([((carry_2_col168) + (M31_131072))]); let carry_3_col169 = ((((conv_mod_tmp_5745_120) + (carry_2_col168))) * (M31_4194304)); trace[169].data[row_index] = carry_3_col169; @@ -932,7 +933,7 @@ sub_components_inputs .range_check_19_inputs[4] .extend([((carry_3_col169) + (M31_131072))].unpack()); -lookup_data.range_check_19[4].push([((carry_3_col169) + (M31_131072))]); +lookup_data.range_check_19_4.push([((carry_3_col169) + (M31_131072))]); let carry_4_col170 = ((((conv_mod_tmp_5745_121) + (carry_3_col169))) * (M31_4194304)); trace[170].data[row_index] = carry_4_col170; @@ -940,7 +941,7 @@ sub_components_inputs .range_check_19_inputs[5] .extend([((carry_4_col170) + (M31_131072))].unpack()); -lookup_data.range_check_19[5].push([((carry_4_col170) + (M31_131072))]); +lookup_data.range_check_19_5.push([((carry_4_col170) + (M31_131072))]); let carry_5_col171 = ((((conv_mod_tmp_5745_122) + (carry_4_col170))) * (M31_4194304)); trace[171].data[row_index] = carry_5_col171; @@ -948,7 +949,7 @@ sub_components_inputs .range_check_19_inputs[6] .extend([((carry_5_col171) + (M31_131072))].unpack()); -lookup_data.range_check_19[6].push([((carry_5_col171) + (M31_131072))]); +lookup_data.range_check_19_6.push([((carry_5_col171) + (M31_131072))]); let carry_6_col172 = ((((conv_mod_tmp_5745_123) + (carry_5_col171))) * (M31_4194304)); trace[172].data[row_index] = carry_6_col172; @@ -956,7 +957,7 @@ sub_components_inputs .range_check_19_inputs[7] .extend([((carry_6_col172) + (M31_131072))].unpack()); -lookup_data.range_check_19[7].push([((carry_6_col172) + (M31_131072))]); +lookup_data.range_check_19_7.push([((carry_6_col172) + (M31_131072))]); let carry_7_col173 = ((((conv_mod_tmp_5745_124) + (carry_6_col172))) * (M31_4194304)); trace[173].data[row_index] = carry_7_col173; @@ -964,7 +965,7 @@ sub_components_inputs .range_check_19_inputs[8] .extend([((carry_7_col173) + (M31_131072))].unpack()); -lookup_data.range_check_19[8].push([((carry_7_col173) + (M31_131072))]); +lookup_data.range_check_19_8.push([((carry_7_col173) + (M31_131072))]); let carry_8_col174 = ((((conv_mod_tmp_5745_125) + (carry_7_col173))) * (M31_4194304)); trace[174].data[row_index] = carry_8_col174; @@ -972,7 +973,7 @@ sub_components_inputs .range_check_19_inputs[9] .extend([((carry_8_col174) + (M31_131072))].unpack()); -lookup_data.range_check_19[9].push([((carry_8_col174) + (M31_131072))]); +lookup_data.range_check_19_9.push([((carry_8_col174) + (M31_131072))]); let carry_9_col175 = ((((conv_mod_tmp_5745_126) + (carry_8_col174))) * (M31_4194304)); trace[175].data[row_index] = carry_9_col175; @@ -980,7 +981,7 @@ sub_components_inputs .range_check_19_inputs[10] .extend([((carry_9_col175) + (M31_131072))].unpack()); -lookup_data.range_check_19[10].push([((carry_9_col175) + (M31_131072))]); +lookup_data.range_check_19_10.push([((carry_9_col175) + (M31_131072))]); let carry_10_col176 = ((((conv_mod_tmp_5745_127) + (carry_9_col175))) * (M31_4194304)); trace[176].data[row_index] = carry_10_col176; @@ -988,7 +989,7 @@ sub_components_inputs .range_check_19_inputs[11] .extend([((carry_10_col176) + (M31_131072))].unpack()); -lookup_data.range_check_19[11].push([((carry_10_col176) + (M31_131072))]); +lookup_data.range_check_19_11.push([((carry_10_col176) + (M31_131072))]); let carry_11_col177 = ((((conv_mod_tmp_5745_128) + (carry_10_col176))) * (M31_4194304)); trace[177].data[row_index] = carry_11_col177; @@ -996,7 +997,7 @@ sub_components_inputs .range_check_19_inputs[12] .extend([((carry_11_col177) + (M31_131072))].unpack()); -lookup_data.range_check_19[12].push([((carry_11_col177) + (M31_131072))]); +lookup_data.range_check_19_12.push([((carry_11_col177) + (M31_131072))]); let carry_12_col178 = ((((conv_mod_tmp_5745_129) + (carry_11_col177))) * (M31_4194304)); trace[178].data[row_index] = carry_12_col178; @@ -1004,7 +1005,7 @@ sub_components_inputs .range_check_19_inputs[13] .extend([((carry_12_col178) + (M31_131072))].unpack()); -lookup_data.range_check_19[13].push([((carry_12_col178) + (M31_131072))]); +lookup_data.range_check_19_13.push([((carry_12_col178) + (M31_131072))]); let carry_13_col179 = ((((conv_mod_tmp_5745_130) + (carry_12_col178))) * (M31_4194304)); trace[179].data[row_index] = carry_13_col179; @@ -1012,7 +1013,7 @@ sub_components_inputs .range_check_19_inputs[14] .extend([((carry_13_col179) + (M31_131072))].unpack()); -lookup_data.range_check_19[14].push([((carry_13_col179) + (M31_131072))]); +lookup_data.range_check_19_14.push([((carry_13_col179) + (M31_131072))]); let carry_14_col180 = ((((conv_mod_tmp_5745_131) + (carry_13_col179))) * (M31_4194304)); trace[180].data[row_index] = carry_14_col180; @@ -1020,7 +1021,7 @@ sub_components_inputs .range_check_19_inputs[15] .extend([((carry_14_col180) + (M31_131072))].unpack()); -lookup_data.range_check_19[15].push([((carry_14_col180) + (M31_131072))]); +lookup_data.range_check_19_15.push([((carry_14_col180) + (M31_131072))]); let carry_15_col181 = ((((conv_mod_tmp_5745_132) + (carry_14_col180))) * (M31_4194304)); trace[181].data[row_index] = carry_15_col181; @@ -1028,7 +1029,7 @@ sub_components_inputs .range_check_19_inputs[16] .extend([((carry_15_col181) + (M31_131072))].unpack()); -lookup_data.range_check_19[16].push([((carry_15_col181) + (M31_131072))]); +lookup_data.range_check_19_16.push([((carry_15_col181) + (M31_131072))]); let carry_16_col182 = ((((conv_mod_tmp_5745_133) + (carry_15_col181))) * (M31_4194304)); trace[182].data[row_index] = carry_16_col182; @@ -1036,7 +1037,7 @@ sub_components_inputs .range_check_19_inputs[17] .extend([((carry_16_col182) + (M31_131072))].unpack()); -lookup_data.range_check_19[17].push([((carry_16_col182) + (M31_131072))]); +lookup_data.range_check_19_17.push([((carry_16_col182) + (M31_131072))]); let carry_17_col183 = ((((conv_mod_tmp_5745_134) + (carry_16_col182))) * (M31_4194304)); trace[183].data[row_index] = carry_17_col183; @@ -1044,7 +1045,7 @@ sub_components_inputs .range_check_19_inputs[18] .extend([((carry_17_col183) + (M31_131072))].unpack()); -lookup_data.range_check_19[18].push([((carry_17_col183) + (M31_131072))]); +lookup_data.range_check_19_18.push([((carry_17_col183) + (M31_131072))]); let carry_18_col184 = ((((conv_mod_tmp_5745_135) + (carry_17_col183))) * (M31_4194304)); trace[184].data[row_index] = carry_18_col184; @@ -1052,7 +1053,7 @@ sub_components_inputs .range_check_19_inputs[19] .extend([((carry_18_col184) + (M31_131072))].unpack()); -lookup_data.range_check_19[19].push([((carry_18_col184) + (M31_131072))]); +lookup_data.range_check_19_19.push([((carry_18_col184) + (M31_131072))]); let carry_19_col185 = ((((conv_mod_tmp_5745_136) + (carry_18_col184))) * (M31_4194304)); trace[185].data[row_index] = carry_19_col185; @@ -1060,7 +1061,7 @@ sub_components_inputs .range_check_19_inputs[20] .extend([((carry_19_col185) + (M31_131072))].unpack()); -lookup_data.range_check_19[20].push([((carry_19_col185) + (M31_131072))]); +lookup_data.range_check_19_20.push([((carry_19_col185) + (M31_131072))]); let carry_20_col186 = ((((conv_mod_tmp_5745_137) + (carry_19_col185))) * (M31_4194304)); trace[186].data[row_index] = carry_20_col186; @@ -1068,7 +1069,7 @@ sub_components_inputs .range_check_19_inputs[21] .extend([((carry_20_col186) + (M31_131072))].unpack()); -lookup_data.range_check_19[21].push([((carry_20_col186) + (M31_131072))]); +lookup_data.range_check_19_21.push([((carry_20_col186) + (M31_131072))]); let carry_21_col187 = ((((((conv_mod_tmp_5745_138) - (((M31_136) * (k_col165))))) + (carry_20_col186))) * (M31_4194304)); trace[187].data[row_index] = carry_21_col187; @@ -1076,7 +1077,7 @@ sub_components_inputs .range_check_19_inputs[22] .extend([((carry_21_col187) + (M31_131072))].unpack()); -lookup_data.range_check_19[22].push([((carry_21_col187) + (M31_131072))]); +lookup_data.range_check_19_22.push([((carry_21_col187) + (M31_131072))]); let carry_22_col188 = ((((conv_mod_tmp_5745_139) + (carry_21_col187))) * (M31_4194304)); trace[188].data[row_index] = carry_22_col188; @@ -1084,7 +1085,7 @@ sub_components_inputs .range_check_19_inputs[23] .extend([((carry_22_col188) + (M31_131072))].unpack()); -lookup_data.range_check_19[23].push([((carry_22_col188) + (M31_131072))]); +lookup_data.range_check_19_23.push([((carry_22_col188) + (M31_131072))]); let carry_23_col189 = ((((conv_mod_tmp_5745_140) + (carry_22_col188))) * (M31_4194304)); trace[189].data[row_index] = carry_23_col189; @@ -1092,7 +1093,7 @@ sub_components_inputs .range_check_19_inputs[24] .extend([((carry_23_col189) + (M31_131072))].unpack()); -lookup_data.range_check_19[24].push([((carry_23_col189) + (M31_131072))]); +lookup_data.range_check_19_24.push([((carry_23_col189) + (M31_131072))]); let carry_24_col190 = ((((conv_mod_tmp_5745_141) + (carry_23_col189))) * (M31_4194304)); trace[190].data[row_index] = carry_24_col190; @@ -1100,7 +1101,7 @@ sub_components_inputs .range_check_19_inputs[25] .extend([((carry_24_col190) + (M31_131072))].unpack()); -lookup_data.range_check_19[25].push([((carry_24_col190) + (M31_131072))]); +lookup_data.range_check_19_25.push([((carry_24_col190) + (M31_131072))]); let carry_25_col191 = ((((conv_mod_tmp_5745_142) + (carry_24_col190))) * (M31_4194304)); trace[191].data[row_index] = carry_25_col191; @@ -1108,7 +1109,7 @@ sub_components_inputs .range_check_19_inputs[26] .extend([((carry_25_col191) + (M31_131072))].unpack()); -lookup_data.range_check_19[26].push([((carry_25_col191) + (M31_131072))]); +lookup_data.range_check_19_26.push([((carry_25_col191) + (M31_131072))]); let carry_26_col192 = ((((conv_mod_tmp_5745_143) + (carry_25_col191))) * (M31_4194304)); trace[192].data[row_index] = carry_26_col192; @@ -1116,7 +1117,7 @@ sub_components_inputs .range_check_19_inputs[27] .extend([((carry_26_col192) + (M31_131072))].unpack()); -lookup_data.range_check_19[27].push([((carry_26_col192) + (M31_131072))]); +lookup_data.range_check_19_27.push([((carry_26_col192) + (M31_131072))]); @@ -1247,8 +1248,8 @@ let next_pc_jnz_col228 = ((((dst_is_zero_tmp_5745_153.as_m31()) * (((input_pc_co -lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); -lookup_data.opcodes[1].push([((((((((pc_update_regular_tmp_5745_23) * (((input_pc_col0) + (((M31_1) + (op1_imm_col8))))))) + (((pc_update_jump_col13) * (((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))))))) + (((pc_update_jump_rel_col14) * (((input_pc_col0) + (((((((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))) - (msb_col221))) - (((M31_134217728) * (mid_limbs_set_col222))))))))))) + (((pc_update_jnz_col15) * (next_pc_jnz_col228)))), ((((((input_ap_col1) + (((ap_update_add_col16) * (((((((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))) - (msb_col221))) - (((M31_134217728) * (mid_limbs_set_col222))))))))) + (((ap_update_add_1_col17) * (M31_1))))) + (((opcode_call_col18) * (M31_2)))), ((((((fp_update_regular_tmp_5745_25) * (input_fp_col2))) + (((opcode_ret_col19) * (((((dst_limb_0_col22) + (((dst_limb_1_col23) * (M31_512))))) + (((dst_limb_2_col24) * (M31_262144))))))))) + (((opcode_call_col18) * (((input_ap_col1) + (M31_2))))))]); +lookup_data.opcodes_0.push([input_pc_col0, input_ap_col1, input_fp_col2]); +lookup_data.opcodes_1.push([((((((((pc_update_regular_tmp_5745_23) * (((input_pc_col0) + (((M31_1) + (op1_imm_col8))))))) + (((pc_update_jump_col13) * (((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))))))) + (((pc_update_jump_rel_col14) * (((input_pc_col0) + (((((((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))) - (msb_col221))) - (((M31_134217728) * (mid_limbs_set_col222))))))))))) + (((pc_update_jnz_col15) * (next_pc_jnz_col228)))), ((((((input_ap_col1) + (((ap_update_add_col16) * (((((((((res_limb_0_col193) + (((res_limb_1_col194) * (M31_512))))) + (((res_limb_2_col195) * (M31_262144))))) - (msb_col221))) - (((M31_134217728) * (mid_limbs_set_col222))))))))) + (((ap_update_add_1_col17) * (M31_1))))) + (((opcode_call_col18) * (M31_2)))), ((((((fp_update_regular_tmp_5745_25) * (input_fp_col2))) + (((opcode_ret_col19) * (((((dst_limb_0_col22) + (((dst_limb_1_col23) * (M31_512))))) + (((dst_limb_2_col24) * (M31_262144))))))))) + (((opcode_call_col18) * (((input_ap_col1) + (M31_2))))))]); }); @@ -1256,11 +1257,11 @@ lookup_data.opcodes[1].push([((((((((pc_update_regular_tmp_5745_23) * (((input_p } pub struct LookupData -{pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3],pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3],pub opcodes: [Vec<[PackedM31; 3]>; 2],pub range_check_19: [Vec<[PackedM31; 1]>; 28],pub range_check_9_9: [Vec<[PackedM31; 2]>; 28],pub verify_instruction: [Vec<[PackedM31; 19]>; 1],} +{memory_address_to_id_0: Vec<[PackedM31; 2]>,memory_address_to_id_1: Vec<[PackedM31; 2]>,memory_address_to_id_2: Vec<[PackedM31; 2]>,memory_id_to_big_0: Vec<[PackedM31; 29]>,memory_id_to_big_1: Vec<[PackedM31; 29]>,memory_id_to_big_2: Vec<[PackedM31; 29]>,opcodes_0: Vec<[PackedM31; 3]>,opcodes_1: Vec<[PackedM31; 3]>,range_check_19_0: Vec<[PackedM31; 1]>,range_check_19_1: Vec<[PackedM31; 1]>,range_check_19_2: Vec<[PackedM31; 1]>,range_check_19_3: Vec<[PackedM31; 1]>,range_check_19_4: Vec<[PackedM31; 1]>,range_check_19_5: Vec<[PackedM31; 1]>,range_check_19_6: Vec<[PackedM31; 1]>,range_check_19_7: Vec<[PackedM31; 1]>,range_check_19_8: Vec<[PackedM31; 1]>,range_check_19_9: Vec<[PackedM31; 1]>,range_check_19_10: Vec<[PackedM31; 1]>,range_check_19_11: Vec<[PackedM31; 1]>,range_check_19_12: Vec<[PackedM31; 1]>,range_check_19_13: Vec<[PackedM31; 1]>,range_check_19_14: Vec<[PackedM31; 1]>,range_check_19_15: Vec<[PackedM31; 1]>,range_check_19_16: Vec<[PackedM31; 1]>,range_check_19_17: Vec<[PackedM31; 1]>,range_check_19_18: Vec<[PackedM31; 1]>,range_check_19_19: Vec<[PackedM31; 1]>,range_check_19_20: Vec<[PackedM31; 1]>,range_check_19_21: Vec<[PackedM31; 1]>,range_check_19_22: Vec<[PackedM31; 1]>,range_check_19_23: Vec<[PackedM31; 1]>,range_check_19_24: Vec<[PackedM31; 1]>,range_check_19_25: Vec<[PackedM31; 1]>,range_check_19_26: Vec<[PackedM31; 1]>,range_check_19_27: Vec<[PackedM31; 1]>,range_check_9_9_0: Vec<[PackedM31; 2]>,range_check_9_9_1: Vec<[PackedM31; 2]>,range_check_9_9_2: Vec<[PackedM31; 2]>,range_check_9_9_3: Vec<[PackedM31; 2]>,range_check_9_9_4: Vec<[PackedM31; 2]>,range_check_9_9_5: Vec<[PackedM31; 2]>,range_check_9_9_6: Vec<[PackedM31; 2]>,range_check_9_9_7: Vec<[PackedM31; 2]>,range_check_9_9_8: Vec<[PackedM31; 2]>,range_check_9_9_9: Vec<[PackedM31; 2]>,range_check_9_9_10: Vec<[PackedM31; 2]>,range_check_9_9_11: Vec<[PackedM31; 2]>,range_check_9_9_12: Vec<[PackedM31; 2]>,range_check_9_9_13: Vec<[PackedM31; 2]>,range_check_9_9_14: Vec<[PackedM31; 2]>,range_check_9_9_15: Vec<[PackedM31; 2]>,range_check_9_9_16: Vec<[PackedM31; 2]>,range_check_9_9_17: Vec<[PackedM31; 2]>,range_check_9_9_18: Vec<[PackedM31; 2]>,range_check_9_9_19: Vec<[PackedM31; 2]>,range_check_9_9_20: Vec<[PackedM31; 2]>,range_check_9_9_21: Vec<[PackedM31; 2]>,range_check_9_9_22: Vec<[PackedM31; 2]>,range_check_9_9_23: Vec<[PackedM31; 2]>,range_check_9_9_24: Vec<[PackedM31; 2]>,range_check_9_9_25: Vec<[PackedM31; 2]>,range_check_9_9_26: Vec<[PackedM31; 2]>,range_check_9_9_27: Vec<[PackedM31; 2]>,verify_instruction_0: Vec<[PackedM31; 19]>,} impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { - Self {memory_address_to_id: [Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),],memory_id_to_big: [Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),],opcodes: [Vec::with_capacity(capacity),Vec::with_capacity(capacity),],range_check_19: [Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),],range_check_9_9: [Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),Vec::with_capacity(capacity),],verify_instruction: [Vec::with_capacity(capacity),],} + Self {memory_address_to_id_0: Vec::with_capacity(capacity),memory_address_to_id_1: Vec::with_capacity(capacity),memory_address_to_id_2: Vec::with_capacity(capacity),memory_id_to_big_0: Vec::with_capacity(capacity),memory_id_to_big_1: Vec::with_capacity(capacity),memory_id_to_big_2: Vec::with_capacity(capacity),opcodes_0: Vec::with_capacity(capacity),opcodes_1: Vec::with_capacity(capacity),range_check_19_0: Vec::with_capacity(capacity),range_check_19_1: Vec::with_capacity(capacity),range_check_19_2: Vec::with_capacity(capacity),range_check_19_3: Vec::with_capacity(capacity),range_check_19_4: Vec::with_capacity(capacity),range_check_19_5: Vec::with_capacity(capacity),range_check_19_6: Vec::with_capacity(capacity),range_check_19_7: Vec::with_capacity(capacity),range_check_19_8: Vec::with_capacity(capacity),range_check_19_9: Vec::with_capacity(capacity),range_check_19_10: Vec::with_capacity(capacity),range_check_19_11: Vec::with_capacity(capacity),range_check_19_12: Vec::with_capacity(capacity),range_check_19_13: Vec::with_capacity(capacity),range_check_19_14: Vec::with_capacity(capacity),range_check_19_15: Vec::with_capacity(capacity),range_check_19_16: Vec::with_capacity(capacity),range_check_19_17: Vec::with_capacity(capacity),range_check_19_18: Vec::with_capacity(capacity),range_check_19_19: Vec::with_capacity(capacity),range_check_19_20: Vec::with_capacity(capacity),range_check_19_21: Vec::with_capacity(capacity),range_check_19_22: Vec::with_capacity(capacity),range_check_19_23: Vec::with_capacity(capacity),range_check_19_24: Vec::with_capacity(capacity),range_check_19_25: Vec::with_capacity(capacity),range_check_19_26: Vec::with_capacity(capacity),range_check_19_27: Vec::with_capacity(capacity),range_check_9_9_0: Vec::with_capacity(capacity),range_check_9_9_1: Vec::with_capacity(capacity),range_check_9_9_2: Vec::with_capacity(capacity),range_check_9_9_3: Vec::with_capacity(capacity),range_check_9_9_4: Vec::with_capacity(capacity),range_check_9_9_5: Vec::with_capacity(capacity),range_check_9_9_6: Vec::with_capacity(capacity),range_check_9_9_7: Vec::with_capacity(capacity),range_check_9_9_8: Vec::with_capacity(capacity),range_check_9_9_9: Vec::with_capacity(capacity),range_check_9_9_10: Vec::with_capacity(capacity),range_check_9_9_11: Vec::with_capacity(capacity),range_check_9_9_12: Vec::with_capacity(capacity),range_check_9_9_13: Vec::with_capacity(capacity),range_check_9_9_14: Vec::with_capacity(capacity),range_check_9_9_15: Vec::with_capacity(capacity),range_check_9_9_16: Vec::with_capacity(capacity),range_check_9_9_17: Vec::with_capacity(capacity),range_check_9_9_18: Vec::with_capacity(capacity),range_check_9_9_19: Vec::with_capacity(capacity),range_check_9_9_20: Vec::with_capacity(capacity),range_check_9_9_21: Vec::with_capacity(capacity),range_check_9_9_22: Vec::with_capacity(capacity),range_check_9_9_23: Vec::with_capacity(capacity),range_check_9_9_24: Vec::with_capacity(capacity),range_check_9_9_25: Vec::with_capacity(capacity),range_check_9_9_26: Vec::with_capacity(capacity),range_check_9_9_27: Vec::with_capacity(capacity),verify_instruction_0: Vec::with_capacity(capacity),} } } @@ -1274,17 +1275,17 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: + memory_address_to_id: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: + memory_id_to_big: &relations::MemoryIdToBig, - opcodes_lookup_elements: + opcodes: &relations::Opcodes, - range_check_19_lookup_elements: + range_check_19: &relations::RangeCheck_19, - range_check_9_9_lookup_elements: + range_check_9_9: &relations::RangeCheck_9_9, - verify_instruction_lookup_elements: + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where @@ -1294,652 +1295,491 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[3]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[4]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[5]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[6]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[7]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[8]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[9]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[10]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[11]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[12]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[13]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[14]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[15]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[16]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[17]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[18]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[19]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[20]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[21]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[22]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[23]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[24]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[25]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .verify_instruction_0, + &self.lookup_data + .memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[26]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .memory_id_to_big_0, + &self.lookup_data + .memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_9_9[27]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_9_9_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .memory_id_to_big_1, + &self.lookup_data + .memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .memory_id_to_big_2, + &self.lookup_data + .range_check_9_9_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_1, + &self.lookup_data + .range_check_9_9_2, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_3, + &self.lookup_data + .range_check_9_9_4, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[3]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_5, + &self.lookup_data + .range_check_9_9_6, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[4]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_7, + &self.lookup_data + .range_check_9_9_8, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[5]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_9, + &self.lookup_data + .range_check_9_9_10, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[6]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_11, + &self.lookup_data + .range_check_9_9_12, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[7]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_13, + &self.lookup_data + .range_check_9_9_14, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[8]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_15, + &self.lookup_data + .range_check_9_9_16, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[9]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_17, + &self.lookup_data + .range_check_9_9_18, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[10]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_19, + &self.lookup_data + .range_check_9_9_20, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[11]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_21, + &self.lookup_data + .range_check_9_9_22, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[12]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_23, + &self.lookup_data + .range_check_9_9_24, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[13]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_25, + &self.lookup_data + .range_check_9_9_26, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_9_9.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[14]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_9_9_27, + &self.lookup_data + .range_check_19_0, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_9_9.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[15]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_1, + &self.lookup_data + .range_check_19_2, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[16]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_3, + &self.lookup_data + .range_check_19_4, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[17]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_5, + &self.lookup_data + .range_check_19_6, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[18]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_7, + &self.lookup_data + .range_check_19_8, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[19]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_9, + &self.lookup_data + .range_check_19_10, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[20]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_11, + &self.lookup_data + .range_check_19_12, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[21]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_13, + &self.lookup_data + .range_check_19_14, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[22]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_15, + &self.lookup_data + .range_check_19_16, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[23]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_17, + &self.lookup_data + .range_check_19_18, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[24]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_19, + &self.lookup_data + .range_check_19_20, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[25]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_21, + &self.lookup_data + .range_check_19_22, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[26]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_23, + &self.lookup_data + .range_check_19_24, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .range_check_19[27]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_25, + &self.lookup_data + .range_check_19_26, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data + .range_check_19_27, + &self.lookup_data + .opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i,p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data - .opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = - opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data + .opcodes_1.iter().enumerate() { + let p0 = + opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs index 0330b048..6fd99188 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 34]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -241,7 +241,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs index 92a35fcd..7a435d9b 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -215,7 +217,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -248,7 +250,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_ap_col1) + ((offset0_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_ap_col1) + ((offset0_col3) - (M31_32768))), dst_id_col5, ]); @@ -310,7 +312,7 @@ pub fn write_trace_simd( trace[33].data[row_index] = dst_limb_27_col33; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col5.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col5, dst_limb_0_col6, dst_limb_1_col7, @@ -342,8 +344,10 @@ pub fn write_trace_simd( dst_limb_27_col33, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col4)), input_fp_col2, @@ -355,19 +359,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -380,10 +386,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -392,42 +398,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs index 5e315c6a..54835d55 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 34]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -241,7 +241,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs index e3475fa6..1e761da1 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_f_dst_base_fp_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -215,7 +217,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -248,7 +250,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_fp_col2) + ((offset0_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_fp_col2) + ((offset0_col3) - (M31_32768))), dst_id_col5, ]); @@ -310,7 +312,7 @@ pub fn write_trace_simd( trace[33].data[row_index] = dst_limb_27_col33; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col5.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col5, dst_limb_0_col6, dst_limb_1_col7, @@ -342,8 +344,10 @@ pub fn write_trace_simd( dst_limb_27_col33, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col4)), input_fp_col2, @@ -355,19 +359,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -380,10 +386,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -392,42 +398,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs index e546a601..5bab6d9d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 42]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 7]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 4]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -363,7 +363,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs index b15197b1..ceeb32dd 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -220,7 +222,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -253,7 +255,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_ap_col1) + ((offset0_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_ap_col1) + ((offset0_col3) - (M31_32768))), dst_id_col5, ]); @@ -315,7 +317,7 @@ pub fn write_trace_simd( trace[33].data[row_index] = dst_limb_27_col33; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col5.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col5, dst_limb_0_col6, dst_limb_1_col7, @@ -426,7 +428,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_pc_col0) + (M31_1)), next_pc_id_col36]); // Cond Decode Small Sign. @@ -447,7 +450,7 @@ pub fn write_trace_simd( trace[41].data[row_index] = next_pc_limb_2_col41; sub_components_inputs.memory_id_to_big_inputs[1].extend(next_pc_id_col36.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ next_pc_id_col36, next_pc_limb_0_col39, next_pc_limb_1_col40, @@ -479,8 +482,10 @@ pub fn write_trace_simd( ((msb_col37) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (((((next_pc_limb_0_col39) + ((next_pc_limb_1_col40) * (M31_512))) + ((next_pc_limb_2_col41) * (M31_262144))) @@ -496,19 +501,25 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -521,10 +532,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -533,58 +544,48 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs index 04d1b992..dc2f232a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 42]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 7]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 4]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -363,7 +363,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs index f88052d0..2b3cb798 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jnz_opcode_is_taken_t_dst_base_fp_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -220,7 +222,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, M31_32767, @@ -253,7 +255,7 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_fp_col2) + ((offset0_col3) - (M31_32768))).unpack()); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((input_fp_col2) + ((offset0_col3) - (M31_32768))), dst_id_col5, ]); @@ -315,7 +317,7 @@ pub fn write_trace_simd( trace[33].data[row_index] = dst_limb_27_col33; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col5.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col5, dst_limb_0_col6, dst_limb_1_col7, @@ -426,7 +428,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_pc_col0) + (M31_1)), next_pc_id_col36]); // Cond Decode Small Sign. @@ -447,7 +450,7 @@ pub fn write_trace_simd( trace[41].data[row_index] = next_pc_limb_2_col41; sub_components_inputs.memory_id_to_big_inputs[1].extend(next_pc_id_col36.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ next_pc_id_col36, next_pc_limb_0_col39, next_pc_limb_1_col40, @@ -479,8 +482,10 @@ pub fn write_trace_simd( ((msb_col37) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (((((next_pc_limb_0_col39) + ((next_pc_limb_1_col40) * (M31_512))) + ((next_pc_limb_2_col41) * (M31_262144))) @@ -496,19 +501,25 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -521,10 +532,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -533,58 +544,48 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs index 60c0bcde..980f250b 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 11]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -169,7 +169,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs index 873f6dcc..818c2d1d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -238,7 +240,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -276,7 +278,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((op1_base_fp_col4) * (input_fp_col2)) + ((op1_base_ap_col5) * (input_ap_col1))) + ((offset2_col3) - (M31_32768))), next_pc_id_col7, @@ -289,7 +291,7 @@ pub fn write_trace_simd( trace[10].data[row_index] = next_pc_limb_2_col10; sub_components_inputs.memory_id_to_big_inputs[0].extend(next_pc_id_col7.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ next_pc_id_col7, next_pc_limb_0_col8, next_pc_limb_1_col9, @@ -321,8 +323,10 @@ pub fn write_trace_simd( M31_0, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ (((next_pc_limb_0_col8) + ((next_pc_limb_1_col9) * (M31_512))) + ((next_pc_limb_2_col10) * (M31_262144))), ((input_ap_col1) + (ap_update_add_1_col6)), @@ -335,19 +339,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -360,10 +366,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -372,42 +378,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs index 92ddd221..d0725dba 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 15]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 7]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 4]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -193,7 +193,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs index c9f5143d..b67666d1 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_f_is_imm_f_is_double_deref_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -241,7 +243,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, offset1_col3, @@ -281,7 +283,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((op0_base_fp_col5) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col5)) * (input_ap_col1))) + ((offset1_col3) - (M31_32768))), @@ -295,7 +297,7 @@ pub fn write_trace_simd( trace[10].data[row_index] = mem1_base_limb_2_col10; sub_components_inputs.memory_id_to_big_inputs[0].extend(mem1_base_id_col7.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ mem1_base_id_col7, mem1_base_limb_0_col8, mem1_base_limb_1_col9, @@ -345,7 +347,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((mem1_base_limb_0_col8) + ((mem1_base_limb_1_col9) * (M31_512))) + ((mem1_base_limb_2_col10) * (M31_262144))) + ((offset2_col4) - (M31_32768))), @@ -359,7 +361,7 @@ pub fn write_trace_simd( trace[14].data[row_index] = next_pc_limb_2_col14; sub_components_inputs.memory_id_to_big_inputs[1].extend(next_pc_id_col11.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ next_pc_id_col11, next_pc_limb_0_col12, next_pc_limb_1_col13, @@ -391,8 +393,10 @@ pub fn write_trace_simd( M31_0, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ (((next_pc_limb_0_col12) + ((next_pc_limb_1_col13) * (M31_512))) + ((next_pc_limb_2_col14) * (M31_262144))), ((input_ap_col1) + (ap_update_add_1_col6)), @@ -405,19 +409,25 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -430,10 +440,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -442,58 +452,48 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs index a1a7ff87..afe0a55a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 13]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -217,7 +217,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs index fa9f65b9..d6169850 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_f_is_double_deref_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -242,7 +244,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -280,7 +282,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((op1_base_fp_col4) * (input_fp_col2)) + ((op1_base_ap_col5) * (input_ap_col1))) + ((offset2_col3) - (M31_32768))), next_pc_id_col7, @@ -304,7 +306,7 @@ pub fn write_trace_simd( trace[12].data[row_index] = next_pc_limb_2_col12; sub_components_inputs.memory_id_to_big_inputs[0].extend(next_pc_id_col7.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ next_pc_id_col7, next_pc_limb_0_col10, next_pc_limb_1_col11, @@ -336,8 +338,10 @@ pub fn write_trace_simd( ((msb_col8) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (((((next_pc_limb_0_col10) + ((next_pc_limb_1_col11) * (M31_512))) + ((next_pc_limb_2_col12) * (M31_262144))) @@ -353,19 +357,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -378,10 +384,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -390,42 +396,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs index 069d4c76..5cc022cd 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 10]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 5]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -207,7 +207,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs index cda40997..3ed3956a 100644 --- a/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/jump_opcode_is_rel_t_is_imm_t_is_double_deref_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -210,7 +212,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32767, M31_32767, @@ -243,7 +245,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[0] + lookup_data + .memory_address_to_id_0 .push([((input_pc_col0) + (M31_1)), next_pc_id_col4]); // Cond Decode Small Sign. @@ -264,7 +267,7 @@ pub fn write_trace_simd( trace[9].data[row_index] = next_pc_limb_2_col9; sub_components_inputs.memory_id_to_big_inputs[0].extend(next_pc_id_col4.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ next_pc_id_col4, next_pc_limb_0_col7, next_pc_limb_1_col8, @@ -296,8 +299,10 @@ pub fn write_trace_simd( ((msb_col5) * (M31_256)), ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (((((next_pc_limb_0_col7) + ((next_pc_limb_1_col8) * (M31_512))) + ((next_pc_limb_2_col9) * (M31_262144))) @@ -313,19 +318,21 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 1], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 1], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -338,10 +345,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -350,42 +357,35 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs index d194ba33..bc2164f4 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/component.rs @@ -33,7 +33,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 126]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 37]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 19]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -1815,7 +1815,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs index 2bb01a78..8b11ca36 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_f/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -302,7 +304,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -342,7 +344,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col6)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -406,7 +408,7 @@ pub fn write_trace_simd( trace[39].data[row_index] = dst_limb_27_col39; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col11.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col11, dst_limb_0_col12, dst_limb_1_col13, @@ -456,7 +458,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col7) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col7)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -520,7 +522,7 @@ pub fn write_trace_simd( trace[68].data[row_index] = op0_limb_27_col68; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col40.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col40, op0_limb_0_col41, op0_limb_1_col42, @@ -568,7 +570,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[2].push([ + lookup_data.memory_address_to_id_2.push([ ((((op1_base_fp_col8) * (input_fp_col2)) + ((op1_base_ap_col9) * (input_ap_col1))) + ((offset2_col5) - (M31_32768))), op1_id_col69, @@ -631,7 +633,7 @@ pub fn write_trace_simd( trace[97].data[row_index] = op1_limb_27_col97; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col69.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col69, op1_limb_0_col70, op1_limb_1_col71, @@ -1634,7 +1636,9 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[0] .extend([((k_col98) + (M31_262144))].unpack()); - lookup_data.range_check_19[0].push([((k_col98) + (M31_262144))]); + lookup_data + .range_check_19_0 + .push([((k_col98) + (M31_262144))]); let carry_0_col99 = ((((conv_mod_tmp_5a14_72) - ((M31_1) * (k_col98))) + (M31_0)) * (M31_4194304)); trace[99].data[row_index] = carry_0_col99; @@ -1642,147 +1646,189 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[1] .extend([((carry_0_col99) + (M31_131072))].unpack()); - lookup_data.range_check_19[1].push([((carry_0_col99) + (M31_131072))]); + lookup_data + .range_check_19_1 + .push([((carry_0_col99) + (M31_131072))]); let carry_1_col100 = (((conv_mod_tmp_5a14_73) + (carry_0_col99)) * (M31_4194304)); trace[100].data[row_index] = carry_1_col100; sub_components_inputs.range_check_19_inputs[2] .extend([((carry_1_col100) + (M31_131072))].unpack()); - lookup_data.range_check_19[2].push([((carry_1_col100) + (M31_131072))]); + lookup_data + .range_check_19_2 + .push([((carry_1_col100) + (M31_131072))]); let carry_2_col101 = (((conv_mod_tmp_5a14_74) + (carry_1_col100)) * (M31_4194304)); trace[101].data[row_index] = carry_2_col101; sub_components_inputs.range_check_19_inputs[3] .extend([((carry_2_col101) + (M31_131072))].unpack()); - lookup_data.range_check_19[3].push([((carry_2_col101) + (M31_131072))]); + lookup_data + .range_check_19_3 + .push([((carry_2_col101) + (M31_131072))]); let carry_3_col102 = (((conv_mod_tmp_5a14_75) + (carry_2_col101)) * (M31_4194304)); trace[102].data[row_index] = carry_3_col102; sub_components_inputs.range_check_19_inputs[4] .extend([((carry_3_col102) + (M31_131072))].unpack()); - lookup_data.range_check_19[4].push([((carry_3_col102) + (M31_131072))]); + lookup_data + .range_check_19_4 + .push([((carry_3_col102) + (M31_131072))]); let carry_4_col103 = (((conv_mod_tmp_5a14_76) + (carry_3_col102)) * (M31_4194304)); trace[103].data[row_index] = carry_4_col103; sub_components_inputs.range_check_19_inputs[5] .extend([((carry_4_col103) + (M31_131072))].unpack()); - lookup_data.range_check_19[5].push([((carry_4_col103) + (M31_131072))]); + lookup_data + .range_check_19_5 + .push([((carry_4_col103) + (M31_131072))]); let carry_5_col104 = (((conv_mod_tmp_5a14_77) + (carry_4_col103)) * (M31_4194304)); trace[104].data[row_index] = carry_5_col104; sub_components_inputs.range_check_19_inputs[6] .extend([((carry_5_col104) + (M31_131072))].unpack()); - lookup_data.range_check_19[6].push([((carry_5_col104) + (M31_131072))]); + lookup_data + .range_check_19_6 + .push([((carry_5_col104) + (M31_131072))]); let carry_6_col105 = (((conv_mod_tmp_5a14_78) + (carry_5_col104)) * (M31_4194304)); trace[105].data[row_index] = carry_6_col105; sub_components_inputs.range_check_19_inputs[7] .extend([((carry_6_col105) + (M31_131072))].unpack()); - lookup_data.range_check_19[7].push([((carry_6_col105) + (M31_131072))]); + lookup_data + .range_check_19_7 + .push([((carry_6_col105) + (M31_131072))]); let carry_7_col106 = (((conv_mod_tmp_5a14_79) + (carry_6_col105)) * (M31_4194304)); trace[106].data[row_index] = carry_7_col106; sub_components_inputs.range_check_19_inputs[8] .extend([((carry_7_col106) + (M31_131072))].unpack()); - lookup_data.range_check_19[8].push([((carry_7_col106) + (M31_131072))]); + lookup_data + .range_check_19_8 + .push([((carry_7_col106) + (M31_131072))]); let carry_8_col107 = (((conv_mod_tmp_5a14_80) + (carry_7_col106)) * (M31_4194304)); trace[107].data[row_index] = carry_8_col107; sub_components_inputs.range_check_19_inputs[9] .extend([((carry_8_col107) + (M31_131072))].unpack()); - lookup_data.range_check_19[9].push([((carry_8_col107) + (M31_131072))]); + lookup_data + .range_check_19_9 + .push([((carry_8_col107) + (M31_131072))]); let carry_9_col108 = (((conv_mod_tmp_5a14_81) + (carry_8_col107)) * (M31_4194304)); trace[108].data[row_index] = carry_9_col108; sub_components_inputs.range_check_19_inputs[10] .extend([((carry_9_col108) + (M31_131072))].unpack()); - lookup_data.range_check_19[10].push([((carry_9_col108) + (M31_131072))]); + lookup_data + .range_check_19_10 + .push([((carry_9_col108) + (M31_131072))]); let carry_10_col109 = (((conv_mod_tmp_5a14_82) + (carry_9_col108)) * (M31_4194304)); trace[109].data[row_index] = carry_10_col109; sub_components_inputs.range_check_19_inputs[11] .extend([((carry_10_col109) + (M31_131072))].unpack()); - lookup_data.range_check_19[11].push([((carry_10_col109) + (M31_131072))]); + lookup_data + .range_check_19_11 + .push([((carry_10_col109) + (M31_131072))]); let carry_11_col110 = (((conv_mod_tmp_5a14_83) + (carry_10_col109)) * (M31_4194304)); trace[110].data[row_index] = carry_11_col110; sub_components_inputs.range_check_19_inputs[12] .extend([((carry_11_col110) + (M31_131072))].unpack()); - lookup_data.range_check_19[12].push([((carry_11_col110) + (M31_131072))]); + lookup_data + .range_check_19_12 + .push([((carry_11_col110) + (M31_131072))]); let carry_12_col111 = (((conv_mod_tmp_5a14_84) + (carry_11_col110)) * (M31_4194304)); trace[111].data[row_index] = carry_12_col111; sub_components_inputs.range_check_19_inputs[13] .extend([((carry_12_col111) + (M31_131072))].unpack()); - lookup_data.range_check_19[13].push([((carry_12_col111) + (M31_131072))]); + lookup_data + .range_check_19_13 + .push([((carry_12_col111) + (M31_131072))]); let carry_13_col112 = (((conv_mod_tmp_5a14_85) + (carry_12_col111)) * (M31_4194304)); trace[112].data[row_index] = carry_13_col112; sub_components_inputs.range_check_19_inputs[14] .extend([((carry_13_col112) + (M31_131072))].unpack()); - lookup_data.range_check_19[14].push([((carry_13_col112) + (M31_131072))]); + lookup_data + .range_check_19_14 + .push([((carry_13_col112) + (M31_131072))]); let carry_14_col113 = (((conv_mod_tmp_5a14_86) + (carry_13_col112)) * (M31_4194304)); trace[113].data[row_index] = carry_14_col113; sub_components_inputs.range_check_19_inputs[15] .extend([((carry_14_col113) + (M31_131072))].unpack()); - lookup_data.range_check_19[15].push([((carry_14_col113) + (M31_131072))]); + lookup_data + .range_check_19_15 + .push([((carry_14_col113) + (M31_131072))]); let carry_15_col114 = (((conv_mod_tmp_5a14_87) + (carry_14_col113)) * (M31_4194304)); trace[114].data[row_index] = carry_15_col114; sub_components_inputs.range_check_19_inputs[16] .extend([((carry_15_col114) + (M31_131072))].unpack()); - lookup_data.range_check_19[16].push([((carry_15_col114) + (M31_131072))]); + lookup_data + .range_check_19_16 + .push([((carry_15_col114) + (M31_131072))]); let carry_16_col115 = (((conv_mod_tmp_5a14_88) + (carry_15_col114)) * (M31_4194304)); trace[115].data[row_index] = carry_16_col115; sub_components_inputs.range_check_19_inputs[17] .extend([((carry_16_col115) + (M31_131072))].unpack()); - lookup_data.range_check_19[17].push([((carry_16_col115) + (M31_131072))]); + lookup_data + .range_check_19_17 + .push([((carry_16_col115) + (M31_131072))]); let carry_17_col116 = (((conv_mod_tmp_5a14_89) + (carry_16_col115)) * (M31_4194304)); trace[116].data[row_index] = carry_17_col116; sub_components_inputs.range_check_19_inputs[18] .extend([((carry_17_col116) + (M31_131072))].unpack()); - lookup_data.range_check_19[18].push([((carry_17_col116) + (M31_131072))]); + lookup_data + .range_check_19_18 + .push([((carry_17_col116) + (M31_131072))]); let carry_18_col117 = (((conv_mod_tmp_5a14_90) + (carry_17_col116)) * (M31_4194304)); trace[117].data[row_index] = carry_18_col117; sub_components_inputs.range_check_19_inputs[19] .extend([((carry_18_col117) + (M31_131072))].unpack()); - lookup_data.range_check_19[19].push([((carry_18_col117) + (M31_131072))]); + lookup_data + .range_check_19_19 + .push([((carry_18_col117) + (M31_131072))]); let carry_19_col118 = (((conv_mod_tmp_5a14_91) + (carry_18_col117)) * (M31_4194304)); trace[118].data[row_index] = carry_19_col118; sub_components_inputs.range_check_19_inputs[20] .extend([((carry_19_col118) + (M31_131072))].unpack()); - lookup_data.range_check_19[20].push([((carry_19_col118) + (M31_131072))]); + lookup_data + .range_check_19_20 + .push([((carry_19_col118) + (M31_131072))]); let carry_20_col119 = (((conv_mod_tmp_5a14_92) + (carry_19_col118)) * (M31_4194304)); trace[119].data[row_index] = carry_20_col119; sub_components_inputs.range_check_19_inputs[21] .extend([((carry_20_col119) + (M31_131072))].unpack()); - lookup_data.range_check_19[21].push([((carry_20_col119) + (M31_131072))]); + lookup_data + .range_check_19_21 + .push([((carry_20_col119) + (M31_131072))]); let carry_21_col120 = ((((conv_mod_tmp_5a14_93) - ((M31_136) * (k_col98))) + (carry_20_col119)) * (M31_4194304)); @@ -1791,45 +1837,59 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[22] .extend([((carry_21_col120) + (M31_131072))].unpack()); - lookup_data.range_check_19[22].push([((carry_21_col120) + (M31_131072))]); + lookup_data + .range_check_19_22 + .push([((carry_21_col120) + (M31_131072))]); let carry_22_col121 = (((conv_mod_tmp_5a14_94) + (carry_21_col120)) * (M31_4194304)); trace[121].data[row_index] = carry_22_col121; sub_components_inputs.range_check_19_inputs[23] .extend([((carry_22_col121) + (M31_131072))].unpack()); - lookup_data.range_check_19[23].push([((carry_22_col121) + (M31_131072))]); + lookup_data + .range_check_19_23 + .push([((carry_22_col121) + (M31_131072))]); let carry_23_col122 = (((conv_mod_tmp_5a14_95) + (carry_22_col121)) * (M31_4194304)); trace[122].data[row_index] = carry_23_col122; sub_components_inputs.range_check_19_inputs[24] .extend([((carry_23_col122) + (M31_131072))].unpack()); - lookup_data.range_check_19[24].push([((carry_23_col122) + (M31_131072))]); + lookup_data + .range_check_19_24 + .push([((carry_23_col122) + (M31_131072))]); let carry_24_col123 = (((conv_mod_tmp_5a14_96) + (carry_23_col122)) * (M31_4194304)); trace[123].data[row_index] = carry_24_col123; sub_components_inputs.range_check_19_inputs[25] .extend([((carry_24_col123) + (M31_131072))].unpack()); - lookup_data.range_check_19[25].push([((carry_24_col123) + (M31_131072))]); + lookup_data + .range_check_19_25 + .push([((carry_24_col123) + (M31_131072))]); let carry_25_col124 = (((conv_mod_tmp_5a14_97) + (carry_24_col123)) * (M31_4194304)); trace[124].data[row_index] = carry_25_col124; sub_components_inputs.range_check_19_inputs[26] .extend([((carry_25_col124) + (M31_131072))].unpack()); - lookup_data.range_check_19[26].push([((carry_25_col124) + (M31_131072))]); + lookup_data + .range_check_19_26 + .push([((carry_25_col124) + (M31_131072))]); let carry_26_col125 = (((conv_mod_tmp_5a14_98) + (carry_25_col124)) * (M31_4194304)); trace[125].data[row_index] = carry_26_col125; sub_components_inputs.range_check_19_inputs[27] .extend([((carry_26_col125) + (M31_131072))].unpack()); - lookup_data.range_check_19[27].push([((carry_26_col125) + (M31_131072))]); + lookup_data + .range_check_19_27 + .push([((carry_26_col125) + (M31_131072))]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_1)), ((input_ap_col1) + (ap_update_add_1_col10)), input_fp_col2, @@ -1840,58 +1900,85 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub range_check_19: [Vec<[PackedM31; 1]>; 28], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + range_check_19_0: Vec<[PackedM31; 1]>, + range_check_19_1: Vec<[PackedM31; 1]>, + range_check_19_2: Vec<[PackedM31; 1]>, + range_check_19_3: Vec<[PackedM31; 1]>, + range_check_19_4: Vec<[PackedM31; 1]>, + range_check_19_5: Vec<[PackedM31; 1]>, + range_check_19_6: Vec<[PackedM31; 1]>, + range_check_19_7: Vec<[PackedM31; 1]>, + range_check_19_8: Vec<[PackedM31; 1]>, + range_check_19_9: Vec<[PackedM31; 1]>, + range_check_19_10: Vec<[PackedM31; 1]>, + range_check_19_11: Vec<[PackedM31; 1]>, + range_check_19_12: Vec<[PackedM31; 1]>, + range_check_19_13: Vec<[PackedM31; 1]>, + range_check_19_14: Vec<[PackedM31; 1]>, + range_check_19_15: Vec<[PackedM31; 1]>, + range_check_19_16: Vec<[PackedM31; 1]>, + range_check_19_17: Vec<[PackedM31; 1]>, + range_check_19_18: Vec<[PackedM31; 1]>, + range_check_19_19: Vec<[PackedM31; 1]>, + range_check_19_20: Vec<[PackedM31; 1]>, + range_check_19_21: Vec<[PackedM31; 1]>, + range_check_19_22: Vec<[PackedM31; 1]>, + range_check_19_23: Vec<[PackedM31; 1]>, + range_check_19_24: Vec<[PackedM31; 1]>, + range_check_19_25: Vec<[PackedM31; 1]>, + range_check_19_26: Vec<[PackedM31; 1]>, + range_check_19_27: Vec<[PackedM31; 1]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - range_check_19: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + range_check_19_0: Vec::with_capacity(capacity), + range_check_19_1: Vec::with_capacity(capacity), + range_check_19_2: Vec::with_capacity(capacity), + range_check_19_3: Vec::with_capacity(capacity), + range_check_19_4: Vec::with_capacity(capacity), + range_check_19_5: Vec::with_capacity(capacity), + range_check_19_6: Vec::with_capacity(capacity), + range_check_19_7: Vec::with_capacity(capacity), + range_check_19_8: Vec::with_capacity(capacity), + range_check_19_9: Vec::with_capacity(capacity), + range_check_19_10: Vec::with_capacity(capacity), + range_check_19_11: Vec::with_capacity(capacity), + range_check_19_12: Vec::with_capacity(capacity), + range_check_19_13: Vec::with_capacity(capacity), + range_check_19_14: Vec::with_capacity(capacity), + range_check_19_15: Vec::with_capacity(capacity), + range_check_19_16: Vec::with_capacity(capacity), + range_check_19_17: Vec::with_capacity(capacity), + range_check_19_18: Vec::with_capacity(capacity), + range_check_19_19: Vec::with_capacity(capacity), + range_check_19_20: Vec::with_capacity(capacity), + range_check_19_21: Vec::with_capacity(capacity), + range_check_19_22: Vec::with_capacity(capacity), + range_check_19_23: Vec::with_capacity(capacity), + range_check_19_24: Vec::with_capacity(capacity), + range_check_19_25: Vec::with_capacity(capacity), + range_check_19_26: Vec::with_capacity(capacity), + range_check_19_27: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -1904,11 +1991,11 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - range_check_19_lookup_elements: &relations::RangeCheck_19, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + range_check_19: &relations::RangeCheck_19, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -1917,298 +2004,243 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[3]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[4]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[5]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[6]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[7]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[8]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[9]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[10]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[11]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[12]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[13]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[14]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.range_check_19_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[15]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_1, + &self.lookup_data.range_check_19_2, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[16]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_3, + &self.lookup_data.range_check_19_4, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[17]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_5, + &self.lookup_data.range_check_19_6, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[18]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_7, + &self.lookup_data.range_check_19_8, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[19]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_9, + &self.lookup_data.range_check_19_10, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[20]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_11, + &self.lookup_data.range_check_19_12, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[21]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_13, + &self.lookup_data.range_check_19_14, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[22]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_15, + &self.lookup_data.range_check_19_16, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[23]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_17, + &self.lookup_data.range_check_19_18, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[24]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_19, + &self.lookup_data.range_check_19_20, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[25]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_21, + &self.lookup_data.range_check_19_22, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[26]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_23, + &self.lookup_data.range_check_19_24, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[27]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_25, + &self.lookup_data.range_check_19_26, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_27, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs index ce1d4ce3..a687104c 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/component.rs @@ -33,7 +33,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 123]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 37]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 19]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -1806,7 +1806,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs index 72be7e18..6d487662 100644 --- a/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/mul_opcode_is_small_f_is_imm_t/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -272,7 +274,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, offset0_col3, offset1_col4, @@ -312,7 +314,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[0].push([ + lookup_data.memory_address_to_id_0.push([ ((((dst_base_fp_col5) * (input_fp_col2)) + (((M31_1) - (dst_base_fp_col5)) * (input_ap_col1))) + ((offset0_col3) - (M31_32768))), @@ -376,7 +378,7 @@ pub fn write_trace_simd( trace[36].data[row_index] = dst_limb_27_col36; sub_components_inputs.memory_id_to_big_inputs[0].extend(dst_id_col8.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ dst_id_col8, dst_limb_0_col9, dst_limb_1_col10, @@ -426,7 +428,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.memory_address_to_id[1].push([ + lookup_data.memory_address_to_id_1.push([ ((((op0_base_fp_col6) * (input_fp_col2)) + (((M31_1) - (op0_base_fp_col6)) * (input_ap_col1))) + ((offset1_col4) - (M31_32768))), @@ -490,7 +492,7 @@ pub fn write_trace_simd( trace[65].data[row_index] = op0_limb_27_col65; sub_components_inputs.memory_id_to_big_inputs[1].extend(op0_id_col37.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ op0_id_col37, op0_limb_0_col38, op0_limb_1_col39, @@ -533,7 +535,9 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[2] .extend(((input_pc_col0) + (M31_1)).unpack()); - lookup_data.memory_address_to_id[2].push([((input_pc_col0) + (M31_1)), op1_id_col66]); + lookup_data + .memory_address_to_id_2 + .push([((input_pc_col0) + (M31_1)), op1_id_col66]); let op1_limb_0_col67 = memory_id_to_big_value_tmp_31b3_13.get_m31(0); trace[67].data[row_index] = op1_limb_0_col67; let op1_limb_1_col68 = memory_id_to_big_value_tmp_31b3_13.get_m31(1); @@ -592,7 +596,7 @@ pub fn write_trace_simd( trace[94].data[row_index] = op1_limb_27_col94; sub_components_inputs.memory_id_to_big_inputs[2].extend(op1_id_col66.unpack()); - lookup_data.memory_id_to_big[2].push([ + lookup_data.memory_id_to_big_2.push([ op1_id_col66, op1_limb_0_col67, op1_limb_1_col68, @@ -1595,7 +1599,9 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[0] .extend([((k_col95) + (M31_262144))].unpack()); - lookup_data.range_check_19[0].push([((k_col95) + (M31_262144))]); + lookup_data + .range_check_19_0 + .push([((k_col95) + (M31_262144))]); let carry_0_col96 = ((((conv_mod_tmp_31b3_69) - ((M31_1) * (k_col95))) + (M31_0)) * (M31_4194304)); trace[96].data[row_index] = carry_0_col96; @@ -1603,147 +1609,189 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[1] .extend([((carry_0_col96) + (M31_131072))].unpack()); - lookup_data.range_check_19[1].push([((carry_0_col96) + (M31_131072))]); + lookup_data + .range_check_19_1 + .push([((carry_0_col96) + (M31_131072))]); let carry_1_col97 = (((conv_mod_tmp_31b3_70) + (carry_0_col96)) * (M31_4194304)); trace[97].data[row_index] = carry_1_col97; sub_components_inputs.range_check_19_inputs[2] .extend([((carry_1_col97) + (M31_131072))].unpack()); - lookup_data.range_check_19[2].push([((carry_1_col97) + (M31_131072))]); + lookup_data + .range_check_19_2 + .push([((carry_1_col97) + (M31_131072))]); let carry_2_col98 = (((conv_mod_tmp_31b3_71) + (carry_1_col97)) * (M31_4194304)); trace[98].data[row_index] = carry_2_col98; sub_components_inputs.range_check_19_inputs[3] .extend([((carry_2_col98) + (M31_131072))].unpack()); - lookup_data.range_check_19[3].push([((carry_2_col98) + (M31_131072))]); + lookup_data + .range_check_19_3 + .push([((carry_2_col98) + (M31_131072))]); let carry_3_col99 = (((conv_mod_tmp_31b3_72) + (carry_2_col98)) * (M31_4194304)); trace[99].data[row_index] = carry_3_col99; sub_components_inputs.range_check_19_inputs[4] .extend([((carry_3_col99) + (M31_131072))].unpack()); - lookup_data.range_check_19[4].push([((carry_3_col99) + (M31_131072))]); + lookup_data + .range_check_19_4 + .push([((carry_3_col99) + (M31_131072))]); let carry_4_col100 = (((conv_mod_tmp_31b3_73) + (carry_3_col99)) * (M31_4194304)); trace[100].data[row_index] = carry_4_col100; sub_components_inputs.range_check_19_inputs[5] .extend([((carry_4_col100) + (M31_131072))].unpack()); - lookup_data.range_check_19[5].push([((carry_4_col100) + (M31_131072))]); + lookup_data + .range_check_19_5 + .push([((carry_4_col100) + (M31_131072))]); let carry_5_col101 = (((conv_mod_tmp_31b3_74) + (carry_4_col100)) * (M31_4194304)); trace[101].data[row_index] = carry_5_col101; sub_components_inputs.range_check_19_inputs[6] .extend([((carry_5_col101) + (M31_131072))].unpack()); - lookup_data.range_check_19[6].push([((carry_5_col101) + (M31_131072))]); + lookup_data + .range_check_19_6 + .push([((carry_5_col101) + (M31_131072))]); let carry_6_col102 = (((conv_mod_tmp_31b3_75) + (carry_5_col101)) * (M31_4194304)); trace[102].data[row_index] = carry_6_col102; sub_components_inputs.range_check_19_inputs[7] .extend([((carry_6_col102) + (M31_131072))].unpack()); - lookup_data.range_check_19[7].push([((carry_6_col102) + (M31_131072))]); + lookup_data + .range_check_19_7 + .push([((carry_6_col102) + (M31_131072))]); let carry_7_col103 = (((conv_mod_tmp_31b3_76) + (carry_6_col102)) * (M31_4194304)); trace[103].data[row_index] = carry_7_col103; sub_components_inputs.range_check_19_inputs[8] .extend([((carry_7_col103) + (M31_131072))].unpack()); - lookup_data.range_check_19[8].push([((carry_7_col103) + (M31_131072))]); + lookup_data + .range_check_19_8 + .push([((carry_7_col103) + (M31_131072))]); let carry_8_col104 = (((conv_mod_tmp_31b3_77) + (carry_7_col103)) * (M31_4194304)); trace[104].data[row_index] = carry_8_col104; sub_components_inputs.range_check_19_inputs[9] .extend([((carry_8_col104) + (M31_131072))].unpack()); - lookup_data.range_check_19[9].push([((carry_8_col104) + (M31_131072))]); + lookup_data + .range_check_19_9 + .push([((carry_8_col104) + (M31_131072))]); let carry_9_col105 = (((conv_mod_tmp_31b3_78) + (carry_8_col104)) * (M31_4194304)); trace[105].data[row_index] = carry_9_col105; sub_components_inputs.range_check_19_inputs[10] .extend([((carry_9_col105) + (M31_131072))].unpack()); - lookup_data.range_check_19[10].push([((carry_9_col105) + (M31_131072))]); + lookup_data + .range_check_19_10 + .push([((carry_9_col105) + (M31_131072))]); let carry_10_col106 = (((conv_mod_tmp_31b3_79) + (carry_9_col105)) * (M31_4194304)); trace[106].data[row_index] = carry_10_col106; sub_components_inputs.range_check_19_inputs[11] .extend([((carry_10_col106) + (M31_131072))].unpack()); - lookup_data.range_check_19[11].push([((carry_10_col106) + (M31_131072))]); + lookup_data + .range_check_19_11 + .push([((carry_10_col106) + (M31_131072))]); let carry_11_col107 = (((conv_mod_tmp_31b3_80) + (carry_10_col106)) * (M31_4194304)); trace[107].data[row_index] = carry_11_col107; sub_components_inputs.range_check_19_inputs[12] .extend([((carry_11_col107) + (M31_131072))].unpack()); - lookup_data.range_check_19[12].push([((carry_11_col107) + (M31_131072))]); + lookup_data + .range_check_19_12 + .push([((carry_11_col107) + (M31_131072))]); let carry_12_col108 = (((conv_mod_tmp_31b3_81) + (carry_11_col107)) * (M31_4194304)); trace[108].data[row_index] = carry_12_col108; sub_components_inputs.range_check_19_inputs[13] .extend([((carry_12_col108) + (M31_131072))].unpack()); - lookup_data.range_check_19[13].push([((carry_12_col108) + (M31_131072))]); + lookup_data + .range_check_19_13 + .push([((carry_12_col108) + (M31_131072))]); let carry_13_col109 = (((conv_mod_tmp_31b3_82) + (carry_12_col108)) * (M31_4194304)); trace[109].data[row_index] = carry_13_col109; sub_components_inputs.range_check_19_inputs[14] .extend([((carry_13_col109) + (M31_131072))].unpack()); - lookup_data.range_check_19[14].push([((carry_13_col109) + (M31_131072))]); + lookup_data + .range_check_19_14 + .push([((carry_13_col109) + (M31_131072))]); let carry_14_col110 = (((conv_mod_tmp_31b3_83) + (carry_13_col109)) * (M31_4194304)); trace[110].data[row_index] = carry_14_col110; sub_components_inputs.range_check_19_inputs[15] .extend([((carry_14_col110) + (M31_131072))].unpack()); - lookup_data.range_check_19[15].push([((carry_14_col110) + (M31_131072))]); + lookup_data + .range_check_19_15 + .push([((carry_14_col110) + (M31_131072))]); let carry_15_col111 = (((conv_mod_tmp_31b3_84) + (carry_14_col110)) * (M31_4194304)); trace[111].data[row_index] = carry_15_col111; sub_components_inputs.range_check_19_inputs[16] .extend([((carry_15_col111) + (M31_131072))].unpack()); - lookup_data.range_check_19[16].push([((carry_15_col111) + (M31_131072))]); + lookup_data + .range_check_19_16 + .push([((carry_15_col111) + (M31_131072))]); let carry_16_col112 = (((conv_mod_tmp_31b3_85) + (carry_15_col111)) * (M31_4194304)); trace[112].data[row_index] = carry_16_col112; sub_components_inputs.range_check_19_inputs[17] .extend([((carry_16_col112) + (M31_131072))].unpack()); - lookup_data.range_check_19[17].push([((carry_16_col112) + (M31_131072))]); + lookup_data + .range_check_19_17 + .push([((carry_16_col112) + (M31_131072))]); let carry_17_col113 = (((conv_mod_tmp_31b3_86) + (carry_16_col112)) * (M31_4194304)); trace[113].data[row_index] = carry_17_col113; sub_components_inputs.range_check_19_inputs[18] .extend([((carry_17_col113) + (M31_131072))].unpack()); - lookup_data.range_check_19[18].push([((carry_17_col113) + (M31_131072))]); + lookup_data + .range_check_19_18 + .push([((carry_17_col113) + (M31_131072))]); let carry_18_col114 = (((conv_mod_tmp_31b3_87) + (carry_17_col113)) * (M31_4194304)); trace[114].data[row_index] = carry_18_col114; sub_components_inputs.range_check_19_inputs[19] .extend([((carry_18_col114) + (M31_131072))].unpack()); - lookup_data.range_check_19[19].push([((carry_18_col114) + (M31_131072))]); + lookup_data + .range_check_19_19 + .push([((carry_18_col114) + (M31_131072))]); let carry_19_col115 = (((conv_mod_tmp_31b3_88) + (carry_18_col114)) * (M31_4194304)); trace[115].data[row_index] = carry_19_col115; sub_components_inputs.range_check_19_inputs[20] .extend([((carry_19_col115) + (M31_131072))].unpack()); - lookup_data.range_check_19[20].push([((carry_19_col115) + (M31_131072))]); + lookup_data + .range_check_19_20 + .push([((carry_19_col115) + (M31_131072))]); let carry_20_col116 = (((conv_mod_tmp_31b3_89) + (carry_19_col115)) * (M31_4194304)); trace[116].data[row_index] = carry_20_col116; sub_components_inputs.range_check_19_inputs[21] .extend([((carry_20_col116) + (M31_131072))].unpack()); - lookup_data.range_check_19[21].push([((carry_20_col116) + (M31_131072))]); + lookup_data + .range_check_19_21 + .push([((carry_20_col116) + (M31_131072))]); let carry_21_col117 = ((((conv_mod_tmp_31b3_90) - ((M31_136) * (k_col95))) + (carry_20_col116)) * (M31_4194304)); @@ -1752,45 +1800,59 @@ pub fn write_trace_simd( sub_components_inputs.range_check_19_inputs[22] .extend([((carry_21_col117) + (M31_131072))].unpack()); - lookup_data.range_check_19[22].push([((carry_21_col117) + (M31_131072))]); + lookup_data + .range_check_19_22 + .push([((carry_21_col117) + (M31_131072))]); let carry_22_col118 = (((conv_mod_tmp_31b3_91) + (carry_21_col117)) * (M31_4194304)); trace[118].data[row_index] = carry_22_col118; sub_components_inputs.range_check_19_inputs[23] .extend([((carry_22_col118) + (M31_131072))].unpack()); - lookup_data.range_check_19[23].push([((carry_22_col118) + (M31_131072))]); + lookup_data + .range_check_19_23 + .push([((carry_22_col118) + (M31_131072))]); let carry_23_col119 = (((conv_mod_tmp_31b3_92) + (carry_22_col118)) * (M31_4194304)); trace[119].data[row_index] = carry_23_col119; sub_components_inputs.range_check_19_inputs[24] .extend([((carry_23_col119) + (M31_131072))].unpack()); - lookup_data.range_check_19[24].push([((carry_23_col119) + (M31_131072))]); + lookup_data + .range_check_19_24 + .push([((carry_23_col119) + (M31_131072))]); let carry_24_col120 = (((conv_mod_tmp_31b3_93) + (carry_23_col119)) * (M31_4194304)); trace[120].data[row_index] = carry_24_col120; sub_components_inputs.range_check_19_inputs[25] .extend([((carry_24_col120) + (M31_131072))].unpack()); - lookup_data.range_check_19[25].push([((carry_24_col120) + (M31_131072))]); + lookup_data + .range_check_19_25 + .push([((carry_24_col120) + (M31_131072))]); let carry_25_col121 = (((conv_mod_tmp_31b3_94) + (carry_24_col120)) * (M31_4194304)); trace[121].data[row_index] = carry_25_col121; sub_components_inputs.range_check_19_inputs[26] .extend([((carry_25_col121) + (M31_131072))].unpack()); - lookup_data.range_check_19[26].push([((carry_25_col121) + (M31_131072))]); + lookup_data + .range_check_19_26 + .push([((carry_25_col121) + (M31_131072))]); let carry_26_col122 = (((conv_mod_tmp_31b3_95) + (carry_25_col121)) * (M31_4194304)); trace[122].data[row_index] = carry_26_col122; sub_components_inputs.range_check_19_inputs[27] .extend([((carry_26_col122) + (M31_131072))].unpack()); - lookup_data.range_check_19[27].push([((carry_26_col122) + (M31_131072))]); + lookup_data + .range_check_19_27 + .push([((carry_26_col122) + (M31_131072))]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ ((input_pc_col0) + (M31_2)), ((input_ap_col1) + (ap_update_add_1_col7)), input_fp_col2, @@ -1801,58 +1863,85 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 3], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 3], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub range_check_19: [Vec<[PackedM31; 1]>; 28], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_address_to_id_2: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + memory_id_to_big_2: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + range_check_19_0: Vec<[PackedM31; 1]>, + range_check_19_1: Vec<[PackedM31; 1]>, + range_check_19_2: Vec<[PackedM31; 1]>, + range_check_19_3: Vec<[PackedM31; 1]>, + range_check_19_4: Vec<[PackedM31; 1]>, + range_check_19_5: Vec<[PackedM31; 1]>, + range_check_19_6: Vec<[PackedM31; 1]>, + range_check_19_7: Vec<[PackedM31; 1]>, + range_check_19_8: Vec<[PackedM31; 1]>, + range_check_19_9: Vec<[PackedM31; 1]>, + range_check_19_10: Vec<[PackedM31; 1]>, + range_check_19_11: Vec<[PackedM31; 1]>, + range_check_19_12: Vec<[PackedM31; 1]>, + range_check_19_13: Vec<[PackedM31; 1]>, + range_check_19_14: Vec<[PackedM31; 1]>, + range_check_19_15: Vec<[PackedM31; 1]>, + range_check_19_16: Vec<[PackedM31; 1]>, + range_check_19_17: Vec<[PackedM31; 1]>, + range_check_19_18: Vec<[PackedM31; 1]>, + range_check_19_19: Vec<[PackedM31; 1]>, + range_check_19_20: Vec<[PackedM31; 1]>, + range_check_19_21: Vec<[PackedM31; 1]>, + range_check_19_22: Vec<[PackedM31; 1]>, + range_check_19_23: Vec<[PackedM31; 1]>, + range_check_19_24: Vec<[PackedM31; 1]>, + range_check_19_25: Vec<[PackedM31; 1]>, + range_check_19_26: Vec<[PackedM31; 1]>, + range_check_19_27: Vec<[PackedM31; 1]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - memory_id_to_big: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - range_check_19: [ - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - Vec::with_capacity(capacity), - ], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_address_to_id_2: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + memory_id_to_big_2: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + range_check_19_0: Vec::with_capacity(capacity), + range_check_19_1: Vec::with_capacity(capacity), + range_check_19_2: Vec::with_capacity(capacity), + range_check_19_3: Vec::with_capacity(capacity), + range_check_19_4: Vec::with_capacity(capacity), + range_check_19_5: Vec::with_capacity(capacity), + range_check_19_6: Vec::with_capacity(capacity), + range_check_19_7: Vec::with_capacity(capacity), + range_check_19_8: Vec::with_capacity(capacity), + range_check_19_9: Vec::with_capacity(capacity), + range_check_19_10: Vec::with_capacity(capacity), + range_check_19_11: Vec::with_capacity(capacity), + range_check_19_12: Vec::with_capacity(capacity), + range_check_19_13: Vec::with_capacity(capacity), + range_check_19_14: Vec::with_capacity(capacity), + range_check_19_15: Vec::with_capacity(capacity), + range_check_19_16: Vec::with_capacity(capacity), + range_check_19_17: Vec::with_capacity(capacity), + range_check_19_18: Vec::with_capacity(capacity), + range_check_19_19: Vec::with_capacity(capacity), + range_check_19_20: Vec::with_capacity(capacity), + range_check_19_21: Vec::with_capacity(capacity), + range_check_19_22: Vec::with_capacity(capacity), + range_check_19_23: Vec::with_capacity(capacity), + range_check_19_24: Vec::with_capacity(capacity), + range_check_19_25: Vec::with_capacity(capacity), + range_check_19_26: Vec::with_capacity(capacity), + range_check_19_27: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -1865,11 +1954,11 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - range_check_19_lookup_elements: &relations::RangeCheck_19, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + range_check_19: &relations::RangeCheck_19, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -1878,298 +1967,243 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[2]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[3]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[4]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[5]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[6]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[7]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[8]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[9]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[10]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[11]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[12]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[13]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.memory_address_to_id_2, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[14]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_2, + &self.lookup_data.range_check_19_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[15]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_1, + &self.lookup_data.range_check_19_2, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[16]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_3, + &self.lookup_data.range_check_19_4, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[17]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_5, + &self.lookup_data.range_check_19_6, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[18]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_7, + &self.lookup_data.range_check_19_8, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[19]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_9, + &self.lookup_data.range_check_19_10, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[20]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_11, + &self.lookup_data.range_check_19_12, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[21]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_13, + &self.lookup_data.range_check_19_14, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[22]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_15, + &self.lookup_data.range_check_19_16, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[23]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_17, + &self.lookup_data.range_check_19_18, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[24]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_19, + &self.lookup_data.range_check_19_20, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[25]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_21, + &self.lookup_data.range_check_19_22, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[26]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_23, + &self.lookup_data.range_check_19_24, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.range_check_19[27]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = range_check_19_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_25, + &self.lookup_data.range_check_19_26, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = range_check_19.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.range_check_19_27, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = range_check_19.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col(); diff --git a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs index 453452f4..20b8e2a9 100644 --- a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/component.rs @@ -32,7 +32,7 @@ impl Claim { pub fn log_sizes(&self) -> TreeVec> { let log_size = std::cmp::max(self.n_calls.next_power_of_two().ilog2(), LOG_N_LANES); let trace_log_sizes = vec![log_size; 11]; - let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 7]; + let interaction_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 4]; let preprocessed_log_sizes = vec![log_size]; TreeVec::new(vec![ preprocessed_log_sizes, @@ -188,7 +188,7 @@ impl FrameworkEval for Eval { ], )); - eval.finalize_logup(); + eval.finalize_logup_in_pairs(); eval } } diff --git a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs index 1ae151af..55ce06d1 100644 --- a/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/ret_opcode/prover.rs @@ -1,5 +1,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] +use std::iter::zip; + use air_structs_derive::SubComponentInputs; use itertools::{chain, zip_eq, Itertools}; use num_traits::{One, Zero}; @@ -183,7 +185,7 @@ pub fn write_trace_simd( .unpack(), ); - lookup_data.verify_instruction[0].push([ + lookup_data.verify_instruction_0.push([ input_pc_col0, M31_32766, M31_32767, @@ -216,7 +218,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[0] .extend(((input_fp_col2) - (M31_1)).unpack()); - lookup_data.memory_address_to_id[0] + lookup_data + .memory_address_to_id_0 .push([((input_fp_col2) - (M31_1)), next_pc_id_col3]); let next_pc_limb_0_col4 = memory_id_to_big_value_tmp_e23a_4.get_m31(0); trace[4].data[row_index] = next_pc_limb_0_col4; @@ -226,7 +229,7 @@ pub fn write_trace_simd( trace[6].data[row_index] = next_pc_limb_2_col6; sub_components_inputs.memory_id_to_big_inputs[0].extend(next_pc_id_col3.unpack()); - lookup_data.memory_id_to_big[0].push([ + lookup_data.memory_id_to_big_0.push([ next_pc_id_col3, next_pc_limb_0_col4, next_pc_limb_1_col5, @@ -269,7 +272,8 @@ pub fn write_trace_simd( sub_components_inputs.memory_address_to_id_inputs[1] .extend(((input_fp_col2) - (M31_2)).unpack()); - lookup_data.memory_address_to_id[1] + lookup_data + .memory_address_to_id_1 .push([((input_fp_col2) - (M31_2)), next_fp_id_col7]); let next_fp_limb_0_col8 = memory_id_to_big_value_tmp_e23a_6.get_m31(0); trace[8].data[row_index] = next_fp_limb_0_col8; @@ -279,7 +283,7 @@ pub fn write_trace_simd( trace[10].data[row_index] = next_fp_limb_2_col10; sub_components_inputs.memory_id_to_big_inputs[1].extend(next_fp_id_col7.unpack()); - lookup_data.memory_id_to_big[1].push([ + lookup_data.memory_id_to_big_1.push([ next_fp_id_col7, next_fp_limb_0_col8, next_fp_limb_1_col9, @@ -311,8 +315,10 @@ pub fn write_trace_simd( M31_0, ]); - lookup_data.opcodes[0].push([input_pc_col0, input_ap_col1, input_fp_col2]); - lookup_data.opcodes[1].push([ + lookup_data + .opcodes_0 + .push([input_pc_col0, input_ap_col1, input_fp_col2]); + lookup_data.opcodes_1.push([ (((next_pc_limb_0_col4) + ((next_pc_limb_1_col5) * (M31_512))) + ((next_pc_limb_2_col6) * (M31_262144))), input_ap_col1, @@ -325,19 +331,25 @@ pub fn write_trace_simd( } pub struct LookupData { - pub memory_address_to_id: [Vec<[PackedM31; 2]>; 2], - pub memory_id_to_big: [Vec<[PackedM31; 29]>; 2], - pub opcodes: [Vec<[PackedM31; 3]>; 2], - pub verify_instruction: [Vec<[PackedM31; 19]>; 1], + memory_address_to_id_0: Vec<[PackedM31; 2]>, + memory_address_to_id_1: Vec<[PackedM31; 2]>, + memory_id_to_big_0: Vec<[PackedM31; 29]>, + memory_id_to_big_1: Vec<[PackedM31; 29]>, + opcodes_0: Vec<[PackedM31; 3]>, + opcodes_1: Vec<[PackedM31; 3]>, + verify_instruction_0: Vec<[PackedM31; 19]>, } impl LookupData { #[allow(unused_variables)] fn with_capacity(capacity: usize) -> Self { Self { - memory_address_to_id: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - memory_id_to_big: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - opcodes: [Vec::with_capacity(capacity), Vec::with_capacity(capacity)], - verify_instruction: [Vec::with_capacity(capacity)], + memory_address_to_id_0: Vec::with_capacity(capacity), + memory_address_to_id_1: Vec::with_capacity(capacity), + memory_id_to_big_0: Vec::with_capacity(capacity), + memory_id_to_big_1: Vec::with_capacity(capacity), + opcodes_0: Vec::with_capacity(capacity), + opcodes_1: Vec::with_capacity(capacity), + verify_instruction_0: Vec::with_capacity(capacity), } } } @@ -350,10 +362,10 @@ impl InteractionClaimGenerator { pub fn write_interaction_trace( self, tree_builder: &mut TreeBuilder<'_, '_, SimdBackend, MC>, - memory_address_to_id_lookup_elements: &relations::MemoryAddressToId, - memory_id_to_big_lookup_elements: &relations::MemoryIdToBig, - opcodes_lookup_elements: &relations::Opcodes, - verify_instruction_lookup_elements: &relations::VerifyInstruction, + memory_address_to_id: &relations::MemoryAddressToId, + memory_id_to_big: &relations::MemoryIdToBig, + opcodes: &relations::Opcodes, + verify_instruction: &relations::VerifyInstruction, ) -> InteractionClaim where SimdBackend: BackendForChannel, @@ -362,58 +374,48 @@ impl InteractionClaimGenerator { let mut logup_gen = LogupTraceGenerator::new(log_size); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.verify_instruction[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = verify_instruction_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); - } - col_gen.finalize_col(); - - let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_address_to_id[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_address_to_id_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.verify_instruction_0, + &self.lookup_data.memory_address_to_id_0, + ) + .enumerate() + { + let p0: PackedQM31 = verify_instruction.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.memory_id_to_big[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = memory_id_to_big_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_0, + &self.lookup_data.memory_address_to_id_1, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = memory_address_to_id.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[0]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, PackedQM31::one(), denom); + for (i, (v0, v1)) in zip( + &self.lookup_data.memory_id_to_big_1, + &self.lookup_data.opcodes_0, + ) + .enumerate() + { + let p0: PackedQM31 = memory_id_to_big.combine(v0); + let p1: PackedQM31 = opcodes.combine(v1); + col_gen.write_frac(i, p0 + p1, p0 * p1); } col_gen.finalize_col(); let mut col_gen = logup_gen.new_col(); - let lookup_row = &self.lookup_data.opcodes[1]; - for (i, lookup_values) in lookup_row.iter().enumerate() { - let denom = opcodes_lookup_elements.combine(lookup_values); - col_gen.write_frac(i, -PackedQM31::one(), denom); + for (i, v0) in self.lookup_data.opcodes_1.iter().enumerate() { + let p0 = opcodes.combine(v0); + col_gen.write_frac(i, -PackedQM31::one(), p0); } col_gen.finalize_col();