Skip to main content

dory_pcs/backends/arkworks/
ark_setup.rs

1//! Arkworks-specific setup wrappers
2//!
3//! Provides wrapper types for `ProverSetup` and `VerifierSetup` with transparent access.
4//! Serialization implementations via `CanonicalSerialize` and `CanonicalDeserialize`
5//! are in the `ark_serde` module.
6
7use crate::setup::{ProverSetup, VerifierSetup};
8use std::ops::{Deref, DerefMut};
9
10use super::BN254;
11
12/// Wrapper around `ProverSetup<BN254>` with arkworks canonical serialization
13///
14/// Provides transparent access to the inner setup while adding support for
15/// arkworks' CanonicalSerialize and CanonicalDeserialize traits, allowing
16/// easy serialization for users of the arkworks ecosystem.
17#[derive(Clone, Debug)]
18pub struct ArkworksProverSetup(pub ProverSetup<BN254>);
19
20/// Wrapper around `VerifierSetup<BN254>` with arkworks canonical serialization
21///
22/// Provides transparent access to the inner setup while adding support for
23/// arkworks' CanonicalSerialize and CanonicalDeserialize traits, allowing
24/// easy serialization for users of the arkworks ecosystem.
25#[derive(Clone, Debug)]
26pub struct ArkworksVerifierSetup(pub VerifierSetup<BN254>);
27
28impl ArkworksProverSetup {
29    /// Generate new prover setup with transparent randomness
30    ///
31    /// For square matrices, generates n = 2^((max_log_n+1)/2) generators for both G1 and G2,
32    /// supporting polynomials up to 2^max_log_n coefficients arranged as n×n matrices.
33    ///
34    /// # Parameters
35    /// - `max_log_n`: Maximum log₂ of polynomial size (for n×n matrix with n² = 2^max_log_n)
36    pub fn new(max_log_n: usize) -> Self {
37        Self(ProverSetup::new(max_log_n))
38    }
39
40    /// Load prover setup from disk cache, or generate and cache if not available
41    #[cfg(all(feature = "disk-persistence", not(target_arch = "wasm32")))]
42    pub fn new_from_urs(max_log_n: usize) -> Self {
43        let (prover_setup, _) = crate::setup::<BN254>(max_log_n);
44        Self(prover_setup)
45    }
46
47    /// Derive verifier setup from this prover setup
48    pub fn to_verifier_setup(&self) -> ArkworksVerifierSetup {
49        ArkworksVerifierSetup(self.0.to_verifier_setup())
50    }
51
52    /// Unwrap into inner `ProverSetup<BN254>`
53    pub fn into_inner(self) -> ProverSetup<BN254> {
54        self.0
55    }
56}
57
58impl ArkworksVerifierSetup {
59    /// Unwrap into inner `VerifierSetup<BN254>`
60    pub fn into_inner(self) -> VerifierSetup<BN254> {
61        self.0
62    }
63}
64
65impl From<ProverSetup<BN254>> for ArkworksProverSetup {
66    fn from(setup: ProverSetup<BN254>) -> Self {
67        Self(setup)
68    }
69}
70
71impl From<ArkworksProverSetup> for ProverSetup<BN254> {
72    fn from(setup: ArkworksProverSetup) -> Self {
73        setup.0
74    }
75}
76
77impl From<VerifierSetup<BN254>> for ArkworksVerifierSetup {
78    fn from(setup: VerifierSetup<BN254>) -> Self {
79        Self(setup)
80    }
81}
82
83impl From<ArkworksVerifierSetup> for VerifierSetup<BN254> {
84    fn from(setup: ArkworksVerifierSetup) -> Self {
85        setup.0
86    }
87}
88
89impl Deref for ArkworksProverSetup {
90    type Target = ProverSetup<BN254>;
91
92    fn deref(&self) -> &Self::Target {
93        &self.0
94    }
95}
96
97impl DerefMut for ArkworksProverSetup {
98    fn deref_mut(&mut self) -> &mut Self::Target {
99        &mut self.0
100    }
101}
102
103impl Deref for ArkworksVerifierSetup {
104    type Target = VerifierSetup<BN254>;
105
106    fn deref(&self) -> &Self::Target {
107        &self.0
108    }
109}
110
111impl DerefMut for ArkworksVerifierSetup {
112    fn deref_mut(&mut self) -> &mut Self::Target {
113        &mut self.0
114    }
115}