snarkvm_console_network/
lib.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
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};
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 cost in microcredits per byte for the deployment transaction.
133    const DEPLOYMENT_FEE_MULTIPLIER: u64 = 1_000; // 1 millicredit per byte
134    /// The multiplier in microcredits for each command in the constructor.
135    const CONSTRUCTOR_FEE_MULTIPLIER: u64 = 100; // 100x per command
136    /// The constant that divides the storage polynomial.
137    const EXECUTION_STORAGE_FEE_SCALING_FACTOR: u64 = 5000;
138    /// The maximum size execution transactions can be before a quadratic storage penalty applies.
139    const EXECUTION_STORAGE_PENALTY_THRESHOLD: u64 = 5000;
140    /// The cost in microcredits per constraint for the deployment transaction.
141    const SYNTHESIS_FEE_MULTIPLIER: u64 = 25; // 25 microcredits per constraint
142    /// The maximum number of variables in a deployment.
143    const MAX_DEPLOYMENT_VARIABLES: u64 = 1 << 21; // 2,097,152 variables
144    /// The maximum number of constraints in a deployment.
145    const MAX_DEPLOYMENT_CONSTRAINTS: u64 = 1 << 21; // 2,097,152 constraints
146    /// The maximum number of microcredits that can be spent as a fee.
147    const MAX_FEE: u64 = 1_000_000_000_000_000;
148    /// A list of consensus versions and their corresponding transaction spend limits in microcredits.
149    //  Note: This value must **not** decrease without considering the impact on transaction validity.
150    const TRANSACTION_SPEND_LIMIT: [(ConsensusVersion, u64); 2] =
151        [(ConsensusVersion::V1, 100_000_000), (ConsensusVersion::V10, 4_000_000)];
152    /// The compute discount approved by ARC 0005.
153    const ARC_0005_COMPUTE_DISCOUNT: u64 = 25;
154
155    /// The anchor height, defined as the expected number of blocks to reach the coinbase target.
156    const ANCHOR_HEIGHT: u32 = Self::ANCHOR_TIME as u32 / Self::BLOCK_TIME as u32;
157    /// The anchor time in seconds.
158    const ANCHOR_TIME: u16 = 25;
159    /// The expected time per block in seconds.
160    const BLOCK_TIME: u16 = 10;
161    /// The number of blocks per epoch.
162    const NUM_BLOCKS_PER_EPOCH: u32 = 3600 / Self::BLOCK_TIME as u32; // 360 blocks == ~1 hour
163
164    /// The maximum number of entries in data.
165    const MAX_DATA_ENTRIES: usize = 32;
166    /// The maximum recursive depth of an entry.
167    /// Note: This value must be strictly less than u8::MAX.
168    const MAX_DATA_DEPTH: usize = 32;
169    /// The maximum number of fields in data (must not exceed u16::MAX).
170    #[allow(clippy::cast_possible_truncation)]
171    const MAX_DATA_SIZE_IN_FIELDS: u32 = ((128 * 1024 * 8) / Field::<Self>::SIZE_IN_DATA_BITS) as u32;
172
173    /// The minimum number of entries in a struct.
174    const MIN_STRUCT_ENTRIES: usize = 1; // This ensures the struct is not empty.
175    /// The maximum number of entries in a struct.
176    const MAX_STRUCT_ENTRIES: usize = Self::MAX_DATA_ENTRIES;
177
178    /// The minimum number of elements in an array.
179    const MIN_ARRAY_ELEMENTS: usize = 1; // This ensures the array is not empty.
180    /// The maximum number of elements in an array.
181    const MAX_ARRAY_ELEMENTS: usize = 512;
182
183    /// The minimum number of entries in a record.
184    const MIN_RECORD_ENTRIES: usize = 1; // This accounts for 'record.owner'.
185    /// The maximum number of entries in a record.
186    const MAX_RECORD_ENTRIES: usize = Self::MIN_RECORD_ENTRIES.saturating_add(Self::MAX_DATA_ENTRIES);
187
188    /// The maximum program size by number of characters.
189    const MAX_PROGRAM_SIZE: usize = 100_000; // 100 KB
190
191    /// The maximum number of mappings in a program.
192    const MAX_MAPPINGS: usize = 31;
193    /// The maximum number of functions in a program.
194    const MAX_FUNCTIONS: usize = 31;
195    /// The maximum number of structs in a program.
196    const MAX_STRUCTS: usize = 10 * Self::MAX_FUNCTIONS;
197    /// The maximum number of records in a program.
198    const MAX_RECORDS: usize = 10 * Self::MAX_FUNCTIONS;
199    /// The maximum number of closures in a program.
200    const MAX_CLOSURES: usize = 2 * Self::MAX_FUNCTIONS;
201    /// The maximum number of operands in an instruction.
202    const MAX_OPERANDS: usize = Self::MAX_INPUTS;
203    /// The maximum number of instructions in a closure or function.
204    const MAX_INSTRUCTIONS: usize = u16::MAX as usize;
205    /// The maximum number of commands in finalize.
206    const MAX_COMMANDS: usize = u16::MAX as usize;
207    /// The maximum number of write commands in finalize.
208    const MAX_WRITES: u16 = 16;
209    /// The maximum number of `position` commands in finalize.
210    const MAX_POSITIONS: usize = u8::MAX as usize;
211
212    /// The maximum number of inputs per transition.
213    const MAX_INPUTS: usize = 16;
214    /// The maximum number of outputs per transition.
215    const MAX_OUTPUTS: usize = 16;
216
217    /// The maximum number of imports.
218    const MAX_IMPORTS: usize = 64;
219
220    /// The maximum number of bytes in a transaction.
221    // Note: This value must **not** be decreased as it would invalidate existing transactions.
222    const MAX_TRANSACTION_SIZE: usize = 128_000; // 128 kB
223
224    /// The state root type.
225    type StateRoot: Bech32ID<Field<Self>>;
226    /// The block hash type.
227    type BlockHash: Bech32ID<Field<Self>>;
228    /// The ratification ID type.
229    type RatificationID: Bech32ID<Field<Self>>;
230    /// The transaction ID type.
231    type TransactionID: Bech32ID<Field<Self>>;
232    /// The transition ID type.
233    type TransitionID: Bech32ID<Field<Self>>;
234    /// The transmission checksum type.
235    type TransmissionChecksum: IntegerType;
236
237    /// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
238    /// Documentation for what is changed at each version can be found in `N::CONSENSUS_VERSION`
239    /// Do not read this directly outside of tests, use `N::CONSENSUS_VERSION_HEIGHTS()` instead.
240    const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS];
241
242    ///  A list of (consensus_version, size) pairs indicating the maximum number of validators in a committee.
243    //  Note: This value must **not** decrease without considering the impact on serialization.
244    //  Decreasing this value will break backwards compatibility of serialization without explicit
245    //  declaration of migration based on round number rather than block height.
246    //  Increasing this value will require a migration to prevent forking during network upgrades.
247    const MAX_CERTIFICATES: [(ConsensusVersion, u16); 5];
248
249    /// Returns the list of consensus versions.
250    #[allow(non_snake_case)]
251    #[cfg(not(any(test, feature = "test", feature = "test_consensus_heights")))]
252    fn CONSENSUS_VERSION_HEIGHTS() -> &'static [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
253        // Initialize the consensus version heights directly from the constant.
254        CONSENSUS_VERSION_HEIGHTS.get_or_init(|| Self::_CONSENSUS_VERSION_HEIGHTS)
255    }
256    /// Returns the list of test consensus versions.
257    #[allow(non_snake_case)]
258    #[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
259    fn CONSENSUS_VERSION_HEIGHTS() -> &'static [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
260        CONSENSUS_VERSION_HEIGHTS.get_or_init(load_test_consensus_heights)
261    }
262
263    /// A set of incrementing consensus version heights used for tests.
264    #[allow(non_snake_case)]
265    #[cfg(any(test, feature = "test", feature = "test_consensus_heights"))]
266    const TEST_CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
267        TEST_CONSENSUS_VERSION_HEIGHTS;
268    /// Returns the consensus version which is active at the given height.
269    #[allow(non_snake_case)]
270    fn CONSENSUS_VERSION(seek_height: u32) -> anyhow::Result<ConsensusVersion> {
271        match Self::CONSENSUS_VERSION_HEIGHTS().binary_search_by(|(_, height)| height.cmp(&seek_height)) {
272            // If a consensus version was found at this height, return it.
273            Ok(index) => Ok(Self::CONSENSUS_VERSION_HEIGHTS()[index].0),
274            // If the specified height was not found, determine whether to return an appropriate version.
275            Err(index) => {
276                if index == 0 {
277                    Err(anyhow!("Expected consensus version 1 to exist at height 0."))
278                } else {
279                    // Return the appropriate version belonging to the height *lower* than the sought height.
280                    Ok(Self::CONSENSUS_VERSION_HEIGHTS()[index - 1].0)
281                }
282            }
283        }
284    }
285    /// Returns the height at which a specified consensus version becomes active.
286    #[allow(non_snake_case)]
287    fn CONSENSUS_HEIGHT(version: ConsensusVersion) -> Result<u32> {
288        Ok(Self::CONSENSUS_VERSION_HEIGHTS().get(version as usize - 1).ok_or(anyhow!("Invalid consensus version"))?.1)
289    }
290    /// Returns the last `MAX_CERTIFICATES` value.
291    #[allow(non_snake_case)]
292    fn LATEST_MAX_CERTIFICATES() -> Result<u16> {
293        Self::MAX_CERTIFICATES.last().map_or(Err(anyhow!("No MAX_CERTIFICATES defined.")), |(_, value)| Ok(*value))
294    }
295
296    /// Returns the block height where the the inclusion proof will be updated.
297    #[allow(non_snake_case)]
298    fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32>;
299
300    /// Returns the genesis block bytes.
301    fn genesis_bytes() -> &'static [u8];
302
303    /// Returns the restrictions list as a JSON-compatible string.
304    fn restrictions_list_as_str() -> &'static str;
305
306    /// Returns the proving key for the given function name in the v0 version of `credits.aleo`.
307    fn get_credits_v0_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>>;
308
309    /// Returns the verifying key for the given function name in the v0 version of `credits.aleo`.
310    fn get_credits_v0_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>>;
311
312    /// Returns the proving key for the given function name in `credits.aleo`.
313    fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>>;
314
315    /// Returns the verifying key for the given function name in `credits.aleo`.
316    fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>>;
317
318    #[cfg(not(feature = "wasm"))]
319    /// Returns the `proving key` for the inclusion_v0 circuit.
320    fn inclusion_v0_proving_key() -> &'static Arc<VarunaProvingKey<Self>>;
321
322    #[cfg(feature = "wasm")]
323    /// Returns the `proving key` for the inclusion_v0 circuit.
324    fn inclusion_v0_proving_key(bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>>;
325
326    /// Returns the `verifying key` for the inclusion_v0 circuit.
327    fn inclusion_v0_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>>;
328
329    #[cfg(not(feature = "wasm"))]
330    /// Returns the `proving key` for the inclusion circuit.
331    fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>>;
332
333    #[cfg(feature = "wasm")]
334    fn inclusion_proving_key(bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>>;
335
336    /// Returns the `verifying key` for the inclusion circuit.
337    fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>>;
338
339    /// Returns the powers of `G`.
340    fn g_powers() -> &'static Vec<Group<Self>>;
341
342    /// Returns the scalar multiplication on the generator `G`.
343    fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self>;
344
345    /// Returns the Varuna universal prover.
346    fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve>;
347
348    /// Returns the Varuna universal verifier.
349    fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve>;
350
351    /// Returns the sponge parameters for Varuna.
352    fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self>;
353
354    /// Returns the commitment domain as a constant field element.
355    fn commitment_domain() -> Field<Self>;
356
357    /// Returns the encryption domain as a constant field element.
358    fn encryption_domain() -> Field<Self>;
359
360    /// Returns the graph key domain as a constant field element.
361    fn graph_key_domain() -> Field<Self>;
362
363    /// Returns the serial number domain as a constant field element.
364    fn serial_number_domain() -> Field<Self>;
365
366    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
367    fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
368
369    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
370    fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
371
372    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
373    fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
374
375    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
376    fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
377
378    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
379    fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
380
381    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
382    fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>;
383
384    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
385    fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
386
387    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
388    fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
389
390    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
391    fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
392
393    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
394    fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
395
396    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
397    fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
398
399    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
400    fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>>;
401
402    /// Returns the BHP hash with an input hasher of 256-bits.
403    fn hash_bhp256(input: &[bool]) -> Result<Field<Self>>;
404
405    /// Returns the BHP hash with an input hasher of 512-bits.
406    fn hash_bhp512(input: &[bool]) -> Result<Field<Self>>;
407
408    /// Returns the BHP hash with an input hasher of 768-bits.
409    fn hash_bhp768(input: &[bool]) -> Result<Field<Self>>;
410
411    /// Returns the BHP hash with an input hasher of 1024-bits.
412    fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>>;
413
414    /// Returns the Keccak hash with a 256-bit output.
415    fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>>;
416
417    /// Returns the Keccak hash with a 384-bit output.
418    fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>>;
419
420    /// Returns the Keccak hash with a 512-bit output.
421    fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>>;
422
423    /// Returns the Pedersen hash for a given (up to) 64-bit input.
424    fn hash_ped64(input: &[bool]) -> Result<Field<Self>>;
425
426    /// Returns the Pedersen hash for a given (up to) 128-bit input.
427    fn hash_ped128(input: &[bool]) -> Result<Field<Self>>;
428
429    /// Returns the Poseidon hash with an input rate of 2.
430    fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>>;
431
432    /// Returns the Poseidon hash with an input rate of 4.
433    fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>>;
434
435    /// Returns the Poseidon hash with an input rate of 8.
436    fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>>;
437
438    /// Returns the SHA-3 hash with a 256-bit output.
439    fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>>;
440
441    /// Returns the SHA-3 hash with a 384-bit output.
442    fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>>;
443
444    /// Returns the SHA-3 hash with a 512-bit output.
445    fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>>;
446
447    /// Returns the extended Poseidon hash with an input rate of 2.
448    fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
449
450    /// Returns the extended Poseidon hash with an input rate of 4.
451    fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
452
453    /// Returns the extended Poseidon hash with an input rate of 8.
454    fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>>;
455
456    /// Returns the BHP hash with an input hasher of 256-bits.
457    fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>>;
458
459    /// Returns the BHP hash with an input hasher of 512-bits.
460    fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>>;
461
462    /// Returns the BHP hash with an input hasher of 768-bits.
463    fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>>;
464
465    /// Returns the BHP hash with an input hasher of 1024-bits.
466    fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>>;
467
468    /// Returns the Pedersen hash for a given (up to) 64-bit input.
469    fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>>;
470
471    /// Returns the Pedersen hash for a given (up to) 128-bit input.
472    fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>>;
473
474    /// Returns the Poseidon hash with an input rate of 2 on the affine curve.
475    fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>>;
476
477    /// Returns the Poseidon hash with an input rate of 4 on the affine curve.
478    fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>>;
479
480    /// Returns the Poseidon hash with an input rate of 8 on the affine curve.
481    fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>>;
482
483    /// Returns the Poseidon hash with an input rate of 2 on the scalar field.
484    fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>>;
485
486    /// Returns the Poseidon hash with an input rate of 4 on the scalar field.
487    fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>>;
488
489    /// Returns the Poseidon hash with an input rate of 8 on the scalar field.
490    fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>>;
491
492    /// Returns a Merkle tree with a BHP leaf hasher of 1024-bits and a BHP path hasher of 512-bits.
493    fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>>;
494
495    /// Returns a Merkle tree with a Poseidon leaf hasher with input rate of 4 and a Poseidon path hasher with input rate of 2.
496    fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>>;
497
498    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
499    #[allow(clippy::ptr_arg)]
500    fn verify_merkle_path_bhp<const DEPTH: u8>(
501        path: &MerklePath<Self, DEPTH>,
502        root: &Field<Self>,
503        leaf: &Vec<bool>,
504    ) -> bool;
505
506    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
507    #[allow(clippy::ptr_arg)]
508    fn verify_merkle_path_psd<const DEPTH: u8>(
509        path: &MerklePath<Self, DEPTH>,
510        root: &Field<Self>,
511        leaf: &Vec<Field<Self>>,
512    ) -> bool;
513}
514
515/// Returns the consensus version heights, initializing them if necessary.
516///
517/// If a `heights` string is provided, it must be a comma-separated list of ascending block heights
518/// starting from zero (e.g., `"0,2,3,4,..."`) with a number of heights exactly equal to the value
519/// of the Network trait's `NUM_CONSENSUS_VERSIONS` constant. These heights correspond to the
520/// activation block of each `ConsensusVersion`.
521///
522/// If `heights` is `None`, the function will use SnarkVM's default test consensus heights.
523///
524/// This function caches the initialized heights, and can be set only once. Further calls will
525/// return the cached heights.
526///
527/// This method should be called by `wasm` users who need to set test values for consensus heights
528/// for purposes such as testing on a local devnet. If this method needs to be used, it should be
529/// called immediately after the wasm module is initialized.
530#[cfg(feature = "wasm")]
531pub fn get_or_init_consensus_version_heights(
532    heights: Option<String>,
533) -> [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] {
534    let heights = load_test_consensus_heights_inner(heights);
535    *CONSENSUS_VERSION_HEIGHTS.get_or_init(|| heights)
536}