diff --git a/barustenberg-benches/benches/a_benchmark.rs b/barustenberg-benches/benches/a_benchmark.rs index c92d8da..4bbc11d 100644 --- a/barustenberg-benches/benches/a_benchmark.rs +++ b/barustenberg-benches/benches/a_benchmark.rs @@ -1,15 +1,15 @@ use criterion::{criterion_group, criterion_main, Criterion}; pub fn add_benchmark(c: &mut Criterion) { - let mut rvg = barustenberg::test_utils::Rvg::deterministic(); - let int_val_1 = rvg.sample(&(0..100i32)); - let int_val_2 = rvg.sample(&(0..100i32)); + // let mut rvg = barustenberg::test_utils::Rvg::deterministic(); + // let int_val_1 = rvg.sample(&(0..100i32)); + // let int_val_2 = rvg.sample(&(0..100i32)); - c.bench_function("add", |b| { - b.iter(|| { - barustenberg::add(int_val_1, int_val_2); - }) - }); + // c.bench_function("add", |b| { + // b.iter(|| { + // barustenberg::add(int_val_1, int_val_2); + // }) + // }); } criterion_group!(benches, add_benchmark); criterion_main!(benches); diff --git a/barustenberg/src/plonk/composer/composer_base.rs b/barustenberg/src/plonk/composer/composer_base.rs index b4ed065..79cc1cb 100644 --- a/barustenberg/src/plonk/composer/composer_base.rs +++ b/barustenberg/src/plonk/composer/composer_base.rs @@ -14,6 +14,7 @@ use crate::{ }, polynomials::Polynomial, srs::reference_string::ReferenceStringFactory, + transcript::Manifest, }; pub(crate) const DUMMY_TAG: u32 = 0; @@ -40,6 +41,12 @@ pub(crate) enum ComposerType { StandardHonk, } +impl ComposerType { + pub(crate) fn create_manifest(self, _x: usize) -> Manifest { + unimplemented!("ComposerType::create_manifest") + } +} + #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(crate) struct CycleNode { pub(crate) gate_index: u32, @@ -652,7 +659,7 @@ pub(crate) trait ComposerBase { let mut selector_poly = (*selector_poly).borrow_mut(); let selector_poly_coefficients = &mut selector_poly.coefficients; - let mut reference_string = (*proving_key.reference_string).borrow_mut(); + let reference_string = (*proving_key.reference_string).borrow_mut(); let mut pippenger_runtime_state = proving_key.pippenger_runtime_state.clone(); // Commit to the constraint selector polynomial and insert the commitment in the verification key. diff --git a/barustenberg/src/plonk/proof_system/utils/permutation.rs b/barustenberg/src/plonk/proof_system/utils/permutation.rs index 6bd8140..7a49f5e 100644 --- a/barustenberg/src/plonk/proof_system/utils/permutation.rs +++ b/barustenberg/src/plonk/proof_system/utils/permutation.rs @@ -1,4 +1,3 @@ -use ark_ec::AffineRepr; use ark_ff::{FftField, Field}; use crate::{ @@ -19,10 +18,7 @@ pub(crate) struct PermutationSubgroupElement { is_tag: bool, } -pub(crate) fn compute_permutation_lagrange_base_single< - H: BarretenHasher, - Fr: Field + FftField, ->( +pub(crate) fn compute_permutation_lagrange_base_single( output: &mut Polynomial, permutation: &[u32], small_domain: &EvaluationDomain, @@ -87,4 +83,4 @@ pub(crate) fn compute_permutation_lagrange_base_single_helper< } } } -} +} \ No newline at end of file diff --git a/barustenberg/src/plonk/proof_system/verifier/mod.rs b/barustenberg/src/plonk/proof_system/verifier/mod.rs index b2fdc6a..3144728 100644 --- a/barustenberg/src/plonk/proof_system/verifier/mod.rs +++ b/barustenberg/src/plonk/proof_system/verifier/mod.rs @@ -26,8 +26,8 @@ use super::verification_key::VerificationKey; use anyhow::{anyhow, Result}; -// #[cfg(test)] -// mod test; +#[cfg(test)] +mod test; #[derive(Debug)] pub struct Verifier> { diff --git a/barustenberg/src/plonk/proof_system/verifier/test.rs b/barustenberg/src/plonk/proof_system/verifier/test.rs index 11c4d59..54ec231 100644 --- a/barustenberg/src/plonk/proof_system/verifier/test.rs +++ b/barustenberg/src/plonk/proof_system/verifier/test.rs @@ -1,74 +1,91 @@ -use ark_ff::FftField; +use crate::{ + plonk::{ + composer::composer_base::ComposerType, + proof_system::{ + commitment_scheme::KateCommitmentScheme, + prover::Prover, + proving_key::ProvingKey, + types::prover_settings::StandardSettings, + utils::permutation::compute_permutation_lagrange_base_single, + widgets::{ + random_widgets::permutation_widget::ProverPermutationWidget, + transition_widgets::arithmetic_widget::ProverArithmeticWidget, + }, + }, + }, + polynomials::Polynomial, + srs::reference_string::{ + file_reference_string::{FileReferenceString, FileReferenceStringFactory}, + ReferenceStringFactory, + }, + transcript::Keccak256, +}; +use ark_ff::UniformRand; +use std::{cell::RefCell, rc::Rc}; use super::*; -impl> Verifier<'_, H, S> { - pub fn generate_verifier(circuit_proving_key: Rc>>) -> Self { - let mut poly_coefficients: Vec<&mut [Fr]> = vec![&mut []; 8]; - poly_coefficients[0] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"q_1".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[1] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"q_2".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[2] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"q_3".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[3] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"q_m".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[4] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"q_c".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[5] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"sigma_1".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[6] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"sigma_2".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); - poly_coefficients[7] = circuit_proving_key - .borrow() - .polynomial_store - .get(&"sigma_3".to_owned()) - .unwrap() - .borrow_mut() - .coefficients - .as_mut_slice(); +impl> Verifier { + pub fn generate_verifier( + circuit_proving_key: Rc>>, + ) -> Self { + let mut polynomials: Vec>>> = Vec::with_capacity(8); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"q_1".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"q_2".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"q_3".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"q_m".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"q_c".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"sigma_1".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"sigma_2".to_owned()) + .unwrap(), + ); + polynomials.push( + circuit_proving_key + .borrow() + .polynomial_store + .get(&"sigma_3".to_owned()) + .unwrap(), + ); let mut commitments = vec![G1Affine::default(); 8]; let mut state = PippengerRuntimeState::new(circuit_proving_key.borrow().circuit_size); @@ -76,12 +93,12 @@ impl> V for i in 0..8 { commitments[i] = G1Affine::from( state.pippenger( - poly_coefficients[i], - *(circuit_proving_key + polynomials[i].borrow_mut().coefficients.as_mut_slice(), + &((*(circuit_proving_key .borrow() .reference_string .borrow() - .get_monomial_points())[..], + .get_monomial_points()))[..]), circuit_proving_key.borrow().circuit_size, false, ), @@ -89,13 +106,14 @@ impl> V } // TODOL: this number of points in arbitrary and needs to be checked with the reference string - let crs = Rc::new(FileReferenceString::new(32, "../srs_db/ignition")); - let circuit_verification_key = Rc::new(VerificationKey::new( + let crs = FileReferenceStringFactory::new("../srs_db/ignition".to_string()); + let vrs = crs.get_verifier_crs().unwrap(); + let mut circuit_verification_key = VerificationKey::new( circuit_proving_key.borrow().circuit_size, circuit_proving_key.borrow().num_public_inputs, - crs, + vrs, circuit_proving_key.borrow().composer_type, - )); + ); circuit_verification_key .commitments @@ -112,7 +130,6 @@ impl> V circuit_verification_key .commitments .insert("Q_C".to_string(), commitments[4]); - circuit_verification_key .commitments .insert("SIGMA_1".to_string(), commitments[5]); @@ -123,8 +140,8 @@ impl> V .commitments .insert("SIGMA_3".to_string(), commitments[7]); - let verifier = Verifier::new( - Some(circuit_verification_key), + let mut verifier = Verifier::new( + Some(Rc::new(RefCell::new(circuit_verification_key))), ComposerType::Standard.create_manifest(0), ); @@ -134,18 +151,20 @@ impl> V } } -fn generate_test_data< - 'a, - Fq: Field + FftField, - Fr: Field + FftField, - G: AffineRepr, - H: BarretenHasher + Default, ->( +fn generate_test_data<'a, H: BarretenHasher + Default + 'static>( n: usize, -) -> Prover<'a, H, StandardSettings> { +) -> Prover> { // create some constraints that satisfy our arithmetic circuit relation - let crs = Rc::new(FileReferenceString::new(n + 1, "../srs_db/ignition")); - let key = Rc::new(ProvingKey::new(n, 0, crs, ComposerType::Standard)); + let crs = Rc::new(RefCell::new(FileReferenceString::new( + n + 1, + "../srs_db/ignition", + ))); + let key = Rc::new(RefCell::new(ProvingKey::new( + n, + 0, + crs, + ComposerType::Standard, + ))); let mut rand = rand::thread_rng(); @@ -186,14 +205,14 @@ fn generate_test_data< } let shift = n / 2; - w_l.coefficients[shift..].copy_from_slice(&w_l.coefficients[..shift]); - w_r.coefficients[shift..].copy_from_slice(&w_r.coefficients[..shift]); - w_o.coefficients[shift..].copy_from_slice(&w_o.coefficients[..shift]); - q_m.coefficients[shift..].copy_from_slice(&q_m.coefficients[..shift]); - q_l.coefficients[shift..].copy_from_slice(&q_l.coefficients[..shift]); - q_r.coefficients[shift..].copy_from_slice(&q_r.coefficients[..shift]); - q_o.coefficients[shift..].copy_from_slice(&q_o.coefficients[..shift]); - q_c.coefficients[shift..].copy_from_slice(&q_c.coefficients[..shift]); + w_l.coefficients[shift..].copy_within(..shift, shift); + w_r.coefficients[shift..].copy_within(..shift, shift); + w_o.coefficients[shift..].copy_within(..shift, shift); + q_m.coefficients[shift..].copy_within(..shift, shift); + q_l.coefficients[shift..].copy_within(..shift, shift); + q_r.coefficients[shift..].copy_within(..shift, shift); + q_o.coefficients[shift..].copy_within(..shift, shift); + q_c.coefficients[shift..].copy_within(..shift, shift); let mut sigma_1_mapping: Vec = vec![0; n]; let mut sigma_2_mapping: Vec = vec![0; n]; @@ -212,7 +231,6 @@ fn generate_test_data< // make last permutation the same as identity permutation // we are setting the permutation in the last 4 gates as identity permutation since // we are cutting out 4 roots as of now. - let num_roots_cut_out_of_the_vanishing_polynomial = 4; for j in 0..num_roots_cut_out_of_the_vanishing_polynomial { let index = (shift - 1 - j) as u32; @@ -224,67 +242,97 @@ fn generate_test_data< sigma_3_mapping[n - 1 - j] = ((n - 1 - j) as u32) + (1 << 31); } - let mut sigma_1 = Polynomial::new(key.circuit_size); - let mut sigma_2 = Polynomial::new(key.circuit_size); - let mut sigma_3 = Polynomial::new(key.circuit_size); + let mut sigma_1 = Polynomial::new(key.borrow().circuit_size); + let mut sigma_2 = Polynomial::new(key.borrow().circuit_size); + let mut sigma_3 = Polynomial::new(key.borrow().circuit_size); - compute_permutation_lagrange_base_single(&mut sigma_1, &sigma_1_mapping, &key.small_domain); - compute_permutation_lagrange_base_single(&mut sigma_2, &sigma_2_mapping, &key.small_domain); - compute_permutation_lagrange_base_single(&mut sigma_3, &sigma_3_mapping, &key.small_domain); + compute_permutation_lagrange_base_single::( + &mut sigma_1, + &sigma_1_mapping, + &key.borrow().small_domain, + ); + compute_permutation_lagrange_base_single::( + &mut sigma_2, + &sigma_2_mapping, + &key.borrow().small_domain, + ); + compute_permutation_lagrange_base_single::( + &mut sigma_3, + &sigma_3_mapping, + &key.borrow().small_domain, + ); let sigma_1_lagrange_base = sigma_1.clone(); let sigma_2_lagrange_base = sigma_2.clone(); let sigma_3_lagrange_base = sigma_3.clone(); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"sigma_1_lagrange".to_string(), sigma_1_lagrange_base); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"sigma_2_lagrange".to_string(), sigma_2_lagrange_base); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"sigma_3_lagrange".to_string(), sigma_3_lagrange_base); - key.small_domain.ifft_inplace(&mut sigma_1); - key.small_domain.ifft_inplace(&mut sigma_2); - key.small_domain.ifft_inplace(&mut sigma_3); + key.borrow().small_domain.ifft_inplace(&mut sigma_1); + key.borrow().small_domain.ifft_inplace(&mut sigma_2); + key.borrow().small_domain.ifft_inplace(&mut sigma_3); const WIDTH: usize = 4; let mut sigma_1_fft = sigma_1.clone(); - sigma_1_fft.resize(key.circuit_size * WIDTH, Fr::zero()); + sigma_1_fft.resize(key.borrow().circuit_size * WIDTH, Fr::zero()); let mut sigma_2_fft = sigma_2.clone(); - sigma_2_fft.resize(key.circuit_size * WIDTH, Fr::zero()); + sigma_2_fft.resize(key.borrow().circuit_size * WIDTH, Fr::zero()); let mut sigma_3_fft = sigma_3.clone(); - sigma_3_fft.resize(key.circuit_size * WIDTH, Fr::zero()); + sigma_3_fft.resize(key.borrow().circuit_size * WIDTH, Fr::zero()); - key.large_domain + key.borrow() + .large_domain .coset_fft_inplace(&mut sigma_1_fft.coefficients[..]); - key.large_domain + key.borrow() + .large_domain .coset_fft_inplace(&mut sigma_2_fft.coefficients[..]); - key.large_domain + key.borrow() + .large_domain .coset_fft_inplace(&mut sigma_3_fft.coefficients[..]); - key.polynomial_store.insert(&"sigma_1".to_string(), sigma_1); - key.polynomial_store.insert(&"sigma_2".to_string(), sigma_2); - key.polynomial_store.insert(&"sigma_3".to_string(), sigma_3); - - key.polynomial_store + key.borrow_mut() + .polynomial_store + .insert(&"sigma_1".to_string(), sigma_1); + key.borrow_mut() + .polynomial_store + .insert(&"sigma_2".to_string(), sigma_2); + key.borrow_mut() + .polynomial_store + .insert(&"sigma_3".to_string(), sigma_3); + + key.borrow_mut() + .polynomial_store .insert(&"sigma_1_fft".to_string(), sigma_1_fft); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"sigma_2_fft".to_string(), sigma_2_fft); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"sigma_3_fft".to_string(), sigma_3_fft); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"w_1_lagrange".to_string(), w_l); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"w_2_lagrange".to_string(), w_r); - key.polynomial_store + key.borrow_mut() + .polynomial_store .insert(&"w_3_lagrange".to_string(), w_o); - key.small_domain.ifft_inplace(&mut q_l); - key.small_domain.ifft_inplace(&mut q_r); - key.small_domain.ifft_inplace(&mut q_o); - key.small_domain.ifft_inplace(&mut q_m); - key.small_domain.ifft_inplace(&mut q_c); + key.borrow().small_domain.ifft_inplace(&mut q_l); + key.borrow().small_domain.ifft_inplace(&mut q_r); + key.borrow().small_domain.ifft_inplace(&mut q_o); + key.borrow().small_domain.ifft_inplace(&mut q_m); + key.borrow().small_domain.ifft_inplace(&mut q_c); let mut q_1_fft = q_l.clone(); q_1_fft.resize(n * 4, Fr::zero()); @@ -297,41 +345,65 @@ fn generate_test_data< let mut q_c_fft = q_c.clone(); q_c_fft.resize(n * 4, Fr::zero()); - key.large_domain + key.borrow_mut() + .large_domain .coset_fft_inplace(&mut q_1_fft.coefficients[..]); - key.large_domain + key.borrow_mut() + .large_domain .coset_fft_inplace(&mut q_2_fft.coefficients[..]); - key.large_domain + key.borrow_mut() + .large_domain .coset_fft_inplace(&mut q_3_fft.coefficients[..]); - key.large_domain + key.borrow_mut() + .large_domain .coset_fft_inplace(&mut q_m_fft.coefficients[..]); - key.large_domain + key.borrow_mut() + .large_domain .coset_fft_inplace(&mut q_c_fft.coefficients[..]); - key.polynomial_store.insert(&"q_1".to_string(), q_l); - key.polynomial_store.insert(&"q_2".to_string(), q_r); - key.polynomial_store.insert(&"q_3".to_string(), q_o); - key.polynomial_store.insert(&"q_m".to_string(), q_m); - key.polynomial_store.insert(&"q_c".to_string(), q_c); - - key.polynomial_store.insert(&"q_1_fft".to_string(), q_1_fft); - key.polynomial_store.insert(&"q_2_fft".to_string(), q_2_fft); - key.polynomial_store.insert(&"q_3_fft".to_string(), q_3_fft); - key.polynomial_store.insert(&"q_m_fft".to_string(), q_m_fft); - key.polynomial_store.insert(&"q_c_fft".to_string(), q_c_fft); - - let permutation_widget: Box> = - Box::new(ProverPermutationWidget::<3>::new(key.clone())); - - let widget: Box> = Box::new( - ProverArithmeticWidget::<_, StandardSettings>::new(key.clone()), - ); + key.borrow_mut() + .polynomial_store + .insert(&"q_1".to_string(), q_l); + key.borrow_mut() + .polynomial_store + .insert(&"q_2".to_string(), q_r); + key.borrow_mut() + .polynomial_store + .insert(&"q_3".to_string(), q_o); + key.borrow_mut() + .polynomial_store + .insert(&"q_m".to_string(), q_m); + key.borrow_mut() + .polynomial_store + .insert(&"q_c".to_string(), q_c); + + key.borrow_mut() + .polynomial_store + .insert(&"q_1_fft".to_string(), q_1_fft); + key.borrow_mut() + .polynomial_store + .insert(&"q_2_fft".to_string(), q_2_fft); + key.borrow_mut() + .polynomial_store + .insert(&"q_3_fft".to_string(), q_3_fft); + key.borrow_mut() + .polynomial_store + .insert(&"q_m_fft".to_string(), q_m_fft); + key.borrow_mut() + .polynomial_store + .insert(&"q_c_fft".to_string(), q_c_fft); + + let permutation_widget: Box> = + Box::new(ProverPermutationWidget::::new(key.clone())); + + let widget: Box> = + Box::new(ProverArithmeticWidget::::new(key.clone())); let kate_commitment_scheme = KateCommitmentScheme::::new(); - let state: Prover<'_, H, StandardSettings> = Prover::new( + let mut state: Prover> = Prover::new( Some(key), - Some(ComposerType::StandardComposer::create_manifest(0)), + Some(ComposerType::Standard.create_manifest(0)), None, ); state.random_widgets.push(permutation_widget); @@ -340,39 +412,18 @@ fn generate_test_data< state } -use std::{cell::RefCell, rc::Rc}; - -use crate::{ - plonk::{ - composer::composer_base::ComposerType, - proof_system::{ - commitment_scheme::KateCommitmentScheme, - prover::Prover, - proving_key::ProvingKey, - types::prover_settings::StandardSettings, - utils::permutation::compute_permutation_lagrange_base_single, - widgets::{ - random_widgets::permutation_widget::ProverPermutationWidget, - transition_widgets::arithmetic_widget::ProverArithmeticWidget, - }, - }, - }, - polynomials::Polynomial, - srs::reference_string::file_reference_string::FileReferenceString, - transcript::Keccak256, -}; - #[test] fn verify_arithmetic_proof_small() { let n = 8; - let state = generate_test_data::(n); - let verifier: Verifier<'_, Keccak256, StandardSettings> = - Verifier::generate_verifier(&state.key); + let mut state = generate_test_data::(n); // Construct proof let proof = state.construct_proof().unwrap(); + let mut verifier: Verifier> = + Verifier::generate_verifier(state.key); + // Verify proof let result = verifier.verify_proof(&proof).unwrap(); @@ -383,13 +434,16 @@ fn verify_arithmetic_proof_small() { fn verify_arithmetic_proof() { let n = 1 << 14; - let state = generate_test_data::(n); - let verifier: Verifier<'_, Keccak256, StandardSettings> = - Verifier::generate_verifier(&state.key); + let mut state = generate_test_data::(n); + let _verifier: Verifier> = + Verifier::generate_verifier(state.key.clone()); // Construct proof let proof = state.construct_proof().unwrap(); + let mut verifier: Verifier> = + Verifier::generate_verifier(state.key.clone()); + // Verify proof let result = verifier.verify_proof(&proof).unwrap(); @@ -401,9 +455,9 @@ fn verify_arithmetic_proof() { fn verify_damaged_proof() { let n = 8; - let state = generate_test_data::(n); - let verifier: Verifier<'_, Keccak256, StandardSettings> = - Verifier::generate_verifier(&state.key); + let state = generate_test_data::(n); + let mut verifier: Verifier> = + Verifier::generate_verifier(state.key); // Create empty proof let proof = Proof::default(); diff --git a/barustenberg/src/plonk/proof_system/widgets/transition_widgets/transition_widget.rs b/barustenberg/src/plonk/proof_system/widgets/transition_widgets/transition_widget.rs index 7152abe..ede5138 100644 --- a/barustenberg/src/plonk/proof_system/widgets/transition_widgets/transition_widget.rs +++ b/barustenberg/src/plonk/proof_system/widgets/transition_widgets/transition_widget.rs @@ -1,6 +1,7 @@ use std::{ cell::RefCell, collections::{HashMap, HashSet}, + fmt::Debug, marker::PhantomData, rc::Rc, sync::Arc, @@ -105,7 +106,7 @@ impl< H: BarretenHasher, F: Field + FftField, G: AffineRepr, - NIndependentRelations: generic_array::ArrayLength + std::fmt::Debug, + NIndependentRelations: generic_array::ArrayLength + Debug, KB: std::fmt::Debug, > TransitionWidgetBase for TransitionWidget where diff --git a/barustenberg/src/polynomials/evaluation_domain.rs b/barustenberg/src/polynomials/evaluation_domain.rs index d45d201..e4d1381 100644 --- a/barustenberg/src/polynomials/evaluation_domain.rs +++ b/barustenberg/src/polynomials/evaluation_domain.rs @@ -1,3 +1,31 @@ +#![cfg_attr(docsrs, feature(doc_cfg))] +#![warn(missing_debug_implementations, missing_docs)] +#![deny(unreachable_pub, private_in_public)] +//! # Evaluation Domain +//! +//! This module contains the `EvaluationDomain` struct and related functionality. +//! It plays an important role in finite field and number-theoretic computations, +//! especially Fast Fourier Transforms (FFTs). In the context of FFTs, the evaluation +//! domain represents a set of points in a finite field where a polynomial is evaluated. +//! +//! The `EvaluationDomain` struct stores various properties of the finite field, +//! such as the size of the domain, the root of unity, and its inverse, among other things. +//! It also maintains lookup tables for the roots of unity required for each FFT round. +//! +//! Furthermore, this struct is designed to support parallel computation. It includes fields +//! that denote the number of threads and thread sizes for these computations. +//! +//! This module also provides specific types for evaluation domains over the fields +//! defined by the ark_bn254 and grumpkin crates, namely `BarretenbergEvaluationDomain` +//! and `GrumpkinEvaluationDomain`. +//! +//! The `compute_num_threads` function calculates the number of threads for parallel +//! computations, depending on the size of the domain and whether multithreading is enabled. +//! It is particularly useful when working with large polynomials and fields. +//! +//! The `compute_lookup_table_single` function is a utility for precomputing and storing +//! the roots of a polynomial in a lookup table, which can greatly accelerate subsequent FFT operations. + use ark_ff::{FftField, Field}; use crate::numeric::bitop::Msb; @@ -9,23 +37,32 @@ pub(crate) const MIN_GROUP_PER_THREAD: usize = 4; pub(crate) struct EvaluationDomain { /// n, always a power of 2 pub(crate) size: usize, - /// num_threads * thread_size = size + /// The number of threads used for parallel computation. pub(crate) num_threads: usize, + /// The size of each thread. + /// num_threads * thread_size = size pub(crate) thread_size: usize, + /// The logarithm base 2 of the domain size (i.e., n). pub(crate) log2_size: usize, + /// The logarithm base 2 of the thread size. pub(crate) log2_thread_size: usize, + /// The logarithm base 2 of the number of threads pub(crate) log2_num_threads: usize, + /// The size of the generator. pub(crate) generator_size: usize, - /// omega; the nth root of unity + /// The Nth root of unity, pub(crate) root: F, - /// omega^{-1} + /// The inverse of the root of unity, omega^{-1}. pub(crate) root_inverse: F, - /// n; same as size + /// The domain, equivalent to the size (i.e., 2^n). pub(crate) domain: F, - /// n^{-1} + /// Equivalent to the domain, but as an inverse (i.e., 2^{-n}). pub(crate) domain_inverse: F, + /// The generator. pub(crate) generator: F, + /// The inverse of the generator. pub(crate) generator_inverse: F, + /// The inverse of four. pub(crate) four_inverse: F, /// An entry for each of the log(n) rounds: each entry is a range that /// specifies the subset of the roots of unity required for that fft round. @@ -37,6 +74,16 @@ pub(crate) struct EvaluationDomain { pub(crate) roots: Vec, } +/// Computes the number of threads to be used based on the domain size and the +/// minimum number of groups per thread. +/// +/// If multithreading feature is enabled, it uses the maximum number of threads +/// that can run simultaneously. If the domain size is smaller than the +/// product of the number of threads and the minimum number of groups per +/// thread, it uses a single thread. +/// +/// Otherwise, it uses the number of threads computed by the `max_threads` +/// function from the `common` module. fn compute_num_threads(size: usize) -> usize { #[cfg(feature = "multithreading")] let num_threads = crate::common::max_threads::compute_num_threads(); diff --git a/barustenberg/src/polynomials/polynomial.rs b/barustenberg/src/polynomials/polynomial.rs index ece9ab8..d9b0c88 100644 --- a/barustenberg/src/polynomials/polynomial.rs +++ b/barustenberg/src/polynomials/polynomial.rs @@ -1,3 +1,50 @@ +#![cfg_attr(docsrs, feature(doc_cfg))] +#![warn(missing_debug_implementations, missing_docs)] +#![deny(unreachable_pub, private_in_public)] +//! This module provides the `Polynomial` struct, which represents a polynomial over a field `F`. +//! +//! The `Polynomial` struct contains methods for constructing polynomials, accessing their +//! components, and performing operations on them. It also provides implementations for common +//! arithmetic operations such as addition, subtraction, and scalar multiplication. +//! +//! Here is a brief description of the main features of this module: +//! +//! # `Polynomial` Struct +//! +//! The `Polynomial` struct holds a vector of coefficients and the size of the polynomial. +//! It is parameterized over a type `F` which is required to implement the `Field` trait. +//! The size of the polynomial corresponds to the number of terms in the polynomial (i.e., degree + 1). +//! The coefficients of the polynomial are represented by a vector of field elements. +//! The `i`-th element of this vector represents the coefficient of the `x^i` term of the polynomial. +//! +//! # Constructors +//! +//! Two constructors are provided: +//! +//! - `from_interpolations`: Constructs a `Polynomial` instance from given interpolation points +//! and function evaluations at these points. +//! - `new`: Creates a new `Polynomial` of a given size, with all coefficients initialized to zero. +//! +//! # Methods +//! +//! Methods provided by the `Polynomial` struct include: +//! +//! - `size`: Returns the size (number of terms) of the polynomial. +//! - `set_coefficient`: Sets the coefficient of the polynomial at a given index. +//! - `resize`: Resizes the polynomial to a new length, filling any additional space with a given value. +//! +//! # Trait Implementations +//! +//! The `Polynomial` struct also implements several traits to provide convenient and efficient +//! operations on the polynomials: +//! +//! - `AddAssign`, `SubAssign`, `MulAssign`: For in-place addition, subtraction, and scalar multiplication. +//! - `IntoIterator`: To convert a `Polynomial` into an iterator over its coefficients. +//! - `Index` and `IndexMut`: To access or modify the coefficients of a `Polynomial` by their indices. +//! +//! This module serves as the core for polynomial operations in this library, providing the basis +//! for efficient polynomial arithmetic over arbitrary fields. + use std::ops::{AddAssign, Index, IndexMut, MulAssign, Range, SubAssign}; use anyhow::Result; @@ -30,6 +77,7 @@ impl Polynomial { }) } + /// Creates a new polynomial of the given size with all coefficients initialized to zero. #[inline] pub(crate) fn new(size: usize) -> Self { let underlying = vec![F::zero(); size]; @@ -38,14 +86,20 @@ impl Polynomial { coefficients: underlying, } } + + /// Returns the number of terms of the polynomial (i.e., degree + 1). #[inline] pub(crate) fn size(&self) -> usize { self.size } + + /// Sets the coefficient at a given index of the polynomial. #[inline] pub(crate) fn set_coefficient(&mut self, idx: usize, v: F) { self.coefficients[idx] = v } + + /// Resizes the polynomial to a new length, filling any additional space with a given value. #[inline] pub(crate) fn resize(&mut self, new_len: usize, val: F) { self.coefficients.resize(new_len, val) @@ -53,6 +107,8 @@ impl Polynomial { } impl AddAssign for Polynomial { + /// Adds another polynomial to `self` in-place. + /// If the other polynomial has a higher degree, `self` is extended with zeros. fn add_assign(&mut self, rhs: Self) { // pad the smaller polynomial with zeros if self.size < rhs.size { @@ -65,6 +121,8 @@ impl AddAssign for Polynomial { } impl SubAssign for Polynomial { + /// Subtracts another polynomial from `self` in-place. + /// If the other polynomial has a higher degree, `self` is extended with zeros. fn sub_assign(&mut self, rhs: Self) { // pad the smaller polynomial with zeros if self.size < rhs.size { @@ -77,6 +135,7 @@ impl SubAssign for Polynomial { } impl MulAssign for Polynomial { + /// Multiplies `self` by a scalar in-place. fn mul_assign(&mut self, rhs: F) { for i in 0..self.size { self.coefficients[i] *= rhs; @@ -88,6 +147,7 @@ impl IntoIterator for Polynomial { type Item = F; type IntoIter = std::vec::IntoIter; + /// Returns an iterator over the coefficients of `self`. fn into_iter(self) -> Self::IntoIter { self.coefficients.into_iter() } @@ -96,12 +156,14 @@ impl IntoIterator for Polynomial { impl Index for Polynomial { type Output = F; + /// Returns a reference to the coefficient at a given index. fn index(&self, index: usize) -> &Self::Output { &self.coefficients[index] } } impl IndexMut for Polynomial { + /// Returns a mutable reference to the coefficient at a given index. fn index_mut(&mut self, index: usize) -> &mut Self::Output { &mut self.coefficients[index] } @@ -110,6 +172,7 @@ impl IndexMut for Polynomial { impl Index> for Polynomial { type Output = [F]; + /// Returns a mutable slice of coefficients for a range of indices. fn index(&self, index: Range) -> &Self::Output { &self.coefficients[index] } @@ -123,6 +186,7 @@ impl IndexMut> for Polynomial { impl Index> for Polynomial { type Output = [F]; + /// Returns a slice of coefficients for a range starting from a given index. fn index(&self, index: std::ops::RangeFrom) -> &Self::Output { &self.coefficients[index] } diff --git a/barustenberg/src/polynomials/polynomial_arithmetic.rs b/barustenberg/src/polynomials/polynomial_arithmetic.rs index eef6780..3c9fb8e 100644 --- a/barustenberg/src/polynomials/polynomial_arithmetic.rs +++ b/barustenberg/src/polynomials/polynomial_arithmetic.rs @@ -1,4 +1,36 @@ -use ark_ff::{batch_inversion, FftField, Field}; +#![cfg_attr(docsrs, feature(doc_cfg))] +#![warn(missing_debug_implementations, missing_docs)] +#![deny(unreachable_pub, private_in_public)] +//! This module provides various functions to perform operations on polynomials, with a focus on +//! arithmetic and evaluation functionality. +//! +//! Polynomials are represented as vectors of field elements where each element is a coefficient +//! in the polynomial. The i-th element of the vector represents the coefficient for the x^i term. +//! +//! # Main Functions +//! +//! - `compute_efficient_interpolation`: Computes the polynomial that interpolates a given set +//! of points in an efficient manner using the Lagrange Interpolation formula. +//! +//! - `evaluate`: Evaluates a given polynomial at a specific point. This function can use parallel +//! computation to speed up the evaluation. +//! +//! - `*_fft_*`: Computes the Fast Fourier Transform (FFT) of a polynomial in multiple different ways. +//! +//! # Helper Functions +//! +//! - `compute_linear_polynomial_product`, `compute_num_threads`, `reverse_bits`, +//! `is_power_of_two_usize`, `compute_barycentric_lagrange_weights`, `compute_multiexp`, +//! `compute_inner_product`: These functions are used as helpers for the main functions to +//! perform operations such as product of linear terms, computation of weights for interpolation, +//! computing multi-exponentiation and inner products, as well as bit manipulation for the FFT. +//! +//! This module forms the computational backbone for performing operations on polynomials, +//! including interpolation, evaluation, and transformations like the FFT. It is built with +//! performance in mind, leveraging concurrent processing where possible. + +use ark_ff::batch_inversion; +use ark_ff::{FftField, Field}; use crate::{common::max_threads::compute_num_threads, numeric::bitop::Msb}; @@ -9,6 +41,25 @@ pub(crate) struct LagrangeEvaluations { } #[inline] +/// Reverses the first `bit_length` bits of a `u32` number. +/// +/// This function takes a `u32` number `x` and a bit length `bit_length`. It reverses the order of +/// the first `bit_length` bits in `x` and returns the result. +/// +/// # Arguments +/// +/// * `x` - A `u32` number whose bits are to be reversed. +/// * `bit_length` - A `u32` specifying the number of bits to be reversed. +/// +/// # Returns +/// +/// * A `u32` number with the first `bit_length` bits reversed. +/// +/// # Examples +/// +/// ``` +/// assert_eq!(reverse_bits(0b1011, 4), 0b1101); +/// ``` fn reverse_bits(x: u32, bit_length: u32) -> u32 { let x = ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1); let x = ((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2); @@ -16,16 +67,78 @@ fn reverse_bits(x: u32, bit_length: u32) -> u32 { let x = ((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8); ((x >> 16) | (x << 16)) >> (32 - bit_length) } + #[inline] +/// Checks whether a `u64` number is a power of two. +/// +/// # Arguments +/// +/// * `x` - A `u64` number to be checked. +/// +/// # Returns +/// +/// * A `bool` that is `true` if `x` is a power of two and `false` otherwise. +/// +/// # Examples +/// +/// ``` +/// assert_eq!(is_power_of_two(4), true); +/// assert_eq!(is_power_of_two(6), false); +/// ``` fn is_power_of_two(x: u64) -> bool { x != 0 && (x & (x - 1)) == 0 } #[inline] +/// Checks whether a `usize` number is a power of two. +/// +/// # Arguments +/// +/// * `x` - A `usize` number to be checked. +/// +/// # Returns +/// +/// * A `bool` that is `true` if `x` is a power of two and `false` otherwise. +/// +/// # Examples +/// +/// ``` +/// assert_eq!(is_power_of_two_usize(4), true); +/// assert_eq!(is_power_of_two_usize(6), false); +/// ``` fn is_power_of_two_usize(x: usize) -> bool { x != 0 && (x & (x - 1)) == 0 } +/// Copies a polynomial from `src` to `dest` with specified numbers of coefficients. +/// +/// This function copies the first `num_src_coefficients` coefficients from `src` to `dest`. If +/// `num_target_coefficients` is greater than `num_src_coefficients`, the remaining coefficients in +/// `dest` are set to zero. +/// +/// # Type Parameters +/// +/// * `Fr` - A type that implements `Copy` and `Default` traits. +/// +/// # Arguments +/// +/// * `src` - A slice of coefficients from the source polynomial. +/// * `dest` - A mutable slice of coefficients where the coefficients from `src` are copied. +/// * `num_src_coefficients` - The number of coefficients to copy from `src`. +/// * `num_target_coefficients` - The total number of coefficients in the target polynomial. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let src = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; // replace `Fr::from` with the appropriate constructor for your field type +/// let mut dest = vec![Fr::default(); 4]; +/// +/// copy_polynomial(&src, &mut dest, src.len(), dest.len()); +/// +/// assert_eq!(dest, vec![Fr::from(1), Fr::from(2), Fr::from(3), Fr::default()]); // replace `Fr::from` and `Fr::default` with the appropriate constructor for your field type +/// ``` fn copy_polynomial( src: &[Fr], dest: &mut [Fr], @@ -51,6 +164,50 @@ use std::ops::{Add, Mul, Sub}; use super::{evaluation_domain::EvaluationDomain, Polynomial}; +/// Performs a serial Fast Fourier Transform (FFT) on a set of polynomials. +/// +/// This function computes the FFT on a set of polynomials represented by `coeffs`. The +/// polynomials are evaluated at the `domain_size`-th roots of unity, given in the `root_table`. +/// +/// It uses an iterative in-place Cooley-Tukey FFT algorithm, which requires that the number +/// of polynomial coefficients (i.e., `domain_size`) is a power of two. +/// +/// The computation is performed in serial, meaning it uses a single thread. For large inputs, +/// a parallel FFT algorithm may be more efficient. +/// +/// # Type Parameters +/// +/// * `Fr` - A field type that implements `Copy`, `Default`, `Add`, `Sub` and `Mul`. The operations +/// must take no arguments and return an instance of the same type. +/// +/// # Arguments +/// +/// * `coeffs` - A mutable slice of vectors representing the coefficients of the polynomials. +/// Each vector is a polynomial and the FFT is performed in-place, meaning the output +/// is stored in `coeffs`. +/// * `domain_size` - The size of the domain over which the FFT is computed. It must be a power +/// of two and divide evenly into the number of polynomials. +/// * `root_table` - A slice of vectors representing the `domain_size`-th roots of unity. These +/// are used in the FFT computation. +/// +/// # Panics +/// +/// Panics if `domain_size` is not a power of two, or if `domain_size` does not divide evenly +/// into the number of polynomials. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let mut coeffs = vec![vec![Fr::from(1), Fr::from(2)], vec![Fr::from(3), Fr::from(4)]]; +/// let root_table = ...; // compute or provide the roots of unity +/// let domain_size = 2; +/// +/// fft_inner_serial(&mut coeffs, domain_size, &root_table); +/// +/// // `coeffs` now contains the FFT of the input polynomials +/// ``` fn fft_inner_serial + Sub + Mul>( coeffs: &mut [Vec], domain_size: usize, @@ -725,15 +882,14 @@ impl EvaluationDomain { // Note: This is a placeholder, replace with actual batch invert function. // TODO add batch invert // invert them all - let result: Result<(), anyhow::Error> = l_1_coefficients - .coefficients - .iter_mut().try_for_each(|x| { - let inverse = x - .inverse() - .ok_or_else(|| anyhow::anyhow!("Failed to find inverse"))?; - *x = inverse; - Ok(()) - }); + let result: Result<(), anyhow::Error> = + l_1_coefficients.coefficients.iter_mut().try_for_each(|x| { + let inverse = x + .inverse() + .ok_or_else(|| anyhow::anyhow!("Failed to find inverse"))?; + *x = inverse; + Ok(()) + }); result?; // Step 2: Compute numerator (1/n)*(X_i^n - 1) @@ -792,7 +948,7 @@ impl EvaluationDomain { let mut work_root = self.root_inverse; // ω^{-1} for denominator in denominators.iter_mut().take(num_coeffs).skip(1) { *denominator = work_root * *z; // denominators[i] will correspond to L_[i+1] (since our 'commented maths' notation indexes - // L_i from 1). So ʓ.ω^{-i} = ʓ.ω^{1-(i+1)} is correct for L_{i+1}. + // L_i from 1). So ʓ.ω^{-i} = ʓ.ω^{1-(i+1)} is correct for L_{i+1}. *denominator -= Fr::one(); work_root *= self.root_inverse; } @@ -812,11 +968,73 @@ impl EvaluationDomain { } } +/// Compute the sum of field elements in a given slice. +/// +/// This function computes the sum of all elements in the input slice `slice` of type `Fr`. It +/// is useful for computing the sum of coefficients of a polynomial represented in coefficient form. +/// +/// # Type Parameters +/// +/// * `Fr` - A type that implements the `Field` trait. +/// +/// # Arguments +/// +/// * `slice` - A slice containing elements of the field `Fr`. +/// +/// # Returns +/// +/// * A field element of type `Fr` representing the sum of all elements in `slice`. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let coeffs = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; // replace `Fr::from` with the appropriate constructor for your field type +/// +/// let sum = compute_sum(&coeffs); +/// +/// assert_eq!(sum, Fr::from(6)); // replace `Fr::from` with the appropriate constructor for your field type +/// ``` fn compute_sum(slice: &[Fr]) -> Fr { slice.iter().copied().fold(Fr::zero(), Add::add) } -pub(crate) fn compute_linear_polynomial_product( +/// Compute the coefficients of a polynomial that is the product of linear polynomials. +/// +/// This function computes the coefficients of a polynomial which is the product of linear (degree 1) +/// polynomials with roots specified by `roots`. Each linear polynomial is of the form `(x - root)`, +/// where `root` is an element from the `roots` slice. The resulting polynomial is therefore of the +/// form `(x - root_1) * (x - root_2) * ... * (x - root_n)`. +/// +/// # Arguments +/// +/// * `roots` - A slice that holds the roots of the linear polynomials. +/// +/// * `dest` - A mutable slice where the computed polynomial coefficients will be stored. It should +/// have length `n + 1` where `n` is the number of roots. +/// +/// * `n` - The number of roots and hence the degree of the resulting polynomial. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let roots = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; // replace `Fr::from` with the appropriate constructor for your field type +/// let mut dest = vec![Fr; 4]; +/// let n = 3; +/// +/// compute_linear_polynomial_product(&roots, &mut dest, n); +/// +/// assert_eq!(dest, vec![24, -50, 35, 1]); +/// ``` +/// +/// # Panics +/// +/// This function will panic if the length of `dest` is not `n + 1`. + +pub(crate) fn compute_linear_polynomial_product( roots: &[Fr], dest: &mut [Fr], n: usize, @@ -841,7 +1059,47 @@ pub(crate) fn compute_linear_polynomial_product( } } -pub(crate) fn compute_efficient_interpolation( +/// Computes efficient interpolation of a polynomial using Lagrange's formula. +/// +/// This function computes an efficient interpolation of a polynomial using Lagrange's technique. +/// Given a set of points (x_i, y_i), it computes the function f(X) such that f(x_i) = y_i for all i. +/// The polynomial is computed as a product of linear factors, divided by a denominator computed from the +/// evaluation points. +/// +/// It uses a technique similar to the Kate commitment scheme for dividing by (X - x_i). +/// +/// # Type Parameters +/// +/// * `Fr` - A field type that implements the `Field` trait. The operations must take no arguments and return an +/// instance of the same type. +/// +/// # Arguments +/// +/// * `src` - A slice representing the coefficients of the polynomial (y_i values). +/// * `dest` - A mutable slice where the interpolated polynomial will be stored. +/// * `evaluation_points` - A slice representing the points at which the polynomial is evaluated (x_i values). +/// * `n` - The number of points. +/// +/// # Returns +/// +/// This function returns a `Result<(), anyhow::Error>`. If the interpolation is successful, it returns `Ok(())`. +/// If an error occurs (e.g., if it fails to find an inverse during computation), it returns `Err(anyhow::Error)`. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let src = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; +/// let evaluation_points = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; +/// let mut dest = vec![Fr::zero(); src.len()]; +/// let n = src.len(); +/// +/// compute_efficient_interpolation(&src, &mut dest, &evaluation_points, n).unwrap(); +/// +/// // `dest` now contains the interpolated polynomial +/// ``` +pub(crate) fn compute_efficient_interpolation( src: &[Fr], dest: &mut [Fr], evaluation_points: &[Fr], @@ -957,6 +1215,46 @@ pub(crate) fn compute_kate_opening_coefficients( Ok(f) } +/// Evaluates a polynomial at a given point. +/// +/// This function evaluates a polynomial represented by `coeffs` at a given point `z`. +/// The computation is parallelized into threads for efficiency. The number of threads is determined by +/// the `compute_num_threads` function, which is assumed to be appropriately defined elsewhere. +/// +/// The polynomial is evaluated using the formula: +/// +/// f(z) = c0 * z^0 + c1 * z^1 + c2 * z^2 + ... + cn * z^n +/// +/// where `ci` are the coefficients of the polynomial. +/// +/// # Type Parameters +/// +/// * `F` - A field type that implements the `Field` trait. The operations must take no arguments and return an +/// instance of the same type. +/// +/// # Arguments +/// +/// * `coeffs` - A slice representing the coefficients of the polynomial. +/// * `z` - A reference to the point at which the polynomial should be evaluated. +/// * `n` - The degree of the polynomial plus one (i.e., the number of coefficients). +/// +/// # Returns +/// +/// This function returns an instance of type `F`, which is the result of the polynomial evaluation at point `z`. +/// +/// # Examples +/// +/// ``` +/// use ...; // import the appropriate crate and function +/// +/// let coeffs = vec![Fr::from(1), Fr::from(2), Fr::from(3)]; +/// let z = Fr::from(5); +/// let n = coeffs.len(); +/// +/// let result = evaluate(&coeffs, &z, n); +/// +/// // `result` is the value of the polynomial at z +/// ``` pub(crate) fn evaluate(coeffs: &[F], z: &F, n: usize) -> F { let num_threads = compute_num_threads(); let range_per_thread = n / num_threads; diff --git a/barustenberg/src/proof_system/work_queue.rs b/barustenberg/src/proof_system/work_queue.rs index 3f868cf..5ff31fb 100644 --- a/barustenberg/src/proof_system/work_queue.rs +++ b/barustenberg/src/proof_system/work_queue.rs @@ -276,7 +276,7 @@ impl WorkQueue assert!( msm_size <= (*(*self.key).borrow().reference_string) - .borrow() + .borrow_mut() .get_monomial_size() ); diff --git a/barustenberg/src/srs/reference_string/file_reference_string.rs b/barustenberg/src/srs/reference_string/file_reference_string.rs index ad0e234..de2e4ef 100644 --- a/barustenberg/src/srs/reference_string/file_reference_string.rs +++ b/barustenberg/src/srs/reference_string/file_reference_string.rs @@ -60,7 +60,7 @@ impl FileReferenceString { } impl ProverReferenceString for FileReferenceString { - fn get_monomial_points(&mut self) -> Rc> { + fn get_monomial_points(&self) -> Rc> { // Implementation depends on your project. todo!() } diff --git a/barustenberg/src/srs/reference_string/mod.rs b/barustenberg/src/srs/reference_string/mod.rs index a533c09..abf447b 100644 --- a/barustenberg/src/srs/reference_string/mod.rs +++ b/barustenberg/src/srs/reference_string/mod.rs @@ -15,7 +15,9 @@ pub(crate) trait VerifierReferenceString: Debug { } pub(crate) trait ProverReferenceString: Debug { - fn get_monomial_points(&mut self) -> Rc>; + // cpp definition for this is non-const but all implementations are const, + // unclear to me that we need a mut ref to self + fn get_monomial_points(&self) -> Rc>; fn get_monomial_size(&self) -> usize; } pub(crate) trait ReferenceStringFactory: Default { diff --git a/barustenberg/src/srs/reference_string/pippenger_reference_string.rs b/barustenberg/src/srs/reference_string/pippenger_reference_string.rs index dfcece7..de2ebbb 100644 --- a/barustenberg/src/srs/reference_string/pippenger_reference_string.rs +++ b/barustenberg/src/srs/reference_string/pippenger_reference_string.rs @@ -32,7 +32,8 @@ impl ProverReferenceString for PippengerReferenceString { todo!() } - fn get_monomial_points(&mut self) -> Rc> { + fn get_monomial_points(&self) -> Rc> { + // will we mutate self here? todo!() } }