Skip to content

Commit

Permalink
Generate periodic vanishing polynomial values (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson authored Jul 18, 2024
1 parent 86ddb92 commit be26562
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! AIR for Poseidon2 hash function from <https://eprint.iacr.org/2023/323.pdf>.
use std::array;
use std::ops::{Add, AddAssign, Mul, Sub};

use itertools::Itertools;
Expand All @@ -9,20 +10,20 @@ use crate::constraint_framework::{EvalAtRow, PointEvaluator, SimdDomainEvaluator
use crate::core::air::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator};
use crate::core::air::mask::fixed_mask_points;
use crate::core::air::{Air, AirProver, Component, ComponentProver, ComponentTrace};
use crate::core::backend::simd::column::BaseFieldVec;
use crate::core::backend::simd::m31::{PackedBaseField, LOG_N_LANES};
use crate::core::backend::simd::m31::{PackedBaseField, PackedM31, LOG_N_LANES};
use crate::core::backend::simd::SimdBackend;
use crate::core::backend::{Col, Column, ColumnOps};
use crate::core::backend::{Col, Column};
use crate::core::channel::Blake2sChannel;
use crate::core::circle::CirclePoint;
use crate::core::constraints::coset_vanishing;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::{FieldExpOps, FieldOps};
use crate::core::fields::FieldExpOps;
use crate::core::pcs::TreeVec;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use crate::core::poly::BitReversedOrder;
use crate::core::prover::VerificationError;
use crate::core::utils::bit_reverse;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::{AirTraceGenerator, AirTraceVerifier, ComponentTraceGenerator};

Expand Down Expand Up @@ -385,11 +386,10 @@ impl ComponentProver<SimdBackend> for PoseidonComponent {
// Denoms.
let span = span!(Level::INFO, "Constraint eval denominators").entered();
let zero_domain = CanonicCoset::new(self.log_column_size()).coset;
let mut denoms =
BaseFieldVec::from_iter(eval_domain.iter().map(|p| coset_vanishing(zero_domain, p)));
<SimdBackend as ColumnOps<BaseField>>::bit_reverse_column(&mut denoms);
let mut denom_inverses = BaseFieldVec::zeros(denoms.len());
<SimdBackend as FieldOps<BaseField>>::batch_inverse(&denoms, &mut denom_inverses);
let denoms_inv: [BaseField; 1 << LOG_EXPAND] =
array::from_fn(|i| coset_vanishing(zero_domain, eval_domain.at(i)).inverse());
let mut packed_denoms_inv = denoms_inv.map(PackedM31::broadcast);
bit_reverse(&mut packed_denoms_inv);
span.exit();

let _span = span!(Level::INFO, "Constraint pointwise eval").entered();
Expand All @@ -414,13 +414,14 @@ impl ComponentProver<SimdBackend> for PoseidonComponent {
for _ in 0..N_INSTANCES_PER_ROW {
evaluator.eval();
}
let row_res = evaluator.eval.row_res;

let packed_denom_inv =
packed_denoms_inv[vec_row >> (zero_domain.log_size() - LOG_N_LANES)];
let quotient = evaluator.eval.row_res * packed_denom_inv;
unsafe {
accum.col.set_packed(
vec_row,
accum.col.packed_at(vec_row) + row_res * denom_inverses.data[vec_row],
)
accum
.col
.set_packed(vec_row, accum.col.packed_at(vec_row) + quotient)
}
assert_eq!(evaluator.eval.constraint_index, n_constraints);
}
Expand Down

0 comments on commit be26562

Please sign in to comment.