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); 6] = [
173 (ConsensusVersion::V1, 100),
174 (ConsensusVersion::V3, 100),
175 (ConsensusVersion::V5, 100),
176 (ConsensusVersion::V6, 100),
177 (ConsensusVersion::V9, 100),
178 (ConsensusVersion::V20, 100),
179 ];
180 #[cfg(any(test, feature = "test"))]
182 const MAX_CERTIFICATES: [(ConsensusVersion, u16); 6] = [
183 (ConsensusVersion::V1, 25),
184 (ConsensusVersion::V3, 25),
185 (ConsensusVersion::V5, 25),
186 (ConsensusVersion::V6, 25),
187 (ConsensusVersion::V9, 25),
188 (ConsensusVersion::V20, 25),
189 ];
190 const NAME: &'static str = "Aleo Canary (v0)";
192 const SHORT_NAME: &'static str = "canary";
194 const _CONSENSUS_VERSION_HEIGHTS: [(ConsensusVersion, u32); NUM_CONSENSUS_VERSIONS] =
198 CANARY_V0_CONSENSUS_VERSION_HEIGHTS;
199
200 #[allow(non_snake_case)]
202 fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32> {
203 Self::CONSENSUS_HEIGHT(ConsensusVersion::V8)
204 }
205
206 fn genesis_bytes() -> &'static [u8] {
208 snarkvm_parameters::canary::GenesisBytes::load_bytes()
209 }
210
211 fn restrictions_list_as_str() -> &'static str {
213 snarkvm_parameters::canary::RESTRICTIONS_LIST
214 }
215
216 fn get_credits_v0_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
218 CANARY_CREDITS_V0_PROVING_KEYS
219 .get(&function_name)
220 .ok_or_else(|| anyhow!("Proving key (v0) for credits.aleo/{function_name}' not found"))
221 }
222
223 fn get_credits_v0_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
225 CANARY_CREDITS_V0_VERIFYING_KEYS
226 .get(&function_name)
227 .ok_or_else(|| anyhow!("Verifying key (v0) for credits_v0.aleo/{function_name}' not found"))
228 }
229
230 fn get_credits_proving_key(function_name: String) -> Result<&'static Arc<VarunaProvingKey<Self>>> {
232 CANARY_CREDITS_PROVING_KEYS
233 .get(&function_name)
234 .ok_or_else(|| anyhow!("Proving key for credits.aleo/{function_name}' not found"))
235 }
236
237 fn get_credits_verifying_key(function_name: String) -> Result<&'static Arc<VarunaVerifyingKey<Self>>> {
239 CANARY_CREDITS_VERIFYING_KEYS
240 .get(&function_name)
241 .ok_or_else(|| anyhow!("Verifying key for credits.aleo/{function_name}' not found"))
242 }
243
244 #[cfg(not(feature = "wasm"))]
245 fn inclusion_v0_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
247 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
248 INSTANCE.get_or_init(|| {
249 Arc::new(
251 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_PROVING_KEY[1..])
252 .expect("Failed to load inclusion_v0 proving key."),
253 )
254 })
255 }
256
257 #[cfg(feature = "wasm")]
258 fn inclusion_v0_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
260 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
261 INSTANCE.get_or_init(|| {
262 inclusion_key_bytes
263 .map(|bytes| {
264 snarkvm_parameters::canary::InclusionV0Prover::verify_bytes(&bytes)
265 .expect("Bytes provided did not match expected inclusion checksum.");
266 Arc::new(
267 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
268 )
269 })
270 .unwrap_or_else(|| {
271 Arc::new(
272 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_PROVING_KEY[1..])
273 .expect("Failed to load inclusion proving key."),
274 )
275 })
276 })
277 }
278
279 fn inclusion_v0_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
281 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
282 INSTANCE.get_or_init(|| {
283 Arc::new(
285 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_V0_VERIFYING_KEY[1..])
286 .expect("Failed to load inclusion_v0 verifying key."),
287 )
288 })
289 }
290
291 #[cfg(not(feature = "wasm"))]
292 fn inclusion_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
294 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
295 INSTANCE.get_or_init(|| {
296 Arc::new(
298 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_PROVING_KEY[1..])
299 .expect("Failed to load inclusion proving key."),
300 )
301 })
302 }
303
304 #[cfg(feature = "wasm")]
305 fn inclusion_proving_key(inclusion_key_bytes: Option<Vec<u8>>) -> &'static Arc<VarunaProvingKey<Self>> {
307 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
308 INSTANCE.get_or_init(|| {
309 inclusion_key_bytes
310 .map(|bytes| {
311 snarkvm_parameters::canary::InclusionProver::verify_bytes(&bytes)
312 .expect("Bytes provided did not match expected inclusion checksum.");
313 Arc::new(
314 CircuitProvingKey::from_bytes_le(&bytes[1..]).expect("Failed to load inclusion proving key."),
315 )
316 })
317 .unwrap_or_else(|| {
318 Arc::new(
319 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_PROVING_KEY[1..])
320 .expect("Failed to load inclusion proving key."),
321 )
322 })
323 })
324 }
325
326 fn inclusion_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
328 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
329 INSTANCE.get_or_init(|| {
330 Arc::new(
332 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::INCLUSION_VERIFYING_KEY[1..])
333 .expect("Failed to load inclusion verifying key."),
334 )
335 })
336 }
337
338 #[cfg(not(feature = "wasm"))]
339 fn translation_credits_proving_key() -> &'static Arc<VarunaProvingKey<Self>> {
341 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
342 INSTANCE.get_or_init(|| {
343 Arc::new(
345 CircuitProvingKey::from_bytes_le(&snarkvm_parameters::canary::TRANSLATION_CREDITS_PROVING_KEY[1..])
346 .expect("Failed to load translation credits proving key."),
347 )
348 })
349 }
350
351 #[cfg(feature = "wasm")]
352 fn translation_credits_proving_key(
354 translation_credits_key_bytes: Option<Vec<u8>>,
355 ) -> &'static Arc<VarunaProvingKey<Self>> {
356 static INSTANCE: OnceLock<Arc<VarunaProvingKey<Console>>> = OnceLock::new();
357 INSTANCE.get_or_init(|| {
358 translation_credits_key_bytes
359 .map(|bytes| {
360 snarkvm_parameters::canary::TranslationCreditsProver::verify_bytes(&bytes)
361 .expect("Bytes provided did not match expected translation credits checksum.");
362 Arc::new(
363 CircuitProvingKey::from_bytes_le(&bytes[1..])
364 .expect("Failed to load translation credits proving key."),
365 )
366 })
367 .unwrap_or_else(|| {
368 Arc::new(
369 CircuitProvingKey::from_bytes_le(
370 &snarkvm_parameters::canary::TRANSLATION_CREDITS_PROVING_KEY[1..],
371 )
372 .expect("Failed to load translation credits proving key."),
373 )
374 })
375 })
376 }
377
378 fn translation_credits_verifying_key() -> &'static Arc<VarunaVerifyingKey<Self>> {
380 static INSTANCE: OnceLock<Arc<VarunaVerifyingKey<Console>>> = OnceLock::new();
381 INSTANCE.get_or_init(|| {
382 Arc::new(
383 CircuitVerifyingKey::from_bytes_le(&snarkvm_parameters::canary::TRANSLATION_CREDITS_VERIFYING_KEY[1..])
384 .expect("Failed to load translation verifying key."),
385 )
386 })
387 }
388
389 fn g_powers() -> &'static Vec<Group<Self>> {
391 &GENERATOR_G
392 }
393
394 fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self> {
396 GENERATOR_G
397 .iter()
398 .zip_eq(&scalar.to_bits_le())
399 .filter_map(|(base, bit)| match bit {
400 true => Some(base),
401 false => None,
402 })
403 .sum()
404 }
405
406 fn varuna_universal_prover() -> &'static UniversalProver<Self::PairingCurve> {
408 MainnetV0::varuna_universal_prover()
409 }
410
411 fn varuna_universal_verifier() -> &'static UniversalVerifier<Self::PairingCurve> {
413 MainnetV0::varuna_universal_verifier()
414 }
415
416 fn varuna_fs_parameters() -> &'static FiatShamirParameters<Self> {
418 &VARUNA_FS_PARAMETERS
419 }
420
421 fn commitment_domain() -> Field<Self> {
423 *COMMITMENT_DOMAIN
424 }
425
426 fn encryption_domain() -> Field<Self> {
428 *ENCRYPTION_DOMAIN
429 }
430
431 fn graph_key_domain() -> Field<Self> {
433 *GRAPH_KEY_DOMAIN
434 }
435
436 fn serial_number_domain() -> Field<Self> {
438 *SERIAL_NUMBER_DOMAIN
439 }
440
441 fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
443 CANARY_BHP_256.commit(input, randomizer)
444 }
445
446 fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
448 CANARY_BHP_512.commit(input, randomizer)
449 }
450
451 fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
453 CANARY_BHP_768.commit(input, randomizer)
454 }
455
456 fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
458 CANARY_BHP_1024.commit(input, randomizer)
459 }
460
461 fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
463 CANARY_PEDERSEN_64.commit(input, randomizer)
464 }
465
466 fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>> {
468 CANARY_PEDERSEN_128.commit(input, randomizer)
469 }
470
471 fn commit_to_group_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
473 CANARY_BHP_256.commit_uncompressed(input, randomizer)
474 }
475
476 fn commit_to_group_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
478 CANARY_BHP_512.commit_uncompressed(input, randomizer)
479 }
480
481 fn commit_to_group_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
483 CANARY_BHP_768.commit_uncompressed(input, randomizer)
484 }
485
486 fn commit_to_group_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
488 CANARY_BHP_1024.commit_uncompressed(input, randomizer)
489 }
490
491 fn commit_to_group_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
493 CANARY_PEDERSEN_64.commit_uncompressed(input, randomizer)
494 }
495
496 fn commit_to_group_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Group<Self>> {
498 CANARY_PEDERSEN_128.commit_uncompressed(input, randomizer)
499 }
500
501 fn hash_bhp256(input: &[bool]) -> Result<Field<Self>> {
503 CANARY_BHP_256.hash(input)
504 }
505
506 fn hash_bhp512(input: &[bool]) -> Result<Field<Self>> {
508 CANARY_BHP_512.hash(input)
509 }
510
511 fn hash_bhp768(input: &[bool]) -> Result<Field<Self>> {
513 CANARY_BHP_768.hash(input)
514 }
515
516 fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>> {
518 CANARY_BHP_1024.hash(input)
519 }
520
521 fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>> {
523 Keccak256::default().hash(input)
524 }
525
526 fn hash_keccak384(input: &[bool]) -> Result<Vec<bool>> {
528 Keccak384::default().hash(input)
529 }
530
531 fn hash_keccak512(input: &[bool]) -> Result<Vec<bool>> {
533 Keccak512::default().hash(input)
534 }
535
536 fn hash_ped64(input: &[bool]) -> Result<Field<Self>> {
538 CANARY_PEDERSEN_64.hash(input)
539 }
540
541 fn hash_ped128(input: &[bool]) -> Result<Field<Self>> {
543 CANARY_PEDERSEN_128.hash(input)
544 }
545
546 fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>> {
548 CANARY_POSEIDON_2.hash(input)
549 }
550
551 fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>> {
553 CANARY_POSEIDON_4.hash(input)
554 }
555
556 fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>> {
558 CANARY_POSEIDON_8.hash(input)
559 }
560
561 fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>> {
563 Sha3_256::default().hash(input)
564 }
565
566 fn hash_sha3_384(input: &[bool]) -> Result<Vec<bool>> {
568 Sha3_384::default().hash(input)
569 }
570
571 fn hash_sha3_512(input: &[bool]) -> Result<Vec<bool>> {
573 Sha3_512::default().hash(input)
574 }
575
576 fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
578 CANARY_POSEIDON_2.hash_many(input, num_outputs)
579 }
580
581 fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
583 CANARY_POSEIDON_4.hash_many(input, num_outputs)
584 }
585
586 fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
588 CANARY_POSEIDON_8.hash_many(input, num_outputs)
589 }
590
591 fn hash_to_group_bhp256(input: &[bool]) -> Result<Group<Self>> {
593 CANARY_BHP_256.hash_uncompressed(input)
594 }
595
596 fn hash_to_group_bhp512(input: &[bool]) -> Result<Group<Self>> {
598 CANARY_BHP_512.hash_uncompressed(input)
599 }
600
601 fn hash_to_group_bhp768(input: &[bool]) -> Result<Group<Self>> {
603 CANARY_BHP_768.hash_uncompressed(input)
604 }
605
606 fn hash_to_group_bhp1024(input: &[bool]) -> Result<Group<Self>> {
608 CANARY_BHP_1024.hash_uncompressed(input)
609 }
610
611 fn hash_to_group_ped64(input: &[bool]) -> Result<Group<Self>> {
613 CANARY_PEDERSEN_64.hash_uncompressed(input)
614 }
615
616 fn hash_to_group_ped128(input: &[bool]) -> Result<Group<Self>> {
618 CANARY_PEDERSEN_128.hash_uncompressed(input)
619 }
620
621 fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>> {
623 CANARY_POSEIDON_2.hash_to_group(input)
624 }
625
626 fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>> {
628 CANARY_POSEIDON_4.hash_to_group(input)
629 }
630
631 fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>> {
633 CANARY_POSEIDON_8.hash_to_group(input)
634 }
635
636 fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>> {
638 CANARY_POSEIDON_2.hash_to_scalar(input)
639 }
640
641 fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>> {
643 CANARY_POSEIDON_4.hash_to_scalar(input)
644 }
645
646 fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>> {
648 CANARY_POSEIDON_8.hash_to_scalar(input)
649 }
650
651 fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>> {
653 MerkleTree::new(&*CANARY_BHP_1024, &*CANARY_BHP_512, leaves)
654 }
655
656 fn merkle_tree_bhp_from_state<const DEPTH: u8>(
659 state: MerkleTreeState<'_, Self>,
660 ) -> Result<BHPMerkleTree<Self, DEPTH>> {
661 MerkleTree::from_state(&*CANARY_BHP_1024, &*CANARY_BHP_512, state)
662 }
663
664 fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>> {
666 MerkleTree::new(&*CANARY_POSEIDON_4, &*CANARY_POSEIDON_2, leaves)
667 }
668
669 fn verify_merkle_path_bhp<const DEPTH: u8>(
671 path: &MerklePath<Self, DEPTH>,
672 root: &Field<Self>,
673 leaf: &Vec<bool>,
674 ) -> bool {
675 path.verify(&*CANARY_BHP_1024, &*CANARY_BHP_512, root, leaf)
676 }
677
678 fn verify_merkle_path_psd<const DEPTH: u8>(
680 path: &MerklePath<Self, DEPTH>,
681 root: &Field<Self>,
682 leaf: &Vec<Field<Self>>,
683 ) -> bool {
684 path.verify(&*CANARY_POSEIDON_4, &*CANARY_POSEIDON_2, root, leaf)
685 }
686
687 fn dynamic_record_leaf_hasher() -> &'static Poseidon8<Self> {
689 &CANARY_DYNAMIC_RECORD_LEAF_HASHER
690 }
691
692 fn dynamic_record_path_hasher() -> &'static Poseidon2<Self> {
694 &CANARY_DYNAMIC_RECORD_PATH_HASHER
695 }
696}
697
698#[cfg(test)]
699mod tests {
700 use super::*;
701
702 type CurrentNetwork = CanaryV0;
703
704 #[test]
705 fn test_g_scalar_multiply() {
706 let scalar = Scalar::rand(&mut TestRng::default());
708 let group = CurrentNetwork::g_scalar_multiply(&scalar);
709 assert_eq!(group, CurrentNetwork::g_powers()[0] * scalar);
710 }
711}