1use super::*;
17use crate::TRANSACTION_PREFIX;
18use snarkvm_console_algorithms::{
19 BHP256,
20 BHP512,
21 BHP768,
22 BHP1024,
23 Blake2Xs,
24 Keccak256,
25 Keccak384,
26 Keccak512,
27 Pedersen64,
28 Pedersen128,
29 Poseidon2,
30 Poseidon4,
31 Poseidon8,
32 Sha3_256,
33 Sha3_384,
34 Sha3_512,
35};
36
37lazy_static! {
38 static ref GENERATOR_G: Vec<Group<CanaryV0 >> = CanaryV0::new_bases("AleoAccountEncryptionAndSignatureScheme0");
40
41 static ref VARUNA_FS_PARAMETERS: FiatShamirParameters<CanaryV0> = FiatShamir::<CanaryV0>::sample_parameters();
43
44 static ref COMMITMENT_DOMAIN: Field<CanaryV0> = Field::<CanaryV0>::new_domain_separator("AleoCommitment0");
46 static ref ENCRYPTION_DOMAIN: Field<CanaryV0> = Field::<CanaryV0>::new_domain_separator("AleoSymmetricEncryption0");
48 static ref GRAPH_KEY_DOMAIN: Field<CanaryV0> = Field::<CanaryV0>::new_domain_separator("AleoGraphKey0");
50 static ref SERIAL_NUMBER_DOMAIN: Field<CanaryV0> = Field::<CanaryV0>::new_domain_separator("AleoSerialNumber0");
52
53 pub static ref CANARY_BHP_256: BHP256<CanaryV0> = BHP256::<CanaryV0>::setup("AleoBHP256").expect("Failed to setup BHP256");
55 pub static ref CANARY_BHP_512: BHP512<CanaryV0> = BHP512::<CanaryV0>::setup("AleoBHP512").expect("Failed to setup BHP512");
57 pub static ref CANARY_BHP_768: BHP768<CanaryV0> = BHP768::<CanaryV0>::setup("AleoBHP768").expect("Failed to setup BHP768");
59 pub static ref CANARY_BHP_1024: BHP1024<CanaryV0> = BHP1024::<CanaryV0>::setup("AleoBHP1024").expect("Failed to setup BHP1024");
61
62 pub static ref CANARY_PEDERSEN_64: Pedersen64<CanaryV0> = Pedersen64::<CanaryV0>::setup("AleoPedersen64");
64 pub static ref CANARY_PEDERSEN_128: Pedersen128<CanaryV0> = Pedersen128::<CanaryV0>::setup("AleoPedersen128");
66
67 pub static ref CANARY_POSEIDON_2: Poseidon2<CanaryV0> = Poseidon2::<CanaryV0>::setup("AleoPoseidon2").expect("Failed to setup Poseidon2");
69 pub static ref CANARY_POSEIDON_4: Poseidon4<CanaryV0> = Poseidon4::<CanaryV0>::setup("AleoPoseidon4").expect("Failed to setup Poseidon4");
71 pub static ref CANARY_POSEIDON_8: Poseidon8<CanaryV0> = Poseidon8::<CanaryV0>::setup("AleoPoseidon8").expect("Failed to setup Poseidon8");
73
74 pub static ref CANARY_DYNAMIC_RECORD_LEAF_HASHER: Poseidon8<CanaryV0> = Poseidon8::<CanaryV0>::setup("DynamicRecordLeafHasher").expect("Failed to setup DynamicRecordLeafHasher");
76 pub static ref CANARY_DYNAMIC_RECORD_PATH_HASHER: Poseidon2<CanaryV0> = Poseidon2::<CanaryV0>::setup("DynamicRecordPathHasher").expect("Failed to setup DynamicRecordPathHasher");
78
79 pub static ref CANARY_CREDITS_V0_PROVING_KEYS: IndexMap<String, Arc<VarunaProvingKey<Console>>> = {
80 let mut map = IndexMap::new();
81 snarkvm_parameters::insert_canary_credit_v0_keys!(map, VarunaProvingKey<Console>, Prover);
82 map
83 };
84 pub static ref CANARY_CREDITS_V0_VERIFYING_KEYS: IndexMap<String, Arc<VarunaVerifyingKey<Console>>> = {
85 let mut map = IndexMap::new();
86 snarkvm_parameters::insert_canary_credit_v0_keys!(map, VarunaVerifyingKey<Console>, Verifier);
87 map
88 };
89
90 pub static ref CANARY_CREDITS_PROVING_KEYS: IndexMap<String, Arc<VarunaProvingKey<Console>>> = {
91 let mut map = IndexMap::new();
92 snarkvm_parameters::insert_canary_credit_keys!(map, VarunaProvingKey<Console>, Prover);
93 map
94 };
95 pub static ref CANARY_CREDITS_VERIFYING_KEYS: IndexMap<String, Arc<VarunaVerifyingKey<Console>>> = {
96 let mut map = IndexMap::new();
97 snarkvm_parameters::insert_canary_credit_keys!(map, VarunaVerifyingKey<Console>, Verifier);
98 map
99 };
100}
101
102#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
103pub struct CanaryV0;
104
105impl CanaryV0 {
106 fn new_bases(message: &str) -> Vec<Group<Self>> {
108 let (base, _, _) = Blake2Xs::hash_to_curve::<<Self as Environment>::Affine>(message);
110
111 let mut g = Group::<Self>::new(base);
113 let mut g_bases = Vec::with_capacity(Scalar::<Self>::size_in_bits());
114 for _ in 0..Scalar::<Self>::size_in_bits() {
115 g_bases.push(g);
116 g = g.double();
117 }
118 g_bases
119 }
120}
121
122impl Environment for CanaryV0 {
123 type Affine = <Console as Environment>::Affine;
124 type BigInteger = <Console as Environment>::BigInteger;
125 type Field = <Console as Environment>::Field;
126 type PairingCurve = <Console as Environment>::PairingCurve;
127 type Projective = <Console as Environment>::Projective;
128 type Scalar = <Console as Environment>::Scalar;
129
130 const EDWARDS_A: Self::Field = Console::EDWARDS_A;
132 const EDWARDS_D: Self::Field = Console::EDWARDS_D;
134 const MONTGOMERY_A: Self::Field = Console::MONTGOMERY_A;
136 const MONTGOMERY_B: Self::Field = Console::MONTGOMERY_B;
138}
139
140impl Network for CanaryV0 {
141 type BlockHash = AleoID<Field<Self>, { hrp2!("ab") }>;
143 type RatificationID = AleoID<Field<Self>, { hrp2!("ar") }>;
145 type StateRoot = AleoID<Field<Self>, { hrp2!("sr") }>;
147 type TransactionID = AleoID<Field<Self>, { hrp2!(TRANSACTION_PREFIX) }>;
149 type TransitionID = AleoID<Field<Self>, { hrp2!("au") }>;
151 type TransmissionChecksum = u128;
153
154 #[cfg(not(feature = "test_targets"))]
156 const GENESIS_COINBASE_TARGET: u64 = (1u64 << 29).saturating_sub(1);
157 #[cfg(feature = "test_targets")]
158 const GENESIS_COINBASE_TARGET: u64 = (1u64 << 5).saturating_sub(1);
159 #[cfg(not(feature = "test_targets"))]
161 const GENESIS_PROOF_TARGET: u64 = 1u64 << 27;
162 #[cfg(feature = "test_targets")]
163 const GENESIS_PROOF_TARGET: u64 = 1u64 << 3;
164 const GENESIS_TIMESTAMP: i64 = 1715776496 ;
166 const ID: u16 = 2;
168 const INCLUSION_FUNCTION_NAME: &'static str = snarkvm_parameters::canary::NETWORK_INCLUSION_FUNCTION_NAME;
170 #[cfg(not(any(test, feature = "test")))]
172 const MAX_CERTIFICATES: [(ConsensusVersion, u16); 5] = [
173 (ConsensusVersion::V1, 100),
174 (ConsensusVersion::V3, 100),
175 (ConsensusVersion::V5, 100),
176 (ConsensusVersion::V6, 100),
177 (ConsensusVersion::V9, 100),
178 ];
179 #[cfg(any(test, feature = "test"))]
181 const MAX_CERTIFICATES: [(ConsensusVersion, u16); 5] = [
182 (ConsensusVersion::V1, 25),
183 (ConsensusVersion::V3, 25),
184 (ConsensusVersion::V5, 25),
185 (ConsensusVersion::V6, 25),
186 (ConsensusVersion::V9, 25),
187 ];
188 const NAME: &'static str = "Aleo Canary (v0)";
190 const SHORT_NAME: &'static str = "canary";
192 const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
196 CANARY_V0_CONSENSUS_VERSION_HEIGHTS;
197
198 #[allow(non_snake_case)]
200 fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32> {
201 Self::CONSENSUS_HEIGHT(ConsensusVersion::V8)
202 }
203
204 fn genesis_bytes() -> &'static [u8] {
206 snarkvm_parameters::canary::GenesisBytes::load_bytes()
207 }
208
209 fn restrictions_list_as_str() -> &'static str {
211 snarkvm_parameters::canary::RESTRICTIONS_LIST
212 }
213
214 fn get_credits_v0_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
216 CANARY_CREDITS_V0_PROVING_KEYS
217 .get(&function_name)
218 .ok_or_else(|| anyhow!("Proving key (v0) for credits.aleo/{function_name}' not found"))
219 }
220
221 fn get_credits_v0_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
223 CANARY_CREDITS_V0_VERIFYING_KEYS
224 .get(&function_name)
225 .ok_or_else(|| anyhow!("Verifying key (v0) for credits_v0.aleo/{function_name}' not found"))
226 }
227
228 fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
230 CANARY_CREDITS_PROVING_KEYS
231 .get(&function_name)
232 .ok_or_else(|| anyhow!("Proving key for credits.aleo/{function_name}' not found"))
233 }
234
235 fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
237 CANARY_CREDITS_VERIFYING_KEYS
238 .get(&function_name)
239 .ok_or_else(|| anyhow!("Verifying key for credits.aleo/{function_name}' not found"))
240 }
241
242 #[cfg(not(feature = "wasm"))]
243 fn inclusion_v0_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
245 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
246 INSTANCE.get_or_init(|| {
247 Arc::new(
249 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_PROVING_KEY[1..])
250 .expect("Failed to load inclusion_v0 proving key."),
251 )
252 })
253 }
254
255 #[cfg(feature = "wasm")]
256 fn inclusion_v0_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
258 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
259 INSTANCE.get_or_init(|| {
260 inclusion_key_bytes
261 .map(|bytes| {
262 snarkvm_parameters::canary::InclusionV0Prover::verify_bytes(&bytes)
263 .expect("Bytes provided did not match expected inclusion checksum.");
264 Arc::new(
265 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
266 )
267 })
268 .unwrap_or_else(|| {
269 Arc::new(
270 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_PROVING_KEY[1..])
271 .expect("Failed to load inclusion proving key."),
272 )
273 })
274 })
275 }
276
277 fn inclusion_v0_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
279 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
280 INSTANCE.get_or_init(|| {
281 Arc::new(
283 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_VERIFYING_KEY[1..])
284 .expect("Failed to load inclusion_v0 verifying key."),
285 )
286 })
287 }
288
289 #[cfg(not(feature = "wasm"))]
290 fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
292 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
293 INSTANCE.get_or_init(|| {
294 Arc::new(
296 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_PROVING_KEY[1..])
297 .expect("Failed to load inclusion proving key."),
298 )
299 })
300 }
301
302 #[cfg(feature = "wasm")]
303 fn inclusion_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
305 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
306 INSTANCE.get_or_init(|| {
307 inclusion_key_bytes
308 .map(|bytes| {
309 snarkvm_parameters::canary::InclusionProver::verify_bytes(&bytes)
310 .expect("Bytes provided did not match expected inclusion checksum.");
311 Arc::new(
312 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
313 )
314 })
315 .unwrap_or_else(|| {
316 Arc::new(
317 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_PROVING_KEY[1..])
318 .expect("Failed to load inclusion proving key."),
319 )
320 })
321 })
322 }
323
324 fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
326 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
327 INSTANCE.get_or_init(|| {
328 Arc::new(
330 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_VERIFYING_KEY[1..])
331 .expect("Failed to load inclusion verifying key."),
332 )
333 })
334 }
335
336 #[cfg(not(feature = "wasm"))]
337 fn translation_credits_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
339 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
340 INSTANCE.get_or_init(|| {
341 Arc::new(
343 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::TRANSLATION_CREDITS_PROVING_KEY[1..])
344 .expect("Failed to load translation credits proving key."),
345 )
346 })
347 }
348
349 #[cfg(feature = "wasm")]
350 fn translation_credits_proving_key(
352 translation_credits_key_bytes: Option<Vec<u8>>,
353 ) -> &'static Arc<VarunaProvingKey<Self>> {
354 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
355 INSTANCE.get_or_init(|| {
356 translation_credits_key_bytes
357 .map(|bytes| {
358 snarkvm_parameters::canary::TranslationCreditsProver::verify_bytes(&bytes)
359 .expect("Bytes provided did not match expected translation credits checksum.");
360 Arc::new(
361 CircuitProvingKey::from_bytes_le(&bytes[1..])
362 .expect("Failed to load translation credits proving key."),
363 )
364 })
365 .unwrap_or_else(|| {
366 Arc::new(
367 CircuitProvingKey::from_bytes_le(
368 &snarkvm_parameters::canary::TRANSLATION_CREDITS_PROVING_KEY[1..],
369 )
370 .expect("Failed to load translation credits proving key."),
371 )
372 })
373 })
374 }
375
376 fn translation_credits_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
378 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
379 INSTANCE.get_or_init(|| {
380 Arc::new(
381 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::TRANSLATION_CREDITS_VERIFYING_KEY[1..])
382 .expect("Failed to load translation verifying key."),
383 )
384 })
385 }
386
387 fn g_powers() -> &'static Vec<Group<Self>> {
389 &GENERATOR_G
390 }
391
392 fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self> {
394 GENERATOR_G
395 .iter()
396 .zip_eq(&scalar.to_bits_le())
397 .filter_map(|(base, bit)| match bit {
398 true => Some(base),
399 false => None,
400 })
401 .sum()
402 }
403
404 fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve> {
406 MainnetV0::varuna_universal_prover()
407 }
408
409 fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve> {
411 MainnetV0::varuna_universal_verifier()
412 }
413
414 fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self> {
416 &VARUNA_FS_PARAMETERS
417 }
418
419 fn commitment_domain() -> Field<Self> {
421 *COMMITMENT_DOMAIN
422 }
423
424 fn encryption_domain() -> Field<Self> {
426 *ENCRYPTION_DOMAIN
427 }
428
429 fn graph_key_domain() -> Field<Self> {
431 *GRAPH_KEY_DOMAIN
432 }
433
434 fn serial_number_domain() -> Field<Self> {
436 *SERIAL_NUMBER_DOMAIN
437 }
438
439 fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
441 CANARY_BHP_256.commit(input, randomizer)
442 }
443
444 fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
446 CANARY_BHP_512.commit(input, randomizer)
447 }
448
449 fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
451 CANARY_BHP_768.commit(input, randomizer)
452 }
453
454 fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
456 CANARY_BHP_1024.commit(input, randomizer)
457 }
458
459 fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
461 CANARY_PEDERSEN_64.commit(input, randomizer)
462 }
463
464 fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
466 CANARY_PEDERSEN_128.commit(input, randomizer)
467 }
468
469 fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
471 CANARY_BHP_256.commit_uncompressed(input, randomizer)
472 }
473
474 fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
476 CANARY_BHP_512.commit_uncompressed(input, randomizer)
477 }
478
479 fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
481 CANARY_BHP_768.commit_uncompressed(input, randomizer)
482 }
483
484 fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
486 CANARY_BHP_1024.commit_uncompressed(input, randomizer)
487 }
488
489 fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
491 CANARY_PEDERSEN_64.commit_uncompressed(input, randomizer)
492 }
493
494 fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
496 CANARY_PEDERSEN_128.commit_uncompressed(input, randomizer)
497 }
498
499 fn hash_bhp256(input: &[bool]) -> Result<Field<Self>> {
501 CANARY_BHP_256.hash(input)
502 }
503
504 fn hash_bhp512(input: &[bool]) -> Result<Field<Self>> {
506 CANARY_BHP_512.hash(input)
507 }
508
509 fn hash_bhp768(input: &[bool]) -> Result<Field<Self>> {
511 CANARY_BHP_768.hash(input)
512 }
513
514 fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>> {
516 CANARY_BHP_1024.hash(input)
517 }
518
519 fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>> {
521 Keccak256::default().hash(input)
522 }
523
524 fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>> {
526 Keccak384::default().hash(input)
527 }
528
529 fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>> {
531 Keccak512::default().hash(input)
532 }
533
534 fn hash_ped64(input: &[bool]) -> Result<Field<Self>> {
536 CANARY_PEDERSEN_64.hash(input)
537 }
538
539 fn hash_ped128(input: &[bool]) -> Result<Field<Self>> {
541 CANARY_PEDERSEN_128.hash(input)
542 }
543
544 fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>> {
546 CANARY_POSEIDON_2.hash(input)
547 }
548
549 fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>> {
551 CANARY_POSEIDON_4.hash(input)
552 }
553
554 fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>> {
556 CANARY_POSEIDON_8.hash(input)
557 }
558
559 fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>> {
561 Sha3_256::default().hash(input)
562 }
563
564 fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>> {
566 Sha3_384::default().hash(input)
567 }
568
569 fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>> {
571 Sha3_512::default().hash(input)
572 }
573
574 fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
576 CANARY_POSEIDON_2.hash_many(input, num_outputs)
577 }
578
579 fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
581 CANARY_POSEIDON_4.hash_many(input, num_outputs)
582 }
583
584 fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
586 CANARY_POSEIDON_8.hash_many(input, num_outputs)
587 }
588
589 fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>> {
591 CANARY_BHP_256.hash_uncompressed(input)
592 }
593
594 fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>> {
596 CANARY_BHP_512.hash_uncompressed(input)
597 }
598
599 fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>> {
601 CANARY_BHP_768.hash_uncompressed(input)
602 }
603
604 fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>> {
606 CANARY_BHP_1024.hash_uncompressed(input)
607 }
608
609 fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>> {
611 CANARY_PEDERSEN_64.hash_uncompressed(input)
612 }
613
614 fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>> {
616 CANARY_PEDERSEN_128.hash_uncompressed(input)
617 }
618
619 fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>> {
621 CANARY_POSEIDON_2.hash_to_group(input)
622 }
623
624 fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>> {
626 CANARY_POSEIDON_4.hash_to_group(input)
627 }
628
629 fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>> {
631 CANARY_POSEIDON_8.hash_to_group(input)
632 }
633
634 fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>> {
636 CANARY_POSEIDON_2.hash_to_scalar(input)
637 }
638
639 fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>> {
641 CANARY_POSEIDON_4.hash_to_scalar(input)
642 }
643
644 fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>> {
646 CANARY_POSEIDON_8.hash_to_scalar(input)
647 }
648
649 fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>> {
651 MerkleTree::new(&*CANARY_BHP_1024, &*CANARY_BHP_512, leaves)
652 }
653
654 fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>> {
656 MerkleTree::new(&*CANARY_POSEIDON_4, &*CANARY_POSEIDON_2, leaves)
657 }
658
659 fn verify_merkle_path_bhp<const DEPTH: u8>(
661 path: &MerklePath<Self, DEPTH>,
662 root: &Field<Self>,
663 leaf: &Vec<bool>,
664 ) -> bool {
665 path.verify(&*CANARY_BHP_1024, &*CANARY_BHP_512, root, leaf)
666 }
667
668 fn verify_merkle_path_psd<const DEPTH: u8>(
670 path: &MerklePath<Self, DEPTH>,
671 root: &Field<Self>,
672 leaf: &Vec<Field<Self>>,
673 ) -> bool {
674 path.verify(&*CANARY_POSEIDON_4, &*CANARY_POSEIDON_2, root, leaf)
675 }
676
677 fn dynamic_record_leaf_hasher() -> &'static Poseidon8<Self> {
679 &CANARY_DYNAMIC_RECORD_LEAF_HASHER
680 }
681
682 fn dynamic_record_path_hasher() -> &'static Poseidon2<Self> {
684 &CANARY_DYNAMIC_RECORD_PATH_HASHER
685 }
686}
687
688#[cfg(test)]
689mod tests {
690 use super::*;
691
692 type CurrentNetwork = CanaryV0;
693
694 #[test]
695 fn test_g_scalar_multiply() {
696 let scalar = Scalar::rand(&mut TestRng::default());
698 let group = CurrentNetwork::g_scalar_multiply(&scalar);
699 assert_eq!(group, CurrentNetwork::g_powers()[0] * scalar);
700 }
701}