Create a new proof. `nonce` is random data that needs to be hashed into the proof and it must be kept same while creating and verifying the proof. One use of `nonce` is for replay protection, here the prover might have chosen its nonce to prevent the verifier from reusing the proof as its own or the verifier might want to require the user to create fresh proof. Also returns the randomness used by
(
rng: &mut R,
proof_spec: ProofSpec<E>,
witnesses: Witnesses<E>,
nonce: Option<Vec<u8>>,
mut config: ProverConfig<E>,
)
| 137 | /// then be used as helpers in subsequent proof creations where these proofs are reused than |
| 138 | /// creating fresh proofs. |
| 139 | pub fn new<R: RngCore, D: FullDigest + Digest>( |
| 140 | rng: &mut R, |
| 141 | proof_spec: ProofSpec<E>, |
| 142 | witnesses: Witnesses<E>, |
| 143 | nonce: Option<Vec<u8>>, |
| 144 | mut config: ProverConfig<E>, |
| 145 | ) -> Result<(Self, BTreeMap<usize, E::ScalarField>), ProofSystemError> { |
| 146 | proof_spec.validate()?; |
| 147 | |
| 148 | // There should be a witness for each statement |
| 149 | expect_equality!( |
| 150 | proof_spec.statements.len(), |
| 151 | witnesses.len(), |
| 152 | ProofSystemError::UnequalWitnessAndStatementCount |
| 153 | ); |
| 154 | |
| 155 | // Keep blinding for each witness reference that is part of an equality. This means that for |
| 156 | // any 2 witnesses that are equal, same blinding will be stored. This will be drained during |
| 157 | // proof creation and should be empty by the end. |
| 158 | let mut blindings = BTreeMap::<WitnessRef, E::ScalarField>::new(); |
| 159 | |
| 160 | // Prepare blindings for any witnesses that need to be proven equal. |
| 161 | let mut disjoint_equalities = vec![]; |
| 162 | if !proof_spec.meta_statements.is_empty() { |
| 163 | disjoint_equalities = proof_spec.meta_statements.disjoint_witness_equalities(); |
| 164 | for eq_wits in disjoint_equalities.clone() { |
| 165 | let blinding = E::ScalarField::rand(rng); |
| 166 | for wr in eq_wits.0 { |
| 167 | // Duplicating the same blinding for faster search |
| 168 | blindings.insert(wr, blinding); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // Prepare commitment keys for running Schnorr protocols of all statements. |
| 174 | let ( |
| 175 | bound_check_lego_comm, |
| 176 | ek_comm, |
| 177 | chunked_comm, |
| 178 | r1cs_comm_keys, |
| 179 | bound_check_bpp_comm, |
| 180 | bound_check_smc_comm, |
| 181 | ineq_comm, |
| 182 | ) = proof_spec.derive_commitment_keys()?; |
| 183 | |
| 184 | let mut sub_protocols = Vec::<SubProtocol<E>>::with_capacity(proof_spec.statements.0.len()); |
| 185 | |
| 186 | // Randomness used by SAVER and LegoGroth16 proofs. This is tracked and returned so subsequent proofs for |
| 187 | // the same public params and witness can reuse this randomness |
| 188 | let mut commitment_randomness = BTreeMap::<usize, E::ScalarField>::new(); |
| 189 | |
| 190 | let mut transcript = MerlinTranscript::new(COMPOSITE_PROOF_LABEL); |
| 191 | if let Some(n) = nonce.as_ref() { |
| 192 | transcript.append_message(NONCE_LABEL, n); |
| 193 | } |
| 194 | if let Some(ctx) = &proof_spec.context { |
| 195 | transcript.append_message(CONTEXT_LABEL, ctx); |
| 196 | } |
nothing calls this directly
no test coverage detected