Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type bounds for FS types #22

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub trait OODIOPattern<F: Field> {
fn add_ood(self, num_samples: usize) -> Self;
}

impl<F> OODIOPattern<F> for IOPattern
impl<F, IOPattern> OODIOPattern<F> for IOPattern
where
F: Field,
IOPattern: FieldIOPattern<F>,
Expand All @@ -24,7 +24,7 @@ pub trait WhirPoWIOPattern {
fn pow(self, bits: f64) -> Self;
}

impl WhirPoWIOPattern for IOPattern
impl <IOPattern> WhirPoWIOPattern for IOPattern
where
IOPattern: PoWIOPattern,
{
Expand Down
Empty file added src/skyscraper.rs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is not meant for this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is accidental LMAO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed :)

Empty file.
21 changes: 8 additions & 13 deletions src/sumcheck/prover_not_skipping.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use ark_ff::Field;
use nimue::{
plugins::ark::{FieldChallenges, FieldIOPattern, FieldWriter},
IOPattern, Merlin, ProofResult,
};
use nimue::{plugins::ark::{FieldChallenges, FieldIOPattern, FieldWriter}, IOPattern, ProofResult};
use nimue_pow::{PoWChallenge, PowStrategy};

use crate::{
Expand All @@ -16,7 +13,7 @@ pub trait SumcheckNotSkippingIOPattern<F: Field> {
fn add_sumcheck(self, folding_factor: usize, pow_bits: f64) -> Self;
}

impl<F> SumcheckNotSkippingIOPattern<F> for IOPattern
impl<F, IOPattern> SumcheckNotSkippingIOPattern<F> for IOPattern
where
F: Field,
IOPattern: FieldIOPattern<F> + WhirPoWIOPattern,
Expand Down Expand Up @@ -59,14 +56,15 @@ where
}
}

pub fn compute_sumcheck_polynomials<S>(
pub fn compute_sumcheck_polynomials<S, Merlin>(
&mut self,
merlin: &mut Merlin,
folding_factor: usize,
pow_bits: f64,
) -> ProofResult<MultilinearPoint<F>>
where
S: PowStrategy,
Merlin: FieldChallenges<F> + FieldWriter<F> + PoWChallenge,
{
let mut res = Vec::with_capacity(folding_factor);

Expand Down Expand Up @@ -103,10 +101,7 @@ where
#[cfg(test)]
mod tests {
use ark_ff::Field;
use nimue::{
plugins::ark::{FieldChallenges, FieldIOPattern, FieldReader},
IOPattern, ProofResult,
};
use nimue::{plugins::ark::{FieldChallenges, FieldIOPattern, FieldReader}, IOPattern, Merlin, ProofResult};
use nimue_pow::blake3::Blake3PoW;

use crate::{
Expand Down Expand Up @@ -157,7 +152,7 @@ mod tests {
);

let folding_randomness_1 =
prover.compute_sumcheck_polynomials::<Blake3PoW>(&mut merlin, folding_factor, 0.)?;
prover.compute_sumcheck_polynomials::<Blake3PoW, Merlin>(&mut merlin, folding_factor, 0.)?;

// Compute the answers
let folded_poly_1 = polynomial.fold(&folding_randomness_1);
Expand Down Expand Up @@ -243,14 +238,14 @@ mod tests {
);

let folding_randomness_1 =
prover.compute_sumcheck_polynomials::<Blake3PoW>(&mut merlin, folding_factor, 0.)?;
prover.compute_sumcheck_polynomials::<Blake3PoW, Merlin>(&mut merlin, folding_factor, 0.)?;

let folded_poly_1 = polynomial.fold(&folding_randomness_1);
let fold_eval = folded_poly_1.evaluate_at_extension(&fold_point);
prover.add_new_equality(&[fold_point.clone()], &combination_randomness, &[fold_eval]);

let folding_randomness_2 =
prover.compute_sumcheck_polynomials::<Blake3PoW>(&mut merlin, folding_factor, 0.)?;
prover.compute_sumcheck_polynomials::<Blake3PoW, Merlin>(&mut merlin, folding_factor, 0.)?;

// Compute the answers
let folded_poly_1 = polynomial.fold(&folding_randomness_1);
Expand Down
4 changes: 2 additions & 2 deletions src/whir/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ where
Self(config)
}

pub fn commit(
pub fn commit<Merlin>(
&self,
merlin: &mut Merlin,
polynomial: CoefficientList<F::BasePrimeField>,
) -> ProofResult<Witness<F, MerkleConfig>>
where
Merlin: FieldChallenges<F> + ByteWriter,
Merlin: FieldWriter<F> + FieldChallenges<F> + ByteWriter,
{
let base_domain = self.0.starting_domain.base_domain.unwrap();
let expansion = base_domain.size() / polynomial.num_coeffs();
Expand Down
2 changes: 1 addition & 1 deletion src/whir/iopattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait WhirIOPattern<F: FftField> {
) -> Self;
}

impl<F> WhirIOPattern<F> for IOPattern
impl<F, IOPattern> WhirIOPattern<F> for IOPattern
where
F: FftField,
IOPattern: ByteIOPattern
Expand Down
20 changes: 12 additions & 8 deletions src/whir/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use ark_crypto_primitives::merkle_tree::{Config, MerkleTree, MultiPath};
use ark_ff::FftField;
use ark_poly::EvaluationDomain;
use nimue::{
plugins::ark::{FieldChallenges, FieldWriter}, ByteWriter, Merlin, ProofResult,
plugins::ark::{FieldChallenges, FieldWriter},
ByteChallenges, ByteWriter, ProofResult,
};
use nimue_pow::{self, PoWChallenge};

Expand Down Expand Up @@ -65,14 +66,14 @@ where
witness.polynomial.num_variables() == self.0.mv_parameters.num_variables
}

pub fn prove(
pub fn prove<Merlin>(
&self,
merlin: &mut Merlin,
statement: Statement<F>,
witness: Witness<F, MerkleConfig>,
) -> ProofResult<WhirProof<MerkleConfig, F>>
where
Merlin: FieldChallenges<F> + ByteWriter,
Merlin: FieldChallenges<F> + FieldWriter<F> + ByteChallenges + ByteWriter + PoWChallenge,
{
assert!(self.validate_parameters());
assert!(self.validate_statement(&statement));
Expand Down Expand Up @@ -118,7 +119,7 @@ where
sumcheck_prover
.as_mut()
.unwrap()
.compute_sumcheck_polynomials::<PowStrategy>(
.compute_sumcheck_polynomials::<PowStrategy, Merlin>(
merlin,
self.0.folding_factor,
self.0.starting_folding_pow_bits,
Expand Down Expand Up @@ -147,11 +148,14 @@ where
self.round(merlin, round_state)
}

fn round(
fn round<Merlin>(
&self,
merlin: &mut Merlin,
mut round_state: RoundState<F, MerkleConfig>,
) -> ProofResult<WhirProof<MerkleConfig, F>> {
) -> ProofResult<WhirProof<MerkleConfig, F>>
where
Merlin: FieldChallenges<F> + ByteChallenges + FieldWriter<F> + ByteWriter + PoWChallenge,
{
// Fold the coefficients
let folded_coefficients = round_state
.coefficients
Expand Down Expand Up @@ -198,7 +202,7 @@ where
.unwrap_or_else(|| {
SumcheckProverNotSkipping::new(folded_coefficients.clone(), &[], &[], &[])
})
.compute_sumcheck_polynomials::<PowStrategy>(
.compute_sumcheck_polynomials::<PowStrategy, Merlin>(
merlin,
self.0.final_sumcheck_rounds,
self.0.final_folding_pow_bits,
Expand Down Expand Up @@ -347,7 +351,7 @@ where
)
});

let folding_randomness = sumcheck_prover.compute_sumcheck_polynomials::<PowStrategy>(
let folding_randomness = sumcheck_prover.compute_sumcheck_polynomials::<PowStrategy, Merlin>(
merlin,
self.0.folding_factor,
round_params.folding_pow_bits,
Expand Down
27 changes: 18 additions & 9 deletions src/whir/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use ark_crypto_primitives::merkle_tree::Config;
use ark_ff::FftField;
use ark_poly::EvaluationDomain;
use nimue::{
plugins::ark::{FieldChallenges, FieldReader},
Arthur, ByteReader, ProofError, ProofResult,
plugins::ark::{FieldChallenges, FieldReader}
, ByteChallenges, ByteReader, ProofError, ProofResult,
};
use nimue_pow::{self, PoWChallenge};

Expand All @@ -15,7 +15,7 @@ use crate::{
parameters::FoldType,
poly_utils::{coeffs::CoefficientList, eq_poly_outside, fold::compute_fold, MultilinearPoint},
sumcheck::proof::SumcheckPolynomial,
utils::{expand_randomness},
utils::expand_randomness,
};

pub struct Verifier<F, MerkleConfig, PowStrategy>
Expand Down Expand Up @@ -76,10 +76,13 @@ where
}
}

fn parse_commitment(
fn parse_commitment<Arthur>(
&self,
arthur: &mut Arthur,
) -> ProofResult<ParsedCommitment<F, MerkleConfig::InnerDigest>> {
) -> ProofResult<ParsedCommitment<F, MerkleConfig::InnerDigest>>
where
Arthur: ByteReader + FieldReader<F> + FieldChallenges<F>,
{
let root: [u8; 32] = arthur.next_bytes()?;

let mut ood_points = vec![F::ZERO; self.params.committment_ood_samples];
Expand All @@ -96,13 +99,16 @@ where
})
}

fn parse_proof(
fn parse_proof<Arthur>(
&self,
arthur: &mut Arthur,
parsed_commitment: &ParsedCommitment<F, MerkleConfig::InnerDigest>,
statement: &Statement<F>, // Will be needed later
whir_proof: &WhirProof<MerkleConfig, F>,
) -> ProofResult<ParsedProof<F>> {
) -> ProofResult<ParsedProof<F>>
where
Arthur: FieldReader<F> + FieldChallenges<F> + PoWChallenge + ByteReader + ByteChallenges,
{
let mut sumcheck_rounds = Vec::new();
let mut folding_randomness: MultilinearPoint<F>;
let initial_combination_randomness;
Expand Down Expand Up @@ -457,12 +463,15 @@ where
result
}

pub fn verify(
pub fn verify<Arthur>(
&self,
arthur: &mut Arthur,
statement: &Statement<F>,
whir_proof: &WhirProof<MerkleConfig, F>,
) -> ProofResult<()> {
) -> ProofResult<()>
where
Arthur: FieldChallenges<F> + FieldReader<F> + ByteChallenges + ByteReader + PoWChallenge,
{
// We first do a pass in which we rederive all the FS challenges
// Then we will check the algebraic part (so to optimise inversions)
let parsed_commitment = self.parse_commitment(arthur)?;
Expand Down