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