snark_verifier/system/halo2/
strategy.rs

1//! Verifier strategy
2
3pub mod ipa {
4    //! IPA verifier strategy
5
6    use crate::halo2_proofs::{
7        plonk::Error,
8        poly::{
9            commitment::MSM,
10            ipa::{
11                commitment::{IPACommitmentScheme, ParamsIPA},
12                msm::MSMIPA,
13                multiopen::VerifierIPA,
14                strategy::GuardIPA,
15            },
16            VerificationStrategy,
17        },
18    };
19    use crate::util::arithmetic::CurveAffine;
20
21    /// Strategy that handles single proof and decide immediately, but also
22    /// returns `g` if the proof is valid.
23    #[derive(Clone, Debug)]
24    pub struct SingleStrategy<'a, C: CurveAffine> {
25        msm: MSMIPA<'a, C>,
26    }
27
28    impl<'a, C: CurveAffine> VerificationStrategy<'a, IPACommitmentScheme<C>, VerifierIPA<'a, C>>
29        for SingleStrategy<'a, C>
30    {
31        type Output = C;
32
33        fn new(params: &'a ParamsIPA<C>) -> Self {
34            SingleStrategy { msm: MSMIPA::new(params) }
35        }
36
37        fn process(
38            self,
39            f: impl FnOnce(MSMIPA<'a, C>) -> Result<GuardIPA<'a, C>, Error>,
40        ) -> Result<Self::Output, Error> {
41            let guard = f(self.msm)?;
42
43            let g = guard.compute_g();
44            let (msm, _) = guard.use_g(g);
45
46            if msm.check() {
47                Ok(g)
48            } else {
49                Err(Error::ConstraintSystemFailure)
50            }
51        }
52
53        fn finalize(self) -> bool {
54            unreachable!()
55        }
56    }
57}