From ec77b4f0a63378ca60fd9269b3092583bb11bcac Mon Sep 17 00:00:00 2001 From: Shady Khalifa Date: Mon, 18 Dec 2023 14:25:18 +0200 Subject: [PATCH] Add more props to the zkSaaS circuit --- pallets/zksaas/src/tests.rs | 10 +++++++++- primitives/src/types/jobs.rs | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pallets/zksaas/src/tests.rs b/pallets/zksaas/src/tests.rs index 965c905c0..5a137fc76 100644 --- a/pallets/zksaas/src/tests.rs +++ b/pallets/zksaas/src/tests.rs @@ -16,6 +16,7 @@ use crate::{mock::*, types::FeeInfo, FeeInfo as FeeInfoStorage}; use ark_crypto_primitives::snark::{CircuitSpecificSetupSNARK, SNARK}; use ark_groth16::Groth16; +use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystem}; use ark_serialize::CanonicalSerialize; use ark_std::{ rand::{Rng, RngCore, SeedableRng}, @@ -84,6 +85,10 @@ fn proof_verification_works() { // Create an instance of our circuit (with the // witness) let c = mimc::MiMCDemo { xl: Some(xl), xr: Some(xr), constants: &constants }; + let cs = ConstraintSystem::::new_ref(); + c.clone().generate_constraints(cs.clone()).unwrap(); + let num_inputs = cs.num_instance_variables(); + let num_constraints = cs.num_constraints(); // Create a groth16 proof with our parameters. let proof = Groth16::::prove(&pk, c, &mut rng).unwrap(); @@ -98,6 +103,8 @@ fn proof_verification_works() { participants: vec![1, 2, 3, 4, 5, 6, 7, 8], system: ZkSaaSSystem::Groth16(Groth16System { circuit: HyperData::Raw(vec![]), + num_inputs: num_inputs as _, + num_constraints: num_constraints as _, proving_key: HyperData::Raw(pk_bytes), verifying_key: vk_bytes, wasm: HyperData::Raw(vec![]), @@ -110,7 +117,7 @@ fn proof_verification_works() { request: ZkSaaSPhaseTwoRequest::Groth16(Groth16ProveRequest { public_input: from_field_elements(&[image]).unwrap(), a_shares: Default::default(), - ax: Default::default(), + ax_shares: Default::default(), qap_shares: Default::default(), }), }); @@ -189,6 +196,7 @@ mod mimc { /// This is our demo circuit for proving knowledge of the /// preimage of a MiMC hash invocation. + #[derive(Clone)] pub struct MiMCDemo<'a, F: Field> { pub xl: Option, pub xr: Option, diff --git a/primitives/src/types/jobs.rs b/primitives/src/types/jobs.rs index 97ec0368c..295349ace 100644 --- a/primitives/src/types/jobs.rs +++ b/primitives/src/types/jobs.rs @@ -105,6 +105,10 @@ pub enum ZkSaaSSystem { pub struct Groth16System { /// R1CS circuit file. pub circuit: HyperData, + /// Number of inputs + pub num_inputs: u64, + /// Number of constraints + pub num_constraints: u64, /// Proving key file. pub proving_key: HyperData, /// Verifying key bytes @@ -134,7 +138,7 @@ pub struct Groth16ProveRequest { /// `ax` is the auxiliary input /// ax = full_assginment[num_inputs..] /// Each element contains a PSS of the auxiliary input - pub ax: Vec, + pub ax_shares: Vec, /// PSS of the QAP polynomials pub qap_shares: Vec, }