snarkvm_parameters/canary/
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
19/// The restrictions list as a JSON-compatible string.
20pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");
21
22const REMOTE_URL: &str = "https://parameters.aleo.org/canary";
23
24// BondPublic
25impl_remote!(BondPublicProver, REMOTE_URL, "resources/", "bond_public", "prover");
26impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier");
27// BondValidator
28impl_remote!(BondValidatorProver, REMOTE_URL, "resources/", "bond_validator", "prover");
29impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier");
30// UnbondPublic
31impl_remote!(UnbondPublicProver, REMOTE_URL, "resources/", "unbond_public", "prover");
32impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier");
33// ClaimUnbondPublic
34impl_remote!(ClaimUnbondPublicProver, REMOTE_URL, "resources/", "claim_unbond_public", "prover");
35impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier");
36// SetValidatorState
37impl_remote!(SetValidatorStateProver, REMOTE_URL, "resources/", "set_validator_state", "prover");
38impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier");
39// TransferPrivate
40impl_remote!(TransferPrivateProver, REMOTE_URL, "resources/", "transfer_private", "prover");
41impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier");
42// TransferPublic
43impl_remote!(TransferPublicProver, REMOTE_URL, "resources/", "transfer_public", "prover");
44impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier");
45// TransferPublicAsSigner
46impl_remote!(TransferPublicAsSignerProver, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover");
47impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier");
48// TransferPrivateToPublic
49impl_remote!(TransferPrivateToPublicProver, REMOTE_URL, "resources/", "transfer_private_to_public", "prover");
50impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier");
51// TransferPublicToPrivate
52impl_remote!(TransferPublicToPrivateProver, REMOTE_URL, "resources/", "transfer_public_to_private", "prover");
53impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier");
54// Join
55impl_remote!(JoinProver, REMOTE_URL, "resources/", "join", "prover");
56impl_local!(JoinVerifier, "resources/", "join", "verifier");
57// Split
58impl_remote!(SplitProver, REMOTE_URL, "resources/", "split", "prover");
59impl_local!(SplitVerifier, "resources/", "split", "verifier");
60// FeePrivate
61impl_remote!(FeePrivateProver, REMOTE_URL, "resources/", "fee_private", "prover");
62impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier");
63// FeePublic
64impl_remote!(FeePublicProver, REMOTE_URL, "resources/", "fee_public", "prover");
65impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier");
66
67#[macro_export]
68macro_rules! insert_canary_credit_keys {
69    ($map:ident, $type:ident<$network:ident>, $variant:ident) => {{
70        paste::paste! {
71            let string = stringify!([<$variant:lower>]);
72            $crate::insert_canary_key!($map, string, $type<$network>, ("bond_public", $crate::canary::[<BondPublic $variant>]::load_bytes()));
73            $crate::insert_canary_key!($map, string, $type<$network>, ("bond_validator", $crate::canary::[<BondValidator $variant>]::load_bytes()));
74            $crate::insert_canary_key!($map, string, $type<$network>, ("unbond_public", $crate::canary::[<UnbondPublic $variant>]::load_bytes()));
75            $crate::insert_canary_key!($map, string, $type<$network>, ("claim_unbond_public", $crate::canary::[<ClaimUnbondPublic $variant>]::load_bytes()));
76            $crate::insert_canary_key!($map, string, $type<$network>, ("set_validator_state", $crate::canary::[<SetValidatorState $variant>]::load_bytes()));
77            $crate::insert_canary_key!($map, string, $type<$network>, ("transfer_private", $crate::canary::[<TransferPrivate $variant>]::load_bytes()));
78            $crate::insert_canary_key!($map, string, $type<$network>, ("transfer_public", $crate::canary::[<TransferPublic $variant>]::load_bytes()));
79            $crate::insert_canary_key!($map, string, $type<$network>, ("transfer_public_as_signer", $crate::canary::[<TransferPublicAsSigner $variant>]::load_bytes()));
80            $crate::insert_canary_key!($map, string, $type<$network>, ("transfer_private_to_public", $crate::canary::[<TransferPrivateToPublic $variant>]::load_bytes()));
81            $crate::insert_canary_key!($map, string, $type<$network>, ("transfer_public_to_private", $crate::canary::[<TransferPublicToPrivate $variant>]::load_bytes()));
82            $crate::insert_canary_key!($map, string, $type<$network>, ("join", $crate::canary::[<Join $variant>]::load_bytes()));
83            $crate::insert_canary_key!($map, string, $type<$network>, ("split", $crate::canary::[<Split $variant>]::load_bytes()));
84            $crate::insert_canary_key!($map, string, $type<$network>, ("fee_private", $crate::canary::[<FeePrivate $variant>]::load_bytes()));
85            $crate::insert_canary_key!($map, string, $type<$network>, ("fee_public", $crate::canary::[<FeePublic $variant>]::load_bytes()));
86        }
87    }};
88}
89
90#[macro_export]
91macro_rules! insert_canary_key {
92    ($map:ident, $string:tt, $type:ident<$network:ident>, ($name:tt, $circuit_key:expr)) => {{
93        // Load the circuit key bytes.
94        let key_bytes: Vec<u8> = $circuit_key.expect(&format!("Failed to load {} bytes", $string));
95        // Recover the circuit key.
96        let key = $type::<$network>::from_bytes_le(&key_bytes[1..]).expect(&format!("Failed to recover {}", $string));
97        // Insert the circuit key.
98        $map.insert($name.to_string(), std::sync::Arc::new(key));
99    }};
100}
101
102// Inclusion
103impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover");
104impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier");
105
106/// The function name for the inclusion circuit.
107pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion";
108
109lazy_static! {
110    pub static ref INCLUSION_PROVING_KEY: Vec<u8> =
111        InclusionProver::load_bytes().expect("Failed to load inclusion proving key");
112    pub static ref INCLUSION_VERIFYING_KEY: Vec<u8> =
113        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifying key");
114}
115
116#[cfg(test)]
117mod tests {
118    use super::*;
119    use wasm_bindgen_test::*;
120    wasm_bindgen_test_configure!(run_in_browser);
121
122    #[allow(dead_code)]
123    #[wasm_bindgen_test]
124    fn test_load_bytes() {
125        BondPublicVerifier::load_bytes().expect("Failed to load bond_public verifier");
126        BondValidatorVerifier::load_bytes().expect("Failed to load bond_validator verifier");
127        UnbondPublicVerifier::load_bytes().expect("Failed to load unbond_public verifier");
128        ClaimUnbondPublicVerifier::load_bytes().expect("Failed to load claim_unbond_public verifier");
129        SetValidatorStateVerifier::load_bytes().expect("Failed to load set_validator_state verifier");
130        TransferPrivateVerifier::load_bytes().expect("Failed to load transfer_private verifier");
131        TransferPublicVerifier::load_bytes().expect("Failed to load transfer_public verifier");
132        TransferPublicAsSignerVerifier::load_bytes().expect("Failed to load transfer_public_as_signer verifier");
133        TransferPrivateToPublicVerifier::load_bytes().expect("Failed to load transfer_private_to_public verifier");
134        TransferPublicToPrivateVerifier::load_bytes().expect("Failed to load transfer_public_to_private verifier");
135        FeePrivateProver::load_bytes().expect("Failed to load fee_private prover");
136        FeePrivateVerifier::load_bytes().expect("Failed to load fee_private verifier");
137        FeePublicProver::load_bytes().expect("Failed to load fee_public prover");
138        FeePublicVerifier::load_bytes().expect("Failed to load fee_public verifier");
139        InclusionProver::load_bytes().expect("Failed to load inclusion prover");
140        InclusionVerifier::load_bytes().expect("Failed to load inclusion verifier");
141    }
142}