Skip to main content

snarkvm_parameters/testnet/
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
19/// The restrictions list as a JSON-compatible string.
20pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");
21
22const REMOTE_URLS: [&str; 2] =
23    ["https://parameters.provable.com/testnet", "https://s3.us-west-1.amazonaws.com/testnet.parameters"];
24
25// BondPublic
26impl_remote!(BondPublicProver, REMOTE_URLS, "resources/", "bond_public", "prover", "credits");
27impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier", "credits");
28// BondValidator
29impl_remote!(BondValidatorProver, REMOTE_URLS, "resources/", "bond_validator", "prover", "credits");
30impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier", "credits");
31// UnbondPublic
32impl_remote!(UnbondPublicProver, REMOTE_URLS, "resources/", "unbond_public", "prover", "credits");
33impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier", "credits");
34// ClaimUnbondPublic
35impl_remote!(ClaimUnbondPublicProver, REMOTE_URLS, "resources/", "claim_unbond_public", "prover", "credits");
36impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier", "credits");
37// SetValidatorState
38impl_remote!(SetValidatorStateProver, REMOTE_URLS, "resources/", "set_validator_state", "prover", "credits");
39impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier", "credits");
40// TransferPrivate
41impl_remote!(TransferPrivateProver, REMOTE_URLS, "resources/", "transfer_private", "prover", "credits");
42impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier", "credits");
43// TransferPublic
44impl_remote!(TransferPublicProver, REMOTE_URLS, "resources/", "transfer_public", "prover", "credits");
45impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier", "credits");
46// TransferPublicAsSigner
47impl_remote!(TransferPublicAsSignerProver, REMOTE_URLS, "resources/", "transfer_public_as_signer", "prover", "credits");
48impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier", "credits");
49// TransferPrivateToPublic
50impl_remote!(TransferPrivateToPublicProver, REMOTE_URLS, "resources/", "transfer_private_to_public", "prover", "credits");
51impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier", "credits");
52// TransferPublicToPrivate
53impl_remote!(TransferPublicToPrivateProver, REMOTE_URLS, "resources/", "transfer_public_to_private", "prover", "credits");
54impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier", "credits");
55// Join
56impl_remote!(JoinProver, REMOTE_URLS, "resources/", "join", "prover", "credits");
57impl_local!(JoinVerifier, "resources/", "join", "verifier", "credits");
58// Split
59impl_remote!(SplitProver, REMOTE_URLS, "resources/", "split", "prover", "credits");
60impl_local!(SplitVerifier, "resources/", "split", "verifier", "credits");
61// FeePrivate
62impl_remote!(FeePrivateProver, REMOTE_URLS, "resources/", "fee_private", "prover", "credits");
63impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier", "credits");
64// FeePublic
65impl_remote!(FeePublicProver, REMOTE_URLS, "resources/", "fee_public", "prover", "credits");
66impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier", "credits");
67// Upgrade
68impl_remote!(UpgradeProver, REMOTE_URLS, "resources/", "upgrade", "prover", "credits");
69impl_local!(UpgradeVerifier, "resources/", "upgrade", "verifier", "credits");
70
71// V0 Credits Keys
72
73// BondPublic
74impl_remote!(BondPublicV0Prover, REMOTE_URLS, "resources/", "bond_public", "prover", "credits_v0");
75impl_local!(BondPublicV0Verifier, "resources/", "bond_public", "verifier", "credits_v0");
76// BondValidator
77impl_remote!(BondValidatorV0Prover, REMOTE_URLS, "resources/", "bond_validator", "prover", "credits_v0");
78impl_local!(BondValidatorV0Verifier, "resources/", "bond_validator", "verifier", "credits_v0");
79// UnbondPublic
80impl_remote!(UnbondPublicV0Prover, REMOTE_URLS, "resources/", "unbond_public", "prover", "credits_v0");
81impl_local!(UnbondPublicV0Verifier, "resources/", "unbond_public", "verifier", "credits_v0");
82// ClaimUnbondPublic
83impl_remote!(ClaimUnbondPublicV0Prover, REMOTE_URLS, "resources/", "claim_unbond_public", "prover", "credits_v0");
84impl_local!(ClaimUnbondPublicV0Verifier, "resources/", "claim_unbond_public", "verifier", "credits_v0");
85// SetValidatorState
86impl_remote!(SetValidatorStateV0Prover, REMOTE_URLS, "resources/", "set_validator_state", "prover", "credits_v0");
87impl_local!(SetValidatorStateV0Verifier, "resources/", "set_validator_state", "verifier", "credits_v0");
88// TransferPrivate
89impl_remote!(TransferPrivateV0Prover, REMOTE_URLS, "resources/", "transfer_private", "prover", "credits_v0");
90impl_local!(TransferPrivateV0Verifier, "resources/", "transfer_private", "verifier", "credits_v0");
91// TransferPublic
92impl_remote!(TransferPublicV0Prover, REMOTE_URLS, "resources/", "transfer_public", "prover", "credits_v0");
93impl_local!(TransferPublicV0Verifier, "resources/", "transfer_public", "verifier", "credits_v0");
94// TransferPublicAsSigner
95impl_remote!(TransferPublicAsSignerV0Prover, REMOTE_URLS, "resources/", "transfer_public_as_signer", "prover", "credits_v0");
96impl_local!(TransferPublicAsSignerV0Verifier, "resources/", "transfer_public_as_signer", "verifier", "credits_v0");
97// TransferPrivateToPublic
98impl_remote!(TransferPrivateToPublicV0Prover, REMOTE_URLS, "resources/", "transfer_private_to_public", "prover", "credits_v0");
99impl_local!(TransferPrivateToPublicV0Verifier, "resources/", "transfer_private_to_public", "verifier", "credits_v0");
100// TransferPublicToPrivate
101impl_remote!(TransferPublicToPrivateV0Prover, REMOTE_URLS, "resources/", "transfer_public_to_private", "prover", "credits_v0");
102impl_local!(TransferPublicToPrivateV0Verifier, "resources/", "transfer_public_to_private", "verifier", "credits_v0");
103// Join
104impl_remote!(JoinV0Prover, REMOTE_URLS, "resources/", "join", "prover", "credits_v0");
105impl_local!(JoinV0Verifier, "resources/", "join", "verifier", "credits_v0");
106// Split
107impl_remote!(SplitV0Prover, REMOTE_URLS, "resources/", "split", "prover", "credits_v0");
108impl_local!(SplitV0Verifier, "resources/", "split", "verifier", "credits_v0");
109// FeePrivate
110impl_remote!(FeePrivateV0Prover, REMOTE_URLS, "resources/", "fee_private", "prover", "credits_v0");
111impl_local!(FeePrivateV0Verifier, "resources/", "fee_private", "verifier", "credits_v0");
112// FeePublic
113impl_remote!(FeePublicV0Prover, REMOTE_URLS, "resources/", "fee_public", "prover", "credits_v0");
114impl_local!(FeePublicV0Verifier, "resources/", "fee_public", "verifier", "credits_v0");
115// Upgrade
116impl_remote!(UpgradeV0Prover, REMOTE_URLS, "resources/", "upgrade", "prover", "credits_v0");
117impl_local!(UpgradeV0Verifier, "resources/", "upgrade", "verifier", "credits_v0");
118
119#[macro_export]
120macro_rules! insert_testnet_credit_keys {
121    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
122        paste::paste! {
123            let string = stringify!([<$variant:lower>]);
124            $crate::insert_testnet_key!($map, string, $type<$network>, ("bond_public", $crate::testnet::[<BondPublic $variant>]::load_bytes()));
125            $crate::insert_testnet_key!($map, string, $type<$network>, ("bond_validator", $crate::testnet::[<BondValidator $variant>]::load_bytes()));
126            $crate::insert_testnet_key!($map, string, $type<$network>, ("unbond_public", $crate::testnet::[<UnbondPublic $variant>]::load_bytes()));
127            $crate::insert_testnet_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::testnet::[<ClaimUnbondPublic $variant>]::load_bytes()));
128            $crate::insert_testnet_key!($map, string, $type<$network>, ("set_validator_state", $crate::testnet::[<SetValidatorState $variant>]::load_bytes()));
129            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_private", $crate::testnet::[<TransferPrivate $variant>]::load_bytes()));
130            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public", $crate::testnet::[<TransferPublic $variant>]::load_bytes()));
131            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::testnet::[<TransferPublicAsSigner $variant>]::load_bytes()));
132            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::testnet::[<TransferPrivateToPublic $variant>]::load_bytes()));
133            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::testnet::[<TransferPublicToPrivate $variant>]::load_bytes()));
134            $crate::insert_testnet_key!($map, string, $type<$network>, ("join", $crate::testnet::[<Join $variant>]::load_bytes()));
135            $crate::insert_testnet_key!($map, string, $type<$network>, ("split", $crate::testnet::[<Split $variant>]::load_bytes()));
136            $crate::insert_testnet_key!($map, string, $type<$network>, ("fee_private", $crate::testnet::[<FeePrivate $variant>]::load_bytes()));
137            $crate::insert_testnet_key!($map, string, $type<$network>, ("fee_public", $crate::testnet::[<FeePublic $variant>]::load_bytes()));
138            $crate::insert_testnet_key!($map, string, $type<$network>, ("upgrade", $crate::testnet::[<Upgrade $variant>]::load_bytes()));
139        }
140    }};
141}
142
143#[macro_export]
144macro_rules! insert_testnet_credit_v0_keys {
145    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
146        paste::paste! {
147            let string = stringify!([<$variant:lower>]);
148            $crate::insert_testnet_key!($map, string, $type<$network>, ("bond_public", $crate::testnet::[<BondPublicV0 $variant>]::load_bytes()));
149            $crate::insert_testnet_key!($map, string, $type<$network>, ("bond_validator", $crate::testnet::[<BondValidatorV0 $variant>]::load_bytes()));
150            $crate::insert_testnet_key!($map, string, $type<$network>, ("unbond_public", $crate::testnet::[<UnbondPublicV0 $variant>]::load_bytes()));
151            $crate::insert_testnet_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::testnet::[<ClaimUnbondPublicV0 $variant>]::load_bytes()));
152            $crate::insert_testnet_key!($map, string, $type<$network>, ("set_validator_state", $crate::testnet::[<SetValidatorStateV0 $variant>]::load_bytes()));
153            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_private", $crate::testnet::[<TransferPrivateV0 $variant>]::load_bytes()));
154            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public", $crate::testnet::[<TransferPublicV0 $variant>]::load_bytes()));
155            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::testnet::[<TransferPublicAsSignerV0 $variant>]::load_bytes()));
156            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::testnet::[<TransferPrivateToPublicV0 $variant>]::load_bytes()));
157            $crate::insert_testnet_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::testnet::[<TransferPublicToPrivateV0 $variant>]::load_bytes()));
158            $crate::insert_testnet_key!($map, string, $type<$network>, ("join", $crate::testnet::[<JoinV0 $variant>]::load_bytes()));
159            $crate::insert_testnet_key!($map, string, $type<$network>, ("split", $crate::testnet::[<SplitV0 $variant>]::load_bytes()));
160            $crate::insert_testnet_key!($map, string, $type<$network>, ("fee_private", $crate::testnet::[<FeePrivateV0 $variant>]::load_bytes()));
161            $crate::insert_testnet_key!($map, string, $type<$network>, ("fee_public", $crate::testnet::[<FeePublicV0 $variant>]::load_bytes()));
162            $crate::insert_testnet_key!($map, string, $type<$network>, ("upgrade", $crate::testnet::[<UpgradeV0 $variant>]::load_bytes()));
163        }
164    }};
165}
166
167#[macro_export]
168macro_rules! insert_testnet_key {
169    ($map:ident, $string:tt, $type:ident<$network:ident>, ($name:tt, $circuit_key:expr)) => {{
170        // Load the circuit key bytes.
171        let key_bytes: Vec<u8> = $circuit_key.expect(&format!("Failed to load {} bytes", $string));
172        // Recover the circuit key.
173        let key = $type::<$network>::from_bytes_le(&key_bytes[1..]).expect(&format!("Failed to recover {}", $string));
174        // Insert the circuit key.
175        $map.insert($name.to_string(), std::sync::Arc::new(key));
176    }};
177}
178
179// Inclusion
180impl_remote!(InclusionV0Prover, REMOTE_URLS, "resources/", "inclusion", "prover", "credits_v0");
181impl_local!(InclusionV0Verifier, "resources/", "inclusion", "verifier", "credits_v0");
182impl_remote!(InclusionProver, REMOTE_URLS, "resources/", "inclusion", "prover", "credits");
183impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier", "credits");
184
185/// The function name for the inclusion circuit.
186pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion";
187
188lazy_static! {
189    pub static ref INCLUSION_V0_PROVING_KEY: Vec<u8> =
190        InclusionV0Prover::load_bytes().expect("Failed to load inclusion_v0 proving key");
191    pub static ref INCLUSION_V0_VERIFYING_KEY: Vec<u8> =
192        InclusionV0Verifier::load_bytes().expect("Failed to load inclusion_v0 verifying key");
193    pub static ref INCLUSION_PROVING_KEY: Vec<u8> = InclusionProver::load_bytes().expect("Failed to load inclusion proving key");
194    pub static ref INCLUSION_VERIFYING_KEY: Vec<u8> =
195        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifying key");
196}
197
198#[cfg(test)]
199mod tests {
200    use super::*;
201    use wasm_bindgen_test::*;
202    wasm_bindgen_test_configure!(run_in_browser);
203
204    #[allow(dead_code)]
205    #[wasm_bindgen_test]
206    fn test_load_bytes() {
207        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
208        BondValidatorVerifier::load_bytes().expect("Failed to load bond_validator verifier");
209        UnbondPublicVerifier::load_bytes().expect("Failed to load unbond_public verifier");
210        ClaimUnbondPublicVerifier::load_bytes().expect("Failed to load claim_unbond_public verifier");
211        SetValidatorStateVerifier::load_bytes().expect("Failed to load set_validator_state verifier");
212        TransferPrivateVerifier::load_bytes().expect("Failed to load transfer_private verifier");
213        TransferPublicVerifier::load_bytes().expect("Failed to load transfer_public verifier");
214        TransferPublicAsSignerVerifier::load_bytes().expect("Failed to load transfer_public_as_signer verifier");
215        TransferPrivateToPublicVerifier::load_bytes().expect("Failed to load transfer_private_to_public verifier");
216        TransferPublicToPrivateVerifier::load_bytes().expect("Failed to load transfer_public_to_private verifier");
217        FeePrivateProver::load_bytes().expect("Failed to load fee_private prover");
218        FeePrivateVerifier::load_bytes().expect("Failed to load fee_private verifier");
219        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
220        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
221        UpgradeProver::load_bytes().expect("Failed to load upgrade prover");
222        UpgradeVerifier::load_bytes().expect("Failed to load upgrade verifier");
223        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
224        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
225    }
226}