From 32d6c02eca869244560f3cf1c7a730a312e7ff16 Mon Sep 17 00:00:00 2001 From: Gali Michlevich Date: Thu, 16 Jan 2025 15:01:15 +0200 Subject: [PATCH] Move Preprocessed Columns Struct to Preprocessed File --- .../prover/src/cairo_air/preprocessed.rs | 38 ++++++++++++++++-- .../memory/memory_address_to_id/component.rs | 2 +- .../memory/memory_address_to_id/prover.rs | 2 +- .../prover/src/components/memory/mod.rs | 40 ------------------- 4 files changed, 37 insertions(+), 45 deletions(-) diff --git a/stwo_cairo_prover/crates/prover/src/cairo_air/preprocessed.rs b/stwo_cairo_prover/crates/prover/src/cairo_air/preprocessed.rs index de66fe08..049c8dea 100644 --- a/stwo_cairo_prover/crates/prover/src/cairo_air/preprocessed.rs +++ b/stwo_cairo_prover/crates/prover/src/cairo_air/preprocessed.rs @@ -1,13 +1,15 @@ use itertools::{chain, Itertools}; use prover_types::simd::LOG_N_LANES; use stwo_prover::constraint_framework::preprocessed_columns::{IsFirst, PreProcessedColumnId}; +use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES}; use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::fields::m31::BaseField; -use stwo_prover::core::poly::circle::CircleEvaluation; +use stwo_prover::core::backend::Col; +use stwo_prover::core::fields::m31::{BaseField, M31}; +use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use super::LOG_MAX_ROWS; -use crate::components::memory::Seq; +use crate::components::range_check_vector::SIMD_ENUMERATION_0; const N_PREPROCESSED_COLUMN_SIZES: usize = (LOG_MAX_ROWS - LOG_N_LANES) as usize + 1; @@ -63,6 +65,36 @@ pub fn preprocessed_trace_columns() -> Vec { .collect_vec() } +/// A column with the numbers [0..(2^log_size)-1]. +#[derive(Debug, Clone)] +pub struct Seq { + pub log_size: u32, +} +impl Seq { + pub const fn new(log_size: u32) -> Self { + Self { log_size } + } + + pub fn packed_at(&self, vec_row: usize) -> PackedM31 { + assert!(vec_row < (1 << self.log_size) / N_LANES); + PackedM31::broadcast(M31::from(vec_row * N_LANES)) + + unsafe { PackedM31::from_simd_unchecked(SIMD_ENUMERATION_0) } + } + + pub fn gen_column_simd(&self) -> CircleEvaluation { + let col = Col::::from_iter( + (0..(1 << self.log_size)).map(BaseField::from), + ); + CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col) + } + + pub fn id(&self) -> PreProcessedColumnId { + PreProcessedColumnId { + id: format!("preprocessed_seq_{}", self.log_size).to_string(), + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs index dca35b7c..eae2cc2d 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/component.rs @@ -9,7 +9,7 @@ use stwo_prover::core::fields::qm31::SecureField; use stwo_prover::core::fields::secure_column::SECURE_EXTENSION_DEGREE; use stwo_prover::core::pcs::TreeVec; -use crate::components::memory::Seq; +use crate::cairo_air::preprocessed::Seq; use crate::relations; /// Split the (ID , Multiplicity) columns to shorter chunks. This is done to improve the performance diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs index 0a718b6d..8ee11686 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/memory_address_to_id/prover.rs @@ -15,7 +15,7 @@ use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; use stwo_prover::core::poly::BitReversedOrder; use super::component::{Claim, InteractionClaim, N_SPLIT_CHUNKS}; -use crate::components::memory::Seq; +use crate::cairo_air::preprocessed::Seq; use crate::components::memory_address_to_id::component::{ N_ID_AND_MULT_COLUMNS_PER_CHUNK, N_TRACE_COLUMNS, }; diff --git a/stwo_cairo_prover/crates/prover/src/components/memory/mod.rs b/stwo_cairo_prover/crates/prover/src/components/memory/mod.rs index d61ba282..16bbdcdb 100644 --- a/stwo_cairo_prover/crates/prover/src/components/memory/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/components/memory/mod.rs @@ -1,46 +1,6 @@ -use stwo_prover::constraint_framework::preprocessed_columns::PreProcessedColumnId; -use stwo_prover::core::backend::simd::m31::{PackedM31, N_LANES}; -use stwo_prover::core::backend::simd::SimdBackend; -use stwo_prover::core::backend::Col; -use stwo_prover::core::fields::m31::{BaseField, M31}; -use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation}; -use stwo_prover::core::poly::BitReversedOrder; - -use crate::components::range_check_vector::SIMD_ENUMERATION_0; - pub mod memory_address_to_id; pub mod memory_id_to_big; /// Used for sanity checks and assertions. pub const LOG_MEMORY_ADDRESS_BOUND: u32 = 27; pub const MEMORY_ADDRESS_BOUND: usize = 1 << LOG_MEMORY_ADDRESS_BOUND; - -/// A column with the numbers [0..(2^log_size)-1]. -#[derive(Debug, Clone)] -pub struct Seq { - pub log_size: u32, -} -impl Seq { - pub const fn new(log_size: u32) -> Self { - Self { log_size } - } - - pub fn packed_at(&self, vec_row: usize) -> PackedM31 { - assert!(vec_row < (1 << self.log_size) / N_LANES); - PackedM31::broadcast(M31::from(vec_row * N_LANES)) - + unsafe { PackedM31::from_simd_unchecked(SIMD_ENUMERATION_0) } - } - - pub fn gen_column_simd(&self) -> CircleEvaluation { - let col = Col::::from_iter( - (0..(1 << self.log_size)).map(BaseField::from), - ); - CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col) - } - - pub fn id(&self) -> PreProcessedColumnId { - PreProcessedColumnId { - id: format!("preprocessed_seq_{}", self.log_size).to_string(), - } - } -}