schnorr_pok 0.23.0

Schnorr, Okamoto, Chaum-Pedersen protocols for proof of knowledge, equality and inequality of one or more discrete logs. Working in elliptic curve and pairing groups
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
use crate::{
    discrete_log::{PokDiscreteLogProtocol, PokPedersenCommitmentProtocol},
    error::SchnorrError,
    SchnorrCommitment,
};
use ark_ec::{AffineRepr, CurveGroup, VariableBaseMSM};
use ark_ff::{PrimeField, Zero};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{
    collections::{BTreeMap, BTreeSet},
    io::Write,
    iter,
    ops::{Add, Neg},
    vec,
    vec::Vec,
};
use dock_crypto_utils::{
    expect_equality, randomized_mult_checker::RandomizedMultChecker, serde_utils::ArkObjectBytes,
};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Same};

/// Response during step 3 of the Schnorr protocol to prove knowledge of 1 or more discrete logs.
/// This is called partial because it does not contain the responses for all the witnesses. This is
/// used when more than one Schnorr protocol is used and some witnesses are to be proved equal among them.
/// Also useful in case of a single Schnorr protocol if some witnesses are to be proved equal.
/// Eg. when proving knowledge of witnesses `m1`, `m2`, `m3`, `m4` in `C = G1 * m1 + G2 * m2 + G3 * m3 + G4 * m4`,
/// if `m1` and `m3` are also witnesses of another Schnorr protocol then this will contain only the responses
/// for `m2` and `m4`. During verification, the responses for `m1` and `m3` will be given to it.
#[serde_as]
#[derive(
    Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
)]
pub struct PartialSchnorrResponse<G: AffineRepr> {
    /// Key of the map is the witness index and value is the response for that witnesses.
    #[serde_as(as = "BTreeMap<Same, ArkObjectBytes>")]
    pub responses: BTreeMap<usize, G::ScalarField>,
    pub total_responses: usize,
}

/// Proof of knowledge of discrete log but does not contain the response as the response comes from another protocol
/// running with it which has the same witness (discrete log)
#[serde_as]
#[derive(
    Default,
    Clone,
    PartialEq,
    Eq,
    Debug,
    CanonicalSerialize,
    CanonicalDeserialize,
    Serialize,
    Deserialize,
)]
pub struct PartialPokDiscreteLog<G: AffineRepr> {
    #[serde_as(as = "ArkObjectBytes")]
    pub t: G,
}

/// Proof of knowledge of 2 discrete logs but contains the response of only 1, i.e. when proving knowledge of witnesses
/// `a` and `b` in `C = G * a + H * b`, contains the response only for witness `a`. This is because response for `b` will
/// come from another Schnorr protocol which also has `b` as one of the witnesses
#[serde_as]
#[derive(
    Default,
    Clone,
    PartialEq,
    Eq,
    Debug,
    CanonicalSerialize,
    CanonicalDeserialize,
    Serialize,
    Deserialize,
)]
pub struct Partial1PokPedersenCommitment<G: AffineRepr> {
    #[serde_as(as = "ArkObjectBytes")]
    pub t: G,
    #[serde_as(as = "ArkObjectBytes")]
    pub response1: G::ScalarField,
}

/// Proof of knowledge of 2 discrete logs but contains the response of only 1, i.e. when proving knowledge of witnesses
/// `a` and `b` in `C = G * a + H * b`, contains the response only for witness `b`. This is because response for `a` will
/// come from another Schnorr protocol which also has `a` as one of the witnesses
#[serde_as]
#[derive(
    Default,
    Clone,
    PartialEq,
    Eq,
    Debug,
    CanonicalSerialize,
    CanonicalDeserialize,
    Serialize,
    Deserialize,
)]
pub struct Partial2PokPedersenCommitment<G: AffineRepr> {
    #[serde_as(as = "ArkObjectBytes")]
    pub t: G,
    #[serde_as(as = "ArkObjectBytes")]
    pub response2: G::ScalarField,
}

/// Proof of knowledge of 2 discrete logs but contains the response for neither, i.e. when proving knowledge of witnesses
/// `a` and `b` in `C = G * a + H * b`, contains no response. This is because response for `a` and `b` will come from
/// another Schnorr protocol which also has `a` and `b` as their witnesses
#[serde_as]
#[derive(
    Default,
    Clone,
    PartialEq,
    Eq,
    Debug,
    CanonicalSerialize,
    CanonicalDeserialize,
    Serialize,
    Deserialize,
)]
pub struct PartialPokPedersenCommitment<G: AffineRepr> {
    #[serde_as(as = "ArkObjectBytes")]
    pub t: G,
}

impl<G: AffineRepr> SchnorrCommitment<G> {
    /// The key of the map is the index for which response has to be generated.
    pub fn partial_response(
        &self,
        witnesses: BTreeMap<usize, G::ScalarField>,
        challenge: &G::ScalarField,
    ) -> Result<PartialSchnorrResponse<G>, SchnorrError> {
        let mut responses = BTreeMap::new();
        for (i, w) in witnesses {
            let b = self
                .blindings
                .get(i)
                .ok_or_else(|| SchnorrError::MissingBlindingAtIndex(i))?;
            responses.insert(i, w * challenge + b);
        }
        Ok(PartialSchnorrResponse {
            responses,
            total_responses: self.blindings.len(),
        })
    }
}

impl<G: AffineRepr> PokDiscreteLogProtocol<G> {
    pub fn gen_partial_proof(self) -> PartialPokDiscreteLog<G> {
        PartialPokDiscreteLog { t: self.t }
    }
}

impl<G: AffineRepr> PokPedersenCommitmentProtocol<G> {
    /// Generate proof when no response has to be generated.
    pub fn gen_partial_proof(self) -> PartialPokPedersenCommitment<G> {
        PartialPokPedersenCommitment { t: self.t }
    }

    /// Generate proof when only response for witness1 has to be generated.
    pub fn gen_partial1_proof(
        self,
        challenge: &G::ScalarField,
    ) -> Partial1PokPedersenCommitment<G> {
        Partial1PokPedersenCommitment {
            t: self.t,
            response1: self.blinding1 + (self.witness1 * *challenge),
        }
    }

    /// Generate proof when only response for witness2 has to be generated.
    pub fn gen_partial2_proof(
        self,
        challenge: &G::ScalarField,
    ) -> Partial2PokPedersenCommitment<G> {
        Partial2PokPedersenCommitment {
            t: self.t,
            response2: self.blinding2 + (self.witness2 * *challenge),
        }
    }
}

impl<G: AffineRepr> PartialSchnorrResponse<G> {
    /// Keys of `missing_responses` are the witness indices whose response was generated while creating this. Instead,
    /// these come from some other Schnorr protocol.
    pub fn is_valid(
        &self,
        bases: &[G],
        y: &G,
        t: &G,
        challenge: &G::ScalarField,
        missing_responses: BTreeMap<usize, G::ScalarField>,
    ) -> Result<(), SchnorrError> {
        let full_resp = self.pre_verify(bases, missing_responses)?;
        if (G::Group::msm_unchecked(bases, &full_resp)
            .add(y.mul_bigint((-*challenge).into_bigint())))
        .into_affine()
            == *t
        {
            Ok(())
        } else {
            Err(SchnorrError::InvalidResponse)
        }
    }

    /// Same as `Self::is_valid` except it uses `RandomizedMultChecker` to combine the scalar multiplication checks into a single
    pub fn verify_using_randomized_mult_checker(
        &self,
        bases: Vec<G>,
        y: G,
        t: G,
        challenge: &G::ScalarField,
        missing_responses: BTreeMap<usize, G::ScalarField>,
        rmc: &mut RandomizedMultChecker<G>,
    ) -> Result<(), SchnorrError> {
        let full_resp = self.pre_verify(&bases, missing_responses)?;
        rmc.add_many(
            bases.into_iter().chain(iter::once(y)),
            full_resp.iter().chain(iter::once(&-*challenge)),
            t,
        );
        Ok(())
    }

    /// Get indices for which it does not have any response. These responses will be fetched from other protocols.
    pub fn get_missing_response_indices(&self) -> BTreeSet<usize> {
        let mut ids = BTreeSet::new();
        for i in 0..self.total_responses {
            if !self.responses.contains_key(&i) {
                ids.insert(i);
            }
        }
        ids
    }

    /// Get response for the specified discrete log
    pub fn get_response(&self, idx: usize) -> Result<&G::ScalarField, SchnorrError> {
        match self.responses.get(&idx) {
            Some(r) => Ok(r),
            None => Err(SchnorrError::MissingResponseAtIndex(idx)),
        }
    }

    pub fn pre_verify(
        &self,
        bases: &[G],
        missing_responses: BTreeMap<usize, G::ScalarField>,
    ) -> Result<Vec<G::ScalarField>, SchnorrError> {
        expect_equality!(
            self.total_responses,
            bases.len(),
            SchnorrError::ExpectedSameSizeSequences
        );
        expect_equality!(
            self.responses.len() + missing_responses.len(),
            bases.len(),
            SchnorrError::ExpectedSameSizeSequences
        );
        let mut full_resp =
            vec![G::ScalarField::zero(); self.responses.len() + missing_responses.len()];
        for (i, r) in missing_responses {
            // Will ensurer that `self.responses` and `missing_responses` are disjoint
            if self.responses.contains_key(&i) {
                return Err(SchnorrError::FoundCommonIndexInOwnAndReceivedResponses(i));
            }
            full_resp[i] = r;
        }
        for (i, r) in &self.responses {
            full_resp[*i] = *r;
        }
        Ok(full_resp)
    }
}

impl<G: AffineRepr> PartialPokDiscreteLog<G> {
    pub fn verify(
        &self,
        y: &G,
        base: &G,
        challenge: &G::ScalarField,
        response: &G::ScalarField,
    ) -> bool {
        let mut expected = base.mul_bigint(response.into_bigint());
        expected -= y.mul_bigint(challenge.into_bigint());
        expected.into_affine() == self.t
    }

    pub fn verify_using_randomized_mult_checker(
        &self,
        y: G,
        base: G,
        challenge: &G::ScalarField,
        response: &G::ScalarField,
        rmc: &mut RandomizedMultChecker<G>,
    ) {
        rmc.add_2(base, response, y, &challenge.neg(), self.t)
    }

    pub fn challenge_contribution<W: Write>(
        &self,
        base: &G,
        y: &G,
        writer: W,
    ) -> Result<(), SchnorrError> {
        PokDiscreteLogProtocol::compute_challenge_contribution(base, y, &self.t, writer)
    }
}

impl<G: AffineRepr> PartialPokPedersenCommitment<G> {
    pub fn verify(
        &self,
        y: &G,
        base1: &G,
        base2: &G,
        challenge: &G::ScalarField,
        response1: &G::ScalarField,
        response2: &G::ScalarField,
    ) -> bool {
        let mut expected = base1.mul_bigint(response1.into_bigint());
        expected += base2.mul_bigint(response2.into_bigint());
        expected -= y.mul_bigint(challenge.into_bigint());
        expected.into_affine() == self.t
    }

    pub fn verify_using_randomized_mult_checker(
        &self,
        y: G,
        base1: G,
        base2: G,
        challenge: &G::ScalarField,
        response1: &G::ScalarField,
        response2: &G::ScalarField,
        rmc: &mut RandomizedMultChecker<G>,
    ) {
        rmc.add_3(
            base1,
            response1,
            base2,
            response2,
            y,
            &challenge.neg(),
            self.t,
        )
    }

    pub fn challenge_contribution<W: Write>(
        &self,
        base1: &G,
        base2: &G,
        y: &G,
        writer: W,
    ) -> Result<(), SchnorrError> {
        PokPedersenCommitmentProtocol::compute_challenge_contribution(
            base1, base2, y, &self.t, writer,
        )
    }
}

impl<G: AffineRepr> Partial1PokPedersenCommitment<G> {
    pub fn verify(
        &self,
        y: &G,
        base1: &G,
        base2: &G,
        challenge: &G::ScalarField,
        response2: &G::ScalarField,
    ) -> bool {
        let mut expected = base1.mul_bigint(self.response1.into_bigint());
        expected += base2.mul_bigint(response2.into_bigint());
        expected -= y.mul_bigint(challenge.into_bigint());
        expected.into_affine() == self.t
    }

    /// Same as `Self::verify` except it uses `RandomizedMultChecker` to combine the scalar multiplication checks into a single
    pub fn verify_using_randomized_mult_checker(
        &self,
        y: G,
        base1: G,
        base2: G,
        challenge: &G::ScalarField,
        response2: &G::ScalarField,
        rmc: &mut RandomizedMultChecker<G>,
    ) {
        rmc.add_3(
            base1,
            &self.response1,
            base2,
            response2,
            y,
            &challenge.neg(),
            self.t,
        )
    }

    pub fn challenge_contribution<W: Write>(
        &self,
        base1: &G,
        base2: &G,
        y: &G,
        writer: W,
    ) -> Result<(), SchnorrError> {
        PokPedersenCommitmentProtocol::compute_challenge_contribution(
            base1, base2, y, &self.t, writer,
        )
    }
}

impl<G: AffineRepr> Partial2PokPedersenCommitment<G> {
    pub fn verify(
        &self,
        y: &G,
        base1: &G,
        base2: &G,
        challenge: &G::ScalarField,
        response1: &G::ScalarField,
    ) -> bool {
        let mut expected = base1.mul_bigint(response1.into_bigint());
        expected += base2.mul_bigint(self.response2.into_bigint());
        expected -= y.mul_bigint(challenge.into_bigint());
        expected.into_affine() == self.t
    }

    /// Same as `Self::verify` except it uses `RandomizedMultChecker` to combine the scalar multiplication checks into a single
    pub fn verify_using_randomized_mult_checker(
        &self,
        y: G,
        base1: G,
        base2: G,
        challenge: &G::ScalarField,
        response1: &G::ScalarField,
        rmc: &mut RandomizedMultChecker<G>,
    ) {
        rmc.add_3(
            base1,
            response1,
            base2,
            &self.response2,
            y,
            &challenge.neg(),
            self.t,
        )
    }

    pub fn challenge_contribution<W: Write>(
        &self,
        base1: &G,
        base2: &G,
        y: &G,
        writer: W,
    ) -> Result<(), SchnorrError> {
        PokPedersenCommitmentProtocol::compute_challenge_contribution(
            base1, base2, y, &self.t, writer,
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::pok_generalized_pedersen::compute_random_oracle_challenge;
    use ark_bls12_381::{Fr, G1Affine, G1Projective};
    use ark_ec::VariableBaseMSM;
    use ark_std::{
        rand::{rngs::StdRng, SeedableRng},
        UniformRand,
    };
    use blake2::Blake2b512;

    #[test]
    fn discrete_log_partial() {
        let mut rng = StdRng::seed_from_u64(0u64);
        let count = 10;
        let bases_1 = (0..count)
            .into_iter()
            .map(|_| G1Affine::rand(&mut rng))
            .collect::<Vec<_>>();
        let bases_2 = (0..count)
            .into_iter()
            .map(|_| G1Affine::rand(&mut rng))
            .collect::<Vec<_>>();
        let witnesses_1 = (0..count)
            .into_iter()
            .map(|_| Fr::rand(&mut rng))
            .collect::<Vec<_>>();
        let common_wit_indices = BTreeSet::from([0, 3, 4, 5, 8]);
        let mut witnesses_2 = (0..count)
            .into_iter()
            .map(|_| Fr::rand(&mut rng))
            .collect::<Vec<_>>();
        for i in &common_wit_indices {
            witnesses_2[*i] = witnesses_1[*i].clone();
        }
        let y_1 = G1Projective::msm_unchecked(&bases_1, &witnesses_1).into_affine();
        let y_2 = G1Projective::msm_unchecked(&bases_2, &witnesses_2).into_affine();

        let blindings_1 = (0..count)
            .into_iter()
            .map(|_| Fr::rand(&mut rng))
            .collect::<Vec<_>>();
        let mut blindings_2 = (0..count)
            .into_iter()
            .map(|_| Fr::rand(&mut rng))
            .collect::<Vec<_>>();
        for i in &common_wit_indices {
            blindings_2[*i] = blindings_1[*i].clone();
        }

        let comm_1 = SchnorrCommitment::new(&bases_1, blindings_1);
        let comm_2 = SchnorrCommitment::new(&bases_2, blindings_2);

        let challenge = Fr::rand(&mut rng);

        let resp_1 = comm_1.response(&witnesses_1, &challenge).unwrap();
        resp_1
            .is_valid(&bases_1, &y_1, &comm_1.t, &challenge)
            .unwrap();

        let mut diff_wits = BTreeMap::new();
        for i in 0..count {
            if !common_wit_indices.contains(&i) {
                diff_wits.insert(i, witnesses_2[i]);
            }
        }
        let resp_2 = comm_2.partial_response(diff_wits, &challenge).unwrap();
        assert_eq!(resp_2.get_missing_response_indices(), common_wit_indices);
        let missing_responses = resp_1.get_responses(&common_wit_indices).unwrap();
        resp_2
            .is_valid(
                &bases_2,
                &y_2,
                &comm_2.t,
                &challenge,
                missing_responses.clone(),
            )
            .unwrap();

        for i in common_wit_indices {
            assert!(resp_2.get_response(i).is_err());
        }

        // Verify using RandomizedMultChecker
        let mut checker = RandomizedMultChecker::new_using_rng(&mut rng);
        resp_1
            .verify_using_randomized_mult_checker(bases_1, y_1, comm_1.t, &challenge, &mut checker)
            .unwrap();
        resp_2
            .verify_using_randomized_mult_checker(
                bases_2,
                y_2,
                comm_2.t,
                &challenge,
                missing_responses,
                &mut checker,
            )
            .unwrap();
        assert!(checker.verify());
    }

    #[test]
    fn ped_comm_partial() {
        let mut rng = StdRng::seed_from_u64(0u64);
        let base1 = G1Affine::rand(&mut rng);
        let base2 = G1Affine::rand(&mut rng);
        let base3 = G1Affine::rand(&mut rng);
        let base4 = G1Affine::rand(&mut rng);
        let base5 = G1Affine::rand(&mut rng);
        let base6 = G1Affine::rand(&mut rng);
        let base7 = G1Affine::rand(&mut rng);
        let base8 = G1Affine::rand(&mut rng);
        let witness1 = Fr::rand(&mut rng);
        let witness2 = Fr::rand(&mut rng);
        let witness3 = Fr::rand(&mut rng);
        let witness4 = Fr::rand(&mut rng);

        let y_1 = (base1 * witness1).into_affine();
        let y_2 = (base2 * witness1).into_affine();

        let blinding1 = Fr::rand(&mut rng);
        let protocol_1 = PokDiscreteLogProtocol::init(witness1, blinding1, &base1);
        let protocol_2 = PokDiscreteLogProtocol::init(witness1, blinding1, &base2);

        let mut chal_contrib_prover = vec![];
        protocol_1
            .challenge_contribution(&base1, &y_1, &mut chal_contrib_prover)
            .unwrap();
        protocol_2
            .challenge_contribution(&base2, &y_2, &mut chal_contrib_prover)
            .unwrap();
        let challenge_prover =
            compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_contrib_prover);
        let proof_1 = protocol_1.gen_proof(&challenge_prover);
        let proof_2 = protocol_2.gen_partial_proof();

        let mut chal_contrib_verifier = vec![];
        proof_1
            .challenge_contribution(&base1, &y_1, &mut chal_contrib_verifier)
            .unwrap();
        proof_2
            .challenge_contribution(&base2, &y_2, &mut chal_contrib_verifier)
            .unwrap();
        let challenge_verifier =
            compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_contrib_verifier);

        assert_eq!(chal_contrib_prover, chal_contrib_verifier);
        assert_eq!(challenge_prover, challenge_verifier);

        assert!(proof_1.verify(&y_1, &base1, &challenge_verifier));
        assert!(proof_2.verify(&y_2, &base2, &challenge_verifier, &proof_1.response));

        let y_1 = (base1 * witness1 + base2 * witness2).into_affine();
        let y_2 = (base3 * witness1 + base4 * witness2).into_affine();
        let y_3 = (base5 * witness1 + base6 * witness3).into_affine();
        let y_4 = (base7 * witness4 + base8 * witness2).into_affine();

        let blinding2 = Fr::rand(&mut rng);
        let blinding3 = Fr::rand(&mut rng);
        let blinding4 = Fr::rand(&mut rng);

        let protocol_1 = PokPedersenCommitmentProtocol::init(
            witness1, blinding1, &base1, witness2, blinding2, &base2,
        );
        let protocol_2 = PokPedersenCommitmentProtocol::init(
            witness1, blinding1, &base3, witness2, blinding2, &base4,
        );
        let protocol_3 = PokPedersenCommitmentProtocol::init(
            witness1, blinding1, &base5, witness3, blinding3, &base6,
        );
        let protocol_4 = PokPedersenCommitmentProtocol::init(
            witness4, blinding4, &base7, witness2, blinding2, &base8,
        );

        let mut chal_contrib_prover = vec![];
        protocol_1
            .challenge_contribution(&base1, &base2, &y_1, &mut chal_contrib_prover)
            .unwrap();
        protocol_2
            .challenge_contribution(&base3, &base4, &y_2, &mut chal_contrib_prover)
            .unwrap();
        protocol_3
            .challenge_contribution(&base5, &base6, &y_3, &mut chal_contrib_prover)
            .unwrap();
        protocol_4
            .challenge_contribution(&base7, &base8, &y_4, &mut chal_contrib_prover)
            .unwrap();
        let challenge_prover =
            compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_contrib_prover);

        let proof_1 = protocol_1.gen_proof(&challenge_prover);
        let proof_2 = protocol_2.gen_partial_proof();
        let proof_3 = protocol_3.gen_partial2_proof(&challenge_prover);
        let proof_4 = protocol_4.gen_partial1_proof(&challenge_prover);

        let mut chal_contrib_verifier = vec![];
        proof_1
            .challenge_contribution(&base1, &base2, &y_1, &mut chal_contrib_verifier)
            .unwrap();
        proof_2
            .challenge_contribution(&base3, &base4, &y_2, &mut chal_contrib_verifier)
            .unwrap();
        proof_3
            .challenge_contribution(&base5, &base6, &y_3, &mut chal_contrib_verifier)
            .unwrap();
        proof_4
            .challenge_contribution(&base7, &base8, &y_4, &mut chal_contrib_verifier)
            .unwrap();

        let challenge_verifier =
            compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_contrib_verifier);

        assert_eq!(chal_contrib_prover, chal_contrib_verifier);
        assert_eq!(challenge_prover, challenge_verifier);
        assert!(proof_1.verify(&y_1, &base1, &base2, &challenge_verifier));
        assert!(proof_2.verify(
            &y_2,
            &base3,
            &base4,
            &challenge_verifier,
            &proof_1.response1,
            &proof_1.response2
        ));
        assert!(proof_3.verify(
            &y_3,
            &base5,
            &base6,
            &challenge_verifier,
            &proof_1.response1
        ));
        assert!(proof_4.verify(
            &y_4,
            &base7,
            &base8,
            &challenge_verifier,
            &proof_1.response2
        ));

        // Verify using RandomizedMultChecker
        let mut checker = RandomizedMultChecker::new_using_rng(&mut rng);
        proof_1.verify_using_randomized_mult_checker(
            y_1,
            base1,
            base2,
            &challenge_verifier,
            &mut checker,
        );
        proof_2.verify_using_randomized_mult_checker(
            y_2,
            base3,
            base4,
            &challenge_verifier,
            &proof_1.response1,
            &proof_1.response2,
            &mut checker,
        );
        proof_3.verify_using_randomized_mult_checker(
            y_3,
            base5,
            base6,
            &challenge_verifier,
            &proof_1.response1,
            &mut checker,
        );
        proof_4.verify_using_randomized_mult_checker(
            y_4,
            base7,
            base8,
            &challenge_verifier,
            &proof_1.response2,
            &mut checker,
        );
        assert!(checker.verify());
    }
}