snarkvm_console_network/
mainnet_v0.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17use snarkvm_console_algorithms::{
18    BHP256,
19    BHP512,
20    BHP768,
21    BHP1024,
22    Blake2Xs,
23    Keccak256,
24    Keccak384,
25    Keccak512,
26    Pedersen64,
27    Pedersen128,
28    Poseidon2,
29    Poseidon4,
30    Poseidon8,
31    Sha3_256,
32    Sha3_384,
33    Sha3_512,
34};
35
36lazy_static! {
37    /// The group bases for the Aleo signature and encryption schemes.
38    pub static ref GENERATOR_G: Vec<Group<MainnetV0 >> = MainnetV0::new_bases("AleoAccountEncryptionAndSignatureScheme0");
39
40    /// The Varuna sponge parameters.
41    pub static ref VARUNA_FS_PARAMETERS: FiatShamirParameters<MainnetV0> = FiatShamir::<MainnetV0>::sample_parameters();
42
43    /// The encryption domain as a constant field element.
44    pub static ref ENCRYPTION_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoSymmetricEncryption0");
45    /// The graph key domain as a constant field element.
46    pub static ref GRAPH_KEY_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoGraphKey0");
47    /// The serial number domain as a constant field element.
48    pub static ref SERIAL_NUMBER_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoSerialNumber0");
49
50    /// The BHP hash function, which can take an input of up to 256 bits.
51    pub static ref BHP_256: BHP256<MainnetV0> = BHP256::<MainnetV0>::setup("AleoBHP256").expect("Failed to setup BHP256");
52    /// The BHP hash function, which can take an input of up to 512 bits.
53    pub static ref BHP_512: BHP512<MainnetV0> = BHP512::<MainnetV0>::setup("AleoBHP512").expect("Failed to setup BHP512");
54    /// The BHP hash function, which can take an input of up to 768 bits.
55    pub static ref BHP_768: BHP768<MainnetV0> = BHP768::<MainnetV0>::setup("AleoBHP768").expect("Failed to setup BHP768");
56    /// The BHP hash function, which can take an input of up to 1024 bits.
57    pub static ref BHP_1024: BHP1024<MainnetV0> = BHP1024::<MainnetV0>::setup("AleoBHP1024").expect("Failed to setup BHP1024");
58
59    /// The Pedersen hash function, which can take an input of up to 64 bits.
60    pub static ref PEDERSEN_64: Pedersen64<MainnetV0> = Pedersen64::<MainnetV0>::setup("AleoPedersen64");
61    /// The Pedersen hash function, which can take an input of up to 128 bits.
62    pub static ref PEDERSEN_128: Pedersen128<MainnetV0> = Pedersen128::<MainnetV0>::setup("AleoPedersen128");
63
64    /// The Poseidon hash function, using a rate of 2.
65    pub static ref POSEIDON_2: Poseidon2<MainnetV0> = Poseidon2::<MainnetV0>::setup("AleoPoseidon2").expect("Failed to setup Poseidon2");
66    /// The Poseidon hash function, using a rate of 4.
67    pub static ref POSEIDON_4: Poseidon4<MainnetV0> = Poseidon4::<MainnetV0>::setup("AleoPoseidon4").expect("Failed to setup Poseidon4");
68    /// The Poseidon hash function, using a rate of 8.
69    pub static ref POSEIDON_8: Poseidon8<MainnetV0> = Poseidon8::<MainnetV0>::setup("AleoPoseidon8").expect("Failed to setup Poseidon8");
70
71    pub static ref CREDITS_PROVING_KEYS: IndexMap<String, Arc<VarunaProvingKey<Console>>> = {
72        let mut map = IndexMap::new();
73        snarkvm_parameters::insert_credit_keys!(map, VarunaProvingKey<Console>, Prover);
74        map
75    };
76    pub static ref CREDITS_VERIFYING_KEYS: IndexMap<String, Arc<VarunaVerifyingKey<Console>>> = {
77        let mut map = IndexMap::new();
78        snarkvm_parameters::insert_credit_keys!(map, VarunaVerifyingKey<Console>, Verifier);
79        map
80    };
81}
82
83pub const TRANSACTION_PREFIX: &str = "at";
84
85#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
86pub struct MainnetV0;
87
88impl MainnetV0 {
89    /// Initializes a new instance of group bases from a given input domain message.
90    fn new_bases(message: &str) -> Vec<Group<Self>> {
91        // Hash the given message to a point on the curve, to initialize the starting base.
92        let (base, _, _) = Blake2Xs::hash_to_curve::<<Self as Environment>::Affine>(message);
93
94        // Compute the bases up to the size of the scalar field (in bits).
95        let mut g = Group::<Self>::new(base);
96        let mut g_bases = Vec::with_capacity(Scalar::<Self>::size_in_bits());
97        for _ in 0..Scalar::<Self>::size_in_bits() {
98            g_bases.push(g);
99            g = g.double();
100        }
101        g_bases
102    }
103}
104
105impl Environment for MainnetV0 {
106    type Affine = <Console as Environment>::Affine;
107    type BigInteger = <Console as Environment>::BigInteger;
108    type Field = <Console as Environment>::Field;
109    type PairingCurve = <Console as Environment>::PairingCurve;
110    type Projective = <Console as Environment>::Projective;
111    type Scalar = <Console as Environment>::Scalar;
112
113    /// The coefficient `A` of the twisted Edwards curve.
114    const EDWARDS_A: Self::Field = Console::EDWARDS_A;
115    /// The coefficient `D` of the twisted Edwards curve.
116    const EDWARDS_D: Self::Field = Console::EDWARDS_D;
117    /// The coefficient `A` of the Montgomery curve.
118    const MONTGOMERY_A: Self::Field = Console::MONTGOMERY_A;
119    /// The coefficient `B` of the Montgomery curve.
120    const MONTGOMERY_B: Self::Field = Console::MONTGOMERY_B;
121}
122
123impl Network for MainnetV0 {
124    /// The block hash type.
125    type BlockHash = AleoID<Field<Self>, { hrp2!("ab") }>;
126    /// The ratification ID type.
127    type RatificationID = AleoID<Field<Self>, { hrp2!("ar") }>;
128    /// The state root type.
129    type StateRoot = AleoID<Field<Self>, { hrp2!("sr") }>;
130    /// The transaction ID type.
131    type TransactionID = AleoID<Field<Self>, { hrp2!(TRANSACTION_PREFIX) }>;
132    /// The transition ID type.
133    type TransitionID = AleoID<Field<Self>, { hrp2!("au") }>;
134    /// The transmission checksum type.
135    type TransmissionChecksum = u128;
136
137    /// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
138    /// Documentation for what is changed at each version can be found in `N::CONSENSUS_VERSION`
139    #[cfg(not(any(test, feature = "test")))]
140    const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 4] = [
141        (ConsensusVersion::V1, 0),
142        (ConsensusVersion::V2, 2_800_000),
143        (ConsensusVersion::V3, 4_900_000),
144        (ConsensusVersion::V4, 6_135_000),
145    ];
146    /// A list of (consensus_version, block_height) pairs indicating when each consensus version takes effect.
147    /// Documentation for what is changed at each version can be found in `N::CONSENSUS_VERSION`
148    #[cfg(any(test, feature = "test"))]
149    const CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); 4] =
150        [(ConsensusVersion::V1, 0), (ConsensusVersion::V2, 10), (ConsensusVersion::V3, 11), (ConsensusVersion::V4, 12)];
151    /// The network edition.
152    const EDITION: u16 = 0;
153    /// The genesis block coinbase target.
154    #[cfg(not(feature = "test"))]
155    const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
156    /// The genesis block coinbase target.
157    /// This is deliberately set to a low value (32) for testing purposes only.
158    #[cfg(feature = "test")]
159    const GENESIS_COINBASE_TARGET: u64 = (1u64 << 5).saturating_sub(1);
160    /// The genesis block proof target.
161    #[cfg(not(feature = "test"))]
162    const GENESIS_PROOF_TARGET: u64 = 1u64 << 27;
163    /// The genesis block proof target.
164    /// This is deliberately set to a low value (8) for testing purposes only.
165    #[cfg(feature = "test")]
166    const GENESIS_PROOF_TARGET: u64 = 1u64 << 3;
167    /// The fixed timestamp of the genesis block.
168    const GENESIS_TIMESTAMP: i64 = 1725462000 /* 2024-09-04 11:00:00 UTC */;
169    /// The network ID.
170    const ID: u16 = 0;
171    /// The function name for the inclusion circuit.
172    const INCLUSION_FUNCTION_NAME: &'static str = snarkvm_parameters::mainnet::NETWORK_INCLUSION_FUNCTION_NAME;
173    /// A list of (consensus_version, size) pairs indicating the maximum number of certificates in a batch.
174    #[cfg(not(any(test, feature = "test")))]
175    const MAX_CERTIFICATES: [(ConsensusVersion, u16); 2] = [(ConsensusVersion::V1, 16), (ConsensusVersion::V3, 25)];
176    /// A list of (consensus_version, size) pairs indicating the maximum number of certificates in a batch.
177    #[cfg(any(test, feature = "test"))]
178    const MAX_CERTIFICATES: [(ConsensusVersion, u16); 2] = [(ConsensusVersion::V1, 100), (ConsensusVersion::V3, 100)];
179    /// The network name.
180    const NAME: &'static str = "Aleo Mainnet (v0)";
181
182    /// Returns the genesis block bytes.
183    fn genesis_bytes() -> &'static [u8] {
184        snarkvm_parameters::mainnet::GenesisBytes::load_bytes()
185    }
186
187    /// Returns the restrictions list as a JSON-compatible string.
188    fn restrictions_list_as_str() -> &'static str {
189        snarkvm_parameters::mainnet::RESTRICTIONS_LIST
190    }
191
192    /// Returns the proving key for the given function name in `credits.aleo`.
193    fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
194        CREDITS_PROVING_KEYS
195            .get(&function_name)
196            .ok_or_else(|| anyhow!("Proving key for credits.aleo/{function_name}' not found"))
197    }
198
199    /// Returns the verifying key for the given function name in `credits.aleo`.
200    fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
201        CREDITS_VERIFYING_KEYS
202            .get(&function_name)
203            .ok_or_else(|| anyhow!("Verifying key for credits.aleo/{function_name}' not found"))
204    }
205
206    /// Returns the `proving key` for the inclusion circuit.
207    fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
208        static INSTANCE: OnceCell<Arc<VarunaProvingKey<Console>>> = OnceCell::new();
209        INSTANCE.get_or_init(|| {
210            // Skipping the first byte, which is the encoded version.
211            Arc::new(
212                CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_PROVING_KEY[1..])
213                    .expect("Failed to load inclusion proving key."),
214            )
215        })
216    }
217
218    /// Returns the `verifying key` for the inclusion circuit.
219    fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
220        static INSTANCE: OnceCell<Arc<VarunaVerifyingKey<Console>>> = OnceCell::new();
221        INSTANCE.get_or_init(|| {
222            // Skipping the first byte, which is the encoded version.
223            Arc::new(
224                CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_VERIFYING_KEY[1..])
225                    .expect("Failed to load inclusion verifying key."),
226            )
227        })
228    }
229
230    /// Returns the powers of `G`.
231    fn g_powers() -> &'static Vec<Group<Self>> {
232        &GENERATOR_G
233    }
234
235    /// Returns the scalar multiplication on the generator `G`.
236    fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self> {
237        GENERATOR_G
238            .iter()
239            .zip_eq(&scalar.to_bits_le())
240            .filter_map(|(base, bit)| match bit {
241                true => Some(base),
242                false => None,
243            })
244            .sum()
245    }
246
247    /// Returns the Varuna universal prover.
248    fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve> {
249        static INSTANCE: OnceCell<UniversalProver<<Console as Environment>::PairingCurve>> = OnceCell::new();
250        INSTANCE.get_or_init(|| {
251            snarkvm_algorithms::polycommit::kzg10::UniversalParams::load()
252                .expect("Failed to load universal SRS (KZG10).")
253                .to_universal_prover()
254                .expect("Failed to convert universal SRS (KZG10) to the prover.")
255        })
256    }
257
258    /// Returns the Varuna universal verifier.
259    fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve> {
260        static INSTANCE: OnceCell<UniversalVerifier<<Console as Environment>::PairingCurve>> = OnceCell::new();
261        INSTANCE.get_or_init(|| {
262            snarkvm_algorithms::polycommit::kzg10::UniversalParams::load()
263                .expect("Failed to load universal SRS (KZG10).")
264                .to_universal_verifier()
265                .expect("Failed to convert universal SRS (KZG10) to the verifier.")
266        })
267    }
268
269    /// Returns the sponge parameters used for the sponge in the Varuna SNARK.
270    fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self> {
271        &VARUNA_FS_PARAMETERS
272    }
273
274    /// Returns the encryption domain as a constant field element.
275    fn encryption_domain() -> Field<Self> {
276        *ENCRYPTION_DOMAIN
277    }
278
279    /// Returns the graph key domain as a constant field element.
280    fn graph_key_domain() -> Field<Self> {
281        *GRAPH_KEY_DOMAIN
282    }
283
284    /// Returns the serial number domain as a constant field element.
285    fn serial_number_domain() -> Field<Self> {
286        *SERIAL_NUMBER_DOMAIN
287    }
288
289    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
290    fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
291        BHP_256.commit(input, randomizer)
292    }
293
294    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
295    fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
296        BHP_512.commit(input, randomizer)
297    }
298
299    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
300    fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
301        BHP_768.commit(input, randomizer)
302    }
303
304    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
305    fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
306        BHP_1024.commit(input, randomizer)
307    }
308
309    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
310    fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
311        PEDERSEN_64.commit(input, randomizer)
312    }
313
314    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
315    fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
316        PEDERSEN_128.commit(input, randomizer)
317    }
318
319    /// Returns a BHP commitment with an input hasher of 256-bits and randomizer.
320    fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
321        BHP_256.commit_uncompressed(input, randomizer)
322    }
323
324    /// Returns a BHP commitment with an input hasher of 512-bits and randomizer.
325    fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
326        BHP_512.commit_uncompressed(input, randomizer)
327    }
328
329    /// Returns a BHP commitment with an input hasher of 768-bits and randomizer.
330    fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
331        BHP_768.commit_uncompressed(input, randomizer)
332    }
333
334    /// Returns a BHP commitment with an input hasher of 1024-bits and randomizer.
335    fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
336        BHP_1024.commit_uncompressed(input, randomizer)
337    }
338
339    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
340    fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
341        PEDERSEN_64.commit_uncompressed(input, randomizer)
342    }
343
344    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
345    fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
346        PEDERSEN_128.commit_uncompressed(input, randomizer)
347    }
348
349    /// Returns the BHP hash with an input hasher of 256-bits.
350    fn hash_bhp256(input: &[bool]) -> Result<Field<Self>> {
351        BHP_256.hash(input)
352    }
353
354    /// Returns the BHP hash with an input hasher of 512-bits.
355    fn hash_bhp512(input: &[bool]) -> Result<Field<Self>> {
356        BHP_512.hash(input)
357    }
358
359    /// Returns the BHP hash with an input hasher of 768-bits.
360    fn hash_bhp768(input: &[bool]) -> Result<Field<Self>> {
361        BHP_768.hash(input)
362    }
363
364    /// Returns the BHP hash with an input hasher of 1024-bits.
365    fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>> {
366        BHP_1024.hash(input)
367    }
368
369    /// Returns the Keccak hash with a 256-bit output.
370    fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>> {
371        Keccak256::default().hash(input)
372    }
373
374    /// Returns the Keccak hash with a 384-bit output.
375    fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>> {
376        Keccak384::default().hash(input)
377    }
378
379    /// Returns the Keccak hash with a 512-bit output.
380    fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>> {
381        Keccak512::default().hash(input)
382    }
383
384    /// Returns the Pedersen hash for a given (up to) 64-bit input.
385    fn hash_ped64(input: &[bool]) -> Result<Field<Self>> {
386        PEDERSEN_64.hash(input)
387    }
388
389    /// Returns the Pedersen hash for a given (up to) 128-bit input.
390    fn hash_ped128(input: &[bool]) -> Result<Field<Self>> {
391        PEDERSEN_128.hash(input)
392    }
393
394    /// Returns the Poseidon hash with an input rate of 2.
395    fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>> {
396        POSEIDON_2.hash(input)
397    }
398
399    /// Returns the Poseidon hash with an input rate of 4.
400    fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>> {
401        POSEIDON_4.hash(input)
402    }
403
404    /// Returns the Poseidon hash with an input rate of 8.
405    fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>> {
406        POSEIDON_8.hash(input)
407    }
408
409    /// Returns the SHA-3 hash with a 256-bit output.
410    fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>> {
411        Sha3_256::default().hash(input)
412    }
413
414    /// Returns the SHA-3 hash with a 384-bit output.
415    fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>> {
416        Sha3_384::default().hash(input)
417    }
418
419    /// Returns the SHA-3 hash with a 512-bit output.
420    fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>> {
421        Sha3_512::default().hash(input)
422    }
423
424    /// Returns the extended Poseidon hash with an input rate of 2.
425    fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
426        POSEIDON_2.hash_many(input, num_outputs)
427    }
428
429    /// Returns the extended Poseidon hash with an input rate of 4.
430    fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
431        POSEIDON_4.hash_many(input, num_outputs)
432    }
433
434    /// Returns the extended Poseidon hash with an input rate of 8.
435    fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
436        POSEIDON_8.hash_many(input, num_outputs)
437    }
438
439    /// Returns the BHP hash with an input hasher of 256-bits.
440    fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>> {
441        BHP_256.hash_uncompressed(input)
442    }
443
444    /// Returns the BHP hash with an input hasher of 512-bits.
445    fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>> {
446        BHP_512.hash_uncompressed(input)
447    }
448
449    /// Returns the BHP hash with an input hasher of 768-bits.
450    fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>> {
451        BHP_768.hash_uncompressed(input)
452    }
453
454    /// Returns the BHP hash with an input hasher of 1024-bits.
455    fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>> {
456        BHP_1024.hash_uncompressed(input)
457    }
458
459    /// Returns the Pedersen hash for a given (up to) 64-bit input.
460    fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>> {
461        PEDERSEN_64.hash_uncompressed(input)
462    }
463
464    /// Returns the Pedersen hash for a given (up to) 128-bit input.
465    fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>> {
466        PEDERSEN_128.hash_uncompressed(input)
467    }
468
469    /// Returns the Poseidon hash with an input rate of 2 on the affine curve.
470    fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>> {
471        POSEIDON_2.hash_to_group(input)
472    }
473
474    /// Returns the Poseidon hash with an input rate of 4 on the affine curve.
475    fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>> {
476        POSEIDON_4.hash_to_group(input)
477    }
478
479    /// Returns the Poseidon hash with an input rate of 8 on the affine curve.
480    fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>> {
481        POSEIDON_8.hash_to_group(input)
482    }
483
484    /// Returns the Poseidon hash with an input rate of 2 on the scalar field.
485    fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>> {
486        POSEIDON_2.hash_to_scalar(input)
487    }
488
489    /// Returns the Poseidon hash with an input rate of 4 on the scalar field.
490    fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>> {
491        POSEIDON_4.hash_to_scalar(input)
492    }
493
494    /// Returns the Poseidon hash with an input rate of 8 on the scalar field.
495    fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>> {
496        POSEIDON_8.hash_to_scalar(input)
497    }
498
499    /// Returns a Merkle tree with a BHP leaf hasher of 1024-bits and a BHP path hasher of 512-bits.
500    fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>> {
501        MerkleTree::new(&*BHP_1024, &*BHP_512, leaves)
502    }
503
504    /// Returns a Merkle tree with a Poseidon leaf hasher with input rate of 4 and a Poseidon path hasher with input rate of 2.
505    fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>> {
506        MerkleTree::new(&*POSEIDON_4, &*POSEIDON_2, leaves)
507    }
508
509    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
510    fn verify_merkle_path_bhp<const DEPTH: u8>(
511        path: &MerklePath<Self, DEPTH>,
512        root: &Field<Self>,
513        leaf: &Vec<bool>,
514    ) -> bool {
515        path.verify(&*BHP_1024, &*BHP_512, root, leaf)
516    }
517
518    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
519    fn verify_merkle_path_psd<const DEPTH: u8>(
520        path: &MerklePath<Self, DEPTH>,
521        root: &Field<Self>,
522        leaf: &Vec<Field<Self>>,
523    ) -> bool {
524        path.verify(&*POSEIDON_4, &*POSEIDON_2, root, leaf)
525    }
526}
527
528#[cfg(test)]
529mod tests {
530    use super::*;
531
532    type CurrentNetwork = MainnetV0;
533
534    #[test]
535    fn test_g_scalar_multiply() {
536        // Compute G^r.
537        let scalar = Scalar::rand(&mut TestRng::default());
538        let group = CurrentNetwork::g_scalar_multiply(&scalar);
539        assert_eq!(group, CurrentNetwork::g_powers()[0] * scalar);
540    }
541}