Skip to content

Commit

Permalink
Move SecureColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 19, 2024
1 parent 69b2fb9 commit 047bfc4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 52 deletions.
7 changes: 3 additions & 4 deletions src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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 @@ -9,6 +9,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;
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 @@ -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;

Expand Down

0 comments on commit 047bfc4

Please sign in to comment.