From 4886ee3a57d66a279dcc17b757d94f98f9d28f21 Mon Sep 17 00:00:00 2001 From: Shahar Samocha Date: Tue, 7 Jan 2025 12:59:49 +0200 Subject: [PATCH] generate enabler column --- .../crates/prover/src/components/utils.rs | 33 ++++++++++++++++++- stwo_cairo_prover/crates/prover/src/lib.rs | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/stwo_cairo_prover/crates/prover/src/components/utils.rs b/stwo_cairo_prover/crates/prover/src/components/utils.rs index 457aad6e..215c3447 100644 --- a/stwo_cairo_prover/crates/prover/src/components/utils.rs +++ b/stwo_cairo_prover/crates/prover/src/components/utils.rs @@ -81,12 +81,23 @@ impl AtomicMultiplicityColumn { } } +/// Generates a padding column for the given padding offset. +/// The padding column is a MultiplicityColumn of length next_power_of_two(padding_offset) where +/// 1. The first `padding_offset` elements set to 1; +/// 2. Otherwise set to 0. +pub fn gen_padding_column(padding_offset: usize) -> MultiplicityColumn { + let log_size = padding_offset.next_power_of_two().ilog2(); + let mut padding_column = MultiplicityColumn::new(1 << log_size); + (0..padding_offset).for_each(|i| padding_column.increase_at(i as u32)); + padding_column +} + #[cfg(test)] mod tests { use num_traits::{One, Zero}; use rand::rngs::SmallRng; use rand::{Rng, SeedableRng}; - use stwo_prover::core::backend::simd::m31::N_LANES; + use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES}; use stwo_prover::core::fields::m31::M31; #[test] @@ -107,4 +118,24 @@ mod tests { assert!(res_chunk.to_array() == expected_chunk); } } + + #[test] + fn test_gen_padding_column() { + let n_calls = 30; + + let enabler_column = super::gen_padding_column(n_calls); + + for (i, val) in enabler_column + .into_simd_vec() + .into_iter() + .flat_map(PackedM31::to_array) + .enumerate() + { + if i < n_calls { + assert_eq!(val, M31::one()); + } else { + assert_eq!(val, M31::zero()); + } + } + } } diff --git a/stwo_cairo_prover/crates/prover/src/lib.rs b/stwo_cairo_prover/crates/prover/src/lib.rs index f0e1cc9e..05480300 100644 --- a/stwo_cairo_prover/crates/prover/src/lib.rs +++ b/stwo_cairo_prover/crates/prover/src/lib.rs @@ -1,4 +1,5 @@ #![feature( + exact_size_is_empty, trait_upcasting, portable_simd, iter_array_chunks,