From 2f3df09c88a534ed5e038666a0a6a911980227c9 Mon Sep 17 00:00:00 2001 From: Shahar Papini Date: Fri, 15 Mar 2024 06:55:26 +0200 Subject: [PATCH] Move SecureColumn --- src/core/air/air_ext.rs | 7 ++- src/core/air/evaluation.rs | 45 ++----------------- src/core/fields/mod.rs | 1 + .../secure_poly.rs => fields/secure.rs} | 43 ++++++++++++++++-- src/core/poly/circle/mod.rs | 2 - src/core/prover/mod.rs | 3 +- 6 files changed, 49 insertions(+), 52 deletions(-) rename src/core/{poly/circle/secure_poly.rs => fields/secure.rs} (52%) diff --git a/src/core/air/air_ext.rs b/src/core/air/air_ext.rs index 574b5b742..2817df889 100644 --- a/src/core/air/air_ext.rs +++ b/src/core/air/air_ext.rs @@ -3,15 +3,14 @@ use std::iter::zip; use itertools::Itertools; -use super::evaluation::{ - DomainEvaluationAccumulator, PointEvaluationAccumulator, SECURE_EXTENSION_DEGREE, -}; +use super::evaluation::{DomainEvaluationAccumulator, PointEvaluationAccumulator}; use super::{Air, ComponentTrace}; use crate::core::backend::CPUBackend; use crate::core::circle::CirclePoint; use crate::core::fields::qm31::SecureField; +use crate::core::fields::secure::{SecureCirclePoly, SECURE_EXTENSION_DEGREE}; use crate::core::fri::CirclePolyDegreeBound; -use crate::core::poly::circle::{CanonicCoset, CirclePoly, SecureCirclePoly}; +use crate::core::poly::circle::{CanonicCoset, CirclePoly}; use crate::core::prover::LOG_BLOWUP_FACTOR; use crate::core::ComponentVec; diff --git a/src/core/air/evaluation.rs b/src/core/air/evaluation.rs index cca111d2e..e89c6df11 100644 --- a/src/core/air/evaluation.rs +++ b/src/core/air/evaluation.rs @@ -3,50 +3,13 @@ //! Given a random alpha, the combined polynomial is defined as //! f(p) = sum_i alpha^{N-1-i} u_i (P). use crate::core::backend::cpu::CPUCircleEvaluation; -use crate::core::backend::{Backend, CPUBackend, Col, Column}; +use crate::core::backend::{Backend, CPUBackend}; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; -use crate::core::fields::{ExtensionOf, FieldExpOps}; -use crate::core::poly::circle::{CanonicCoset, CirclePoly, SecureCirclePoly}; +use crate::core::fields::secure::{SecureCirclePoly, SecureColumn}; +use crate::core::fields::FieldExpOps; +use crate::core::poly::circle::{CanonicCoset, CirclePoly}; use crate::core::poly::BitReversedOrder; -use crate::core::utils::IteratorMutExt; - -pub const SECURE_EXTENSION_DEGREE: usize = - >::EXTENSION_DEGREE; - -// TODO(spapini): find a better place for this -pub struct SecureColumn { - pub cols: [Col; SECURE_EXTENSION_DEGREE], -} - -impl SecureColumn { - fn at(&self, index: usize) -> SecureField { - SecureField::from_m31_array(std::array::from_fn(|i| self.cols[i][index])) - } - - fn set(&mut self, index: usize, value: SecureField) { - self.cols - .iter_mut() - .map(|c| &mut c[index]) - .assign(value.to_m31_array()); - } -} - -impl SecureColumn { - pub fn zeros(len: usize) -> Self { - Self { - cols: std::array::from_fn(|_| Col::::zeros(len)), - } - } - - pub fn len(&self) -> usize { - self.cols[0].len() - } - - pub fn is_empty(&self) -> bool { - self.cols[0].is_empty() - } -} /// Accumulates evaluations of u_i(P0) at a single point. /// Computes f(P0), the combined polynomial at that point. diff --git a/src/core/fields/mod.rs b/src/core/fields/mod.rs index 72693b5fa..e804100c8 100644 --- a/src/core/fields/mod.rs +++ b/src/core/fields/mod.rs @@ -9,6 +9,7 @@ use super::backend::ColumnOps; pub mod cm31; pub mod m31; pub mod qm31; +pub mod secure; pub trait FieldOps: ColumnOps { // TODO(Ohad): change to use a mutable slice. diff --git a/src/core/poly/circle/secure_poly.rs b/src/core/fields/secure.rs similarity index 52% rename from src/core/poly/circle/secure_poly.rs rename to src/core/fields/secure.rs index 986c648bd..f557952e7 100644 --- a/src/core/poly/circle/secure_poly.rs +++ b/src/core/fields/secure.rs @@ -1,12 +1,48 @@ use std::ops::Deref; -use crate::core::air::evaluation::SECURE_EXTENSION_DEGREE; +use super::m31::BaseField; +use super::qm31::SecureField; +use super::ExtensionOf; use crate::core::backend::cpu::CPUCirclePoly; +use crate::core::backend::{Backend, CPUBackend, Col, Column}; use crate::core::circle::CirclePoint; -use crate::core::fields::qm31::SecureField; +use crate::core::utils::IteratorMutExt; -pub struct SecureCirclePoly(pub [CPUCirclePoly; SECURE_EXTENSION_DEGREE]); +pub const SECURE_EXTENSION_DEGREE: usize = + >::EXTENSION_DEGREE; + +pub struct SecureColumn { + pub cols: [Col; SECURE_EXTENSION_DEGREE], +} +impl SecureColumn { + pub fn at(&self, index: usize) -> SecureField { + SecureField::from_m31_array(std::array::from_fn(|i| self.cols[i][index])) + } + + pub fn set(&mut self, index: usize, value: SecureField) { + self.cols + .iter_mut() + .map(|c| &mut c[index]) + .assign(value.to_m31_array()); + } +} +impl SecureColumn { + pub fn zeros(len: usize) -> Self { + Self { + cols: std::array::from_fn(|_| Col::::zeros(len)), + } + } + pub fn len(&self) -> usize { + self.cols[0].len() + } + + pub fn is_empty(&self) -> bool { + self.cols[0].is_empty() + } +} + +pub struct SecureCirclePoly(pub [CPUCirclePoly; SECURE_EXTENSION_DEGREE]); impl SecureCirclePoly { pub fn eval_at_point(&self, point: CirclePoint) -> SecureField { combine_secure_value(self.eval_columns_at_point(point)) @@ -24,7 +60,6 @@ impl SecureCirclePoly { ] } } - impl Deref for SecureCirclePoly { type Target = [CPUCirclePoly; SECURE_EXTENSION_DEGREE]; diff --git a/src/core/poly/circle/mod.rs b/src/core/poly/circle/mod.rs index 639696bae..d2b97c082 100644 --- a/src/core/poly/circle/mod.rs +++ b/src/core/poly/circle/mod.rs @@ -3,14 +3,12 @@ mod domain; mod evaluation; mod ops; mod poly; -mod secure_poly; pub use canonic::CanonicCoset; pub use domain::CircleDomain; pub use evaluation::{CircleEvaluation, CosetSubEvaluation}; pub use ops::PolyOps; pub use poly::CirclePoly; -pub use secure_poly::{combine_secure_value, SecureCirclePoly}; #[cfg(test)] mod tests { diff --git a/src/core/prover/mod.rs b/src/core/prover/mod.rs index 497f12079..abecd21c5 100644 --- a/src/core/prover/mod.rs +++ b/src/core/prover/mod.rs @@ -12,7 +12,8 @@ use crate::core::circle::CirclePoint; use crate::core::commitment_scheme::{CommitmentSchemeProver, CommitmentSchemeVerifier}; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; -use crate::core::poly::circle::{combine_secure_value, CircleEvaluation}; +use crate::core::fields::secure::combine_secure_value; +use crate::core::poly::circle::CircleEvaluation; use crate::core::poly::BitReversedOrder; use crate::core::ComponentVec;