Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

range check small table #167

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stwo_cairo_prover/crates/prover/src/cairo_air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
Loading