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
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", "credits");
88impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier", "credits");
89// BondValidator
90impl_remote!(BondValidatorProver, REMOTE_URL, "resources/", "bond_validator", "prover", "credits");
91impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier", "credits");
92// UnbondPublic
93impl_remote!(UnbondPublicProver, REMOTE_URL, "resources/", "unbond_public", "prover", "credits");
94impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier", "credits");
95// ClaimUnbondPublic
96impl_remote!(ClaimUnbondPublicProver, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits");
97impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier", "credits");
98// SetValidatorState
99impl_remote!(SetValidatorStateProver, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits");
100impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier", "credits");
101// TransferPrivate
102impl_remote!(TransferPrivateProver, REMOTE_URL, "resources/", "transfer_private", "prover", "credits");
103impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier", "credits");
104// TransferPublic
105impl_remote!(TransferPublicProver, REMOTE_URL, "resources/", "transfer_public", "prover", "credits");
106impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier", "credits");
107// TransferPublicAsSigner
108impl_remote!(TransferPublicAsSignerProver, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits");
109impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier", "credits");
110// TransferPrivateToPublic
111impl_remote!(TransferPrivateToPublicProver, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits");
112impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier", "credits");
113// TransferPublicToPrivate
114impl_remote!(TransferPublicToPrivateProver, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits");
115impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier", "credits");
116// Join
117impl_remote!(JoinProver, REMOTE_URL, "resources/", "join", "prover", "credits");
118impl_local!(JoinVerifier, "resources/", "join", "verifier", "credits");
119// Split
120impl_remote!(SplitProver, REMOTE_URL, "resources/", "split", "prover", "credits");
121impl_local!(SplitVerifier, "resources/", "split", "verifier", "credits");
122// FeePrivate
123impl_remote!(FeePrivateProver, REMOTE_URL, "resources/", "fee_private", "prover", "credits");
124impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier", "credits");
125// FeePublic
126impl_remote!(FeePublicProver, REMOTE_URL, "resources/", "fee_public", "prover", "credits");
127impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier", "credits");
128// Upgrade
129impl_remote!(UpgradeProver, REMOTE_URL, "resources/", "upgrade", "prover", "credits");
130impl_local!(UpgradeVerifier, "resources/", "upgrade", "verifier", "credits");
131
132// V0 Credits Keys
133
134// BondPublic
135impl_remote!(BondPublicV0Prover, REMOTE_URL, "resources/", "bond_public", "prover", "credits_v0");
136impl_local!(BondPublicV0Verifier, "resources/", "bond_public", "verifier", "credits_v0");
137// BondValidator
138impl_remote!(BondValidatorV0Prover, REMOTE_URL, "resources/", "bond_validator", "prover", "credits_v0");
139impl_local!(BondValidatorV0Verifier, "resources/", "bond_validator", "verifier", "credits_v0");
140// UnbondPublic
141impl_remote!(UnbondPublicV0Prover, REMOTE_URL, "resources/", "unbond_public", "prover", "credits_v0");
142impl_local!(UnbondPublicV0Verifier, "resources/", "unbond_public", "verifier", "credits_v0");
143// ClaimUnbondPublic
144impl_remote!(ClaimUnbondPublicV0Prover, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits_v0");
145impl_local!(ClaimUnbondPublicV0Verifier, "resources/", "claim_unbond_public", "verifier", "credits_v0");
146// SetValidatorState
147impl_remote!(SetValidatorStateV0Prover, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits_v0");
148impl_local!(SetValidatorStateV0Verifier, "resources/", "set_validator_state", "verifier", "credits_v0");
149// TransferPrivate
150impl_remote!(TransferPrivateV0Prover, REMOTE_URL, "resources/", "transfer_private", "prover", "credits_v0");
151impl_local!(TransferPrivateV0Verifier, "resources/", "transfer_private", "verifier", "credits_v0");
152// TransferPublic
153impl_remote!(TransferPublicV0Prover, REMOTE_URL, "resources/", "transfer_public", "prover", "credits_v0");
154impl_local!(TransferPublicV0Verifier, "resources/", "transfer_public", "verifier", "credits_v0");
155// TransferPublicAsSigner
156impl_remote!(TransferPublicAsSignerV0Prover, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits_v0");
157impl_local!(TransferPublicAsSignerV0Verifier, "resources/", "transfer_public_as_signer", "verifier", "credits_v0");
158// TransferPrivateToPublic
159impl_remote!(TransferPrivateToPublicV0Prover, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits_v0");
160impl_local!(TransferPrivateToPublicV0Verifier, "resources/", "transfer_private_to_public", "verifier", "credits_v0");
161// TransferPublicToPrivate
162impl_remote!(TransferPublicToPrivateV0Prover, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits_v0");
163impl_local!(TransferPublicToPrivateV0Verifier, "resources/", "transfer_public_to_private", "verifier", "credits_v0");
164// Join
165impl_remote!(JoinV0Prover, REMOTE_URL, "resources/", "join", "prover", "credits_v0");
166impl_local!(JoinV0Verifier, "resources/", "join", "verifier", "credits_v0");
167// Split
168impl_remote!(SplitV0Prover, REMOTE_URL, "resources/", "split", "prover", "credits_v0");
169impl_local!(SplitV0Verifier, "resources/", "split", "verifier", "credits_v0");
170// FeePrivate
171impl_remote!(FeePrivateV0Prover, REMOTE_URL, "resources/", "fee_private", "prover", "credits_v0");
172impl_local!(FeePrivateV0Verifier, "resources/", "fee_private", "verifier", "credits_v0");
173// FeePublic
174impl_remote!(FeePublicV0Prover, REMOTE_URL, "resources/", "fee_public", "prover", "credits_v0");
175impl_local!(FeePublicV0Verifier, "resources/", "fee_public", "verifier", "credits_v0");
176// Upgrade
177impl_remote!(UpgradeV0Prover, REMOTE_URL, "resources/", "upgrade", "prover", "credits_v0");
178impl_local!(UpgradeV0Verifier, "resources/", "upgrade", "verifier", "credits_v0");
179
180#[macro_export]
181macro_rules! insert_credit_keys {
182    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
183        paste::paste! {
184            let string = stringify!([<$variant:lower>]);
185            $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[<BondPublic $variant>]::load_bytes()));
186            $crate::insert_key!($map, string, $type<$network>, ("bond_validator", $crate::mainnet::[<BondValidator $variant>]::load_bytes()));
187            $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[<UnbondPublic $variant>]::load_bytes()));
188            $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[<ClaimUnbondPublic $variant>]::load_bytes()));
189            $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[<SetValidatorState $variant>]::load_bytes()));
190            $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[<TransferPrivate $variant>]::load_bytes()));
191            $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[<TransferPublic $variant>]::load_bytes()));
192            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::mainnet::[<TransferPublicAsSigner $variant>]::load_bytes()));
193            $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[<TransferPrivateToPublic $variant>]::load_bytes()));
194            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[<TransferPublicToPrivate $variant>]::load_bytes()));
195            $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[<Join $variant>]::load_bytes()));
196            $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[<Split $variant>]::load_bytes()));
197            $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[<FeePrivate $variant>]::load_bytes()));
198            $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[<FeePublic $variant>]::load_bytes()));
199            $crate::insert_key!($map, string, $type<$network>, ("upgrade", $crate::mainnet::[<Upgrade $variant>]::load_bytes()));
200        }
201    }};
202}
203
204#[macro_export]
205macro_rules! insert_credit_v0_keys {
206    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
207        paste::paste! {
208            let string = stringify!([<$variant:lower>]);
209            $crate::insert_key!($map, string, $type<$network>, ("bond_public", $crate::mainnet::[<BondPublicV0 $variant>]::load_bytes()));
210            $crate::insert_key!($map, string, $type<$network>, ("bond_validator", $crate::mainnet::[<BondValidatorV0 $variant>]::load_bytes()));
211            $crate::insert_key!($map, string, $type<$network>, ("unbond_public", $crate::mainnet::[<UnbondPublicV0 $variant>]::load_bytes()));
212            $crate::insert_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::mainnet::[<ClaimUnbondPublicV0 $variant>]::load_bytes()));
213            $crate::insert_key!($map, string, $type<$network>, ("set_validator_state", $crate::mainnet::[<SetValidatorStateV0 $variant>]::load_bytes()));
214            $crate::insert_key!($map, string, $type<$network>, ("transfer_private", $crate::mainnet::[<TransferPrivateV0 $variant>]::load_bytes()));
215            $crate::insert_key!($map, string, $type<$network>, ("transfer_public", $crate::mainnet::[<TransferPublicV0 $variant>]::load_bytes()));
216            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::mainnet::[<TransferPublicAsSignerV0 $variant>]::load_bytes()));
217            $crate::insert_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::mainnet::[<TransferPrivateToPublicV0 $variant>]::load_bytes()));
218            $crate::insert_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::mainnet::[<TransferPublicToPrivateV0 $variant>]::load_bytes()));
219            $crate::insert_key!($map, string, $type<$network>, ("join", $crate::mainnet::[<JoinV0 $variant>]::load_bytes()));
220            $crate::insert_key!($map, string, $type<$network>, ("split", $crate::mainnet::[<SplitV0 $variant>]::load_bytes()));
221            $crate::insert_key!($map, string, $type<$network>, ("fee_private", $crate::mainnet::[<FeePrivateV0 $variant>]::load_bytes()));
222            $crate::insert_key!($map, string, $type<$network>, ("fee_public", $crate::mainnet::[<FeePublicV0 $variant>]::load_bytes()));
223            $crate::insert_key!($map, string, $type<$network>, ("upgrade", $crate::mainnet::[<UpgradeV0 $variant>]::load_bytes()));
224        }
225    }};
226}
227
228#[macro_export]
229macro_rules! insert_key {
230    ($map:ident, $string:tt, $type:ident<$network:ident>, ($name:tt, $circuit_key:expr)) => {{
231        // Load the circuit key bytes.
232        let key_bytes: Vec<u8> = $circuit_key.expect(&format!("Failed to load {} bytes", $string));
233        // Recover the circuit key.
234        let key = $type::<$network>::from_bytes_le(&key_bytes[1..]).expect(&format!("Failed to recover {}", $string));
235        // Insert the circuit key.
236        $map.insert($name.to_string(), std::sync::Arc::new(key));
237    }};
238}
239
240// Inclusion
241impl_remote!(InclusionV0Prover, REMOTE_URL, "resources/", "inclusion", "prover", "credits_v0");
242impl_local!(InclusionV0Verifier, "resources/", "inclusion", "verifier", "credits_v0");
243impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover", "credits");
244impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier", "credits");
245
246/// The function name for the inclusion circuit.
247pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion";
248
249lazy_static! {
250    pub static ref INCLUSION_V0_PROVING_KEY: Vec<u8> =
251        InclusionV0Prover::load_bytes().expect("Failed to load inclusion_v0 proving key");
252    pub static ref INCLUSION_V0_VERIFYING_KEY: Vec<u8> =
253        InclusionV0Verifier::load_bytes().expect("Failed to load inclusion_v0 verifying key");
254    pub static ref INCLUSION_PROVING_KEY: Vec<u8> = InclusionProver::load_bytes().expect("Failed to load inclusion proving key");
255    pub static ref INCLUSION_VERIFYING_KEY: Vec<u8> =
256        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifying key");
257}
258
259#[cfg(test)]
260mod tests {
261    use super::*;
262    use wasm_bindgen_test::*;
263    wasm_bindgen_test_configure!(run_in_browser);
264
265    #[ignore]
266    #[test]
267    fn test_load_bytes_mini() {
268        Degree16::load_bytes().expect("Failed to load degree 16");
269        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
270        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
271        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
272        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
273        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
274    }
275
276    #[allow(dead_code)]
277    #[wasm_bindgen_test]
278    fn test_load_bytes() {
279        Degree16::load_bytes().expect("Failed to load degree 16");
280        Degree17::load_bytes().expect("Failed to load degree 17");
281        Degree18::load_bytes().expect("Failed to load degree 18");
282        Degree19::load_bytes().expect("Failed to load degree 19");
283        Degree20::load_bytes().expect("Failed to load degree 20");
284        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
285        BondValidatorVerifier::load_bytes().expect("Failed to load bond_validator verifier");
286        UnbondPublicVerifier::load_bytes().expect("Failed to load unbond_public verifier");
287        ClaimUnbondPublicVerifier::load_bytes().expect("Failed to load claim_unbond_public verifier");
288        SetValidatorStateVerifier::load_bytes().expect("Failed to load set_validator_state verifier");
289        TransferPrivateVerifier::load_bytes().expect("Failed to load transfer_private verifier");
290        TransferPublicVerifier::load_bytes().expect("Failed to load transfer_public verifier");
291        TransferPublicAsSignerVerifier::load_bytes().expect("Failed to load transfer_public_as_signer verifier");
292        TransferPrivateToPublicVerifier::load_bytes().expect("Failed to load transfer_private_to_public verifier");
293        TransferPublicToPrivateVerifier::load_bytes().expect("Failed to load transfer_public_to_private verifier");
294        FeePrivateProver::load_bytes().expect("Failed to load fee_private prover");
295        FeePrivateVerifier::load_bytes().expect("Failed to load fee_private verifier");
296        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
297        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
298        UpgradeProver::load_bytes().expect("Failed to load upgrade prover");
299        UpgradeVerifier::load_bytes().expect("Failed to load upgrade verifier");
300        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
301        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
302    }
303}