w3f_pcs/pcs/id/
mod.rs

1use ark_ff::Zero;
2use ark_poly::Polynomial;
3use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
4use ark_std::vec::Vec;
5
6use crate::pcs::*;
7use crate::utils::poly;
8use crate::Poly;
9
10#[derive(Clone, PartialEq, Eq, Debug, CanonicalSerialize, CanonicalDeserialize)]
11pub struct WrappedPolynomial<F: PrimeField>(pub Poly<F>);
12
13impl<F: PrimeField> WrappedPolynomial<F> {
14    fn evaluate(&self, x: &F) -> F {
15        self.0.evaluate(x)
16    }
17}
18
19impl<F: PrimeField> Add<Self> for WrappedPolynomial<F> {
20    type Output = WrappedPolynomial<F>;
21
22    fn add(self, other: WrappedPolynomial<F>) -> Self::Output {
23        WrappedPolynomial(self.0 + other.0)
24    }
25}
26
27impl<F: PrimeField> Sub<Self> for WrappedPolynomial<F> {
28    type Output = WrappedPolynomial<F>;
29
30    fn sub(self, other: WrappedPolynomial<F>) -> Self::Output {
31        let mut temp = self.0;
32        temp -= &other.0; //TODO
33        WrappedPolynomial(temp)
34    }
35}
36
37impl<F: PrimeField> core::iter::Sum<Self> for WrappedPolynomial<F> {
38    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
39        iter.reduce(|a, b| a + b).unwrap()
40    }
41}
42
43impl<F: PrimeField> Commitment<F> for WrappedPolynomial<F> {
44    fn mul(&self, by: F) -> Self {
45        let mut temp = Poly::zero(); //TODO
46        temp += (by, &self.0);
47        WrappedPolynomial(temp)
48    }
49
50    fn combine(coeffs: &[F], commitments: &[Self]) -> Self {
51        let polys = commitments
52            .to_vec()
53            .into_iter()
54            .map(|c| c.0)
55            .collect::<Vec<_>>();
56        let combined = poly::sum_with_coeffs(coeffs.to_vec(), &polys);
57        WrappedPolynomial(combined)
58    }
59}
60
61impl CommitterKey for () {
62    fn max_degree(&self) -> usize {
63        usize::MAX >> 1
64    }
65}
66
67impl VerifierKey for () {
68    fn max_points(&self) -> usize {
69        1
70    }
71}
72
73impl RawVerifierKey for () {
74    type VK = ();
75
76    fn prepare(&self) -> () {
77        ()
78    }
79}
80
81impl PcsParams for () {
82    type CK = ();
83    type VK = ();
84    type RVK = ();
85
86    fn ck(&self) -> () {
87        ()
88    }
89
90    fn vk(&self) -> () {
91        ()
92    }
93
94    fn raw_vk(&self) -> () {
95        ()
96    }
97}
98
99#[derive(Clone)]
100pub struct IdentityCommitment {}
101
102impl<F: PrimeField> PCS<F> for IdentityCommitment {
103    type C = WrappedPolynomial<F>;
104    type Proof = ();
105    type CK = ();
106    type VK = ();
107    type Params = ();
108
109    fn setup<R: Rng>(_max_degree: usize, _rng: &mut R) -> Self::Params {
110        ()
111    }
112
113    fn commit(_ck: &(), p: &Poly<F>) -> Result<Self::C, ()> {
114        Ok(WrappedPolynomial(p.clone()))
115    }
116
117    fn open(_ck: &(), _p: &Poly<F>, _x: F) -> Result<Self::Proof, ()> {
118        Ok(())
119    }
120
121    fn verify(_vk: &(), c: Self::C, x: F, z: F, _proof: Self::Proof) -> Result<(), ()> {
122        (c.evaluate(&x) == z).then(|| ()).ok_or(())
123    }
124}