snarkvm_parameters/mainnet/
mod.rs

1// Copyright (c) 2019-2025 Provable Inc.
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.provable.com/mainnet";
26
27// Degrees
28impl_local!(Degree15, "resources/", "powers-of-beta-15", "usrs");
29impl_remote!(Degree16, REMOTE_URL, "resources/", "powers-of-beta-16", "usrs");
30impl_remote!(Degree17, REMOTE_URL, "resources/", "powers-of-beta-17", "usrs");
31impl_remote!(Degree18, REMOTE_URL, "resources/", "powers-of-beta-18", "usrs");
32impl_remote!(Degree19, REMOTE_URL, "resources/", "powers-of-beta-19", "usrs");
33impl_remote!(Degree20, REMOTE_URL, "resources/", "powers-of-beta-20", "usrs");
34impl_remote!(Degree21, REMOTE_URL, "resources/", "powers-of-beta-21", "usrs");
35impl_remote!(Degree22, REMOTE_URL, "resources/", "powers-of-beta-22", "usrs");
36impl_remote!(Degree23, REMOTE_URL, "resources/", "powers-of-beta-23", "usrs");
37impl_remote!(Degree24, REMOTE_URL, "resources/", "powers-of-beta-24", "usrs");
38impl_remote!(Degree25, REMOTE_URL, "resources/", "powers-of-beta-25", "usrs");
39// TODO (nkls): restore on CI.
40// The SRS is only used for proving and we don't currently support provers of
41// this size. When a users wants to create a proof, they load the appropriate
42// powers for the circuit in `batch_circuit_setup` which calls `max_degree`
43// based on the domain size.
44#[cfg(feature = "large_params")]
45impl_remote!(Degree26, REMOTE_URL, "resources/", "powers-of-beta-26", "usrs");
46#[cfg(feature = "large_params")]
47impl_remote!(Degree27, REMOTE_URL, "resources/", "powers-of-beta-27", "usrs");
48#[cfg(feature = "large_params")]
49impl_remote!(Degree28, REMOTE_URL, "resources/", "powers-of-beta-28", "usrs");
50
51// Shifted Degrees
52impl_local!(ShiftedDegree15, "resources/", "shifted-powers-of-beta-15", "usrs");
53impl_local!(ShiftedDegree16, "resources/", "shifted-powers-of-beta-16", "usrs");
54impl_remote!(ShiftedDegree17, REMOTE_URL, "resources/", "shifted-powers-of-beta-17", "usrs");
55impl_remote!(ShiftedDegree18, REMOTE_URL, "resources/", "shifted-powers-of-beta-18", "usrs");
56impl_remote!(ShiftedDegree19, REMOTE_URL, "resources/", "shifted-powers-of-beta-19", "usrs");
57impl_remote!(ShiftedDegree20, REMOTE_URL, "resources/", "shifted-powers-of-beta-20", "usrs");
58impl_remote!(ShiftedDegree21, REMOTE_URL, "resources/", "shifted-powers-of-beta-21", "usrs");
59impl_remote!(ShiftedDegree22, REMOTE_URL, "resources/", "shifted-powers-of-beta-22", "usrs");
60impl_remote!(ShiftedDegree23, REMOTE_URL, "resources/", "shifted-powers-of-beta-23", "usrs");
61impl_remote!(ShiftedDegree24, REMOTE_URL, "resources/", "shifted-powers-of-beta-24", "usrs");
62impl_remote!(ShiftedDegree25, REMOTE_URL, "resources/", "shifted-powers-of-beta-25", "usrs");
63// TODO (nkls): restore on CI.
64// See `Degree28` above for context.
65#[cfg(feature = "large_params")]
66impl_remote!(ShiftedDegree26, REMOTE_URL, "resources/", "shifted-powers-of-beta-26", "usrs");
67#[cfg(feature = "large_params")]
68impl_remote!(ShiftedDegree27, REMOTE_URL, "resources/", "shifted-powers-of-beta-27", "usrs");
69
70// Powers of Beta Times Gamma * G
71impl_local!(Gamma, "resources/", "powers-of-beta-gamma", "usrs");
72// Negative Powers of Beta in G2
73impl_local!(NegBeta, "resources/", "neg-powers-of-beta", "usrs");
74// Negative Powers of Beta in G2
75impl_local!(BetaH, "resources/", "beta-h", "usrs");
76
77// BondPublic
78impl_remote!(BondPublicProver, REMOTE_URL, "resources/", "bond_public", "prover", "credits");
79impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier", "credits");
80// BondValidator
81impl_remote!(BondValidatorProver, REMOTE_URL, "resources/", "bond_validator", "prover", "credits");
82impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier", "credits");
83// UnbondPublic
84impl_remote!(UnbondPublicProver, REMOTE_URL, "resources/", "unbond_public", "prover", "credits");
85impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier", "credits");
86// ClaimUnbondPublic
87impl_remote!(ClaimUnbondPublicProver, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits");
88impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier", "credits");
89// SetValidatorState
90impl_remote!(SetValidatorStateProver, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits");
91impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier", "credits");
92// TransferPrivate
93impl_remote!(TransferPrivateProver, REMOTE_URL, "resources/", "transfer_private", "prover", "credits");
94impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier", "credits");
95// TransferPublic
96impl_remote!(TransferPublicProver, REMOTE_URL, "resources/", "transfer_public", "prover", "credits");
97impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier", "credits");
98// TransferPublicAsSigner
99impl_remote!(TransferPublicAsSignerProver, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits");
100impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier", "credits");
101// TransferPrivateToPublic
102impl_remote!(TransferPrivateToPublicProver, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits");
103impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier", "credits");
104// TransferPublicToPrivate
105impl_remote!(TransferPublicToPrivateProver, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits");
106impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier", "credits");
107// Join
108impl_remote!(JoinProver, REMOTE_URL, "resources/", "join", "prover", "credits");
109impl_local!(JoinVerifier, "resources/", "join", "verifier", "credits");
110// Split
111impl_remote!(SplitProver, REMOTE_URL, "resources/", "split", "prover", "credits");
112impl_local!(SplitVerifier, "resources/", "split", "verifier", "credits");
113// FeePrivate
114impl_remote!(FeePrivateProver, REMOTE_URL, "resources/", "fee_private", "prover", "credits");
115impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier", "credits");
116// FeePublic
117impl_remote!(FeePublicProver, REMOTE_URL, "resources/", "fee_public", "prover", "credits");
118impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier", "credits");
119// Upgrade
120impl_remote!(UpgradeProver, REMOTE_URL, "resources/", "upgrade", "prover", "credits");
121impl_local!(UpgradeVerifier, "resources/", "upgrade", "verifier", "credits");
122
123// V0 Credits Keys
124
125// BondPublic
126impl_remote!(BondPublicV0Prover, REMOTE_URL, "resources/", "bond_public", "prover", "credits_v0");
127impl_local!(BondPublicV0Verifier, "resources/", "bond_public", "verifier", "credits_v0");
128// BondValidator
129impl_remote!(BondValidatorV0Prover, REMOTE_URL, "resources/", "bond_validator", "prover", "credits_v0");
130impl_local!(BondValidatorV0Verifier, "resources/", "bond_validator", "verifier", "credits_v0");
131// UnbondPublic
132impl_remote!(UnbondPublicV0Prover, REMOTE_URL, "resources/", "unbond_public", "prover", "credits_v0");
133impl_local!(UnbondPublicV0Verifier, "resources/", "unbond_public", "verifier", "credits_v0");
134// ClaimUnbondPublic
135impl_remote!(ClaimUnbondPublicV0Prover, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits_v0");
136impl_local!(ClaimUnbondPublicV0Verifier, "resources/", "claim_unbond_public", "verifier", "credits_v0");
137// SetValidatorState
138impl_remote!(SetValidatorStateV0Prover, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits_v0");
139impl_local!(SetValidatorStateV0Verifier, "resources/", "set_validator_state", "verifier", "credits_v0");
140// TransferPrivate
141impl_remote!(TransferPrivateV0Prover, REMOTE_URL, "resources/", "transfer_private", "prover", "credits_v0");
142impl_local!(TransferPrivateV0Verifier, "resources/", "transfer_private", "verifier", "credits_v0");
143// TransferPublic
144impl_remote!(TransferPublicV0Prover, REMOTE_URL, "resources/", "transfer_public", "prover", "credits_v0");
145impl_local!(TransferPublicV0Verifier, "resources/", "transfer_public", "verifier", "credits_v0");
146// TransferPublicAsSigner
147impl_remote!(TransferPublicAsSignerV0Prover, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits_v0");
148impl_local!(TransferPublicAsSignerV0Verifier, "resources/", "transfer_public_as_signer", "verifier", "credits_v0");
149// TransferPrivateToPublic
150impl_remote!(TransferPrivateToPublicV0Prover, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits_v0");
151impl_local!(TransferPrivateToPublicV0Verifier, "resources/", "transfer_private_to_public", "verifier", "credits_v0");
152// TransferPublicToPrivate
153impl_remote!(TransferPublicToPrivateV0Prover, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits_v0");
154impl_local!(TransferPublicToPrivateV0Verifier, "resources/", "transfer_public_to_private", "verifier", "credits_v0");
155// Join
156impl_remote!(JoinV0Prover, REMOTE_URL, "resources/", "join", "prover", "credits_v0");
157impl_local!(JoinV0Verifier, "resources/", "join", "verifier", "credits_v0");
158// Split
159impl_remote!(SplitV0Prover, REMOTE_URL, "resources/", "split", "prover", "credits_v0");
160impl_local!(SplitV0Verifier, "resources/", "split", "verifier", "credits_v0");
161// FeePrivate
162impl_remote!(FeePrivateV0Prover, REMOTE_URL, "resources/", "fee_private", "prover", "credits_v0");
163impl_local!(FeePrivateV0Verifier, "resources/", "fee_private", "verifier", "credits_v0");
164// FeePublic
165impl_remote!(FeePublicV0Prover, REMOTE_URL, "resources/", "fee_public", "prover", "credits_v0");
166impl_local!(FeePublicV0Verifier, "resources/", "fee_public", "verifier", "credits_v0");
167// Upgrade
168impl_remote!(UpgradeV0Prover, REMOTE_URL, "resources/", "upgrade", "prover", "credits_v0");
169impl_local!(UpgradeV0Verifier, "resources/", "upgrade", "verifier", "credits_v0");
170
171#[macro_export]
172macro_rules! insert_credit_keys {
173    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
174        paste::paste! {
175            let string = stringify!([<$variant:lower>]);
176            $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[<BondPublic $variant>]::load_bytes()));
177            $crate::insert_key!($map, string, $type<$network>, ("bond_validator", $crate::mainnet::[<BondValidator $variant>]::load_bytes()));
178            $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[<UnbondPublic $variant>]::load_bytes()));
179            $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[<ClaimUnbondPublic $variant>]::load_bytes()));
180            $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[<SetValidatorState $variant>]::load_bytes()));
181            $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[<TransferPrivate $variant>]::load_bytes()));
182            $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[<TransferPublic $variant>]::load_bytes()));
183            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::mainnet::[<TransferPublicAsSigner $variant>]::load_bytes()));
184            $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[<TransferPrivateToPublic $variant>]::load_bytes()));
185            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[<TransferPublicToPrivate $variant>]::load_bytes()));
186            $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[<Join $variant>]::load_bytes()));
187            $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[<Split $variant>]::load_bytes()));
188            $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[<FeePrivate $variant>]::load_bytes()));
189            $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[<FeePublic $variant>]::load_bytes()));
190            $crate::insert_key!($map, string, $type<$network>, ("upgrade", $crate::mainnet::[<Upgrade $variant>]::load_bytes()));
191        }
192    }};
193}
194
195#[macro_export]
196macro_rules! insert_credit_v0_keys {
197    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
198        paste::paste! {
199            let string = stringify!([<$variant:lower>]);
200            $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[<BondPublicV0 $variant>]::load_bytes()));
201            $crate::insert_key!($map, string, $type<$network>, ("bond_validator", $crate::mainnet::[<BondValidatorV0 $variant>]::load_bytes()));
202            $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[<UnbondPublicV0 $variant>]::load_bytes()));
203            $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[<ClaimUnbondPublicV0 $variant>]::load_bytes()));
204            $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[<SetValidatorStateV0 $variant>]::load_bytes()));
205            $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[<TransferPrivateV0 $variant>]::load_bytes()));
206            $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[<TransferPublicV0 $variant>]::load_bytes()));
207            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::mainnet::[<TransferPublicAsSignerV0 $variant>]::load_bytes()));
208            $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[<TransferPrivateToPublicV0 $variant>]::load_bytes()));
209            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[<TransferPublicToPrivateV0 $variant>]::load_bytes()));
210            $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[<JoinV0 $variant>]::load_bytes()));
211            $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[<SplitV0 $variant>]::load_bytes()));
212            $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[<FeePrivateV0 $variant>]::load_bytes()));
213            $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[<FeePublicV0 $variant>]::load_bytes()));
214            $crate::insert_key!($map, string, $type<$network>, ("upgrade", $crate::mainnet::[<UpgradeV0 $variant>]::load_bytes()));
215        }
216    }};
217}
218
219#[macro_export]
220macro_rules! insert_key {
221    ($map:ident, $string:tt, $type:ident<$network:ident>, ($name:tt, $circuit_key:expr)) => {{
222        // Load the circuit key bytes.
223        let key_bytes: Vec<u8> = $circuit_key.expect(&format!("Failed to load {} bytes", $string));
224        // Recover the circuit key.
225        let key = $type::<$network>::from_bytes_le(&key_bytes[1..]).expect(&format!("Failed to recover {}", $string));
226        // Insert the circuit key.
227        $map.insert($name.to_string(), std::sync::Arc::new(key));
228    }};
229}
230
231// Inclusion
232impl_remote!(InclusionV0Prover, REMOTE_URL, "resources/", "inclusion", "prover", "credits_v0");
233impl_local!(InclusionV0Verifier, "resources/", "inclusion", "verifier", "credits_v0");
234impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover", "credits");
235impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier", "credits");
236
237/// The function name for the inclusion circuit.
238pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion";
239
240lazy_static! {
241    pub static ref INCLUSION_V0_PROVING_KEY: Vec<u8> =
242        InclusionV0Prover::load_bytes().expect("Failed to load inclusion_v0 proving key");
243    pub static ref INCLUSION_V0_VERIFYING_KEY: Vec<u8> =
244        InclusionV0Verifier::load_bytes().expect("Failed to load inclusion_v0 verifying key");
245    pub static ref INCLUSION_PROVING_KEY: Vec<u8> = InclusionProver::load_bytes().expect("Failed to load inclusion proving key");
246    pub static ref INCLUSION_VERIFYING_KEY: Vec<u8> =
247        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifying key");
248}
249
250#[cfg(test)]
251mod tests {
252    use super::*;
253    use wasm_bindgen_test::*;
254    wasm_bindgen_test_configure!(run_in_browser);
255
256    #[ignore]
257    #[test]
258    fn test_load_bytes_mini() {
259        Degree16::load_bytes().expect("Failed to load degree 16");
260        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
261        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
262        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
263        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
264        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
265    }
266
267    #[allow(dead_code)]
268    #[wasm_bindgen_test]
269    fn test_load_bytes() {
270        Degree16::load_bytes().expect("Failed to load degree 16");
271        Degree17::load_bytes().expect("Failed to load degree 17");
272        Degree18::load_bytes().expect("Failed to load degree 18");
273        Degree19::load_bytes().expect("Failed to load degree 19");
274        Degree20::load_bytes().expect("Failed to load degree 20");
275        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
276        BondValidatorVerifier::load_bytes().expect("Failed to load bond_validator verifier");
277        UnbondPublicVerifier::load_bytes().expect("Failed to load unbond_public verifier");
278        ClaimUnbondPublicVerifier::load_bytes().expect("Failed to load claim_unbond_public verifier");
279        SetValidatorStateVerifier::load_bytes().expect("Failed to load set_validator_state verifier");
280        TransferPrivateVerifier::load_bytes().expect("Failed to load transfer_private verifier");
281        TransferPublicVerifier::load_bytes().expect("Failed to load transfer_public verifier");
282        TransferPublicAsSignerVerifier::load_bytes().expect("Failed to load transfer_public_as_signer verifier");
283        TransferPrivateToPublicVerifier::load_bytes().expect("Failed to load transfer_private_to_public verifier");
284        TransferPublicToPrivateVerifier::load_bytes().expect("Failed to load transfer_public_to_private verifier");
285        FeePrivateProver::load_bytes().expect("Failed to load fee_private prover");
286        FeePrivateVerifier::load_bytes().expect("Failed to load fee_private verifier");
287        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
288        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
289        UpgradeProver::load_bytes().expect("Failed to load upgrade prover");
290        UpgradeVerifier::load_bytes().expect("Failed to load upgrade verifier");
291        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
292        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
293    }
294}