Skip to content

Commit d0d725c

Browse files
rozbbweikengchen
andauthored
Add proof input preprocessing (#30)
* Implemented groth16 public input preprocessing * Added entry in CHANGELOG * Update CHANGELOG.md Co-authored-by: Weikeng Chen <[email protected]>
1 parent 5e0800a commit d0d725c

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Pending
2+
- [\#30](https://github.com/arkworks-rs/groth16/pull/30) Add proof input preprocessing.
23

34
### Breaking changes
45
- [\#21](https://github.com/arkworks-rs/groth16/pull/21) Change the `generate_parameters` interface to take generators as input.

src/verifier.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ pub fn prepare_verifying_key<E: PairingEngine>(vk: &VerifyingKey<E>) -> Prepared
1717
}
1818
}
1919

20-
/// Verify a Groth16 proof `proof` against the prepared verification key `pvk`,
21-
/// with respect to the instance `public_inputs`.
22-
pub fn verify_proof<E: PairingEngine>(
20+
/// Prepare proof inputs for use with [`verify_proof_with_prepared_inputs`], wrt the prepared
21+
/// verification key `pvk` and instance public inputs.
22+
pub fn prepare_inputs<E: PairingEngine>(
2323
pvk: &PreparedVerifyingKey<E>,
24-
proof: &Proof<E>,
2524
public_inputs: &[E::Fr],
26-
) -> R1CSResult<bool> {
25+
) -> R1CSResult<E::G1Projective> {
2726
if (public_inputs.len() + 1) != pvk.vk.gamma_abc_g1.len() {
2827
return Err(SynthesisError::MalformedVerifyingKey);
2928
}
@@ -33,10 +32,24 @@ pub fn verify_proof<E: PairingEngine>(
3332
g_ic.add_assign(&b.mul(i.into_repr()));
3433
}
3534

35+
Ok(g_ic)
36+
}
37+
38+
/// Verify a Groth16 proof `proof` against the prepared verification key `pvk` and prepared public
39+
/// inputs. This should be preferred over [`verify_proof`] if the instance's public inputs are
40+
/// known in advance.
41+
pub fn verify_proof_with_prepared_inputs<E: PairingEngine>(
42+
pvk: &PreparedVerifyingKey<E>,
43+
proof: &Proof<E>,
44+
prepared_inputs: &E::G1Projective,
45+
) -> R1CSResult<bool> {
3646
let qap = E::miller_loop(
3747
[
3848
(proof.a.into(), proof.b.into()),
39-
(g_ic.into_affine().into(), pvk.gamma_g2_neg_pc.clone()),
49+
(
50+
prepared_inputs.into_affine().into(),
51+
pvk.gamma_g2_neg_pc.clone(),
52+
),
4053
(proof.c.into(), pvk.delta_g2_neg_pc.clone()),
4154
]
4255
.iter(),
@@ -46,3 +59,14 @@ pub fn verify_proof<E: PairingEngine>(
4659

4760
Ok(test == pvk.alpha_g1_beta_g2)
4861
}
62+
63+
/// Verify a Groth16 proof `proof` against the prepared verification key `pvk`,
64+
/// with respect to the instance `public_inputs`.
65+
pub fn verify_proof<E: PairingEngine>(
66+
pvk: &PreparedVerifyingKey<E>,
67+
proof: &Proof<E>,
68+
public_inputs: &[E::Fr],
69+
) -> R1CSResult<bool> {
70+
let prepared_inputs = prepare_inputs(pvk, public_inputs)?;
71+
verify_proof_with_prepared_inputs(pvk, proof, &prepared_inputs)
72+
}

0 commit comments

Comments
 (0)