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