mod.rs
1 // Copyright (c) 2019-2025 Alpha-Delta Network Inc. 2 // This file is part of the deltavm 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 16 pub mod genesis; 17 pub use genesis::*; 18 19 pub mod powers; 20 pub use powers::*; 21 22 /// The restrictions list as a JSON-compatible string. 23 pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json"); 24 25 const REMOTE_URL: &str = "https://parameters.provable.com/mainnet"; 26 27 // Degrees 28 impl_local!(Degree15, "resources/", "powers-of-beta-15", "usrs"); 29 impl_remote!(Degree16, REMOTE_URL, "resources/", "powers-of-beta-16", "usrs"); 30 impl_remote!(Degree17, REMOTE_URL, "resources/", "powers-of-beta-17", "usrs"); 31 impl_remote!(Degree18, REMOTE_URL, "resources/", "powers-of-beta-18", "usrs"); 32 impl_remote!(Degree19, REMOTE_URL, "resources/", "powers-of-beta-19", "usrs"); 33 impl_remote!(Degree20, REMOTE_URL, "resources/", "powers-of-beta-20", "usrs"); 34 impl_remote!(Degree21, REMOTE_URL, "resources/", "powers-of-beta-21", "usrs"); 35 impl_remote!(Degree22, REMOTE_URL, "resources/", "powers-of-beta-22", "usrs"); 36 impl_remote!(Degree23, REMOTE_URL, "resources/", "powers-of-beta-23", "usrs"); 37 impl_remote!(Degree24, REMOTE_URL, "resources/", "powers-of-beta-24", "usrs"); 38 impl_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")] 45 impl_remote!(Degree26, REMOTE_URL, "resources/", "powers-of-beta-26", "usrs"); 46 #[cfg(feature = "large_params")] 47 impl_remote!(Degree27, REMOTE_URL, "resources/", "powers-of-beta-27", "usrs"); 48 #[cfg(feature = "large_params")] 49 impl_remote!(Degree28, REMOTE_URL, "resources/", "powers-of-beta-28", "usrs"); 50 51 // Shifted Degrees 52 impl_local!(ShiftedDegree15, "resources/", "shifted-powers-of-beta-15", "usrs"); 53 impl_local!(ShiftedDegree16, "resources/", "shifted-powers-of-beta-16", "usrs"); 54 impl_remote!(ShiftedDegree17, REMOTE_URL, "resources/", "shifted-powers-of-beta-17", "usrs"); 55 impl_remote!(ShiftedDegree18, REMOTE_URL, "resources/", "shifted-powers-of-beta-18", "usrs"); 56 impl_remote!(ShiftedDegree19, REMOTE_URL, "resources/", "shifted-powers-of-beta-19", "usrs"); 57 impl_remote!(ShiftedDegree20, REMOTE_URL, "resources/", "shifted-powers-of-beta-20", "usrs"); 58 impl_remote!(ShiftedDegree21, REMOTE_URL, "resources/", "shifted-powers-of-beta-21", "usrs"); 59 impl_remote!(ShiftedDegree22, REMOTE_URL, "resources/", "shifted-powers-of-beta-22", "usrs"); 60 impl_remote!(ShiftedDegree23, REMOTE_URL, "resources/", "shifted-powers-of-beta-23", "usrs"); 61 impl_remote!(ShiftedDegree24, REMOTE_URL, "resources/", "shifted-powers-of-beta-24", "usrs"); 62 impl_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")] 66 impl_remote!(ShiftedDegree26, REMOTE_URL, "resources/", "shifted-powers-of-beta-26", "usrs"); 67 #[cfg(feature = "large_params")] 68 impl_remote!(ShiftedDegree27, REMOTE_URL, "resources/", "shifted-powers-of-beta-27", "usrs"); 69 70 // Powers of Beta Times Gamma * G 71 impl_local!(Gamma, "resources/", "powers-of-beta-gamma", "usrs"); 72 // Negative Powers of Beta in G2 73 impl_local!(NegBeta, "resources/", "neg-powers-of-beta", "usrs"); 74 // Negative Powers of Beta in G2 75 impl_local!(BetaH, "resources/", "beta-h", "usrs"); 76 77 // BondPublic 78 impl_remote!(BondPublicProver, REMOTE_URL, "resources/", "bond_public", "prover", "credits"); 79 impl_local!(BondPublicVerifier, "resources/", "bond_public", "verifier", "credits"); 80 // BondValidator 81 impl_remote!(BondValidatorProver, REMOTE_URL, "resources/", "bond_validator", "prover", "credits"); 82 impl_local!(BondValidatorVerifier, "resources/", "bond_validator", "verifier", "credits"); 83 // UnbondPublic 84 impl_remote!(UnbondPublicProver, REMOTE_URL, "resources/", "unbond_public", "prover", "credits"); 85 impl_local!(UnbondPublicVerifier, "resources/", "unbond_public", "verifier", "credits"); 86 // ClaimUnbondPublic 87 impl_remote!(ClaimUnbondPublicProver, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits"); 88 impl_local!(ClaimUnbondPublicVerifier, "resources/", "claim_unbond_public", "verifier", "credits"); 89 // SetValidatorState 90 impl_remote!(SetValidatorStateProver, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits"); 91 impl_local!(SetValidatorStateVerifier, "resources/", "set_validator_state", "verifier", "credits"); 92 // TransferPrivate 93 impl_remote!(TransferPrivateProver, REMOTE_URL, "resources/", "transfer_private", "prover", "credits"); 94 impl_local!(TransferPrivateVerifier, "resources/", "transfer_private", "verifier", "credits"); 95 // TransferPublic 96 impl_remote!(TransferPublicProver, REMOTE_URL, "resources/", "transfer_public", "prover", "credits"); 97 impl_local!(TransferPublicVerifier, "resources/", "transfer_public", "verifier", "credits"); 98 // TransferPublicAsSigner 99 impl_remote!(TransferPublicAsSignerProver, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits"); 100 impl_local!(TransferPublicAsSignerVerifier, "resources/", "transfer_public_as_signer", "verifier", "credits"); 101 // TransferPrivateToPublic 102 impl_remote!(TransferPrivateToPublicProver, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits"); 103 impl_local!(TransferPrivateToPublicVerifier, "resources/", "transfer_private_to_public", "verifier", "credits"); 104 // TransferPublicToPrivate 105 impl_remote!(TransferPublicToPrivateProver, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits"); 106 impl_local!(TransferPublicToPrivateVerifier, "resources/", "transfer_public_to_private", "verifier", "credits"); 107 // Join 108 impl_remote!(JoinProver, REMOTE_URL, "resources/", "join", "prover", "credits"); 109 impl_local!(JoinVerifier, "resources/", "join", "verifier", "credits"); 110 // Split 111 impl_remote!(SplitProver, REMOTE_URL, "resources/", "split", "prover", "credits"); 112 impl_local!(SplitVerifier, "resources/", "split", "verifier", "credits"); 113 // FeePrivate 114 impl_remote!(FeePrivateProver, REMOTE_URL, "resources/", "fee_private", "prover", "credits"); 115 impl_local!(FeePrivateVerifier, "resources/", "fee_private", "verifier", "credits"); 116 // FeePublic 117 impl_remote!(FeePublicProver, REMOTE_URL, "resources/", "fee_public", "prover", "credits"); 118 impl_local!(FeePublicVerifier, "resources/", "fee_public", "verifier", "credits"); 119 // Upgrade 120 impl_remote!(UpgradeProver, REMOTE_URL, "resources/", "upgrade", "prover", "credits"); 121 impl_local!(UpgradeVerifier, "resources/", "upgrade", "verifier", "credits"); 122 123 // V0 Credits Keys 124 125 // BondPublic 126 impl_remote!(BondPublicV0Prover, REMOTE_URL, "resources/", "bond_public", "prover", "credits_v0"); 127 impl_local!(BondPublicV0Verifier, "resources/", "bond_public", "verifier", "credits_v0"); 128 // BondValidator 129 impl_remote!(BondValidatorV0Prover, REMOTE_URL, "resources/", "bond_validator", "prover", "credits_v0"); 130 impl_local!(BondValidatorV0Verifier, "resources/", "bond_validator", "verifier", "credits_v0"); 131 // UnbondPublic 132 impl_remote!(UnbondPublicV0Prover, REMOTE_URL, "resources/", "unbond_public", "prover", "credits_v0"); 133 impl_local!(UnbondPublicV0Verifier, "resources/", "unbond_public", "verifier", "credits_v0"); 134 // ClaimUnbondPublic 135 impl_remote!(ClaimUnbondPublicV0Prover, REMOTE_URL, "resources/", "claim_unbond_public", "prover", "credits_v0"); 136 impl_local!(ClaimUnbondPublicV0Verifier, "resources/", "claim_unbond_public", "verifier", "credits_v0"); 137 // SetValidatorState 138 impl_remote!(SetValidatorStateV0Prover, REMOTE_URL, "resources/", "set_validator_state", "prover", "credits_v0"); 139 impl_local!(SetValidatorStateV0Verifier, "resources/", "set_validator_state", "verifier", "credits_v0"); 140 // TransferPrivate 141 impl_remote!(TransferPrivateV0Prover, REMOTE_URL, "resources/", "transfer_private", "prover", "credits_v0"); 142 impl_local!(TransferPrivateV0Verifier, "resources/", "transfer_private", "verifier", "credits_v0"); 143 // TransferPublic 144 impl_remote!(TransferPublicV0Prover, REMOTE_URL, "resources/", "transfer_public", "prover", "credits_v0"); 145 impl_local!(TransferPublicV0Verifier, "resources/", "transfer_public", "verifier", "credits_v0"); 146 // TransferPublicAsSigner 147 impl_remote!(TransferPublicAsSignerV0Prover, REMOTE_URL, "resources/", "transfer_public_as_signer", "prover", "credits_v0"); 148 impl_local!(TransferPublicAsSignerV0Verifier, "resources/", "transfer_public_as_signer", "verifier", "credits_v0"); 149 // TransferPrivateToPublic 150 impl_remote!(TransferPrivateToPublicV0Prover, REMOTE_URL, "resources/", "transfer_private_to_public", "prover", "credits_v0"); 151 impl_local!(TransferPrivateToPublicV0Verifier, "resources/", "transfer_private_to_public", "verifier", "credits_v0"); 152 // TransferPublicToPrivate 153 impl_remote!(TransferPublicToPrivateV0Prover, REMOTE_URL, "resources/", "transfer_public_to_private", "prover", "credits_v0"); 154 impl_local!(TransferPublicToPrivateV0Verifier, "resources/", "transfer_public_to_private", "verifier", "credits_v0"); 155 // Join 156 impl_remote!(JoinV0Prover, REMOTE_URL, "resources/", "join", "prover", "credits_v0"); 157 impl_local!(JoinV0Verifier, "resources/", "join", "verifier", "credits_v0"); 158 // Split 159 impl_remote!(SplitV0Prover, REMOTE_URL, "resources/", "split", "prover", "credits_v0"); 160 impl_local!(SplitV0Verifier, "resources/", "split", "verifier", "credits_v0"); 161 // FeePrivate 162 impl_remote!(FeePrivateV0Prover, REMOTE_URL, "resources/", "fee_private", "prover", "credits_v0"); 163 impl_local!(FeePrivateV0Verifier, "resources/", "fee_private", "verifier", "credits_v0"); 164 // FeePublic 165 impl_remote!(FeePublicV0Prover, REMOTE_URL, "resources/", "fee_public", "prover", "credits_v0"); 166 impl_local!(FeePublicV0Verifier, "resources/", "fee_public", "verifier", "credits_v0"); 167 // Upgrade 168 impl_remote!(UpgradeV0Prover, REMOTE_URL, "resources/", "upgrade", "prover", "credits_v0"); 169 impl_local!(UpgradeV0Verifier, "resources/", "upgrade", "verifier", "credits_v0"); 170 171 #[macro_export] 172 macro_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] 196 macro_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] 220 macro_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 232 impl_remote!(InclusionV0Prover, REMOTE_URL, "resources/", "inclusion", "prover", "credits_v0"); 233 impl_local!(InclusionV0Verifier, "resources/", "inclusion", "verifier", "credits_v0"); 234 impl_remote!(InclusionProver, REMOTE_URL, "resources/", "inclusion", "prover", "credits"); 235 impl_local!(InclusionVerifier, "resources/", "inclusion", "verifier", "credits"); 236 237 /// The function name for the inclusion circuit. 238 pub const NETWORK_INCLUSION_FUNCTION_NAME: &str = "inclusion"; 239 240 lazy_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)] 251 mod 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 }