Skip to main content

snarkvm_console_network/
lib.rs

1// Copyright (c) 2019-2026 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
16#![forbid(unsafe_code)]
17#![allow(clippy::too_many_arguments)]
18#![warn(clippy::cast_possible_truncation)]
19
20#[macro_use]
21extern crate lazy_static;
22
23pub use snarkvm_console_network_environment as environment;
24pub use snarkvm_console_network_environment::*;
25
26mod helpers;
27pub use helpers::*;
28
29mod canary_v0;
30pub use canary_v0::*;
31
32mod consensus_heights;
33pub use consensus_heights::*;
34
35mod mainnet_v0;
36pub use mainnet_v0::*;
37
38mod testnet_v0;
39
40pub use testnet_v0::*;
41
42pub mod prelude {
43    #[cfg(feature = "wasm")]
44    pub use crate::get_or_init_consensus_version_heights;
45    pub use crate::{
46        CANARY_V0_CONSENSUS_VERSION_HEIGHTS,
47        CanaryV0,
48        ConsensusVersion,
49        MAINNET_V0_CONSENSUS_VERSION_HEIGHTS,
50        MainnetV0,
51        Network,
52        TEST_CONSENSUS_VERSION_HEIGHTS,
53        TESTNET_V0_CONSENSUS_VERSION_HEIGHTS,
54        TestnetV0,
55        consensus_config_value,
56        consensus_config_value_by_version,
57        environment::prelude::*,
58    };
59}
60
61pub use crate::environment::prelude::*;
62
63use snarkvm_algorithms::{
64    AlgebraicSponge,
65    crypto_hash::PoseidonSponge,
66    snark::varuna::{CircuitProvingKey, CircuitVerifyingKey, VarunaHidingMode},
67    srs::{UniversalProver, UniversalVerifier},
68};
69use snarkvm_console_algorithms::{BHP512, BHP1024, Poseidon2, Poseidon4, Poseidon8};
70use snarkvm_console_collections::merkle_tree::{MerklePath, MerkleTree};
71use snarkvm_console_types::{Field, Group, Scalar};
72use snarkvm_curves::PairingEngine;
73
74use indexmap::IndexMap;
75use std::sync::{Arc, OnceLock};
76
77/// A helper type for the BHP Merkle tree.
78pub type BHPMerkleTree<N, const DEPTH: u8> = MerkleTree<N, BHP1024<N>, BHP512<N>, DEPTH>;
79/// A helper type for the Poseidon Merkle tree.
80pub type PoseidonMerkleTree<N, const DEPTH: u8> = MerkleTree<N, Poseidon4<N>, Poseidon2<N>, DEPTH>;
81
82/// Helper types for the Varuna parameters.
83type Fq<N> = <<N as Environment>::PairingCurve as PairingEngine>::Fq;
84pub type FiatShamir<N> = PoseidonSponge<Fq<N>, 2, 1>;
85pub type FiatShamirParameters<N> = <FiatShamir<N> as AlgebraicSponge<Fq<N>, 2>>::Parameters;
86
87/// Helper types for the Varuna proving and verifying key.
88pub(crate) type VarunaProvingKey<N> = CircuitProvingKey<<N as Environment>::PairingCurve, VarunaHidingMode>;
89pub(crate) type VarunaVerifyingKey<N> = CircuitVerifyingKey<<N as Environment>::PairingCurve>;
90
91/// A list of consensus versions and their corresponding block heights.
92static CONSENSUS_VERSION_HEIGHTS: OnceLock<[(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS]> = OnceLock::new();
93
94pub trait Network:
95    'static
96    + Environment
97    + Copy
98    + Clone
99    + Debug
100    + Eq
101    + PartialEq
102    + core::hash::Hash
103    + Serialize
104    + DeserializeOwned
105    + for<'a> Deserialize<'a>
106    + Send
107    + Sync
108{
109    /// The network ID.
110    const ID: u16;
111    /// The (long) network name.
112    const NAME: &'static str;
113    /// The short network name (used, for example, in query URLs).
114    const SHORT_NAME: &'static str;
115
116    /// The function name for the inclusion circuit.
117    const INCLUSION_FUNCTION_NAME: &'static str;
118
119    /// The fixed timestamp of the genesis block.
120    const GENESIS_TIMESTAMP: i64;
121    /// The genesis block coinbase target.
122    const GENESIS_COINBASE_TARGET: u64;
123    /// The genesis block proof target.
124    const GENESIS_PROOF_TARGET: u64;
125    /// The maximum number of solutions that can be included per block as a power of 2.
126    const MAX_SOLUTIONS_AS_POWER_OF_TWO: u8 = 2; // 4 solutions
127    /// The maximum number of solutions that can be included per block.
128    const MAX_SOLUTIONS: usize = 1 << Self::MAX_SOLUTIONS_AS_POWER_OF_TWO; // 4 solutions
129
130    /// The starting supply of Aleo credits.
131    const STARTING_SUPPLY: u64 = 1_500_000_000_000_000; // 1.5B credits
132    /// The maximum supply of Aleo credits.
133    /// This value represents the absolute upper bound on all ALEO created over the lifetime of the network.
134    const MAX_SUPPLY: u64 = 5_000_000_000_000_000; // 5B credits
135    /// The block height that upper bounds the total supply of Aleo credits to 5 billion.
136    #[cfg(not(feature = "test"))]
137    const MAX_SUPPLY_LIMIT_HEIGHT: u32 = 263_527_685;
138    /// The block height that upper bounds the total supply of Aleo credits to 5 billion.
139    /// This is deliberately set to a low value for testing purposes only.
140    #[cfg(feature = "test")]
141    const MAX_SUPPLY_LIMIT_HEIGHT: u32 = 5;
142    /// The cost in microcredits per byte for the deployment transaction.
143    const DEPLOYMENT_FEE_MULTIPLIER: u64 = 1_000; // 1 millicredit per byte
144    /// The multiplier in microcredits for each command in the constructor.
145    const CONSTRUCTOR_FEE_MULTIPLIER: u64 = 100; // 100x per command
146    /// The constant that divides the storage polynomial.
147    const EXECUTION_STORAGE_FEE_SCALING_FACTOR: u64 = 5000;
148    /// The maximum size execution transactions can be before a quadratic storage penalty applies.
149    const EXECUTION_STORAGE_PENALTY_THRESHOLD: u64 = 5000;
150    /// The cost in microcredits per constraint for the deployment transaction.
151    const SYNTHESIS_FEE_MULTIPLIER: u64 = 25; // 25 microcredits per constraint
152    /// The maximum number of variables in a deployment. This limit was enforced at the transaction level up to
153    /// consensus version V16 (inclusive), skipped at V18 in favor of a block-wide synthesis limit, and
154    /// replaced by `MAX_DEPLOYMENT_VARIABLES_V2` from V19. This corresponds to ~0.5 second single-threaded
155    /// runtime at mainnet launch reference validator hardware.
156    const MAX_DEPLOYMENT_VARIABLES: u64 = 1 << 21; // 2,097,152 variables
157    /// The maximum number of constraints in a deployment. This limit was enforced at the transaction level up to
158    /// consensus version V16 (inclusive), skipped at V18 in favor of a block-wide synthesis limit, and
159    /// replaced by `MAX_DEPLOYMENT_CONSTRAINTS_V2` from V19. This corresponds to ~0.5 second single-threaded
160    /// runtime at mainnet launch reference validator hardware.
161    const MAX_DEPLOYMENT_CONSTRAINTS: u64 = 1 << 21; // 2,097,152 constraints
162    /// The maximum number of variables in a deployment. Enforced at the transaction level from consensus
163    /// version V19.
164    const MAX_DEPLOYMENT_VARIABLES_V2: u64 = 1 << 22; // 4,194,304 variables
165    /// The maximum number of constraints in a deployment. Enforced at the transaction level from consensus
166    /// version V19.
167    const MAX_DEPLOYMENT_CONSTRAINTS_V2: u64 = 1 << 22; // 4,194,304 constraints
168    /// Approximate conversion factor from non-zero circuit entries to seconds of certificate-verification work
169    /// when checking a deployment. From it, a per-proposal synthesis limit is enforced at consensus
170    /// version V18 which overrides the two per-transaction limits above.
171    const SYNTHESIS_PER_SECOND_OF_RUNTIME: u64 = 1_500_000;
172    const MAX_BATCH_PROOF_INSTANCES: usize = 128;
173    /// The maximum number of microcredits that can be spent as a fee.
174    const MAX_FEE: u64 = 1_000_000_000_000_000;
175    /// A list of consensus versions and their corresponding transaction spend limits in microcredits.
176    //  Note: This value must **not** decrease without considering the impact on transaction validity.
177    const TRANSACTION_SPEND_LIMIT: [(ConsensusVersion, u64); 2] =
178        [(ConsensusVersion::V1, 100_000_000), (ConsensusVersion::V10, 4_000_000)];
179    /// The compute discount approved by ARC 0005.
180    const ARC_0005_COMPUTE_DISCOUNT: u64 =
181        Self::CREDITS_PER_SECOND_OF_RUNTIME[0].1 / Self::CREDITS_PER_SECOND_OF_RUNTIME[1].1;
182    /// The number of microcredits representing a second of runtime.
183    const CREDITS_PER_SECOND_OF_RUNTIME: [(ConsensusVersion, u64); 2] =
184        [(ConsensusVersion::V1, 100_000_000), (ConsensusVersion::V10, 4_000_000)];
185
186    /// The anchor height, defined as the expected number of blocks to reach the coinbase target.
187    /// Note: The anchor height used exclusively by `coinbase_reward_v1`.
188    const ANCHOR_HEIGHT: u32 = Self::REWARD_ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32;
189    /// The anchor time used specifically for calculating the coinbase reward.
190    /// We ensure that the reward anchor time matches the original ConsensusVersion::V1 anchor time
191    /// to maintain the original coinbase reward schedule.
192    const REWARD_ANCHOR_TIME: u16 = 25;
193    /// A list of (consensus_version, anchor_time_in_seconds) pairs (sparse).
194    /// Each entry takes effect at the specified version and remains active until the next entry.
195    /// The anchor time, defined as the expected time in seconds to reach the coinbase target.
196    const ANCHOR_TIMES: [(ConsensusVersion, u16); 3] = [
197        (ConsensusVersion::V1, Self::REWARD_ANCHOR_TIME),
198        (ConsensusVersion::V15, 35),
199        (ConsensusVersion::V17, Self::REWARD_ANCHOR_TIME),
200    ];
201    /// The expected time per block in seconds.
202    const BLOCK_TIME: u16 = 10;
203    /// The number of blocks per epoch.
204    #[cfg(not(feature = "test"))]
205    const NUM_BLOCKS_PER_EPOCH: u32 = 3600 / Self::BLOCK_TIME as u32; // 360 blocks == ~1 hour
206    /// The number of blocks per epoch.
207    /// This is deliberately set to a low value for testing purposes only.
208    #[cfg(feature = "test")]
209    const NUM_BLOCKS_PER_EPOCH: u32 = 10;
210
211    /// The maximum number of entries in data.
212    const MAX_DATA_ENTRIES: usize = 32;
213    /// The maximum recursive depth of an entry.
214    /// Note: This value must be strictly less than u8::MAX.
215    const MAX_DATA_DEPTH: usize = 32;
216    /// The maximum number of fields in data (must not exceed u16::MAX).
217    #[allow(clippy::cast_possible_truncation)]
218    const MAX_DATA_SIZE_IN_FIELDS: u32 = ((128 * 1024 * 8) / Field::<Self>::SIZE_IN_DATA_BITS) as u32;
219
220    /// The minimum number of entries in a struct.
221    const MIN_STRUCT_ENTRIES: usize = 1; // This ensures the struct is not empty.
222    /// The maximum number of entries in a struct.
223    const MAX_STRUCT_ENTRIES: usize = Self::MAX_DATA_ENTRIES;
224
225    /// The minimum number of elements in an array.
226    const MIN_ARRAY_ELEMENTS: usize = 1; // This ensures the array is not empty.
227    ///  A list of (consensus_version, size) pairs indicating the maximum number of elements in an array.
228    const MAX_ARRAY_ELEMENTS: [(ConsensusVersion, usize); 3] =
229        [(ConsensusVersion::V1, 32), (ConsensusVersion::V11, 512), (ConsensusVersion::V14, 2048)];
230
231    /// The minimum number of entries in a record.
232    const MIN_RECORD_ENTRIES: usize = 1; // This accounts for 'record.owner'.
233    /// The maximum number of entries in a record.
234    const MAX_RECORD_ENTRIES: usize = Self::MIN_RECORD_ENTRIES.saturating_add(Self::MAX_DATA_ENTRIES);
235
236    /// The maximum program size by number of characters.
237    const MAX_PROGRAM_SIZE: [(ConsensusVersion, usize); 3] = [
238        (ConsensusVersion::V1, 100_000),    // 100 kB
239        (ConsensusVersion::V14, 512_000),   // 512 kB
240        (ConsensusVersion::V16, 2_048_000), // 2048 kB
241    ];
242    /// The maximum number of mappings in a program.
243    const MAX_MAPPINGS: usize = 31;
244    /// The maximum number of functions in a program.
245    const MAX_FUNCTIONS: usize = 31;
246    /// The maximum number of structs in a program.
247    const MAX_STRUCTS: usize = 10 * Self::MAX_FUNCTIONS;
248    /// The maximum number of records in a program.
249    const MAX_RECORDS: usize = 10 * Self::MAX_FUNCTIONS;
250    /// The maximum number of closures in a program.
251    const MAX_CLOSURES: usize = 2 * Self::MAX_FUNCTIONS;
252    /// The maximum number of view functions in a program.
253    const MAX_VIEWS: usize = 2 * Self::MAX_FUNCTIONS;
254    /// The maximum number of operands in an instruction.
255    const MAX_OPERANDS: usize = Self::MAX_INPUTS;
256    /// The maximum number of instructions in a closure or function.
257    const MAX_INSTRUCTIONS: usize = u16::MAX as usize;
258    /// The maximum number of commands in finalize.
259    const MAX_COMMANDS: usize = u16::MAX as usize;
260    /// The maximum number of `call` commands in a finalize body. Matched to
261    /// `Transaction::MAX_TRANSITIONS` so view-call arity in a finalize is bounded analogously
262    /// to the static-call bound on transition graphs.
263    const MAX_CALLS: usize = 32;
264    /// The maximum number of write commands in finalize.
265    const MAX_WRITES: [(ConsensusVersion, u16); 2] = [(ConsensusVersion::V1, 16), (ConsensusVersion::V14, 32)];
266    /// The maximum number of `position` commands in finalize.
267    const MAX_POSITIONS: usize = u8::MAX as usize;
268
269    /// The maximum number of inputs per transition.
270    const MAX_INPUTS: usize = 16;
271    /// The maximum number of outputs per transition.
272    const MAX_OUTPUTS: usize = 16;
273
274    /// The maximum number of imports.
275    const MAX_IMPORTS: usize = 64;
276
277    /// A list of consensus versions and their corresponding maximum transaction sizes in bytes.
278    ///
279    /// A transaction consists of fixed identifiers, deployment data, and fees.
280    /// Fixed components include identifiers, ownership, checksums, and fees.
281    /// Variable components include the program bytecode and verifying-key entries.
282    /// Verifying-key entries scale with the number of functions and records.
283    ///
284    /// MAX_TRANSACTION_SIZE = C + MAX_PROGRAM_SIZE + (673 + 58) * (MAX_FUNCTIONS + MAX_RECORDS)
285    /// C = fixed size components (Up to 2367 bytes)
286    // Note: This value must **not** decrease without considering the impact on transaction validity.
287    const MAX_TRANSACTION_SIZE: [(ConsensusVersion, usize); 3] = [
288        (ConsensusVersion::V1, 128_000),    // 128 kB
289        (ConsensusVersion::V14, 768_000),   // 768 kB
290        (ConsensusVersion::V16, 2_304_000), // 2304 kB
291    ];
292
293    /// The state root type.
294    type StateRoot: Bech32ID<Field<Self>>;
295    /// The block hash type.
296    type BlockHash: Bech32ID<Field<Self>>;
297    /// The ratification ID type.
298    type RatificationID: Bech32ID<Field<Self>>;
299    /// The transaction ID type.
300    type TransactionID: Bech32ID<Field<Self>>;
301    /// The transition ID type.
302    type TransitionID: Bech32ID<Field<Self>>;
303    /// The transmission checksum type.
304    type TransmissionChecksum: IntegerType;
305
306    /// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
307    /// Documentation for what is changed at each version can be found in `N::CONSENSUS_VERSION`
308    /// Do not read this directly outside of tests, use `N::CONSENSUS_VERSION_HEIGHTS()` instead.
309    const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS];
310
311    ///  A list of (consensus_version, size) pairs indicating the maximum number of validators in a committee.
312    //  Note: This value must **not** decrease without considering the impact on serialization.
313    //  Decreasing this value will break backwards compatibility of serialization without explicit
314    //  declaration of migration based on round number rather than block height.
315    //  Increasing this value will require a migration to prevent forking during network upgrades.
316    const MAX_CERTIFICATES: [(ConsensusVersion, u16); 5];
317
318    /// Returns the list of consensus versions.
319    #[allow(non_snake_case)]
320    #[cfg(not(any(test, feature = "test", feature = "test_consensus_heights")))]
321    fn CONSENSUS_VERSION_HEIGHTS() -> &'static [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
322        // Initialize the consensus version heights directly from the constant.
323        CONSENSUS_VERSION_HEIGHTS.get_or_init(|| Self::_CONSENSUS_VERSION_HEIGHTS)
324    }
325    /// Returns the list of test consensus versions.
326    #[allow(non_snake_case)]
327    #[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
328    fn CONSENSUS_VERSION_HEIGHTS() -> &'static [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
329        CONSENSUS_VERSION_HEIGHTS.get_or_init(load_test_consensus_heights)
330    }
331
332    /// A set of incrementing consensus version heights used for tests.
333    #[allow(non_snake_case)]
334    #[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
335    const TEST_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
336        TEST_CONSENSUS_VERSION_HEIGHTS;
337    /// Returns the consensus version which is active at the given height.
338    #[allow(non_snake_case)]
339    fn CONSENSUS_VERSION(seek_height: u32) -> anyhow::Result<ConsensusVersion> {
340        match Self::CONSENSUS_VERSION_HEIGHTS().binary_search_by(|(_, height)| height.cmp(&seek_height)) {
341            // If a consensus version was found at this height, return it.
342            Ok(index) => Ok(Self::CONSENSUS_VERSION_HEIGHTS()[index].0),
343            // If the specified height was not found, determine whether to return an appropriate version.
344            Err(index) => {
345                if index == 0 {
346                    Err(anyhow!("Expected consensus version 1 to exist at height 0."))
347                } else {
348                    // Return the appropriate version belonging to the height *lower* than the sought height.
349                    Ok(Self::CONSENSUS_VERSION_HEIGHTS()[index - 1].0)
350                }
351            }
352        }
353    }
354    /// Returns the height at which a specified consensus version becomes active.
355    #[allow(non_snake_case)]
356    fn CONSENSUS_HEIGHT(version: ConsensusVersion) -> Result<u32> {
357        Ok(Self::CONSENSUS_VERSION_HEIGHTS().get(version as usize - 1).ok_or(anyhow!("Invalid consensus version"))?.1)
358    }
359    /// Returns the last `MAX_ARRAY_ELEMENTS` value.
360    #[allow(non_snake_case)]
361    fn LATEST_MAX_ARRAY_ELEMENTS() -> usize {
362        Self::MAX_ARRAY_ELEMENTS.last().expect("MAX_ARRAY_ELEMENTS must have at least one entry").1
363    }
364    /// Returns the last `MAX_CERTIFICATES` value.
365    #[allow(non_snake_case)]
366    fn LATEST_MAX_CERTIFICATES() -> u16 {
367        Self::MAX_CERTIFICATES.last().expect("MAX_CERTIFICATES must have at least one entry").1
368    }
369
370    /// Returns the last `MAX_PROGRAM_SIZE` value.
371    #[allow(non_snake_case)]
372    fn LATEST_MAX_PROGRAM_SIZE() -> usize {
373        Self::MAX_PROGRAM_SIZE.last().expect("MAX_PROGRAM_SIZE must have at least one entry").1
374    }
375
376    /// Returns the last `MAX_WRITES` value.
377    #[allow(non_snake_case)]
378    fn LATEST_MAX_WRITES() -> u16 {
379        Self::MAX_WRITES.last().expect("MAX_WRITES must have at least one entry").1
380    }
381
382    /// Returns the last `MAX_TRANSACTION_SIZE` value.
383    #[allow(non_snake_case)]
384    fn LATEST_MAX_TRANSACTION_SIZE() -> usize {
385        Self::MAX_TRANSACTION_SIZE.last().expect("MAX_TRANSACTION_SIZE must have at least one entry").1
386    }
387
388    /// Returns the block height where the the inclusion proof will be updated.
389    #[allow(non_snake_case)]
390    fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32>;
391
392    /// Returns the genesis block bytes.
393    fn genesis_bytes() -> &'static [u8];
394
395    /// Returns the restrictions list as a JSON-compatible string.
396    fn restrictions_list_as_str() -> &'static str;
397
398    /// Returns the proving key for the given function name in the v0 version of `credits.aleo`.
399    fn get_credits_v0_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>>;
400
401    /// Returns the verifying key for the given function name in the v0 version of `credits.aleo`.
402    fn get_credits_v0_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>>;
403
404    /// Returns the proving key for the given function name in `credits.aleo`.
405    fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>>;
406
407    /// Returns the verifying key for the given function name in `credits.aleo`.
408    fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>>;
409
410    #[cfg(not(feature = "wasm"))]
411    /// Returns the `proving key` for the inclusion_v0 circuit.
412    fn inclusion_v0_proving_key() -> &'static Arc<VarunaProvingKey<Self>>;
413
414    #[cfg(feature = "wasm")]
415    /// Returns the `proving key` for the inclusion_v0 circuit.
416    fn inclusion_v0_proving_key(bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>>;
417
418    /// Returns the `verifying key` for the inclusion_v0 circuit.
419    fn inclusion_v0_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>>;
420
421    #[cfg(not(feature = "wasm"))]
422    /// Returns the `proving key` for the inclusion circuit.
423    fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>>;
424
425    #[cfg(feature = "wasm")]
426    fn inclusion_proving_key(bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>>;
427
428    /// Returns the `verifying key` for the inclusion circuit.
429    fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>>;
430
431    #[cfg(not(feature = "wasm"))]
432    /// Returns the `proving key` for the translation circuit.
433    fn translation_credits_proving_key() -> &'static Arc<VarunaProvingKey<Self>>;
434
435    #[cfg(feature = "wasm")]
436    /// Returns the `proving key` for the translation circuit.
437    fn translation_credits_proving_key(bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>>;
438
439    /// Returns the `verifying key` for the translation circuit.
440    fn translation_credits_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>>;
441
442    /// Returns the powers of `G`.
443    fn g_powers() -> &'static Vec<Group<Self>>;
444
445    /// Returns the scalar multiplication on the generator `G`.
446    fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self>;
447
448    /// Returns the Varuna universal prover.
449    fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve>;
450
451    /// Returns the Varuna universal verifier.
452    fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve>;
453
454    /// Returns the sponge parameters for Varuna.
455    fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self>;
456
457    /// Returns the commitment domain as a constant field element.
458    fn commitment_domain() -> Field<Self>;
459
460    /// Returns the encryption domain as a constant field element.
461    fn encryption_domain() -> Field<Self>;
462
463    /// Returns the graph key domain as a constant field element.
464    fn graph_key_domain() -> Field<Self>;
465
466    /// Returns the serial number domain as a constant field element.
467    fn serial_number_domain() -> Field<Self>;
468
469    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
470    fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
471
472    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
473    fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
474
475    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
476    fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
477
478    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
479    fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
480
481    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
482    fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
483
484    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
485    fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
486
487    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
488    fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
489
490    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
491    fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
492
493    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
494    fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
495
496    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
497    fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
498
499    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
500    fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
501
502    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
503    fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
504
505    /// Returns the BHP hash with an input hasher of 256-bits.
506    fn hash_bhp256(input: &[bool]) -> Result<Field<Self>>;
507
508    /// Returns the BHP hash with an input hasher of 512-bits.
509    fn hash_bhp512(input: &[bool]) -> Result<Field<Self>>;
510
511    /// Returns the BHP hash with an input hasher of 768-bits.
512    fn hash_bhp768(input: &[bool]) -> Result<Field<Self>>;
513
514    /// Returns the BHP hash with an input hasher of 1024-bits.
515    fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>>;
516
517    /// Returns the Keccak hash with a 256-bit output.
518    fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>>;
519
520    /// Returns the Keccak hash with a 384-bit output.
521    fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>>;
522
523    /// Returns the Keccak hash with a 512-bit output.
524    fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>>;
525
526    /// Returns the Pedersen hash for a given (up to) 64-bit input.
527    fn hash_ped64(input: &[bool]) -> Result<Field<Self>>;
528
529    /// Returns the Pedersen hash for a given (up to) 128-bit input.
530    fn hash_ped128(input: &[bool]) -> Result<Field<Self>>;
531
532    /// Returns the Poseidon hash with an input rate of 2.
533    fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>>;
534
535    /// Returns the Poseidon hash with an input rate of 4.
536    fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>>;
537
538    /// Returns the Poseidon hash with an input rate of 8.
539    fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>>;
540
541    /// Returns the SHA-3 hash with a 256-bit output.
542    fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>>;
543
544    /// Returns the SHA-3 hash with a 384-bit output.
545    fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>>;
546
547    /// Returns the SHA-3 hash with a 512-bit output.
548    fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>>;
549
550    /// Returns the extended Poseidon hash with an input rate of 2.
551    fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
552
553    /// Returns the extended Poseidon hash with an input rate of 4.
554    fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
555
556    /// Returns the extended Poseidon hash with an input rate of 8.
557    fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
558
559    /// Returns the BHP hash with an input hasher of 256-bits.
560    fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>>;
561
562    /// Returns the BHP hash with an input hasher of 512-bits.
563    fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>>;
564
565    /// Returns the BHP hash with an input hasher of 768-bits.
566    fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>>;
567
568    /// Returns the BHP hash with an input hasher of 1024-bits.
569    fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>>;
570
571    /// Returns the Pedersen hash for a given (up to) 64-bit input.
572    fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>>;
573
574    /// Returns the Pedersen hash for a given (up to) 128-bit input.
575    fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>>;
576
577    /// Returns the Poseidon hash with an input rate of 2 on the affine curve.
578    fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>>;
579
580    /// Returns the Poseidon hash with an input rate of 4 on the affine curve.
581    fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>>;
582
583    /// Returns the Poseidon hash with an input rate of 8 on the affine curve.
584    fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>>;
585
586    /// Returns the Poseidon hash with an input rate of 2 on the scalar field.
587    fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>>;
588
589    /// Returns the Poseidon hash with an input rate of 4 on the scalar field.
590    fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>>;
591
592    /// Returns the Poseidon hash with an input rate of 8 on the scalar field.
593    fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>>;
594
595    /// Returns a Merkle tree with a BHP leaf hasher of 1024-bits and a BHP path hasher of 512-bits.
596    fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>>;
597
598    /// Returns a Merkle tree with a Poseidon leaf hasher with input rate of 4 and a Poseidon path hasher with input rate of 2.
599    fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>>;
600
601    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
602    #[allow(clippy::ptr_arg)]
603    fn verify_merkle_path_bhp<const DEPTH: u8>(
604        path: &MerklePath<Self, DEPTH>,
605        root: &Field<Self>,
606        leaf: &Vec<bool>,
607    ) -> bool;
608
609    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
610    #[allow(clippy::ptr_arg)]
611    fn verify_merkle_path_psd<const DEPTH: u8>(
612        path: &MerklePath<Self, DEPTH>,
613        root: &Field<Self>,
614        leaf: &Vec<Field<Self>>,
615    ) -> bool;
616
617    /// Returns the Poseidon leaf hasher for dynamic records (rate 8).
618    fn dynamic_record_leaf_hasher() -> &'static Poseidon8<Self>;
619
620    /// Returns the Poseidon path hasher for dynamic records (rate 2).
621    fn dynamic_record_path_hasher() -> &'static Poseidon2<Self>;
622}
623
624/// Returns the consensus version heights, initializing them if necessary.
625///
626/// If a `heights` string is provided, it must be a comma-separated list of ascending block heights
627/// starting from zero (e.g., `"0,2,3,4,..."`) with a number of heights exactly equal to the value
628/// of the Network trait's `NUM_CONSENSUS_VERSIONS` constant. These heights correspond to the
629/// activation block of each `ConsensusVersion`.
630///
631/// If `heights` is `None`, the function will use SnarkVM's default test consensus heights.
632///
633/// This function caches the initialized heights, and can be set only once. Further calls will
634/// return the cached heights.
635///
636/// This method should be called by `wasm` users who need to set test values for consensus heights
637/// for purposes such as testing on a local devnet. If this method needs to be used, it should be
638/// called immediately after the wasm module is initialized.
639#[cfg(feature = "wasm")]
640pub fn get_or_init_consensus_version_heights(
641    heights: Option<String>,
642) -> [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
643    let heights = load_test_consensus_heights_inner(heights);
644    *CONSENSUS_VERSION_HEIGHTS.get_or_init(|| heights)
645}