Skip to content

Commit

Permalink
Prepare commitmentschem per size (#537)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/stwo/537)
<!-- Reviewable:end -->
  • Loading branch information
spapinistarkware authored Mar 25, 2024
1 parent 8a75935 commit 5e418ee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core/fields/secure_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ impl SecureColumn<CPUBackend> {
.map(|c| &mut c[index])
.assign(value.to_m31_array());
}

// TODO(spapini): Remove when we no longer use CircleEvaluation<SecureField>.
pub fn to_cpu(&self) -> Vec<SecureField> {
(0..self.len()).map(|i| self.at(i)).collect()
}
}
impl<B: Backend> SecureColumn<B> {
pub fn zeros(len: usize) -> Self {
Expand Down
9 changes: 9 additions & 0 deletions src/core/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,15 @@ impl<F: ExtensionOf<BaseField>> SparseCircleEvaluation<F> {
}
}

impl<'a, F: ExtensionOf<BaseField>> IntoIterator for &'a mut SparseCircleEvaluation<F> {
type Item = &'a mut CircleEvaluation<CPUBackend, F, BitReversedOrder>;
type IntoIter = std::slice::IterMut<'a, CircleEvaluation<CPUBackend, F, BitReversedOrder>>;

fn into_iter(self) -> Self::IntoIter {
self.subcircle_evals.iter_mut()
}
}

/// Holds a small foldable subset of univariate SecureField polynomial evaluations.
/// Evaluation is held at the CPU backend.
#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/core/poly/circle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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::SecureCirclePoly;
pub use secure_poly::{SecureCirclePoly, SecureEvaluation};

#[cfg(test)]
mod tests {
Expand Down
23 changes: 21 additions & 2 deletions src/core/poly/circle/secure_poly.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::ops::Deref;

use crate::core::backend::cpu::CPUCirclePoly;
use super::CircleDomain;
use crate::core::backend::cpu::{CPUCircleEvaluation, CPUCirclePoly};
use crate::core::backend::{Backend, CPUBackend};
use crate::core::circle::CirclePoint;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE;
use crate::core::fields::secure_column::{SecureColumn, SECURE_EXTENSION_DEGREE};
use crate::core::poly::BitReversedOrder;

pub struct SecureCirclePoly(pub [CPUCirclePoly; SECURE_EXTENSION_DEGREE]);

Expand All @@ -24,6 +27,10 @@ impl SecureCirclePoly {
]
}

pub fn log_size(&self) -> u32 {
self[0].log_size()
}

/// Evaluates the polynomial at a point, given evaluations of its composing base field
/// polynomials at that point.
pub fn eval_from_partial_evals(evals: [SecureField; SECURE_EXTENSION_DEGREE]) -> SecureField {
Expand All @@ -42,3 +49,15 @@ impl Deref for SecureCirclePoly {
&self.0
}
}

pub struct SecureEvaluation<B: Backend> {
pub domain: CircleDomain,
pub values: SecureColumn<B>,
}

impl SecureEvaluation<CPUBackend> {
// TODO(spapini): Remove when we no longer use CircleEvaluation<SecureField>.
pub fn to_cpu(self) -> CPUCircleEvaluation<SecureField, BitReversedOrder> {
CPUCircleEvaluation::new(self.domain, self.values.to_cpu())
}
}

0 comments on commit 5e418ee

Please sign in to comment.