snarkvm_circuit_account/compute_key/
from.rs1use super::*;
17
18impl<A: Aleo> From<(Group<A>, Group<A>)> for ComputeKey<A> {
19 fn from((pk_sig, pr_sig): (Group<A>, Group<A>)) -> Self {
21 let sk_prf = A::hash_to_scalar_psd4(&[pk_sig.to_x_coordinate(), pr_sig.to_x_coordinate()]);
23 Self { pk_sig, pr_sig, sk_prf }
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use crate::{Circuit, helpers::generate_account};
32
33 use anyhow::Result;
34 use snarkvm_circuit_network::AleoV0;
35
36 const ITERATIONS: u64 = 10;
37
38 fn check_from(
39 mode: Mode,
40 num_constants: u64,
41 num_public: u64,
42 num_private: u64,
43 num_constraints: u64,
44 ) -> Result<()> {
45 for i in 0..ITERATIONS {
46 let (_, compute_key, _, _) = generate_account()?;
48
49 let pk_sig = Group::new(mode, compute_key.pk_sig());
51 let pr_sig = Group::new(mode, compute_key.pr_sig());
52
53 Circuit::scope(format!("{mode} {i}"), || {
54 let candidate = ComputeKey::<AleoV0>::from((pk_sig, pr_sig));
55 assert_eq!(compute_key, candidate.eject_value());
56 if i > 0 {
57 assert_scope!(num_constants, num_public, num_private, num_constraints);
58 }
59 });
60 Circuit::reset();
61 }
62 Ok(())
63 }
64
65 #[test]
66 fn test_from_constant() -> Result<()> {
67 check_from(Mode::Constant, 254, 0, 0, 0)
68 }
69
70 #[test]
71 fn test_from_public() -> Result<()> {
72 check_from(Mode::Public, 1, 0, 845, 847)
73 }
74
75 #[test]
76 fn test_from_private() -> Result<()> {
77 check_from(Mode::Private, 1, 0, 845, 847)
78 }
79}