snark_verifier/
cost.rs

1//! Cost estimation.
2
3use std::ops::Add;
4
5/// Cost of verification.
6#[derive(Debug, Default, Clone, PartialEq, Eq)]
7pub struct Cost {
8    /// Number of instances.
9    pub num_instance: usize,
10    /// Number of commitments in proof.
11    pub num_commitment: usize,
12    /// Number of evaluations in proof.
13    pub num_evaluation: usize,
14    /// Number of scalar multiplications to perform.
15    pub num_msm: usize,
16    /// Number of pairings to perform.
17    pub num_pairing: usize,
18}
19
20impl Add<Cost> for Cost {
21    type Output = Cost;
22
23    fn add(mut self, rhs: Cost) -> Self::Output {
24        self.num_instance += rhs.num_instance;
25        self.num_commitment += rhs.num_commitment;
26        self.num_evaluation += rhs.num_evaluation;
27        self.num_msm += rhs.num_msm;
28        self.num_pairing += rhs.num_pairing;
29        self
30    }
31}
32
33/// For estimating cost of a verifier.
34pub trait CostEstimation<T> {
35    /// Input for [`CostEstimation::estimate_cost`].
36    type Input;
37
38    /// Estimate cost of verifier given the input.
39    fn estimate_cost(input: &Self::Input) -> Cost;
40}