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