Skip to content

Commit

Permalink
Add FiatShamirRng
Browse files Browse the repository at this point in the history
  • Loading branch information
vlopes11 committed Jun 3, 2022
1 parent 2825b97 commit 870d2f6
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/constraints/ahp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
sponge::CryptographicSpongeVarNonNative,
CryptographicSpongeParameters, PhantomData, PrimeField, String, ToString, Vec,
};
use ark_nonnative_field::NonNativeFieldVar;
use ark_nonnative_field::{params::OptimizationType, NonNativeFieldVar};
use ark_poly::univariate::DensePolynomial;
use ark_poly_commit::{
EvaluationsVar, LCTerm, LabeledPointVar, LinearCombinationCoeffVar, LinearCombinationVar,
Expand Down Expand Up @@ -103,7 +103,7 @@ where
elems.append(&mut comm.to_constraint_field().unwrap());
});
sponge_var.absorb(&elems)?;
sponge_var.absorb_nonnative(&message)?;
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
}

// obtain four elements from the sponge_var
Expand Down Expand Up @@ -153,7 +153,7 @@ where
elems.append(&mut comm.to_constraint_field().unwrap());
});
sponge_var.absorb(&elems)?;
sponge_var.absorb_nonnative(&message)?;
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
}

// obtain one element from the sponge_var
Expand Down Expand Up @@ -195,7 +195,7 @@ where
elems.append(&mut comm.to_constraint_field().unwrap());
});
sponge_var.absorb(&elems)?;
sponge_var.absorb_nonnative(&message)?;
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
}

// obtain one element from the sponge_var
Expand Down
12 changes: 8 additions & 4 deletions src/constraints/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
CryptographicSpongeWithRate,
};
use crate::{
Box, CryptographicSpongeParameters, IndexProverKey, IndexVerifierKey, Marlin, MarlinConfig,
PreparedIndexVerifierKey, Proof, String, ToString, UniversalSRS, Vec,
Box, CryptographicSpongeParameters, FiatShamirRng, IndexProverKey, IndexVerifierKey, Marlin,
MarlinConfig, PreparedIndexVerifierKey, Proof, String, ToString, UniversalSRS, Vec,
};
use ark_crypto_primitives::snark::{
constraints::{SNARKGadget, UniversalSetupSNARKGadget},
Expand Down Expand Up @@ -157,7 +157,11 @@ where
}

fn verify(vk: &Self::VerifyingKey, x: &[F], proof: &Self::Proof) -> Result<bool, Self::Error> {
match Marlin::<F, FSF, S, PC, MC>::verify::<OptionalRng<ChaChaRng>>(vk, x, proof, None) {
// TODO define a rate
let rate = 4;
let mut rng: FiatShamirRng<F, FSF, S> = FiatShamirRng::new(rate);

match Marlin::<F, FSF, S, PC, MC>::verify(vk, x, proof, Some(&mut rng)) {
Ok(res) => Ok(res),
Err(e) => Err(Box::new(MarlinError::from(e))),
}
Expand Down Expand Up @@ -513,11 +517,11 @@ mod test {
"The native verification check fails."
);

/*
let cs_sys = ConstraintSystem::<MNT4Fq>::new();
let cs = ConstraintSystemRef::new(cs_sys);
cs.set_optimization_goal(OptimizationGoal::Weight);

/*
let input_gadget = <TestSNARKGadget as SNARKGadget<
<MNT4_298 as PairingEngine>::Fr,
<MNT4_298 as PairingEngine>::Fq,
Expand Down
6 changes: 3 additions & 3 deletions src/constraints/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
CryptographicSpongeParameters, CryptographicSpongeWithRate, Error, PhantomData, PrimeField,
String, Vec,
};
use ark_nonnative_field::NonNativeFieldVar;
use ark_nonnative_field::{params::OptimizationType, NonNativeFieldVar};
use ark_poly::univariate::DensePolynomial;
use ark_poly_commit::{PCCheckRandomDataVar, PCCheckVar, PolynomialCommitment};
use ark_r1cs_std::{bits::boolean::Boolean, fields::FieldVar, R1CSVar, ToConstraintFieldGadget};
Expand Down Expand Up @@ -59,7 +59,7 @@ where

eprintln!("before AHP: constraints: {}", cs.num_constraints());

sponge_var.absorb_nonnative(&public_input)?;
sponge_var.absorb_nonnative(&public_input, OptimizationType::Weight)?;

let (_, verifier_state) = AHPForR1CS::<F, CF, S, SVN, PC, PCG>::verifier_first_round(
index_pvk.domain_h_size,
Expand Down Expand Up @@ -116,7 +116,7 @@ where
}
}

sponge_var.absorb_nonnative(&evals_vec)?;
sponge_var.absorb_nonnative(&evals_vec, OptimizationType::Weight)?;

let (opening_challenges, opening_challenges_bits) =
sponge_var.squeeze_nonnative_field_elements(num_opening_challenges)?;
Expand Down
Loading

0 comments on commit 870d2f6

Please sign in to comment.