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

generate enabler column #333

Closed
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
33 changes: 32 additions & 1 deletion stwo_cairo_prover/crates/prover/src/components/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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());
}
}
}
}
1 change: 1 addition & 0 deletions stwo_cairo_prover/crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(
exact_size_is_empty,
trait_upcasting,
portable_simd,
iter_array_chunks,
Expand Down
Loading