snark_verifier/system/halo2/
strategy.rs

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
//! Verifier strategy

pub mod ipa {
    //! IPA verifier strategy

    use crate::halo2_proofs::{
        plonk::Error,
        poly::{
            commitment::MSM,
            ipa::{
                commitment::{IPACommitmentScheme, ParamsIPA},
                msm::MSMIPA,
                multiopen::VerifierIPA,
                strategy::GuardIPA,
            },
            VerificationStrategy,
        },
    };
    use crate::util::arithmetic::CurveAffine;

    /// Strategy that handles single proof and decide immediately, but also
    /// returns `g` if the proof is valid.
    #[derive(Clone, Debug)]
    pub struct SingleStrategy<'a, C: CurveAffine> {
        msm: MSMIPA<'a, C>,
    }

    impl<'a, C: CurveAffine> VerificationStrategy<'a, IPACommitmentScheme<C>, VerifierIPA<'a, C>>
        for SingleStrategy<'a, C>
    {
        type Output = C;

        fn new(params: &'a ParamsIPA<C>) -> Self {
            SingleStrategy { msm: MSMIPA::new(params) }
        }

        fn process(
            self,
            f: impl FnOnce(MSMIPA<'a, C>) -> Result<GuardIPA<'a, C>, Error>,
        ) -> Result<Self::Output, Error> {
            let guard = f(self.msm)?;

            let g = guard.compute_g();
            let (msm, _) = guard.use_g(g);

            if msm.check() {
                Ok(g)
            } else {
                Err(Error::ConstraintSystemFailure)
            }
        }

        fn finalize(self) -> bool {
            unreachable!()
        }
    }
}