Skip to content

Commit

Permalink
Use precomputed twiddles (#494)
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/494)
<!-- Reviewable:end -->
  • Loading branch information
spapinistarkware authored Apr 15, 2024
1 parent a8d128b commit ae2aa27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/core/commitment_scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentSchemeProver<B> {
}
}

pub fn commit(&mut self, polynomials: ColumnVec<CirclePoly<B>>, channel: &mut ProofChannel) {
let tree = CommitmentTreeProver::new(polynomials, self.log_blowup_factor, channel);
pub fn commit(
&mut self,
polynomials: ColumnVec<CirclePoly<B>>,
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) {
let tree =
CommitmentTreeProver::new(polynomials, self.log_blowup_factor, channel, twiddles);
self.trees.push(tree);
}

Expand Down Expand Up @@ -147,13 +153,15 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentTreeProver<B> {
polynomials: ColumnVec<CirclePoly<B>>,
log_blowup_factor: u32,
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) -> Self {
let span = span!(Level::INFO, "Commitment evaluation").entered();
let evaluations = polynomials
.iter()
.map(|poly| {
poly.evaluate(
poly.evaluate_with_twiddles(
CanonicCoset::new(poly.log_size() + log_blowup_factor).circle_domain(),
twiddles,
)
})
.collect_vec();
Expand Down
26 changes: 17 additions & 9 deletions src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,26 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(
});
}

let span = span!(Level::INFO, "Precompute twiddle").entered();
let twiddles = B::precompute_twiddles(
CanonicCoset::new(air.composition_log_degree_bound() + LOG_BLOWUP_FACTOR)
.circle_domain()
.half_coset,
);
span.exit();

// Evaluate and commit on trace.
// TODO(spapini): Commit on trace outside.
let span = span!(Level::INFO, "Trace interpolation").entered();
let trace_polys = trace.into_iter().map(|poly| poly.interpolate()).collect();
let trace_polys = trace
.into_iter()
.map(|poly| poly.interpolate_with_twiddles(&twiddles))
.collect();
span.exit();

let mut commitment_scheme = CommitmentSchemeProver::new(LOG_BLOWUP_FACTOR);
let span = span!(Level::INFO, "Trace commitment").entered();
commitment_scheme.commit(trace_polys, channel);
commitment_scheme.commit(trace_polys, channel, &twiddles);
span.exit();

// Evaluate and commit on composition polynomial.
Expand All @@ -92,7 +103,7 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(
span.exit();

let span = span!(Level::INFO, "Composition commitment").entered();
commitment_scheme.commit(composition_polynomial_poly.to_vec(), channel);
commitment_scheme.commit(composition_polynomial_poly.to_vec(), channel, &twiddles);
span.exit();

// Draw OODS point.
Expand Down Expand Up @@ -255,7 +266,7 @@ mod tests {
use crate::core::circle::{CirclePoint, CirclePointIndex, Coset};
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::poly::circle::{CircleDomain, MAX_CIRCLE_DOMAIN_LOG_SIZE};
use crate::core::poly::circle::{CanonicCoset, CircleDomain, MAX_CIRCLE_DOMAIN_LOG_SIZE};
use crate::core::prover::{prove, ProvingError};
use crate::core::test_utils::test_channel;
use crate::qm31;
Expand Down Expand Up @@ -373,13 +384,10 @@ mod tests {
let air = TestAir {
component: TestComponent {
log_size: LOG_DOMAIN_SIZE,
max_constraint_log_degree_bound: LOG_DOMAIN_SIZE,
max_constraint_log_degree_bound: LOG_DOMAIN_SIZE + 1,
},
};
let domain = CircleDomain::new(Coset::new(
CirclePointIndex::generator(),
LOG_DOMAIN_SIZE - 1,
));
let domain = CanonicCoset::new(LOG_DOMAIN_SIZE).circle_domain();
let values = vec![BaseField::zero(); 1 << LOG_DOMAIN_SIZE];
let trace = vec![CPUCircleEvaluation::new(domain, values)];

Expand Down

0 comments on commit ae2aa27

Please sign in to comment.