snarkvm_circuit_account/signature/helpers/
to_fields.rs1use super::*;
17
18#[cfg(feature = "console")]
19impl<A: Aleo> ToFields for Signature<A> {
20 type Field = Field<A>;
21
22 fn to_fields(&self) -> Vec<Self::Field> {
24 let mut fields = vec![self.challenge.to_field(), self.response.to_field()];
25 fields.extend(self.compute_key.to_fields());
26 fields
27 }
28}
29
30#[cfg(all(test, feature = "console"))]
31mod tests {
32 use super::*;
33 use crate::Circuit;
34 use snarkvm_circuit_network::AleoV0;
35
36 use console::ToFields as ConsoleToFields;
37 use snarkvm_utilities::TestRng;
38
39 type CurrentAleo = AleoV0;
40
41 const ITERATIONS: u64 = 128;
42
43 fn check_to_fields(
44 mode: Mode,
45 rng: &mut TestRng,
46 num_constants: u64,
47 num_public: u64,
48 num_private: u64,
49 num_constraints: u64,
50 ) {
51 for i in 0..ITERATIONS {
52 let expected = crate::helpers::generate_signature(i, rng);
54 let candidate = Signature::<CurrentAleo>::new(mode, expected);
55
56 CurrentAleo::scope(format!("{mode} {expected} {i}"), || {
57 let candidate = candidate.to_fields();
59 assert_eq!(4, candidate.len());
60 assert_scope!(num_constants, num_public, num_private, num_constraints);
61
62 let candidate_bits_le = candidate.to_bits_le();
64 assert_eq!(1012, candidate_bits_le.len());
65
66 let expected_bits = expected.to_fields().unwrap().to_bits_le();
68 for (expected_bit, candidate_bit) in expected_bits.iter().zip_eq(&candidate_bits_le) {
69 assert_eq!(*expected_bit, candidate_bit.eject_value());
70 }
71 });
72 CurrentAleo::reset();
73 }
74 }
75
76 #[test]
77 fn test_signature_to_fields_constant() {
78 let mut rng = TestRng::default();
79 check_to_fields(Mode::Constant, &mut rng, 0, 0, 0, 0);
80 }
81
82 #[test]
83 fn test_signature_to_fields_public() {
84 let mut rng = TestRng::default();
85 check_to_fields(Mode::Public, &mut rng, 0, 0, 0, 0);
86 }
87
88 #[test]
89 fn test_signature_to_fields_private() {
90 let mut rng = TestRng::default();
91 check_to_fields(Mode::Private, &mut rng, 0, 0, 0, 0);
92 }
93}