snarkvm_parameters/mainnet/
mod.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16pub mod genesis;
17pub use genesis::*;
18
19pub mod powers;
20pub use powers::*;
21
22/// The restrictions list as a JSON-compatible string.
23pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");
24
25const REMOTE_URL: &str = "https://parameters.aleo.org/mainnet";
26
27// Degrees
28#[cfg(not(feature = "wasm"))]
29impl_local!(Degree15, "resources/", "powers-of-beta-15", "usrs");
30#[cfg(feature = "wasm")]
31impl_remote!(Degree15, REMOTE_URL, "resources/", "powers-of-beta-15", "usrs");
32impl_remote!(Degree16, REMOTE_URL, "resources/", "powers-of-beta-16", "usrs");
33impl_remote!(Degree17, REMOTE_URL, "resources/", "powers-of-beta-17", "usrs");
34impl_remote!(Degree18, REMOTE_URL, "resources/", "powers-of-beta-18", "usrs");
35impl_remote!(Degree19, REMOTE_URL, "resources/", "powers-of-beta-19", "usrs");
36impl_remote!(Degree20, REMOTE_URL, "resources/", "powers-of-beta-20", "usrs");
37impl_remote!(Degree21, REMOTE_URL, "resources/", "powers-of-beta-21", "usrs");
38impl_remote!(Degree22, REMOTE_URL, "resources/", "powers-of-beta-22", "usrs");
39impl_remote!(Degree23, REMOTE_URL, "resources/", "powers-of-beta-23", "usrs");
40impl_remote!(Degree24, REMOTE_URL, "resources/", "powers-of-beta-24", "usrs");
41impl_remote!(Degree25, REMOTE_URL, "resources/", "powers-of-beta-25", "usrs");
42// TODO (nkls): restore on CI.
43// The SRS is only used for proving and we don't currently support provers of
44// this size. When a users wants to create a proof, they load the appropriate
45// powers for the circuit in `batch_circuit_setup` which calls `max_degree`
46// based on the domain size.
47#[cfg(feature = "large_params")]
48impl_remote!(Degree26, REMOTE_URL, "resources/", "powers-of-beta-26", "usrs");
49#[cfg(feature = "large_params")]
50impl_remote!(Degree27, REMOTE_URL, "resources/", "powers-of-beta-27", "usrs");
51#[cfg(feature = "large_params")]
52impl_remote!(Degree28, REMOTE_URL, "resources/", "powers-of-beta-28", "usrs");
53
54// Shifted Degrees
55#[cfg(not(feature = "wasm"))]
56impl_local!(ShiftedDegree15, "resources/", "shifted-powers-of-beta-15", "usrs");
57#[cfg(feature = "wasm")]
58impl_remote!(ShiftedDegree15, REMOTE_URL, "resources/", "shifted-powers-of-beta-15", "usrs");
59#[cfg(not(feature = "wasm"))]
60impl_local!(ShiftedDegree16, "resources/", "shifted-powers-of-beta-16", "usrs");
61#[cfg(feature = "wasm")]
62impl_remote!(ShiftedDegree16, REMOTE_URL, "resources/", "shifted-powers-of-beta-16", "usrs");
63impl_remote!(ShiftedDegree17, REMOTE_URL, "resources/", "shifted-powers-of-beta-17", "usrs");
64impl_remote!(ShiftedDegree18, REMOTE_URL, "resources/", "shifted-powers-of-beta-18", "usrs");
65impl_remote!(ShiftedDegree19, REMOTE_URL, "resources/", "shifted-powers-of-beta-19", "usrs");
66impl_remote!(ShiftedDegree20, REMOTE_URL, "resources/", "shifted-powers-of-beta-20", "usrs");
67impl_remote!(ShiftedDegree21, REMOTE_URL, "resources/", "shifted-powers-of-beta-21", "usrs");
68impl_remote!(ShiftedDegree22, REMOTE_URL, "resources/", "shifted-powers-of-beta-22", "usrs");
69impl_remote!(ShiftedDegree23, REMOTE_URL, "resources/", "shifted-powers-of-beta-23", "usrs");
70impl_remote!(ShiftedDegree24, REMOTE_URL, "resources/", "shifted-powers-of-beta-24", "usrs");
71impl_remote!(ShiftedDegree25, REMOTE_URL, "resources/", "shifted-powers-of-beta-25", "usrs");
72// TODO (nkls): restore on CI.
73// See `Degree28` above for context.
74#[cfg(feature = "large_params")]
75impl_remote!(ShiftedDegree26, REMOTE_URL, "resources/", "shifted-powers-of-beta-26", "usrs");
76#[cfg(feature = "large_params")]
77impl_remote!(ShiftedDegree27, REMOTE_URL, "resources/", "shifted-powers-of-beta-27", "usrs");
78
79// Powers of Beta Times Gamma * G
80impl_local!(Gamma, "resources/", "powers-of-beta-gamma", "usrs");
81// Negative Powers of Beta in G2
82impl_local!(NegBeta, "resources/", "neg-powers-of-beta", "usrs");
83// Negative Powers of Beta in G2
84impl_local!(BetaH, "resources/", "beta-h", "usrs");
85
86// BondPublic
87impl_remote!(BondPublicProver, REMOTE_URL, "resources/", "bond_public", "prover");
88impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier");
89// BondValidator
90impl_remote!(BondValidatorProver, REMOTE_URL, "resources/", "bond_validator", "prover");
91impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier");
92// UnbondPublic
93impl_remote!(UnbondPublicProver, REMOTE_URL, "resources/", "unbond_public", "prover");
94impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier");
95// ClaimUnbondPublic
96impl_remote!(ClaimUnbondPublicProver, REMOTE_URL, "resources/", "claim_unbond_public", "prover");
97impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier");
98// SetValidatorState
99impl_remote!(SetValidatorStateProver, REMOTE_URL, "resources/", "set_validator_state", "prover");
100impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier");
101// TransferPrivate
102impl_remote!(TransferPrivateProver, REMOTE_URL, "resources/", "transfer_private", "prover");
103impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier");
104// TransferPublic
105impl_remote!(TransferPublicProver, REMOTE_URL, "resources/", "transfer_public", "prover");
106impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier");
107// TransferPublicAsSigner
108impl_remote!(TransferPublicAsSignerProver, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover");
109impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier");
110// TransferPrivateToPublic
111impl_remote!(TransferPrivateToPublicProver, REMOTE_URL, "resources/", "transfer_private_to_public", "prover");
112impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier");
113// TransferPublicToPrivate
114impl_remote!(TransferPublicToPrivateProver, REMOTE_URL, "resources/", "transfer_public_to_private", "prover");
115impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier");
116// Join
117impl_remote!(JoinProver, REMOTE_URL, "resources/", "join", "prover");
118impl_local!(JoinVerifier, "resources/", "join", "verifier");
119// Split
120impl_remote!(SplitProver, REMOTE_URL, "resources/", "split", "prover");
121impl_local!(SplitVerifier, "resources/", "split", "verifier");
122// FeePrivate
123impl_remote!(FeePrivateProver, REMOTE_URL, "resources/", "fee_private", "prover");
124impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier");
125// FeePublic
126impl_remote!(FeePublicProver, REMOTE_URL, "resources/", "fee_public", "prover");
127impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier");
128
129#[macro_export]
130macro_rules! insert_credit_keys {
131    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
132        paste::paste! {
133            let string = stringify!([<$variant:lower>]);
134            $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[<BondPublic $variant>]::load_bytes()));
135            $crate::insert_key!($map, string, $type<$network>, ("bond_validator", $crate::mainnet::[<BondValidator $variant>]::load_bytes()));
136            $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[<UnbondPublic $variant>]::load_bytes()));
137            $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[<ClaimUnbondPublic $variant>]::load_bytes()));
138            $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[<SetValidatorState $variant>]::load_bytes()));
139            $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[<TransferPrivate $variant>]::load_bytes()));
140            $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[<TransferPublic $variant>]::load_bytes()));
141            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::mainnet::[<TransferPublicAsSigner $variant>]::load_bytes()));
142            $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[<TransferPrivateToPublic $variant>]::load_bytes()));
143            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[<TransferPublicToPrivate $variant>]::load_bytes()));
144            $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[<Join $variant>]::load_bytes()));
145            $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[<Split $variant>]::load_bytes()));
146            $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[<FeePrivate $variant>]::load_bytes()));
147            $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[<FeePublic $variant>]::load_bytes()));
148        }
149    }};
150}
151
152#[macro_export]
153macro_rules! insert_key {
154    ($map:ident, $string:tt, $type:ident<$network:ident>, ($name:tt, $circuit_key:expr)) => {{
155        // Load the circuit key bytes.
156        let key_bytes: Vec<u8> = $circuit_key.expect(&format!("Failed to load {} bytes", $string));
157        // Recover the circuit key.
158        let key = $type::<$network>::from_bytes_le(&key_bytes[1..]).expect(&format!("Failed to recover {}", $string));
159        // Insert the circuit key.
160        $map.insert($name.to_string(), std::sync::Arc::new(key));
161    }};
162}
163
164// Inclusion
165impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover");
166impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier");
167
168/// The function name for the inclusion circuit.
169pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion";
170
171lazy_static! {
172    pub static ref INCLUSION_PROVING_KEY: Vec<u8> =
173        InclusionProver::load_bytes().expect("Failed to load inclusion proving key");
174    pub static ref INCLUSION_VERIFYING_KEY: Vec<u8> =
175        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifying key");
176}
177
178#[cfg(test)]
179mod tests {
180    use super::*;
181    use wasm_bindgen_test::*;
182    wasm_bindgen_test_configure!(run_in_browser);
183
184    #[ignore]
185    #[test]
186    fn test_load_bytes_mini() {
187        Degree16::load_bytes().expect("Failed to load degree 16");
188        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
189        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
190        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
191        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
192        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
193    }
194
195    #[allow(dead_code)]
196    #[wasm_bindgen_test]
197    fn test_load_bytes() {
198        Degree16::load_bytes().expect("Failed to load degree 16");
199        Degree17::load_bytes().expect("Failed to load degree 17");
200        Degree18::load_bytes().expect("Failed to load degree 18");
201        Degree19::load_bytes().expect("Failed to load degree 19");
202        Degree20::load_bytes().expect("Failed to load degree 20");
203        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
204        BondValidatorVerifier::load_bytes().expect("Failed to load bond_validator verifier");
205        UnbondPublicVerifier::load_bytes().expect("Failed to load unbond_public verifier");
206        ClaimUnbondPublicVerifier::load_bytes().expect("Failed to load claim_unbond_public verifier");
207        SetValidatorStateVerifier::load_bytes().expect("Failed to load set_validator_state verifier");
208        TransferPrivateVerifier::load_bytes().expect("Failed to load transfer_private verifier");
209        TransferPublicVerifier::load_bytes().expect("Failed to load transfer_public verifier");
210        TransferPublicAsSignerVerifier::load_bytes().expect("Failed to load transfer_public_as_signer verifier");
211        TransferPrivateToPublicVerifier::load_bytes().expect("Failed to load transfer_private_to_public verifier");
212        TransferPublicToPrivateVerifier::load_bytes().expect("Failed to load transfer_public_to_private verifier");
213        FeePrivateProver::load_bytes().expect("Failed to load fee_private prover");
214        FeePrivateVerifier::load_bytes().expect("Failed to load fee_private verifier");
215        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
216        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
217        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
218        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
219    }
220}