Skip to content

Commit 870d2f6

Browse files
committed
Add FiatShamirRng
1 parent 2825b97 commit 870d2f6

File tree

7 files changed

+666
-12
lines changed

7 files changed

+666
-12
lines changed

src/constraints/ahp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
sponge::CryptographicSpongeVarNonNative,
99
CryptographicSpongeParameters, PhantomData, PrimeField, String, ToString, Vec,
1010
};
11-
use ark_nonnative_field::NonNativeFieldVar;
11+
use ark_nonnative_field::{params::OptimizationType, NonNativeFieldVar};
1212
use ark_poly::univariate::DensePolynomial;
1313
use ark_poly_commit::{
1414
EvaluationsVar, LCTerm, LabeledPointVar, LinearCombinationCoeffVar, LinearCombinationVar,
@@ -103,7 +103,7 @@ where
103103
elems.append(&mut comm.to_constraint_field().unwrap());
104104
});
105105
sponge_var.absorb(&elems)?;
106-
sponge_var.absorb_nonnative(&message)?;
106+
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
107107
}
108108

109109
// obtain four elements from the sponge_var
@@ -153,7 +153,7 @@ where
153153
elems.append(&mut comm.to_constraint_field().unwrap());
154154
});
155155
sponge_var.absorb(&elems)?;
156-
sponge_var.absorb_nonnative(&message)?;
156+
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
157157
}
158158

159159
// obtain one element from the sponge_var
@@ -195,7 +195,7 @@ where
195195
elems.append(&mut comm.to_constraint_field().unwrap());
196196
});
197197
sponge_var.absorb(&elems)?;
198-
sponge_var.absorb_nonnative(&message)?;
198+
sponge_var.absorb_nonnative(&message, OptimizationType::Weight)?;
199199
}
200200

201201
// obtain one element from the sponge_var

src/constraints/snark.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
CryptographicSpongeWithRate,
99
};
1010
use crate::{
11-
Box, CryptographicSpongeParameters, IndexProverKey, IndexVerifierKey, Marlin, MarlinConfig,
12-
PreparedIndexVerifierKey, Proof, String, ToString, UniversalSRS, Vec,
11+
Box, CryptographicSpongeParameters, FiatShamirRng, IndexProverKey, IndexVerifierKey, Marlin,
12+
MarlinConfig, PreparedIndexVerifierKey, Proof, String, ToString, UniversalSRS, Vec,
1313
};
1414
use ark_crypto_primitives::snark::{
1515
constraints::{SNARKGadget, UniversalSetupSNARKGadget},
@@ -157,7 +157,11 @@ where
157157
}
158158

159159
fn verify(vk: &Self::VerifyingKey, x: &[F], proof: &Self::Proof) -> Result<bool, Self::Error> {
160-
match Marlin::<F, FSF, S, PC, MC>::verify::<OptionalRng<ChaChaRng>>(vk, x, proof, None) {
160+
// TODO define a rate
161+
let rate = 4;
162+
let mut rng: FiatShamirRng<F, FSF, S> = FiatShamirRng::new(rate);
163+
164+
match Marlin::<F, FSF, S, PC, MC>::verify(vk, x, proof, Some(&mut rng)) {
161165
Ok(res) => Ok(res),
162166
Err(e) => Err(Box::new(MarlinError::from(e))),
163167
}
@@ -513,11 +517,11 @@ mod test {
513517
"The native verification check fails."
514518
);
515519

516-
/*
517520
let cs_sys = ConstraintSystem::<MNT4Fq>::new();
518521
let cs = ConstraintSystemRef::new(cs_sys);
519522
cs.set_optimization_goal(OptimizationGoal::Weight);
520523

524+
/*
521525
let input_gadget = <TestSNARKGadget as SNARKGadget<
522526
<MNT4_298 as PairingEngine>::Fr,
523527
<MNT4_298 as PairingEngine>::Fq,

src/constraints/verifier.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
CryptographicSpongeParameters, CryptographicSpongeWithRate, Error, PhantomData, PrimeField,
66
String, Vec,
77
};
8-
use ark_nonnative_field::NonNativeFieldVar;
8+
use ark_nonnative_field::{params::OptimizationType, NonNativeFieldVar};
99
use ark_poly::univariate::DensePolynomial;
1010
use ark_poly_commit::{PCCheckRandomDataVar, PCCheckVar, PolynomialCommitment};
1111
use ark_r1cs_std::{bits::boolean::Boolean, fields::FieldVar, R1CSVar, ToConstraintFieldGadget};
@@ -59,7 +59,7 @@ where
5959

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

62-
sponge_var.absorb_nonnative(&public_input)?;
62+
sponge_var.absorb_nonnative(&public_input, OptimizationType::Weight)?;
6363

6464
let (_, verifier_state) = AHPForR1CS::<F, CF, S, SVN, PC, PCG>::verifier_first_round(
6565
index_pvk.domain_h_size,
@@ -116,7 +116,7 @@ where
116116
}
117117
}
118118

119-
sponge_var.absorb_nonnative(&evals_vec)?;
119+
sponge_var.absorb_nonnative(&evals_vec, OptimizationType::Weight)?;
120120

121121
let (opening_challenges, opening_challenges_bits) =
122122
sponge_var.squeeze_nonnative_field_elements(num_opening_challenges)?;

0 commit comments

Comments
 (0)