Skip to content

Commit b88aa82

Browse files
authored
Update crr1csproof.rs
1 parent 19e94bb commit b88aa82

File tree

1 file changed

+2
-135
lines changed

1 file changed

+2
-135
lines changed

spartan/src/crr1csproof.rs

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ impl<G: CurveGroup, PC: PolyCommitmentScheme<G>> CRR1CSProof<G, PC> {
257257
) -> (CRR1CSProof<G, PC>, Vec<G::ScalarField>, Vec<G::ScalarField>) {
258258
let timer_prove = Timer::new("CRR1CSProof::prove");
259259

260-
// Check if witness size is a power of two
261260
let witness_size = witness.W.len();
262261
assert!(witness_size.is_power_of_two(), "Witness size must be a power of two");
263262

@@ -278,10 +277,7 @@ impl<G: CurveGroup, PC: PolyCommitmentScheme<G>> CRR1CSProof<G, PC> {
278277

279278
let (inst, input, vars) = (&_inst, _input.assignment.as_slice(), _vars.assignment);
280279

281-
// we currently require the number of |inputs| + 1 to be at most number of vars
282280
assert!(input.len() < vars.len());
283-
284-
// Check if E vector size is power of two and matches witness size
285281
assert!(E.len().is_power_of_two(), "Error vector size must be a power of two");
286282
assert_eq!(witness_size, E.len(), "Witness and error vector sizes must match");
287283

@@ -557,136 +553,13 @@ impl<G: CurveGroup, PC: PolyCommitmentScheme<G>> CRR1CSProof<G, PC> {
557553
#[cfg(test)]
558554
mod tests {
559555
use crate::polycommitments::hyrax::Hyrax;
560-
561556
use crate::{crr1cs::produce_synthetic_crr1cs, r1csinstance::R1CSInstance};
562-
563557
use super::*;
564558
use ark_bls12_381::Fr;
565559
use ark_bls12_381::G1Projective;
566560
use ark_ff::PrimeField;
567561
use ark_std::test_rng;
568562

569-
fn produce_tiny_r1cs<F: PrimeField>() -> (R1CSInstance<F>, Vec<F>, Vec<F>) {
570-
// three constraints over five variables Z1, Z2, Z3, Z4, and Z5
571-
// rounded to the nearest power of two
572-
let num_cons = 128;
573-
let num_vars = 256;
574-
let num_inputs = 2;
575-
576-
// encode the above constraints into three matrices
577-
let mut A: Vec<(usize, usize, F)> = Vec::new();
578-
let mut B: Vec<(usize, usize, F)> = Vec::new();
579-
let mut C: Vec<(usize, usize, F)> = Vec::new();
580-
581-
let one = F::one();
582-
// constraint 0 entries
583-
// (Z1 + Z2) * I0 - Z3 = 0;
584-
A.push((0, 0, one));
585-
A.push((0, 1, one));
586-
B.push((0, num_vars + 1, one));
587-
C.push((0, 2, one));
588-
589-
// constraint 1 entries
590-
// (Z1 + I1) * (Z3) - Z4 = 0
591-
A.push((1, 0, one));
592-
A.push((1, num_vars + 2, one));
593-
B.push((1, 2, one));
594-
C.push((1, 3, one));
595-
// constraint 3 entries
596-
// Z5 * 1 - 0 = 0
597-
A.push((2, 4, one));
598-
B.push((2, num_vars, one));
599-
600-
let inst = R1CSInstance::new(num_cons, num_vars, num_inputs, &A, &B, &C);
601-
602-
// compute a satisfying assignment
603-
let mut prng = test_rng();
604-
let i0 = F::rand(&mut prng);
605-
let i1 = F::rand(&mut prng);
606-
let z1 = F::rand(&mut prng);
607-
let z2 = F::rand(&mut prng);
608-
let z3 = (z1 + z2) * i0; // constraint 1: (Z1 + Z2) * I0 - Z3 = 0;
609-
let z4 = (z1 + i1) * z3; // constraint 2: (Z1 + I1) * (Z3) - Z4 = 0
610-
let z5 = F::zero(); //constraint 3
611-
612-
let mut vars = vec![F::zero(); num_vars];
613-
vars[0] = z1;
614-
vars[1] = z2;
615-
vars[2] = z3;
616-
vars[3] = z4;
617-
vars[4] = z5;
618-
619-
let mut input = vec![F::zero(); num_inputs];
620-
input[0] = i0;
621-
input[1] = i1;
622-
623-
(inst, vars, input)
624-
}
625-
626-
#[test]
627-
fn test_tiny_r1cs() {
628-
test_tiny_r1cs_helper::<Fr>()
629-
}
630-
631-
fn test_tiny_r1cs_helper<F: PrimeField>() {
632-
let (inst, vars, input) = tests::produce_tiny_r1cs::<F>();
633-
let is_sat = inst.is_sat(&vars, &input);
634-
assert!(is_sat);
635-
}
636-
637-
#[test]
638-
fn test_synthetic_r1cs() {
639-
test_synthetic_r1cs_helper::<Fr>()
640-
}
641-
642-
fn test_synthetic_r1cs_helper<F: PrimeField>() {
643-
let (inst, vars, input) = R1CSInstance::<F>::produce_synthetic_r1cs(1024, 1024, 10);
644-
let is_sat = inst.is_sat(&vars, &input);
645-
assert!(is_sat);
646-
}
647-
648-
#[test]
649-
pub fn check_crr1cs_proof() {
650-
check_crr1cs_proof_helper::<G1Projective, Hyrax<G1Projective>>()
651-
}
652-
fn check_crr1cs_proof_helper<G: CurveGroup, PC: PolyCommitmentScheme<G>>() {
653-
let num_vars = 1024;
654-
let num_cons = num_vars;
655-
let num_inputs = 10;
656-
let (shape, instance, witness, gens) =
657-
produce_synthetic_crr1cs::<G, PC>(num_cons, num_vars, num_inputs);
658-
assert!(is_sat(&shape, &instance, &witness, &gens.gens_r1cs_sat).unwrap());
659-
let (num_cons, num_vars, _num_inputs) = (
660-
shape.get_num_cons(),
661-
shape.get_num_vars(),
662-
shape.get_num_inputs(),
663-
);
664-
665-
let mut prover_transcript = Transcript::new(b"example");
666-
667-
let (proof, rx, ry) = CRR1CSProof::prove(
668-
&shape,
669-
&instance,
670-
witness,
671-
&gens.gens_r1cs_sat,
672-
&mut prover_transcript,
673-
);
674-
675-
let inst_evals = shape.inst.inst.evaluate(&rx, &ry);
676-
677-
let mut verifier_transcript = Transcript::new(b"example");
678-
assert!(proof
679-
.verify(
680-
num_vars,
681-
num_cons,
682-
&instance,
683-
&inst_evals,
684-
&mut verifier_transcript,
685-
&gens.gens_r1cs_sat.keys.vk,
686-
)
687-
.is_ok());
688-
}
689-
690563
#[test]
691564
#[should_panic(expected = "Witness size must be a power of two")]
692565
fn test_witness_size_not_power_of_two() {
@@ -696,12 +569,9 @@ mod tests {
696569
let (shape, instance, mut witness, gens) =
697570
produce_synthetic_crr1cs::<G1Projective, Hyrax<G1Projective>>(num_cons, num_vars, num_inputs);
698571

699-
// Modify witness to have non-power-of-two size
700-
witness.W = vec![Fr::zero(); 1023]; // Not a power of two
701-
572+
witness.W = vec![Fr::zero(); 1023];
702573
let mut prover_transcript = Transcript::new(b"example");
703574

704-
// This should panic because witness size is not power of two
705575
let _ = CRR1CSProof::prove(
706576
&shape,
707577
&instance,
@@ -720,12 +590,9 @@ mod tests {
720590
let (shape, instance, mut witness, gens) =
721591
produce_synthetic_crr1cs::<G1Projective, Hyrax<G1Projective>>(num_cons, num_vars, num_inputs);
722592

723-
// Modify error vector to have non-power-of-two size
724-
witness.E = vec![Fr::zero(); 1023]; // Not a power of two
725-
593+
witness.E = vec![Fr::zero(); 1023];
726594
let mut prover_transcript = Transcript::new(b"example");
727595

728-
// This should panic because error vector size is not power of two
729596
let _ = CRR1CSProof::prove(
730597
&shape,
731598
&instance,

0 commit comments

Comments
 (0)