Skip to main content

snarkvm_algorithms/snark/varuna/
varuna.rs

1// Copyright (c) 2019-2026 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::Certificate;
17use crate::{
18    AlgebraicSponge,
19    SNARK,
20    SNARKError,
21    fft::EvaluationDomain,
22    polycommit::sonic_pc::{
23        Commitment,
24        CommitterUnionKey,
25        Evaluations,
26        LabeledCommitment,
27        QuerySet,
28        Randomness,
29        SonicKZG10,
30    },
31    r1cs::{ConstraintSynthesizer, SynthesisError},
32    snark::varuna::{
33        CircuitProvingKey,
34        CircuitVerifyingKey,
35        Proof,
36        SNARKMode,
37        UniversalSRS,
38        VarunaVersion,
39        ahp::{AHPError, AHPForR1CS, CircuitId, EvaluationsProvider},
40        proof,
41        prover,
42        witness_label,
43    },
44    srs::UniversalVerifier,
45};
46use snarkvm_curves::PairingEngine;
47use snarkvm_fields::{One, PrimeField, ToConstraintField, Zero};
48use snarkvm_utilities::{ToBytes, dev_eprintln, dev_println, to_bytes_le};
49
50use anyhow::{Result, anyhow, bail, ensure};
51use core::marker::PhantomData;
52use itertools::Itertools;
53use rand::{CryptoRng, Rng};
54use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc};
55
56use crate::srs::UniversalProver;
57
58/// The Varuna proof system.
59#[derive(Clone, Debug)]
60pub struct VarunaSNARK<E: PairingEngine, FS: AlgebraicSponge<E::Fq, 2>, SM: SNARKMode>(
61    #[doc(hidden)] PhantomData<(E, FS, SM)>,
62);
63
64impl<E: PairingEngine, FS: AlgebraicSponge<E::Fq, 2>, SM: SNARKMode> VarunaSNARK<E, FS, SM> {
65    /// The personalization string for this protocol.
66    /// Used to personalize the Fiat-Shamir RNG.
67    pub const PROTOCOL_NAME: &'static [u8] = b"VARUNA-2023";
68
69    // TODO: implement optimizations resulting from batching
70    //       (e.g. computing a common set of Lagrange powers, FFT precomputations,
71    // etc)
72    pub fn batch_circuit_setup<C: ConstraintSynthesizer<E::Fr>>(
73        universal_srs: &UniversalSRS<E>,
74        circuits: &[&C],
75    ) -> Result<Vec<(CircuitProvingKey<E, SM>, CircuitVerifyingKey<E>)>> {
76        let index_time = start_timer!(|| "Varuna::CircuitSetup");
77
78        let universal_prover = &universal_srs.to_universal_prover()?;
79
80        let mut circuit_keys = Vec::with_capacity(circuits.len());
81        for circuit in circuits {
82            let mut indexed_circuit = AHPForR1CS::<_, SM>::index(*circuit)?;
83            // TODO: Add check that c is in the correct mode.
84            // Ensure the universal SRS supports the circuit size.
85            universal_srs.download_powers_for(0..indexed_circuit.max_degree()?).map_err(|e| {
86                anyhow!("Failed to download powers for degree {}: {e}", indexed_circuit.max_degree().unwrap())
87            })?;
88            let coefficient_support = AHPForR1CS::<E::Fr, SM>::get_degree_bounds(&indexed_circuit.index_info)?;
89
90            // Varuna only needs degree 2 random polynomials.
91            let supported_hiding_bound = 1;
92            let supported_lagrange_sizes = [].into_iter(); // TODO: consider removing lagrange_bases_at_beta_g from CommitterKey
93            let (committer_key, _) = SonicKZG10::<E, FS>::trim(
94                universal_srs,
95                indexed_circuit.max_degree()?,
96                supported_lagrange_sizes,
97                supported_hiding_bound,
98                Some(coefficient_support.as_slice()),
99            )?;
100
101            let ck = CommitterUnionKey::union(std::iter::once(&committer_key));
102
103            let commit_time = start_timer!(|| format!("Commit to index polynomials for {}", indexed_circuit.id));
104            let setup_rng = None::<&mut dyn Rng>; // We do not randomize the commitments
105
106            let (mut circuit_commitments, commitment_randomnesses): (_, _) = SonicKZG10::<E, FS>::commit(
107                universal_prover,
108                &ck,
109                indexed_circuit.interpolate_matrix_evals()?.map(Into::into),
110                setup_rng,
111            )?;
112            let empty_randomness = Randomness::<E>::empty();
113            ensure!(commitment_randomnesses.iter().all(|r| r == &empty_randomness));
114            end_timer!(commit_time);
115
116            circuit_commitments.sort_by(|c1, c2| c1.label().cmp(c2.label()));
117            let circuit_commitments = circuit_commitments.into_iter().map(|c| *c.commitment()).collect();
118            indexed_circuit.prune_row_col_evals();
119            let circuit_verifying_key = CircuitVerifyingKey {
120                circuit_info: indexed_circuit.index_info,
121                circuit_commitments,
122                id: indexed_circuit.id,
123            };
124            let circuit_proving_key = CircuitProvingKey {
125                circuit_verifying_key: circuit_verifying_key.clone(),
126                circuit: Arc::new(indexed_circuit),
127                committer_key: Arc::new(committer_key),
128            };
129            circuit_keys.push((circuit_proving_key, circuit_verifying_key));
130        }
131
132        end_timer!(index_time);
133        Ok(circuit_keys)
134    }
135
136    fn init_sponge<'a>(
137        fs_parameters: &FS::Parameters,
138        inputs_and_batch_sizes: &BTreeMap<CircuitId, (usize, &[Vec<E::Fr>])>,
139        circuit_commitments: impl Iterator<Item = &'a [crate::polycommit::sonic_pc::Commitment<E>]>,
140    ) -> FS {
141        let mut sponge = FS::new_with_parameters(fs_parameters);
142        sponge.absorb_bytes(Self::PROTOCOL_NAME);
143        for (batch_size, inputs) in inputs_and_batch_sizes.values() {
144            sponge.absorb_bytes(&(*batch_size as u64).to_le_bytes());
145            for input in inputs.iter() {
146                sponge.absorb_nonnative_field_elements(input.iter().copied());
147            }
148        }
149        for circuit_specific_commitments in circuit_commitments {
150            sponge.absorb_native_field_elements(circuit_specific_commitments);
151        }
152        sponge
153    }
154
155    fn init_sponge_for_certificate(
156        fs_parameters: &FS::Parameters,
157        verifying_key: &CircuitVerifyingKey<E>,
158    ) -> Result<FS> {
159        let mut sponge = FS::new_with_parameters(fs_parameters);
160        sponge.absorb_bytes(&to_bytes_le![&Self::PROTOCOL_NAME]?);
161        sponge.absorb_bytes(&verifying_key.circuit_info.to_bytes_le()?);
162        sponge.absorb_native_field_elements(&verifying_key.circuit_commitments);
163        sponge.absorb_bytes(&verifying_key.id.0);
164        Ok(sponge)
165    }
166
167    fn absorb_labeled_with_sums(
168        comms: &[LabeledCommitment<Commitment<E>>],
169        sums: &[prover::MatrixSums<E::Fr>],
170        sponge: &mut FS,
171    ) {
172        let commitments: Vec<_> = comms.iter().map(|c| *c.commitment()).collect();
173        Self::absorb_with_sums(&commitments, sums, sponge)
174    }
175
176    fn absorb_labeled(comms: &[LabeledCommitment<Commitment<E>>], sponge: &mut FS) {
177        let commitments: Vec<_> = comms.iter().map(|c| *c.commitment()).collect();
178        Self::absorb(&commitments, sponge);
179    }
180
181    fn absorb(commitments: &[Commitment<E>], sponge: &mut FS) {
182        let sponge_time = start_timer!(|| "Absorbing commitments");
183        sponge.absorb_native_field_elements(commitments);
184        end_timer!(sponge_time);
185    }
186
187    fn absorb_with_sums(commitments: &[Commitment<E>], sums: &[prover::MatrixSums<E::Fr>], sponge: &mut FS) {
188        let sponge_time = start_timer!(|| "Absorbing commitments and message");
189        Self::absorb(commitments, sponge);
190        Self::absorb_sums(sums, sponge);
191        end_timer!(sponge_time);
192    }
193
194    fn absorb_sums(sums: &[prover::MatrixSums<E::Fr>], sponge: &mut FS) {
195        for sum in sums.iter() {
196            sponge.absorb_nonnative_field_elements([sum.sum_a, sum.sum_b, sum.sum_c]);
197        }
198    }
199}
200
201impl<E: PairingEngine, FS, SM> SNARK for VarunaSNARK<E, FS, SM>
202where
203    E::Fr: PrimeField,
204    E::Fq: PrimeField,
205    FS: AlgebraicSponge<E::Fq, 2>,
206    SM: SNARKMode,
207{
208    type BaseField = E::Fq;
209    type Certificate = Certificate<E>;
210    type FSParameters = FS::Parameters;
211    type FiatShamirRng = FS;
212    type Proof = Proof<E>;
213    type ProvingKey = CircuitProvingKey<E, SM>;
214    type ScalarField = E::Fr;
215    type UniversalProver = UniversalProver<E>;
216    type UniversalSRS = UniversalSRS<E>;
217    type UniversalVerifier = UniversalVerifier<E>;
218    type VerifierInput = [E::Fr];
219    type VerifyingKey = CircuitVerifyingKey<E>;
220
221    fn universal_setup(max_degree: usize) -> Result<Self::UniversalSRS> {
222        let setup_time = start_timer!(|| { format!("Varuna::UniversalSetup with max_degree {max_degree}",) });
223        let srs = SonicKZG10::<E, FS>::load_srs(max_degree).map_err(Into::into);
224        end_timer!(setup_time);
225        srs
226    }
227
228    /// Generates the circuit proving and verifying keys.
229    /// This is a deterministic algorithm that anyone can rerun.
230    fn circuit_setup<C: ConstraintSynthesizer<E::Fr>>(
231        universal_srs: &Self::UniversalSRS,
232        circuit: &C,
233    ) -> Result<(Self::ProvingKey, Self::VerifyingKey)> {
234        let mut circuit_keys = Self::batch_circuit_setup::<C>(universal_srs, &[circuit])?;
235        ensure!(circuit_keys.len() == 1);
236        Ok(circuit_keys.pop().unwrap())
237    }
238
239    /// Prove that the verifying key commitments commit to the indexed circuit's
240    /// polynomials
241    fn prove_vk(
242        universal_prover: &Self::UniversalProver,
243        fs_parameters: &Self::FSParameters,
244        verifying_key: &Self::VerifyingKey,
245        proving_key: &Self::ProvingKey,
246    ) -> Result<Self::Certificate> {
247        // Initialize sponge
248        let mut sponge = Self::init_sponge_for_certificate(fs_parameters, verifying_key)?;
249        // Compute challenges for linear combination, and the point to evaluate the
250        // polynomials at. The linear combination requires `num_polynomials - 1`
251        // coefficients (since the first coeff is 1), and so we squeeze out
252        // `num_polynomials` points.
253        let mut challenges = sponge.squeeze_nonnative_field_elements(verifying_key.circuit_commitments.len());
254        let point = challenges.pop().ok_or(anyhow!("Failed to squeeze random element"))?;
255        let one = E::Fr::one();
256        let linear_combination_challenges = core::iter::once(&one).chain(challenges.iter());
257
258        let circuit_id = std::iter::once(&verifying_key.id);
259        let circuit_poly_info = AHPForR1CS::<E::Fr, SM>::index_polynomial_info(circuit_id);
260
261        // We will construct a linear combination and provide a proof of evaluation of
262        // the lc at `point`.
263        let mut lc = crate::polycommit::sonic_pc::LinearCombination::empty("circuit_check");
264        for (label, &c) in circuit_poly_info.keys().zip(linear_combination_challenges) {
265            lc.add(c, label.clone());
266        }
267
268        let query_set = QuerySet::from_iter([("circuit_check".into(), ("challenge".into(), point))]);
269        let committer_key = CommitterUnionKey::union(std::iter::once(proving_key.committer_key.as_ref()));
270
271        let empty_randomness = vec![Randomness::<E>::empty(); 12];
272        let certificate = SonicKZG10::<E, FS>::open_combinations(
273            universal_prover,
274            &committer_key,
275            &[lc],
276            proving_key.circuit.interpolate_matrix_evals()?,
277            &empty_randomness,
278            &query_set,
279            &mut sponge,
280        )?;
281
282        Ok(Self::Certificate::new(certificate))
283    }
284
285    /// Verify that the verifying key commitments commit to the indexed
286    /// circuit's polynomials Verify that the verifying key's circuit_info
287    /// is correct
288    fn verify_vk<C: ConstraintSynthesizer<Self::ScalarField>>(
289        universal_verifier: &Self::UniversalVerifier,
290        fs_parameters: &Self::FSParameters,
291        circuit: &C,
292        verifying_key: &Self::VerifyingKey,
293        certificate: &Self::Certificate,
294    ) -> Result<bool> {
295        // Ensure the VerifyingKey encodes the expected circuit.
296        let circuit_id = &verifying_key.id;
297        let state = AHPForR1CS::<E::Fr, SM>::index_helper(circuit)?;
298        if state.index_info != verifying_key.circuit_info {
299            bail!("Circuit info mismatch, expected {:?}, got {:?}", verifying_key.circuit_info, state.index_info);
300        }
301        if state.id != *circuit_id {
302            bail!("Circuit ID mismatch, expected {:?}, got {:?}.", circuit_id, state.id);
303        }
304
305        // Make sure certificate is not hiding
306        if certificate.pc_proof.is_hiding() {
307            bail!("Certificate should not be hiding");
308        }
309
310        // Initialize sponge.
311        let mut sponge = Self::init_sponge_for_certificate(fs_parameters, verifying_key)?;
312
313        // Compute challenges for linear combination, and the point to evaluate the
314        // polynomials at. The linear combination requires `num_polynomials - 1`
315        // coefficients (since the first coeff is 1), and so we squeeze out
316        // `num_polynomials` points.
317        let mut challenges = sponge.squeeze_nonnative_field_elements(verifying_key.circuit_commitments.len());
318        let point = challenges.pop().ok_or(anyhow!("Failed to squeeze random element"))?;
319        let combiners = core::iter::once(E::Fr::one()).chain(challenges);
320
321        // We will construct a linear combination and provide a proof of evaluation of
322        // the lc at `point`.
323        let (lc, evaluation) =
324            AHPForR1CS::<E::Fr, SM>::evaluate_index_polynomials(state, circuit_id, point, combiners)?;
325
326        ensure!(verifying_key.circuit_commitments.len() == lc.terms.len());
327        let commitments = verifying_key
328            .iter()
329            .cloned()
330            .zip_eq(lc.terms.keys())
331            .map(|(c, label)| LabeledCommitment::new(format!("{label:?}"), c, None))
332            .collect_vec();
333        let evaluations = Evaluations::from_iter([(("circuit_check".into(), point), evaluation)]);
334        let query_set = QuerySet::from_iter([("circuit_check".into(), ("challenge".into(), point))]);
335
336        SonicKZG10::<E, FS>::check_combinations(
337            universal_verifier,
338            &[lc],
339            &commitments,
340            &query_set,
341            &evaluations,
342            &certificate.pc_proof,
343            &mut sponge,
344        )
345    }
346
347    /// This is the main entrypoint for creating proofs.
348    /// You can find a specification of the prover algorithm in:
349    /// <https://github.com/ProvableHQ/protocol-docs>
350    fn prove_batch<C: ConstraintSynthesizer<E::Fr>, R: Rng + CryptoRng>(
351        universal_prover: &Self::UniversalProver,
352        fs_parameters: &Self::FSParameters,
353        varuna_version: VarunaVersion,
354        keys_to_constraints: &BTreeMap<&CircuitProvingKey<E, SM>, &[C]>,
355        zk_rng: &mut R,
356    ) -> Result<Self::Proof> {
357        let prover_time = start_timer!(|| "Varuna::Prover");
358        if keys_to_constraints.is_empty() {
359            bail!(SNARKError::EmptyBatch);
360        }
361
362        let mut circuits_to_constraints = BTreeMap::new();
363        for (pk, constraints) in keys_to_constraints {
364            circuits_to_constraints.insert(pk.circuit.deref(), *constraints);
365        }
366        let prover_state = AHPForR1CS::<_, SM>::init_prover(&circuits_to_constraints, zk_rng)?;
367
368        // extract information from the prover key and state to consume in further
369        // calculations
370        let mut batch_sizes = BTreeMap::new();
371        let mut circuit_infos = BTreeMap::new();
372        let mut inputs_and_batch_sizes = BTreeMap::new();
373        let mut total_instances = 0usize;
374        let mut public_inputs = BTreeMap::new(); // inputs need to live longer than the rest of prover_state
375        let num_unique_circuits = keys_to_constraints.len();
376        let mut circuit_ids = Vec::with_capacity(num_unique_circuits);
377
378        #[cfg(feature = "snark-print")]
379        {
380            // Display the batch sizes and (padded) public inputs
381            let batch_sizes = keys_to_constraints
382                .keys()
383                .map(|pk| {
384                    prover_state
385                        .batch_size(&pk.circuit)
386                        .ok_or(anyhow!("[Varuna::prove_batch] Batch not found for circuit {:?}", pk.circuit.id))
387                })
388                .collect::<Result<Vec<_>>>()?;
389
390            println!("[Varuna::prove_batch] Batch sizes: {batch_sizes:?}\n");
391
392            for (i, (key, batch_size)) in keys_to_constraints.keys().zip(batch_sizes.iter()).enumerate() {
393                println!("  - Circuit {i}: {} ({batch_size} instance(s))\n", key.circuit_verifying_key.id);
394                // Safe: `prover_state` was initialized from the same circuits as
395                // `keys_to_constraints`, so `key.circuit` is always present.
396                for (j, public_input) in prover_state.public_inputs(&key.circuit).unwrap().iter().enumerate() {
397                    println!("    - Instance {j}");
398                    // We prepend the initial constant 1 to facilitate collation with displayed
399                    // verifier inputs
400                    println!("      - 0: {}", E::Fr::one());
401                    for (k, value) in public_input.iter().enumerate() {
402                        println!("      - {}: {value}", k + 1);
403                    }
404                    println!();
405                }
406            }
407        }
408
409        for pk in keys_to_constraints.keys() {
410            let batch_size = prover_state.batch_size(&pk.circuit).ok_or(anyhow!("Batch size not found."))?;
411            let public_input = prover_state.public_inputs(&pk.circuit).ok_or(anyhow!("Public input not found."))?;
412
413            let padded_public_input =
414                prover_state.padded_public_inputs(&pk.circuit).ok_or(anyhow!("Padded public input not found."))?;
415
416            let circuit_id = pk.circuit.id;
417            batch_sizes.insert(circuit_id, batch_size);
418            circuit_infos.insert(circuit_id, &pk.circuit_verifying_key.circuit_info);
419            inputs_and_batch_sizes.insert(circuit_id, (batch_size, padded_public_input));
420            public_inputs.insert(circuit_id, public_input);
421            total_instances = total_instances.saturating_add(batch_size);
422
423            circuit_ids.push(circuit_id);
424        }
425        ensure!(prover_state.total_instances == total_instances);
426
427        let committer_key = CommitterUnionKey::union(keys_to_constraints.keys().map(|pk| pk.committer_key.deref()));
428
429        let circuit_commitments =
430            keys_to_constraints.keys().map(|pk| pk.circuit_verifying_key.circuit_commitments.as_slice());
431        dev_println!("inputs_and_batch_sizes: {inputs_and_batch_sizes:?}");
432        let mut sponge = Self::init_sponge(fs_parameters, &inputs_and_batch_sizes, circuit_commitments.clone());
433
434        // --------------------------------------------------------------------
435        // First round
436
437        let prover_state = AHPForR1CS::<_, SM>::prover_first_round(prover_state, zk_rng)?;
438
439        let first_round_comm_time = start_timer!(|| "Committing to first round polys");
440        let (first_commitments, first_commitment_randomnesses) = {
441            let first_round_oracles = prover_state.first_round_oracles.as_ref().unwrap();
442            SonicKZG10::<E, FS>::commit(
443                universal_prover,
444                &committer_key,
445                first_round_oracles.iter().map(Into::into),
446                SM::ZK.then_some(zk_rng),
447            )?
448        };
449        end_timer!(first_round_comm_time);
450
451        Self::absorb_labeled(&first_commitments, &mut sponge);
452
453        let (verifier_first_message, verifier_state) = AHPForR1CS::<_, SM>::verifier_first_round(
454            &batch_sizes,
455            &circuit_infos,
456            prover_state.max_constraint_domain,
457            prover_state.max_variable_domain,
458            prover_state.max_non_zero_domain,
459            &mut sponge,
460        )?;
461        // --------------------------------------------------------------------
462
463        // --------------------------------------------------------------------
464        // Second round
465
466        let (second_oracles, prover_state) =
467            AHPForR1CS::<_, SM>::prover_second_round(&verifier_first_message, prover_state, zk_rng)?;
468
469        let second_round_comm_time = start_timer!(|| "Committing to second round polys");
470        let (second_commitments, second_commitment_randomnesses) = SonicKZG10::<E, FS>::commit(
471            universal_prover,
472            &committer_key,
473            second_oracles.iter().map(Into::into),
474            SM::ZK.then_some(zk_rng),
475        )?;
476        end_timer!(second_round_comm_time);
477
478        Self::absorb_labeled(&second_commitments, &mut sponge);
479
480        let (verifier_second_msg, verifier_state) =
481            AHPForR1CS::<_, SM>::verifier_second_round(verifier_state, &mut sponge, varuna_version)?;
482        // --------------------------------------------------------------------
483
484        // --------------------------------------------------------------------
485        // Preparation for third round
486
487        let (prover_prepare_third_message, prover_state, verifier_prepare_third_msg, verifier_state) = {
488            match varuna_version {
489                VarunaVersion::V1 => (None, prover_state, None, verifier_state),
490                VarunaVersion::V2 => {
491                    let (prover_prepare_third_message, prover_state) = AHPForR1CS::<_, SM>::prover_prepare_third_round(
492                        &verifier_first_message,
493                        &verifier_second_msg,
494                        prover_state,
495                        zk_rng,
496                    )?;
497
498                    Self::absorb_sums(
499                        &prover_prepare_third_message.sums.clone().into_iter().flatten().collect_vec(),
500                        &mut sponge,
501                    );
502
503                    let (verifier_prepare_third_msg, verifier_state) =
504                        AHPForR1CS::<_, SM>::verifier_prepare_third_round(
505                            verifier_state,
506                            &batch_sizes,
507                            &circuit_infos,
508                            &mut sponge,
509                        )?;
510
511                    (Some(prover_prepare_third_message), prover_state, Some(verifier_prepare_third_msg), verifier_state)
512                }
513            }
514        };
515        // --------------------------------------------------------------------
516
517        // --------------------------------------------------------------------
518        // Third round
519
520        let (prover_third_message, third_oracles, prover_state) = AHPForR1CS::<_, SM>::prover_third_round(
521            &verifier_first_message,
522            &verifier_second_msg,
523            &verifier_prepare_third_msg,
524            prover_state,
525            zk_rng,
526            varuna_version,
527        )?;
528
529        let third_round_comm_time = start_timer!(|| "Committing to third round polys");
530        let (third_commitments, third_commitment_randomnesses) = SonicKZG10::<E, FS>::commit(
531            universal_prover,
532            &committer_key,
533            third_oracles.iter().map(Into::into),
534            SM::ZK.then_some(zk_rng),
535        )?;
536        end_timer!(third_round_comm_time);
537
538        match varuna_version {
539            VarunaVersion::V1 => {
540                let prover_third_message = prover_third_message
541                    .clone()
542                    .ok_or_else(|| anyhow!("Expected prover to contribute sums in the third round."))?;
543                if prover_prepare_third_message.is_some() {
544                    return Err(anyhow!("Expected prover to not contribute sums in the prepare third round."))?;
545                }
546                Self::absorb_labeled_with_sums(
547                    &third_commitments,
548                    &prover_third_message.sums.into_iter().flatten().collect_vec(),
549                    &mut sponge,
550                );
551            }
552            VarunaVersion::V2 => {
553                if prover_third_message.is_some() {
554                    return Err(anyhow!("Expected prover to not contribute sums in the third round."))?;
555                }
556                Self::absorb_labeled(&third_commitments, &mut sponge);
557            }
558        }
559
560        // Extract the prover's third message to be used in the verifier's third round.
561        let prover_third_message = match varuna_version {
562            VarunaVersion::V1 => prover_third_message,
563            VarunaVersion::V2 => prover_prepare_third_message,
564        }
565        .ok_or_else(|| anyhow!("Prover did not contribute sums in the expected round."))?;
566
567        let (verifier_third_msg, verifier_state) =
568            AHPForR1CS::<_, SM>::verifier_third_round(verifier_state, &mut sponge)?;
569        // --------------------------------------------------------------------
570
571        // --------------------------------------------------------------------
572        // Fourth round
573
574        let (prover_fourth_message, fourth_oracles, mut prover_state) =
575            AHPForR1CS::<_, SM>::prover_fourth_round(&verifier_second_msg, &verifier_third_msg, prover_state, zk_rng)?;
576
577        let fourth_round_comm_time = start_timer!(|| "Committing to fourth round polys");
578        let (fourth_commitments, fourth_commitment_randomnesses) = SonicKZG10::<E, FS>::commit(
579            universal_prover,
580            &committer_key,
581            fourth_oracles.iter().map(Into::into),
582            SM::ZK.then_some(zk_rng),
583        )?;
584        end_timer!(fourth_round_comm_time);
585
586        Self::absorb_labeled_with_sums(&fourth_commitments, &prover_fourth_message.sums, &mut sponge);
587
588        let (verifier_fourth_msg, verifier_state) =
589            AHPForR1CS::<_, SM>::verifier_fourth_round(verifier_state, &mut sponge)?;
590        // --------------------------------------------------------------------
591
592        // We take out values from state before they are consumed.
593        let first_round_oracles = prover_state.first_round_oracles.take().unwrap();
594        let index_a_polys =
595            prover_state.circuit_specific_states.values_mut().flat_map(|s| s.a_polys.take().unwrap()).collect_vec();
596        let index_b_polys =
597            prover_state.circuit_specific_states.values_mut().flat_map(|s| s.b_polys.take().unwrap()).collect_vec();
598
599        // --------------------------------------------------------------------
600        // Fifth round
601        let fifth_oracles = AHPForR1CS::<_, SM>::prover_fifth_round(verifier_fourth_msg, prover_state, zk_rng)?;
602
603        let fifth_round_comm_time = start_timer!(|| "Committing to fifth round polys");
604        let (fifth_commitments, fifth_commitment_randomnesses) = SonicKZG10::<E, FS>::commit(
605            universal_prover,
606            &committer_key,
607            fifth_oracles.iter().map(Into::into),
608            SM::ZK.then_some(zk_rng),
609        )?;
610        end_timer!(fifth_round_comm_time);
611
612        Self::absorb_labeled(&fifth_commitments, &mut sponge);
613
614        let verifier_state = AHPForR1CS::<_, SM>::verifier_fifth_round(verifier_state, &mut sponge)?;
615        // --------------------------------------------------------------------
616
617        // Gather prover polynomials in one vector.
618        let polynomials: Vec<_> = index_a_polys
619            .into_iter()
620            .chain(index_b_polys)
621            .chain(first_round_oracles.into_iter())
622            .chain(second_oracles.into_iter())
623            .chain(third_oracles.into_iter())
624            .chain(fourth_oracles.into_iter())
625            .chain(fifth_oracles.into_iter())
626            .collect();
627        ensure!(
628            polynomials.len()
629                == num_unique_circuits * 6 + // numerator and denominator for each matrix sumcheck
630            AHPForR1CS::<E::Fr, SM>::num_first_round_oracles(total_instances) +
631            AHPForR1CS::<E::Fr, SM>::num_second_round_oracles() +
632            AHPForR1CS::<E::Fr, SM>::num_third_round_oracles() +
633            AHPForR1CS::<E::Fr, SM>::num_fourth_round_oracles(num_unique_circuits) +
634            AHPForR1CS::<E::Fr, SM>::num_fifth_round_oracles()
635        );
636
637        // Gather commitments in one vector.
638        let witness_comm_len = if SM::ZK { first_commitments.len() - 1 } else { first_commitments.len() };
639        let mask_poly = SM::ZK.then(|| *first_commitments[witness_comm_len].commitment());
640        let witness_commitments = first_commitments[..witness_comm_len]
641            .iter()
642            .map(|c| proof::WitnessCommitments { w: *c.commitment() })
643            .collect_vec();
644        let fourth_commitments_chunked = fourth_commitments.chunks_exact(3);
645        let (g_a_commitments, g_b_commitments, g_c_commitments) = fourth_commitments_chunked
646            .map(|c| (*c[0].commitment(), *c[1].commitment(), *c[2].commitment()))
647            .multiunzip();
648
649        #[rustfmt::skip]
650        let commitments = proof::Commitments {
651            witness_commitments,
652            mask_poly,
653            h_0: *second_commitments[0].commitment(),
654            g_1: *third_commitments[0].commitment(),
655            h_1: *third_commitments[1].commitment(),
656            g_a_commitments,
657            g_b_commitments,
658            g_c_commitments,
659            h_2: *fifth_commitments[0].commitment(),
660        };
661
662        // Gather commitment randomness together.
663        let indexer_randomness = vec![Randomness::<E>::empty(); 6 * num_unique_circuits];
664        let commitment_randomnesses: Vec<Randomness<E>> = indexer_randomness
665            .into_iter()
666            .chain(first_commitment_randomnesses)
667            .chain(second_commitment_randomnesses)
668            .chain(third_commitment_randomnesses)
669            .chain(fourth_commitment_randomnesses)
670            .chain(fifth_commitment_randomnesses)
671            .collect();
672
673        let empty_randomness = Randomness::<E>::empty();
674        if SM::ZK {
675            ensure!(commitment_randomnesses.iter().any(|r| r != &empty_randomness));
676        } else {
677            ensure!(commitment_randomnesses.iter().all(|r| r == &empty_randomness));
678        }
679
680        // Compute the AHP verifier's query set.
681        let (query_set, verifier_state) = AHPForR1CS::<_, SM>::verifier_query_set(verifier_state);
682        dev_println!("Final challenge gamma: {:?}", verifier_state.gamma);
683        let lc_s = AHPForR1CS::<_, SM>::construct_linear_combinations(
684            &public_inputs,
685            &polynomials,
686            &prover_third_message,
687            &prover_fourth_message,
688            &verifier_state,
689            varuna_version,
690        )?;
691
692        let eval_time = start_timer!(|| "Evaluating linear combinations over query set");
693        let mut evaluations = std::collections::BTreeMap::new();
694        for (label, (_, point)) in query_set.to_set() {
695            if !AHPForR1CS::<E::Fr, SM>::LC_WITH_ZERO_EVAL.contains(&label.as_str()) {
696                let lc = lc_s.get(&label).ok_or_else(|| AHPError::MissingEval(label.to_string()))?;
697                let evaluation = polynomials.get_lc_eval(lc, point)?;
698                evaluations.insert(label, evaluation);
699            }
700        }
701
702        let evaluations = proof::Evaluations::from_map(&evaluations, batch_sizes.clone());
703        end_timer!(eval_time);
704
705        sponge.absorb_nonnative_field_elements(evaluations.to_field_elements());
706
707        let pc_proof = SonicKZG10::<E, FS>::open_combinations(
708            universal_prover,
709            &committer_key,
710            lc_s.values(),
711            polynomials,
712            &commitment_randomnesses,
713            &query_set.to_set(),
714            &mut sponge,
715        )?;
716
717        let proof = Proof::<E>::new(
718            batch_sizes,
719            commitments,
720            evaluations,
721            prover_third_message,
722            prover_fourth_message,
723            pc_proof,
724        )?;
725        proof.check_batch_sizes()?;
726        ensure!(proof.pc_proof.is_hiding() == SM::ZK);
727
728        end_timer!(prover_time);
729        Ok(proof)
730    }
731
732    /// This is the main entrypoint for verifying proofs.
733    /// You can find a specification of the verifier algorithm in:
734    /// <https://github.com/ProvableHQ/protocol-docs>
735    fn verify_batch<B: Borrow<Self::VerifierInput>>(
736        universal_verifier: &Self::UniversalVerifier,
737        fs_parameters: &Self::FSParameters,
738        varuna_version: VarunaVersion,
739        keys_to_inputs: &BTreeMap<&Self::VerifyingKey, &[B]>,
740        proof: &Self::Proof,
741    ) -> Result<bool> {
742        if keys_to_inputs.is_empty() {
743            bail!(SNARKError::EmptyBatch);
744        }
745
746        proof.check_batch_sizes()?;
747        let batch_sizes_vec = proof.batch_sizes();
748        let mut batch_sizes = BTreeMap::new();
749        ensure!(
750            keys_to_inputs.len() == batch_sizes_vec.len(),
751            "[verify batch] Expected {} keys to inputs, but {} were provided.",
752            batch_sizes_vec.len(),
753            keys_to_inputs.len()
754        );
755        for (i, (vk, public_inputs_i)) in keys_to_inputs.iter().enumerate() {
756            batch_sizes.insert(vk.id, batch_sizes_vec[i]);
757
758            if public_inputs_i.is_empty() {
759                bail!(SNARKError::EmptyBatch);
760            }
761
762            if public_inputs_i.len() != batch_sizes_vec[i] {
763                bail!(SNARKError::BatchSizeMismatch);
764            }
765        }
766
767        // collect values into structures for our calculations
768        let mut max_num_constraints = 0;
769        let mut max_num_variables = 0;
770        let mut max_non_zero_domain = None;
771        let mut public_inputs = BTreeMap::new();
772        let mut padded_public_vec = Vec::with_capacity(keys_to_inputs.len());
773        let mut inputs_and_batch_sizes = BTreeMap::new();
774        let mut input_domains = BTreeMap::new();
775        let mut circuit_infos = BTreeMap::new();
776        let mut circuit_ids = Vec::with_capacity(keys_to_inputs.len());
777
778        #[cfg(feature = "snark-print")]
779        {
780            // Display the batch sizes and (padded) public inputs
781            println!(
782                "[Varuna::verify_batch] Batch sizes: {:?}\n",
783                keys_to_inputs.values().map(|instances| instances.len()).collect_vec()
784            );
785
786            for (i, (circuit, public_inputs)) in keys_to_inputs.iter().enumerate() {
787                println!("  - Circuit {i}: {} ({} instance(s))\n", circuit.id, public_inputs.len());
788                for (j, public_input) in public_inputs.iter().enumerate() {
789                    let public_input = public_input.borrow().to_field_elements()?;
790                    println!("    - Instance {j}");
791                    for (k, value) in public_input.iter().enumerate() {
792                        println!("      - {k}: {value}");
793                    }
794                    println!("\n");
795                }
796            }
797        }
798
799        for (&vk, &public_inputs_i) in keys_to_inputs.iter() {
800            max_num_constraints = max_num_constraints.max(vk.circuit_info.num_constraints);
801            max_num_variables = max_num_variables.max(vk.circuit_info.num_public_and_private_variables);
802
803            let non_zero_domains = AHPForR1CS::<_, SM>::cmp_non_zero_domains(&vk.circuit_info, max_non_zero_domain)?;
804            max_non_zero_domain = non_zero_domains.max_non_zero_domain;
805
806            let input_domain = EvaluationDomain::<E::Fr>::new(vk.circuit_info.num_public_inputs)
807                .ok_or(anyhow!("Failed to create EvaluationDomain from num_public_inputs"))?;
808            input_domains.insert(vk.id, input_domain);
809
810            let input_fields = public_inputs_i
811                .iter()
812                .map(|input| {
813                    let input = input.borrow().to_field_elements()?;
814                    ensure!(input.len() > 0);
815                    ensure!(input[0] == E::Fr::one());
816                    if input.len() > input_domain.size() {
817                        bail!(SNARKError::PublicInputSizeMismatch);
818                    }
819                    Ok(input)
820                })
821                .collect::<Result<Vec<_>, _>>()?;
822
823            let (padded_public_inputs_i, parsed_public_inputs_i): (Vec<_>, Vec<_>) = {
824                input_fields
825                    .iter()
826                    .map(|input| {
827                        let input_len = input.len().max(input_domain.size());
828                        let mut new_input = Vec::with_capacity(input_len);
829                        new_input.extend_from_slice(input);
830                        new_input.resize(input_len, E::Fr::zero());
831                        dev_println!("[verify Batch] Number of padded public variables: {}", new_input.len());
832                        let unformatted = prover::ConstraintSystem::unformat_public_input(&new_input);
833                        (new_input, unformatted)
834                    })
835                    .unzip()
836            };
837
838            let circuit_id = vk.id;
839            public_inputs.insert(circuit_id, parsed_public_inputs_i);
840
841            padded_public_vec.push(padded_public_inputs_i);
842
843            circuit_infos.insert(circuit_id, &vk.circuit_info);
844            circuit_ids.push(circuit_id);
845        }
846        for (i, (vk, &batch_size)) in keys_to_inputs.keys().zip(batch_sizes.values()).enumerate() {
847            inputs_and_batch_sizes.insert(vk.id, (batch_size, padded_public_vec[i].as_slice()));
848        }
849        let max_constraint_domain =
850            EvaluationDomain::<E::Fr>::new(max_num_constraints).ok_or(SynthesisError::PolyTooLarge)?;
851        let max_variable_domain =
852            EvaluationDomain::<E::Fr>::new(max_num_variables).ok_or(SynthesisError::PolyTooLarge)?;
853        let max_non_zero_domain = max_non_zero_domain.ok_or(SynthesisError::PolyTooLarge)?;
854
855        let comms = &proof.commitments;
856        let proof_has_correct_zk_mode = if SM::ZK {
857            proof.pc_proof.is_hiding() & comms.mask_poly.is_some()
858        } else {
859            !proof.pc_proof.is_hiding() & comms.mask_poly.is_none()
860        };
861        if !proof_has_correct_zk_mode {
862            dev_eprintln!(
863                "Found `mask_poly` in the first round when not expected, or proof has incorrect hiding mode ({})",
864                proof.pc_proof.is_hiding()
865            );
866            return Ok(false);
867        }
868
869        let verifier_time = start_timer!(|| format!("Varuna::Verify with batch sizes: {batch_sizes:?}"));
870
871        let first_round_info = AHPForR1CS::<E::Fr, SM>::first_round_polynomial_info(batch_sizes.iter());
872
873        let mut first_comms_consumed = 0;
874        let mut first_commitments = batch_sizes
875            .iter()
876            .flat_map(|(circuit_id, &batch_size)| {
877                let first_comms = comms.witness_commitments[first_comms_consumed..][..batch_size]
878                    .iter()
879                    .enumerate()
880                    .map(|(j, w_comm)| {
881                        LabeledCommitment::new_with_info(
882                            &first_round_info[&witness_label(*circuit_id, "w", j)],
883                            w_comm.w,
884                        )
885                    });
886                first_comms_consumed += batch_size;
887                first_comms
888            })
889            .collect_vec();
890
891        if SM::ZK {
892            first_commitments.push(LabeledCommitment::new_with_info(
893                first_round_info.get("mask_poly").ok_or(anyhow!("Missing mask_poly"))?,
894                comms.mask_poly.ok_or(anyhow!("Missing mask_poly"))?,
895            ));
896        }
897
898        let second_round_info = AHPForR1CS::<E::Fr, SM>::second_round_polynomial_info();
899        let second_commitments = [LabeledCommitment::new_with_info(&second_round_info["h_0"], comms.h_0)];
900
901        let third_round_info = AHPForR1CS::<E::Fr, SM>::third_round_polynomial_info(max_variable_domain.size());
902        let third_commitments = [
903            LabeledCommitment::new_with_info(&third_round_info["g_1"], comms.g_1),
904            LabeledCommitment::new_with_info(&third_round_info["h_1"], comms.h_1),
905        ];
906
907        ensure!(
908            comms.g_a_commitments.len() == comms.g_b_commitments.len(),
909            "[verify Batch] Expected {} g_a commitments to match {} g_b commitments.",
910            comms.g_b_commitments.len(),
911            comms.g_a_commitments.len()
912        );
913        ensure!(
914            comms.g_a_commitments.len() == comms.g_c_commitments.len(),
915            "[verify Batch] Expected {} g_a commitments to match {} g_c commitments.",
916            comms.g_c_commitments.len(),
917            comms.g_a_commitments.len()
918        );
919        ensure!(
920            comms.g_a_commitments.len() == circuit_ids.len(),
921            "[verify Batch] Expected {} g_a commitments to match {} circuit ids.",
922            circuit_ids.len(),
923            comms.g_a_commitments.len()
924        );
925        let fourth_round_info =
926            AHPForR1CS::<E::Fr, SM>::fourth_round_polynomial_info(circuit_infos.clone().into_iter());
927        let fourth_commitments = comms
928            .g_a_commitments
929            .iter()
930            .zip_eq(comms.g_b_commitments.iter())
931            .zip_eq(comms.g_c_commitments.iter())
932            .zip_eq(circuit_ids.iter())
933            .flat_map(|(((g_a, g_b), g_c), circuit_id)| {
934                [
935                    LabeledCommitment::new_with_info(&fourth_round_info[&witness_label(*circuit_id, "g_a", 0)], *g_a),
936                    LabeledCommitment::new_with_info(&fourth_round_info[&witness_label(*circuit_id, "g_b", 0)], *g_b),
937                    LabeledCommitment::new_with_info(&fourth_round_info[&witness_label(*circuit_id, "g_c", 0)], *g_c),
938                ]
939            })
940            .collect_vec();
941
942        let fifth_round_info = AHPForR1CS::<E::Fr, SM>::fifth_round_polynomial_info();
943        let fifth_commitments = [LabeledCommitment::new_with_info(&fifth_round_info["h_2"], comms.h_2)];
944
945        let circuit_commitments = keys_to_inputs.keys().map(|vk| vk.circuit_commitments.as_slice());
946        dev_println!("inputs_and_batch_sizes: {inputs_and_batch_sizes:?}");
947        let mut sponge = Self::init_sponge(fs_parameters, &inputs_and_batch_sizes, circuit_commitments.clone());
948
949        // --------------------------------------------------------------------
950        // First round
951        let first_round_time = start_timer!(|| "First round");
952        Self::absorb_labeled(&first_commitments, &mut sponge);
953        let (_, verifier_state) = AHPForR1CS::<_, SM>::verifier_first_round(
954            &batch_sizes,
955            &circuit_infos,
956            max_constraint_domain,
957            max_variable_domain,
958            max_non_zero_domain,
959            &mut sponge,
960        )?;
961        end_timer!(first_round_time);
962        // --------------------------------------------------------------------
963
964        // --------------------------------------------------------------------
965        // Second round
966        let second_round_time = start_timer!(|| "Second round");
967        Self::absorb_labeled(&second_commitments, &mut sponge);
968        let (_, verifier_state) =
969            AHPForR1CS::<_, SM>::verifier_second_round(verifier_state, &mut sponge, varuna_version)?;
970        end_timer!(second_round_time);
971        // --------------------------------------------------------------------
972
973        // --------------------------------------------------------------------
974        // Prep third round
975        let verifier_state = {
976            match varuna_version {
977                VarunaVersion::V1 => verifier_state,
978                VarunaVersion::V2 => {
979                    let prepare_third_round_time = start_timer!(|| "Prep third round");
980                    Self::absorb_sums(&proof.third_msg.sums.clone().into_iter().flatten().collect_vec(), &mut sponge);
981                    let (_, verifier_state) = AHPForR1CS::<_, SM>::verifier_prepare_third_round(
982                        verifier_state,
983                        &batch_sizes,
984                        &circuit_infos,
985                        &mut sponge,
986                    )?;
987                    end_timer!(prepare_third_round_time);
988                    verifier_state
989                }
990            }
991        };
992        // --------------------------------------------------------------------
993
994        // --------------------------------------------------------------------
995        // Third round
996        let third_round_time = start_timer!(|| "Third round");
997        match varuna_version {
998            VarunaVersion::V1 => {
999                Self::absorb_labeled_with_sums(
1000                    &third_commitments,
1001                    &proof.third_msg.sums.clone().into_iter().flatten().collect_vec(),
1002                    &mut sponge,
1003                );
1004            }
1005            VarunaVersion::V2 => {
1006                Self::absorb_labeled(&third_commitments, &mut sponge);
1007            }
1008        }
1009        let (_, verifier_state) = AHPForR1CS::<_, SM>::verifier_third_round(verifier_state, &mut sponge)?;
1010        end_timer!(third_round_time);
1011        // --------------------------------------------------------------------
1012
1013        // --------------------------------------------------------------------
1014        // Fourth round
1015        let fourth_round_time = start_timer!(|| "Fourth round");
1016
1017        Self::absorb_labeled_with_sums(&fourth_commitments, &proof.fourth_msg.sums, &mut sponge);
1018        let (_, verifier_state) = AHPForR1CS::<_, SM>::verifier_fourth_round(verifier_state, &mut sponge)?;
1019        end_timer!(fourth_round_time);
1020        // --------------------------------------------------------------------
1021
1022        // --------------------------------------------------------------------
1023        // Fifth round
1024        let fifth_round_time = start_timer!(|| "Fifth round");
1025
1026        Self::absorb_labeled(&fifth_commitments, &mut sponge);
1027        let verifier_state = AHPForR1CS::<_, SM>::verifier_fifth_round(verifier_state, &mut sponge)?;
1028        end_timer!(fifth_round_time);
1029        // --------------------------------------------------------------------
1030
1031        // Collect degree bounds for commitments. Indexed polynomials have *no*
1032        // degree bounds because we know the committed index polynomial has the
1033        // correct degree.
1034
1035        ensure!(
1036            circuit_commitments.len() == circuit_ids.len(),
1037            "[verify Batch] Expected {} circuit commitments, but {} were provided.",
1038            circuit_ids.len(),
1039            circuit_commitments.len()
1040        );
1041        let commitments: Vec<_> = circuit_commitments
1042            .into_iter()
1043            .flatten()
1044            .zip_eq(AHPForR1CS::<E::Fr, SM>::index_polynomial_info(circuit_ids.iter()).values())
1045            .map(|(c, info)| LabeledCommitment::new_with_info(info, *c))
1046            .chain(first_commitments)
1047            .chain(second_commitments)
1048            .chain(third_commitments)
1049            .chain(fourth_commitments)
1050            .chain(fifth_commitments)
1051            .collect();
1052
1053        let query_set_time = start_timer!(|| "Constructing query set");
1054        let (query_set, verifier_state) = AHPForR1CS::<_, SM>::verifier_query_set(verifier_state);
1055        end_timer!(query_set_time);
1056
1057        sponge.absorb_nonnative_field_elements(proof.evaluations.to_field_elements());
1058
1059        let mut evaluations = Evaluations::new();
1060
1061        let mut current_circuit_id = "".to_string();
1062        let mut circuit_index: i64 = -1;
1063
1064        for (label, (_point_name, q)) in query_set.to_set() {
1065            if AHPForR1CS::<E::Fr, SM>::LC_WITH_ZERO_EVAL.contains(&label.as_ref()) {
1066                evaluations.insert((label, q), E::Fr::zero());
1067            } else {
1068                if label != "g_1" {
1069                    let circuit_id = CircuitId::from_witness_label(&label).to_string();
1070                    if circuit_id != current_circuit_id {
1071                        circuit_index += 1;
1072                        current_circuit_id = circuit_id;
1073                    }
1074                }
1075                let eval = proof
1076                    .evaluations
1077                    .get(circuit_index as usize, &label)
1078                    .ok_or_else(|| AHPError::MissingEval(label.clone()))?;
1079                evaluations.insert((label, q), eval);
1080            }
1081        }
1082
1083        let lc_time = start_timer!(|| "Constructing linear combinations");
1084        let lc_s = AHPForR1CS::<_, SM>::construct_linear_combinations(
1085            &public_inputs,
1086            &evaluations,
1087            &proof.third_msg,
1088            &proof.fourth_msg,
1089            &verifier_state,
1090            varuna_version,
1091        )?;
1092        end_timer!(lc_time);
1093
1094        let pc_time = start_timer!(|| "Checking linear combinations with PC");
1095        let evaluations_are_correct = SonicKZG10::<E, FS>::check_combinations(
1096            universal_verifier,
1097            lc_s.values(),
1098            &commitments,
1099            &query_set.to_set(),
1100            &evaluations,
1101            &proof.pc_proof,
1102            &mut sponge,
1103        )?;
1104        end_timer!(pc_time);
1105
1106        if !evaluations_are_correct {
1107            dev_eprintln!("SonicKZG10::Check failed using final challenge gamma: {:?}", verifier_state.gamma);
1108        }
1109
1110        end_timer!(verifier_time, || format!(
1111            " SonicKZG10::Check for AHP Verifier linear equations: {}",
1112            evaluations_are_correct & proof_has_correct_zk_mode
1113        ));
1114        Ok(evaluations_are_correct & proof_has_correct_zk_mode)
1115    }
1116}