diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs index 06eaaf84..f0e7e1d7 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs @@ -207,6 +207,7 @@ impl CairoComponents { id_to_f252::SmallEval::new( cairo_claim.memory_id_to_value.clone(), interaction_elements.memory_id_to_value_lookup.clone(), + interaction_elements.range9_9_lookup.clone(), interaction_claim.memory_id_to_value.clone(), ), ); diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/component.rs b/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/component.rs index 068b99aa..0cb1f8cb 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/component.rs @@ -102,6 +102,7 @@ impl FrameworkEval for BigEval { pub struct SmallEval { pub log_n_rows: u32, pub lookup_elements: RelationElements, + pub range_check_9_9_relation: range_check_9_9::RelationElements, pub claimed_sum: QM31, } impl SmallEval { @@ -111,11 +112,13 @@ impl SmallEval { pub fn new( claim: Claim, lookup_elements: RelationElements, + range_check_9_9_relation: range_check_9_9::RelationElements, interaction_claim: InteractionClaim, ) -> Self { Self { log_n_rows: claim.small_log_size, lookup_elements, + range_check_9_9_relation, claimed_sum: interaction_claim.small_claimed_sum, } } @@ -143,6 +146,16 @@ impl FrameworkEval for SmallEval { ); logup.write_frac(&mut eval, frac); + // Range check elements. + for (l, r) in id_and_value[MEMORY_ID_SIZE..].iter().tuples() { + let frac = Fraction::new( + E::EF::one(), + self.range_check_9_9_relation + .combine(&[l.clone(), r.clone()]), + ); + logup.write_frac(&mut eval, frac); + } + logup.finalize(&mut eval); eval @@ -165,7 +178,10 @@ impl Claim { let interaction_log_sizes = chain!( // A lookup for every pair of limbs, and a yield of the value. vec![self.big_log_size; SECURE_EXTENSION_DEGREE * (N_M31_IN_FELT252.div_ceil(2) + 1)], - vec![self.small_log_size; SECURE_EXTENSION_DEGREE] + vec![ + self.small_log_size; + SECURE_EXTENSION_DEGREE * (N_M31_IN_SMALL_FELT252.div_ceil(2) + 1) + ] ) .collect(); diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/prover.rs b/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/prover.rs index 26e0dc0f..25f12311 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/id_to_f252/prover.rs @@ -126,12 +126,16 @@ impl ClaimGenerator { let small_multiplicities = small_table_trace.last().unwrap().data.clone(); // Add inputs to range check that all the values are 9-bit felts. - // TODO(Ohad): rangecheck the small values. for (col0, col1) in big_ids_and_values[MEMORY_ID_SIZE..].iter().tuples() { for (val0, val1) in zip_eq(col0, col1) { range_check_9_9_trace_generator.add_packed_m31(&[*val0, *val1]); } } + for (col0, col1) in small_ids_and_values[MEMORY_ID_SIZE..].iter().tuples() { + for (val0, val1) in zip_eq(col0, col1) { + range_check_9_9_trace_generator.add_packed_m31(&[*val0, *val1]); + } + } // Extend trace. let big_log_size = big_table_trace[0].len().ilog2(); @@ -310,6 +314,21 @@ impl InteractionClaimGenerator { col_gen.write_frac(vec_row, (-self.small_multiplicities[vec_row]).into(), denom); } col_gen.finalize_col(); + + // Every element is 9-bit. + for (l, r) in self.small_ids_and_values[MEMORY_ID_SIZE..].iter().tuples() { + let mut col_gen = small_values_logup_gen.new_col(); + for (vec_row, (l1, l2)) in zip(l, r).enumerate() { + // TOOD(alont) Add 2-batching. + col_gen.write_frac( + vec_row, + PackedQM31::broadcast(M31(1).into()), + range9_9_lookup_elements.combine(&[*l1, *l2]), + ); + } + col_gen.finalize_col(); + } + let (trace, small_claimed_sum) = small_values_logup_gen.finalize_last(); tree_builder.extend_evals(trace);