Skip to content

Commit

Permalink
Move SecureColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 21, 2024
1 parent 07a69ae commit 1f8868b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use super::{Air, ComponentTrace};
use crate::core::backend::CPUBackend;
use crate::core::circle::CirclePoint;
use crate::core::fields::qm31::SecureField;
use crate::core::poly::circle::{CanonicCoset, CirclePoly, SecureCirclePoly};
use crate::core::fields::secure::SecureCirclePoly;
use crate::core::poly::circle::{CanonicCoset, CirclePoly};
use crate::core::prover::LOG_BLOWUP_FACTOR;
use crate::core::ComponentVec;

Expand Down
45 changes: 4 additions & 41 deletions src/core/air/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
<SecureField as ExtensionOf<BaseField>>::EXTENSION_DEGREE;

// TODO(spapini): find a better place for this
pub struct SecureColumn<B: Backend> {
pub cols: [Col<B, BaseField>; SECURE_EXTENSION_DEGREE],
}

impl SecureColumn<CPUBackend> {
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<B: Backend> SecureColumn<B> {
pub fn zeros(len: usize) -> Self {
Self {
cols: std::array::from_fn(|_| Col::<B, BaseField>::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.
Expand Down
1 change: 1 addition & 0 deletions src/core/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::backend::ColumnOps;
pub mod cm31;
pub mod m31;
pub mod qm31;
pub mod secure;

pub trait FieldOps<F: Field>: ColumnOps<F> {
// TODO(Ohad): change to use a mutable slice.
Expand Down
43 changes: 39 additions & 4 deletions src/core/poly/circle/secure_poly.rs → src/core/fields/secure.rs
Original file line number Diff line number Diff line change
@@ -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 =
<SecureField as ExtensionOf<BaseField>>::EXTENSION_DEGREE;

pub struct SecureColumn<B: Backend> {
pub cols: [Col<B, BaseField>; SECURE_EXTENSION_DEGREE],
}
impl SecureColumn<CPUBackend> {
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<B: Backend> SecureColumn<B> {
pub fn zeros(len: usize) -> Self {
Self {
cols: std::array::from_fn(|_| Col::<B, BaseField>::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>) -> SecureField {
combine_secure_value(self.eval_columns_at_point(point))
Expand All @@ -24,7 +60,6 @@ impl SecureCirclePoly {
]
}
}

impl Deref for SecureCirclePoly {
type Target = [CPUCirclePoly; SECURE_EXTENSION_DEGREE];

Expand Down
2 changes: 0 additions & 2 deletions src/core/poly/circle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ mod domain;
mod evaluation;
mod ops;
mod poly;
mod secure_poly;

pub use canonic::CanonicCoset;
pub use domain::{CircleDomain, MAX_CIRCLE_DOMAIN_LOG_SIZE};
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 {
Expand Down
3 changes: 2 additions & 1 deletion src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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;

Expand Down

0 comments on commit 1f8868b

Please sign in to comment.