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

Add proof input preprocessing #30

Merged
merged 3 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Pending
- [\#30](https://github.com/arkworks-rs/groth16/pull/30) Add proof input preprocessing.

### Breaking changes
- [\#21](https://github.com/arkworks-rs/groth16/pull/21) Change the `generate_parameters` interface to take generators as input.
Expand Down
36 changes: 30 additions & 6 deletions src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ pub fn prepare_verifying_key<E: PairingEngine>(vk: &VerifyingKey<E>) -> Prepared
}
}

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

Ok(g_ic)
}

/// Verify a Groth16 proof `proof` against the prepared verification key `pvk` and prepared public
/// inputs. This should be preferred over [`verify_proof`] if the instance's public inputs are
/// known in advance.
pub fn verify_proof_with_prepared_inputs<E: PairingEngine>(
pvk: &PreparedVerifyingKey<E>,
proof: &Proof<E>,
prepared_inputs: &E::G1Projective,
) -> R1CSResult<bool> {
let qap = E::miller_loop(
[
(proof.a.into(), proof.b.into()),
(g_ic.into_affine().into(), pvk.gamma_g2_neg_pc.clone()),
(
prepared_inputs.into_affine().into(),
pvk.gamma_g2_neg_pc.clone(),
),
(proof.c.into(), pvk.delta_g2_neg_pc.clone()),
]
.iter(),
Expand All @@ -46,3 +59,14 @@ pub fn verify_proof<E: PairingEngine>(

Ok(test == pvk.alpha_g1_beta_g2)
}

/// Verify a Groth16 proof `proof` against the prepared verification key `pvk`,
/// with respect to the instance `public_inputs`.
pub fn verify_proof<E: PairingEngine>(
pvk: &PreparedVerifyingKey<E>,
proof: &Proof<E>,
public_inputs: &[E::Fr],
) -> R1CSResult<bool> {
let prepared_inputs = prepare_inputs(pvk, public_inputs)?;
verify_proof_with_prepared_inputs(pvk, proof, &prepared_inputs)
}