Skip to main content

proof_system/statement/accumulator/
detached.rs

1use crate::{error::ProofSystemError, setup_params::SetupParams, statement::Statement};
2use ark_ec::pairing::Pairing;
3use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
4use ark_std::vec::Vec;
5use dock_crypto_utils::serde_utils::ArkObjectBytes;
6use serde::{Deserialize, Serialize};
7use serde_with::serde_as;
8use vb_accumulator::prelude::{
9    MembershipProvingKey, NonMembershipProvingKey, PublicKey, SetupParams as AccumParams,
10};
11
12#[serde_as]
13#[derive(
14    Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
15)]
16#[serde(bound = "")]
17pub struct DetachedAccumulatorMembershipProver<E: Pairing> {
18    #[serde_as(as = "ArkObjectBytes")]
19    pub accumulator_value: E::G1Affine,
20    pub params: Option<AccumParams<E>>,
21    pub public_key: Option<PublicKey<E>>,
22    pub proving_key: Option<MembershipProvingKey<E::G1Affine>>,
23    pub params_ref: Option<usize>,
24    pub public_key_ref: Option<usize>,
25    pub proving_key_ref: Option<usize>,
26}
27
28impl<E: Pairing> DetachedAccumulatorMembershipProver<E> {
29    /// Create a statement by passing the accumulator params, public key and proving key directly.
30    pub fn new_statement_from_params(
31        params: AccumParams<E>,
32        public_key: PublicKey<E>,
33        proving_key: MembershipProvingKey<E::G1Affine>,
34        accumulator_value: E::G1Affine,
35    ) -> Statement<E> {
36        Statement::DetachedAccumulatorMembershipProver(Self {
37            accumulator_value,
38            params: Some(params),
39            public_key: Some(public_key),
40            proving_key: Some(proving_key),
41            params_ref: None,
42            public_key_ref: None,
43            proving_key_ref: None,
44        })
45    }
46
47    /// Create a statement by passing the indices of accumulator params, public key and proving key in `SetupParams`.
48    pub fn new_statement_from_params_ref(
49        params_ref: usize,
50        public_key_ref: usize,
51        proving_key_ref: usize,
52        accumulator_value: E::G1Affine,
53    ) -> Statement<E> {
54        Statement::DetachedAccumulatorMembershipProver(Self {
55            accumulator_value,
56            params: None,
57            public_key: None,
58            proving_key: None,
59            params_ref: Some(params_ref),
60            public_key_ref: Some(public_key_ref),
61            proving_key_ref: Some(proving_key_ref),
62        })
63    }
64
65    impl_getters!(
66        AccumParams,
67        VbAccumulatorParams,
68        PublicKey,
69        VbAccumulatorPublicKey,
70        MembershipProvingKey,
71        VbAccumulatorMemProvingKey
72    );
73}
74
75#[serde_as]
76#[derive(
77    Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
78)]
79#[serde(bound = "")]
80pub struct DetachedAccumulatorMembershipVerifier<E: Pairing> {
81    pub params: Option<AccumParams<E>>,
82    pub public_key: Option<PublicKey<E>>,
83    pub proving_key: Option<MembershipProvingKey<E::G1Affine>>,
84    pub params_ref: Option<usize>,
85    pub public_key_ref: Option<usize>,
86    pub proving_key_ref: Option<usize>,
87}
88
89impl<E: Pairing> DetachedAccumulatorMembershipVerifier<E> {
90    /// Create a statement by passing the accumulator params, public key and proving key directly.
91    pub fn new_statement_from_params(
92        params: AccumParams<E>,
93        public_key: PublicKey<E>,
94        proving_key: MembershipProvingKey<E::G1Affine>,
95    ) -> Statement<E> {
96        Statement::DetachedAccumulatorMembershipVerifier(Self {
97            params: Some(params),
98            public_key: Some(public_key),
99            proving_key: Some(proving_key),
100            params_ref: None,
101            public_key_ref: None,
102            proving_key_ref: None,
103        })
104    }
105
106    /// Create a statement by passing the indices of accumulator params, public key and proving key in `SetupParams`.
107    pub fn new_statement_from_params_ref(
108        params_ref: usize,
109        public_key_ref: usize,
110        proving_key_ref: usize,
111    ) -> Statement<E> {
112        Statement::DetachedAccumulatorMembershipVerifier(Self {
113            params: None,
114            public_key: None,
115            proving_key: None,
116            params_ref: Some(params_ref),
117            public_key_ref: Some(public_key_ref),
118            proving_key_ref: Some(proving_key_ref),
119        })
120    }
121
122    impl_getters!(
123        AccumParams,
124        VbAccumulatorParams,
125        PublicKey,
126        VbAccumulatorPublicKey,
127        MembershipProvingKey,
128        VbAccumulatorMemProvingKey
129    );
130}
131
132#[serde_as]
133#[derive(
134    Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
135)]
136#[serde(bound = "")]
137pub struct DetachedAccumulatorNonMembershipProver<E: Pairing> {
138    #[serde_as(as = "ArkObjectBytes")]
139    pub accumulator_value: E::G1Affine,
140    pub params: Option<AccumParams<E>>,
141    pub public_key: Option<PublicKey<E>>,
142    pub proving_key: Option<NonMembershipProvingKey<E::G1Affine>>,
143    pub params_ref: Option<usize>,
144    pub public_key_ref: Option<usize>,
145    pub proving_key_ref: Option<usize>,
146}
147
148impl<E: Pairing> DetachedAccumulatorNonMembershipProver<E> {
149    /// Create a statement by passing the accumulator params, public key and proving key directly.
150    pub fn new_statement_from_params(
151        params: AccumParams<E>,
152        public_key: PublicKey<E>,
153        proving_key: NonMembershipProvingKey<E::G1Affine>,
154        accumulator_value: E::G1Affine,
155    ) -> Statement<E> {
156        Statement::DetachedAccumulatorNonMembershipProver(Self {
157            accumulator_value,
158            params: Some(params),
159            public_key: Some(public_key),
160            proving_key: Some(proving_key),
161            params_ref: None,
162            public_key_ref: None,
163            proving_key_ref: None,
164        })
165    }
166
167    /// Create a statement by passing the indices of accumulator params, public key and proving key in `SetupParams`.
168    pub fn new_statement_from_params_ref(
169        params_ref: usize,
170        public_key_ref: usize,
171        proving_key_ref: usize,
172        accumulator_value: E::G1Affine,
173    ) -> Statement<E> {
174        Statement::DetachedAccumulatorNonMembershipProver(Self {
175            accumulator_value,
176            params: None,
177            public_key: None,
178            proving_key: None,
179            params_ref: Some(params_ref),
180            public_key_ref: Some(public_key_ref),
181            proving_key_ref: Some(proving_key_ref),
182        })
183    }
184
185    impl_getters!(
186        AccumParams,
187        VbAccumulatorParams,
188        PublicKey,
189        VbAccumulatorPublicKey,
190        NonMembershipProvingKey,
191        VbAccumulatorNonMemProvingKey
192    );
193}
194
195#[serde_as]
196#[derive(
197    Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize, Serialize, Deserialize,
198)]
199#[serde(bound = "")]
200pub struct DetachedAccumulatorNonMembershipVerifier<E: Pairing> {
201    pub params: Option<AccumParams<E>>,
202    pub public_key: Option<PublicKey<E>>,
203    pub proving_key: Option<NonMembershipProvingKey<E::G1Affine>>,
204    pub params_ref: Option<usize>,
205    pub public_key_ref: Option<usize>,
206    pub proving_key_ref: Option<usize>,
207}
208
209impl<E: Pairing> DetachedAccumulatorNonMembershipVerifier<E> {
210    /// Create a statement by passing the accumulator params, public key and proving key directly.
211    pub fn new_statement_from_params(
212        params: AccumParams<E>,
213        public_key: PublicKey<E>,
214        proving_key: NonMembershipProvingKey<E::G1Affine>,
215    ) -> Statement<E> {
216        Statement::DetachedAccumulatorNonMembershipVerifier(Self {
217            params: Some(params),
218            public_key: Some(public_key),
219            proving_key: Some(proving_key),
220            params_ref: None,
221            public_key_ref: None,
222            proving_key_ref: None,
223        })
224    }
225
226    /// Create a statement by passing the indices of accumulator params, public key and proving key in `SetupParams`.
227    pub fn new_statement_from_params_ref(
228        params_ref: usize,
229        public_key_ref: usize,
230        proving_key_ref: usize,
231    ) -> Statement<E> {
232        Statement::DetachedAccumulatorNonMembershipVerifier(Self {
233            params: None,
234            public_key: None,
235            proving_key: None,
236            params_ref: Some(params_ref),
237            public_key_ref: Some(public_key_ref),
238            proving_key_ref: Some(proving_key_ref),
239        })
240    }
241
242    impl_getters!(
243        AccumParams,
244        VbAccumulatorParams,
245        PublicKey,
246        VbAccumulatorPublicKey,
247        NonMembershipProvingKey,
248        VbAccumulatorNonMemProvingKey
249    );
250}