snarkvm_circuit_account/compute_key/helpers/
to_fields.rs1use super::*;
17
18impl<A: Aleo> ToFields for ComputeKey<A> {
19 type Field = Field<A>;
20
21 fn to_fields(&self) -> Vec<Self::Field> {
23 vec![self.pk_sig().to_field(), self.pr_sig().to_field()]
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::Circuit;
31 use snarkvm_circuit_network::AleoV0;
32 use snarkvm_utilities::TestRng;
33
34 use console::ToFields as ConsoleToFields;
35
36 type CurrentAleo = AleoV0;
37
38 const ITERATIONS: u64 = 100;
39
40 fn check_to_fields(mode: Mode, num_constants: u64, num_public: u64, num_private: u64, num_constraints: u64) {
41 let rng = &mut TestRng::default();
42
43 for i in 0..ITERATIONS {
44 let expected = console::ComputeKey::try_from(console::PrivateKey::new(rng).unwrap()).unwrap();
46 let candidate = ComputeKey::<CurrentAleo>::new(mode, expected);
47
48 CurrentAleo::scope(format!("{mode} {i}"), || {
49 let candidate = candidate.to_fields();
50 assert_eq!(candidate.len(), 2);
51
52 let expected = expected.to_fields().unwrap();
53 assert_eq!(expected.len(), 2);
54
55 for (expected_field, candidate_field) in expected.iter().zip_eq(candidate.iter()) {
56 assert_eq!(*expected_field, candidate_field.eject_value());
57 }
58 assert_scope!(num_constants, num_public, num_private, num_constraints);
59 });
60 }
61 }
62
63 #[test]
64 fn test_to_fields_constant() {
65 check_to_fields(Mode::Constant, 0, 0, 0, 0);
66 }
67
68 #[test]
69 fn test_to_fields_public() {
70 check_to_fields(Mode::Public, 0, 0, 0, 0);
71 }
72
73 #[test]
74 fn test_to_fields_private() {
75 check_to_fields(Mode::Private, 0, 0, 0, 0);
76 }
77}