Skip to content

Commit

Permalink
QuotientOps
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 18, 2024
1 parent 8bca9cc commit eb3cd37
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/backend/cpu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod circle;
mod fri;
pub mod quotients;

use std::fmt::Debug;

Expand Down
45 changes: 45 additions & 0 deletions src/core/backend/cpu/quotients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use num_traits::Zero;

use super::CPUBackend;
use crate::core::air::accumulation::ColumnAccumulator;
use crate::core::backend::Col;
use crate::core::commitment_scheme::quotients::{BatchedColumnOpenings, QuotientOps};
use crate::core::constraints::pair_vanishing;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::{ComplexConjugate, FieldExpOps};
use crate::core::poly::circle::CircleDomain;
use crate::core::utils::bit_reverse_index;

impl QuotientOps for CPUBackend {
fn accumulate_quotients(
domain: CircleDomain,
mut accum: ColumnAccumulator<'_, Self>,
columns: &[Col<Self, BaseField>],
random_coeff: SecureField,
openings: &[BatchedColumnOpenings],
) {
for row in 0..domain.size() {
let domain_point = domain.at(bit_reverse_index(row, domain.log_size()));
let mut row_accumlator = SecureField::zero();
for opening in openings {
let mut numerator = SecureField::zero();
for (column_index, open_value) in &opening.column_indices_and_values {
let column = &columns[*column_index];
let value = column[row];
numerator = numerator * random_coeff + (value - *open_value);
}

let denominator = pair_vanishing(
opening.point,
opening.point.complex_conjugate(),
domain_point.into_ef(),
);

row_accumlator *= random_coeff.pow(opening.column_indices_and_values.len() as u128)
+ numerator / denominator;
}
accum.accumulate(row, row_accumlator);
}
}
}
1 change: 1 addition & 0 deletions src/core/commitment_scheme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! the unique decoding regime. This is enough for a STARK proof though, where we onyl want to imply
//! the existence of such polynomials, and re ok with having a small decoding list.
pub mod quotients;
mod utils;

use std::iter::zip;
Expand Down
21 changes: 21 additions & 0 deletions src/core/commitment_scheme/quotients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::core::air::accumulation::ColumnAccumulator;
use crate::core::backend::{Backend, Col};
use crate::core::circle::CirclePoint;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::poly::circle::CircleDomain;

pub trait QuotientOps: Backend {
fn accumulate_quotients(
domain: CircleDomain,
accum: ColumnAccumulator<'_, Self>,
columns: &[Col<Self, BaseField>],
random_coeff: SecureField,
openings: &[BatchedColumnOpenings],
);
}

pub struct BatchedColumnOpenings {
pub point: CirclePoint<SecureField>,
pub column_indices_and_values: Vec<(usize, SecureField)>,
}

0 comments on commit eb3cd37

Please sign in to comment.