1use 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 pub static ref GENERATOR_G: Vec<Group<MainnetV0 >> = MainnetV0::new_bases("AleoAccountEncryptionAndSignatureScheme0");
39
40 pub static ref VARUNA_FS_PARAMETERS: FiatShamirParameters<MainnetV0> = FiatShamir::<MainnetV0>::sample_parameters();
42
43 static ref COMMITMENT_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoCommitment0");
45 pub static ref ENCRYPTION_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoSymmetricEncryption0");
47 pub static ref GRAPH_KEY_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoGraphKey0");
49 pub static ref SERIAL_NUMBER_DOMAIN: Field<MainnetV0> = Field::<MainnetV0>::new_domain_separator("AleoSerialNumber0");
51
52 pub static ref BHP_256: BHP256<MainnetV0> = BHP256::<MainnetV0>::setup("AleoBHP256").expect("Failed to setup BHP256");
54 pub static ref BHP_512: BHP512<MainnetV0> = BHP512::<MainnetV0>::setup("AleoBHP512").expect("Failed to setup BHP512");
56 pub static ref BHP_768: BHP768<MainnetV0> = BHP768::<MainnetV0>::setup("AleoBHP768").expect("Failed to setup BHP768");
58 pub static ref BHP_1024: BHP1024<MainnetV0> = BHP1024::<MainnetV0>::setup("AleoBHP1024").expect("Failed to setup BHP1024");
60
61 pub static ref PEDERSEN_64: Pedersen64<MainnetV0> = Pedersen64::<MainnetV0>::setup("AleoPedersen64");
63 pub static ref PEDERSEN_128: Pedersen128<MainnetV0> = Pedersen128::<MainnetV0>::setup("AleoPedersen128");
65
66 pub static ref POSEIDON_2: Poseidon2<MainnetV0> = Poseidon2::<MainnetV0>::setup("AleoPoseidon2").expect("Failed to setup Poseidon2");
68 pub static ref POSEIDON_4: Poseidon4<MainnetV0> = Poseidon4::<MainnetV0>::setup("AleoPoseidon4").expect("Failed to setup Poseidon4");
70 pub static ref POSEIDON_8: Poseidon8<MainnetV0> = Poseidon8::<MainnetV0>::setup("AleoPoseidon8").expect("Failed to setup Poseidon8");
72
73 pub static ref DYNAMIC_RECORD_LEAF_HASHER: Poseidon8<MainnetV0> = Poseidon8::<MainnetV0>::setup("DynamicRecordLeafHasher").expect("Failed to setup DynamicRecordLeafHasher");
75 pub static ref DYNAMIC_RECORD_PATH_HASHER: Poseidon2<MainnetV0> = Poseidon2::<MainnetV0>::setup("DynamicRecordPathHasher").expect("Failed to setup DynamicRecordPathHasher");
77
78 pub static ref CREDITS_V0_PROVING_KEYS: IndexMap<String, Arc<VarunaProvingKey<Console>>> = {
79 let mut map = IndexMap::new();
80 snarkvm_parameters::insert_credit_v0_keys!(map, VarunaProvingKey<Console>, Prover);
81 map
82 };
83 pub static ref CREDITS_V0_VERIFYING_KEYS: IndexMap<String, Arc<VarunaVerifyingKey<Console>>> = {
84 let mut map = IndexMap::new();
85 snarkvm_parameters::insert_credit_v0_keys!(map, VarunaVerifyingKey<Console>, Verifier);
86 map
87 };
88
89 pub static ref CREDITS_PROVING_KEYS: IndexMap<String, Arc<VarunaProvingKey<Console>>> = {
90 let mut map = IndexMap::new();
91 snarkvm_parameters::insert_credit_keys!(map, VarunaProvingKey<Console>, Prover);
92 map
93 };
94 pub static ref CREDITS_VERIFYING_KEYS: IndexMap<String, Arc<VarunaVerifyingKey<Console>>> = {
95 let mut map = IndexMap::new();
96 snarkvm_parameters::insert_credit_keys!(map, VarunaVerifyingKey<Console>, Verifier);
97 map
98 };
99}
100
101pub const TRANSACTION_PREFIX: &str = "at";
102
103#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
104pub struct MainnetV0;
105
106impl MainnetV0 {
107 fn new_bases(message: &str) -> Vec<Group<Self>> {
109 let (base, _, _) = Blake2Xs::hash_to_curve::<<Self as Environment>::Affine>(message);
111
112 let mut g = Group::<Self>::new(base);
114 let mut g_bases = Vec::with_capacity(Scalar::<Self>::size_in_bits());
115 for _ in 0..Scalar::<Self>::size_in_bits() {
116 g_bases.push(g);
117 g = g.double();
118 }
119 g_bases
120 }
121}
122
123impl Environment for MainnetV0 {
124 type Affine = <Console as Environment>::Affine;
125 type BigInteger = <Console as Environment>::BigInteger;
126 type Field = <Console as Environment>::Field;
127 type PairingCurve = <Console as Environment>::PairingCurve;
128 type Projective = <Console as Environment>::Projective;
129 type Scalar = <Console as Environment>::Scalar;
130
131 const EDWARDS_A: Self::Field = Console::EDWARDS_A;
133 const EDWARDS_D: Self::Field = Console::EDWARDS_D;
135 const MONTGOMERY_A: Self::Field = Console::MONTGOMERY_A;
137 const MONTGOMERY_B: Self::Field = Console::MONTGOMERY_B;
139}
140
141impl Network for MainnetV0 {
142 type BlockHash = AleoID<Field<Self>, { hrp2!("ab") }>;
144 type RatificationID = AleoID<Field<Self>, { hrp2!("ar") }>;
146 type StateRoot = AleoID<Field<Self>, { hrp2!("sr") }>;
148 type TransactionID = AleoID<Field<Self>, { hrp2!(TRANSACTION_PREFIX) }>;
150 type TransitionID = AleoID<Field<Self>, { hrp2!("au") }>;
152 type TransmissionChecksum = u128;
154
155 #[cfg(not(feature = "test"))]
157 const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
158 #[cfg(feature = "test")]
161 const GENESIS_COINBASE_TARGET: u64 = (1u64 << 5).saturating_sub(1);
162 #[cfg(not(feature = "test"))]
164 const GENESIS_PROOF_TARGET: u64 = 1u64 << 27;
165 #[cfg(feature = "test")]
168 const GENESIS_PROOF_TARGET: u64 = 1u64 << 3;
169 const GENESIS_TIMESTAMP: i64 = 1725462000 ;
171 const ID: u16 = 0;
173 const INCLUSION_FUNCTION_NAME: &'static str = snarkvm_parameters::mainnet::NETWORK_INCLUSION_FUNCTION_NAME;
175 #[cfg(not(any(test, feature = "test")))]
177 const MAX_CERTIFICATES: [(ConsensusVersion, u16); 6] = [
178 (ConsensusVersion::V1, 16),
179 (ConsensusVersion::V3, 25),
180 (ConsensusVersion::V5, 30),
181 (ConsensusVersion::V6, 35),
182 (ConsensusVersion::V9, 40),
183 (ConsensusVersion::V20, 40),
184 ];
185 #[cfg(any(test, feature = "test"))]
187 const MAX_CERTIFICATES: [(ConsensusVersion, u16); 6] = [
188 (ConsensusVersion::V1, 100),
189 (ConsensusVersion::V3, 101),
190 (ConsensusVersion::V5, 102),
191 (ConsensusVersion::V6, 103),
192 (ConsensusVersion::V9, 104),
193 (ConsensusVersion::V20, 105),
194 ];
195 const NAME: &'static str = "Aleo Mainnet (v0)";
197 const SHORT_NAME: &'static str = "mainnet";
199 const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
203 MAINNET_V0_CONSENSUS_VERSION_HEIGHTS;
204
205 #[allow(non_snake_case)]
207 fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32> {
208 Self::CONSENSUS_HEIGHT(ConsensusVersion::V8)
209 }
210
211 fn genesis_bytes() -> &'static [u8] {
213 snarkvm_parameters::mainnet::GenesisBytes::load_bytes()
214 }
215
216 fn restrictions_list_as_str() -> &'static str {
218 snarkvm_parameters::mainnet::RESTRICTIONS_LIST
219 }
220
221 fn get_credits_v0_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
223 CREDITS_V0_PROVING_KEYS
224 .get(&function_name)
225 .ok_or_else(|| anyhow!("Proving key (v0) for credits.aleo/{function_name}' not found"))
226 }
227
228 fn get_credits_v0_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
230 CREDITS_V0_VERIFYING_KEYS
231 .get(&function_name)
232 .ok_or_else(|| anyhow!("Verifying key (v0) for credits_v0.aleo/{function_name}' not found"))
233 }
234
235 fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
237 CREDITS_PROVING_KEYS
238 .get(&function_name)
239 .ok_or_else(|| anyhow!("Proving key for credits.aleo/{function_name}' not found"))
240 }
241
242 fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
244 CREDITS_VERIFYING_KEYS
245 .get(&function_name)
246 .ok_or_else(|| anyhow!("Verifying key for credits.aleo/{function_name}' not found"))
247 }
248
249 #[cfg(not(feature = "wasm"))]
250 fn inclusion_v0_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
252 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
253 INSTANCE.get_or_init(|| {
254 Arc::new(
256 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_V0_PROVING_KEY[1..])
257 .expect("Failed to load inclusion_v0 proving key."),
258 )
259 })
260 }
261
262 #[cfg(feature = "wasm")]
263 fn inclusion_v0_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
265 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
266 INSTANCE.get_or_init(|| {
267 inclusion_key_bytes
268 .map(|bytes| {
269 snarkvm_parameters::mainnet::InclusionV0Prover::verify_bytes(&bytes)
270 .expect("Bytes provided did not match expected inclusion checksum.");
271 Arc::new(
272 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
273 )
274 })
275 .unwrap_or_else(|| {
276 Arc::new(
277 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_V0_PROVING_KEY[1..])
278 .expect("Failed to load inclusion proving key."),
279 )
280 })
281 })
282 }
283
284 fn inclusion_v0_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
286 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
287 INSTANCE.get_or_init(|| {
288 Arc::new(
290 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_V0_VERIFYING_KEY[1..])
291 .expect("Failed to load inclusion_v0 verifying key."),
292 )
293 })
294 }
295
296 #[cfg(not(feature = "wasm"))]
297 fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
299 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
300 INSTANCE.get_or_init(|| {
301 Arc::new(
303 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_PROVING_KEY[1..])
304 .expect("Failed to load inclusion proving key."),
305 )
306 })
307 }
308
309 #[cfg(feature = "wasm")]
310 fn inclusion_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
312 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
313 INSTANCE.get_or_init(|| {
314 inclusion_key_bytes
315 .map(|bytes| {
316 snarkvm_parameters::mainnet::InclusionProver::verify_bytes(&bytes)
317 .expect("Bytes provided did not match expected inclusion checksum.");
318 Arc::new(
319 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
320 )
321 })
322 .unwrap_or_else(|| {
323 Arc::new(
324 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_PROVING_KEY[1..])
325 .expect("Failed to load inclusion proving key."),
326 )
327 })
328 })
329 }
330
331 fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
333 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
334 INSTANCE.get_or_init(|| {
335 Arc::new(
337 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::mainnet::INCLUSION_VERIFYING_KEY[1..])
338 .expect("Failed to load inclusion verifying key."),
339 )
340 })
341 }
342
343 #[cfg(not(feature = "wasm"))]
344 fn translation_credits_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
346 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
347 INSTANCE.get_or_init(|| {
348 Arc::new(
350 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::mainnet::TRANSLATION_CREDITS_PROVING_KEY[1..])
351 .expect("Failed to load translation credits proving key."),
352 )
353 })
354 }
355
356 #[cfg(feature = "wasm")]
357 fn translation_credits_proving_key(
359 translation_credits_key_bytes: Option<Vec<u8>>,
360 ) -> &'static Arc<VarunaProvingKey<Self>> {
361 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
362 INSTANCE.get_or_init(|| {
363 translation_credits_key_bytes
364 .map(|bytes| {
365 snarkvm_parameters::mainnet::TranslationCreditsProver::verify_bytes(&bytes)
366 .expect("Bytes provided did not match expected translation credits checksum.");
367 Arc::new(
368 CircuitProvingKey::from_bytes_le(&bytes[1..])
369 .expect("Failed to load translation credits proving key."),
370 )
371 })
372 .unwrap_or_else(|| {
373 Arc::new(
374 CircuitProvingKey::from_bytes_le(
375 &snarkvm_parameters::mainnet::TRANSLATION_CREDITS_PROVING_KEY[1..],
376 )
377 .expect("Failed to load translation credits proving key."),
378 )
379 })
380 })
381 }
382
383 fn translation_credits_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
385 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
386 INSTANCE.get_or_init(|| {
387 Arc::new(
388 CircuitVerifyingKey::from_bytes_le(
389 &snarkvm_parameters::mainnet::TRANSLATION_CREDITS_VERIFYING_KEY[1..],
390 )
391 .expect("Failed to load translation verifying key."),
392 )
393 })
394 }
395
396 fn g_powers() -> &'static Vec<Group<Self>> {
398 &GENERATOR_G
399 }
400
401 fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self> {
403 GENERATOR_G
404 .iter()
405 .zip_eq(&scalar.to_bits_le())
406 .filter_map(|(base, bit)| match bit {
407 true => Some(base),
408 false => None,
409 })
410 .sum()
411 }
412
413 fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve> {
415 static INSTANCE: OnceLock<UniversalProver<<Console as Environment>::PairingCurve>> = OnceLock::new();
416 INSTANCE.get_or_init(|| {
417 snarkvm_algorithms::polycommit::kzg10::UniversalParams::load()
418 .expect("Failed to load universal SRS (KZG10).")
419 .to_universal_prover()
420 .expect("Failed to convert universal SRS (KZG10) to the prover.")
421 })
422 }
423
424 fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve> {
426 static INSTANCE: OnceLock<UniversalVerifier<<Console as Environment>::PairingCurve>> = OnceLock::new();
427 INSTANCE.get_or_init(|| {
428 snarkvm_algorithms::polycommit::kzg10::UniversalParams::load()
429 .expect("Failed to load universal SRS (KZG10).")
430 .to_universal_verifier()
431 .expect("Failed to convert universal SRS (KZG10) to the verifier.")
432 })
433 }
434
435 fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self> {
437 &VARUNA_FS_PARAMETERS
438 }
439
440 fn commitment_domain() -> Field<Self> {
442 *COMMITMENT_DOMAIN
443 }
444
445 fn encryption_domain() -> Field<Self> {
447 *ENCRYPTION_DOMAIN
448 }
449
450 fn graph_key_domain() -> Field<Self> {
452 *GRAPH_KEY_DOMAIN
453 }
454
455 fn serial_number_domain() -> Field<Self> {
457 *SERIAL_NUMBER_DOMAIN
458 }
459
460 fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
462 BHP_256.commit(input, randomizer)
463 }
464
465 fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
467 BHP_512.commit(input, randomizer)
468 }
469
470 fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
472 BHP_768.commit(input, randomizer)
473 }
474
475 fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
477 BHP_1024.commit(input, randomizer)
478 }
479
480 fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
482 PEDERSEN_64.commit(input, randomizer)
483 }
484
485 fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
487 PEDERSEN_128.commit(input, randomizer)
488 }
489
490 fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
492 BHP_256.commit_uncompressed(input, randomizer)
493 }
494
495 fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
497 BHP_512.commit_uncompressed(input, randomizer)
498 }
499
500 fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
502 BHP_768.commit_uncompressed(input, randomizer)
503 }
504
505 fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
507 BHP_1024.commit_uncompressed(input, randomizer)
508 }
509
510 fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
512 PEDERSEN_64.commit_uncompressed(input, randomizer)
513 }
514
515 fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
517 PEDERSEN_128.commit_uncompressed(input, randomizer)
518 }
519
520 fn hash_bhp256(input: &[bool]) -> Result<Field<Self>> {
522 BHP_256.hash(input)
523 }
524
525 fn hash_bhp512(input: &[bool]) -> Result<Field<Self>> {
527 BHP_512.hash(input)
528 }
529
530 fn hash_bhp768(input: &[bool]) -> Result<Field<Self>> {
532 BHP_768.hash(input)
533 }
534
535 fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>> {
537 BHP_1024.hash(input)
538 }
539
540 fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>> {
542 Keccak256::default().hash(input)
543 }
544
545 fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>> {
547 Keccak384::default().hash(input)
548 }
549
550 fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>> {
552 Keccak512::default().hash(input)
553 }
554
555 fn hash_ped64(input: &[bool]) -> Result<Field<Self>> {
557 PEDERSEN_64.hash(input)
558 }
559
560 fn hash_ped128(input: &[bool]) -> Result<Field<Self>> {
562 PEDERSEN_128.hash(input)
563 }
564
565 fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>> {
567 POSEIDON_2.hash(input)
568 }
569
570 fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>> {
572 POSEIDON_4.hash(input)
573 }
574
575 fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>> {
577 POSEIDON_8.hash(input)
578 }
579
580 fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>> {
582 Sha3_256::default().hash(input)
583 }
584
585 fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>> {
587 Sha3_384::default().hash(input)
588 }
589
590 fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>> {
592 Sha3_512::default().hash(input)
593 }
594
595 fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
597 POSEIDON_2.hash_many(input, num_outputs)
598 }
599
600 fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
602 POSEIDON_4.hash_many(input, num_outputs)
603 }
604
605 fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
607 POSEIDON_8.hash_many(input, num_outputs)
608 }
609
610 fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>> {
612 BHP_256.hash_uncompressed(input)
613 }
614
615 fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>> {
617 BHP_512.hash_uncompressed(input)
618 }
619
620 fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>> {
622 BHP_768.hash_uncompressed(input)
623 }
624
625 fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>> {
627 BHP_1024.hash_uncompressed(input)
628 }
629
630 fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>> {
632 PEDERSEN_64.hash_uncompressed(input)
633 }
634
635 fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>> {
637 PEDERSEN_128.hash_uncompressed(input)
638 }
639
640 fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>> {
642 POSEIDON_2.hash_to_group(input)
643 }
644
645 fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>> {
647 POSEIDON_4.hash_to_group(input)
648 }
649
650 fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>> {
652 POSEIDON_8.hash_to_group(input)
653 }
654
655 fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>> {
657 POSEIDON_2.hash_to_scalar(input)
658 }
659
660 fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>> {
662 POSEIDON_4.hash_to_scalar(input)
663 }
664
665 fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>> {
667 POSEIDON_8.hash_to_scalar(input)
668 }
669
670 fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>> {
672 MerkleTree::new(&*BHP_1024, &*BHP_512, leaves)
673 }
674
675 fn merkle_tree_bhp_from_state<const DEPTH: u8>(
678 state: MerkleTreeState<'_, Self>,
679 ) -> Result<BHPMerkleTree<Self, DEPTH>> {
680 MerkleTree::from_state(&*BHP_1024, &*BHP_512, state)
681 }
682
683 fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>> {
685 MerkleTree::new(&*POSEIDON_4, &*POSEIDON_2, leaves)
686 }
687
688 fn verify_merkle_path_bhp<const DEPTH: u8>(
690 path: &MerklePath<Self, DEPTH>,
691 root: &Field<Self>,
692 leaf: &Vec<bool>,
693 ) -> bool {
694 path.verify(&*BHP_1024, &*BHP_512, root, leaf)
695 }
696
697 fn verify_merkle_path_psd<const DEPTH: u8>(
699 path: &MerklePath<Self, DEPTH>,
700 root: &Field<Self>,
701 leaf: &Vec<Field<Self>>,
702 ) -> bool {
703 path.verify(&*POSEIDON_4, &*POSEIDON_2, root, leaf)
704 }
705
706 fn dynamic_record_leaf_hasher() -> &'static Poseidon8<Self> {
708 &DYNAMIC_RECORD_LEAF_HASHER
709 }
710
711 fn dynamic_record_path_hasher() -> &'static Poseidon2<Self> {
713 &DYNAMIC_RECORD_PATH_HASHER
714 }
715}
716
717#[cfg(test)]
718mod tests {
719 use super::*;
720
721 type CurrentNetwork = MainnetV0;
722
723 #[test]
724 fn test_g_scalar_multiply() {
725 let scalar = Scalar::rand(&mut TestRng::default());
727 let group = CurrentNetwork::g_scalar_multiply(&scalar);
728 assert_eq!(group, CurrentNetwork::g_powers()[0] * scalar);
729 }
730}