snarkvm_circuit_account/signature/helpers/
to_fields.rsuse super::*;
#[cfg(feature = "console")]
impl<A: Aleo> ToFields for Signature<A> {
type Field = Field<A>;
fn to_fields(&self) -> Vec<Self::Field> {
let mut fields = vec![self.challenge.to_field(), self.response.to_field()];
fields.extend(self.compute_key.to_fields());
fields
}
}
#[cfg(all(test, feature = "console"))]
mod tests {
use super::*;
use crate::Circuit;
use snarkvm_circuit_network::AleoV0;
use console::ToFields as ConsoleToFields;
use snarkvm_utilities::TestRng;
type CurrentAleo = AleoV0;
const ITERATIONS: u64 = 128;
fn check_to_fields(
mode: Mode,
rng: &mut TestRng,
num_constants: u64,
num_public: u64,
num_private: u64,
num_constraints: u64,
) {
for i in 0..ITERATIONS {
let expected = crate::helpers::generate_signature(i, rng);
let candidate = Signature::<CurrentAleo>::new(mode, expected);
CurrentAleo::scope(format!("{mode} {expected} {i}"), || {
let candidate = candidate.to_fields();
assert_eq!(4, candidate.len());
assert_scope!(num_constants, num_public, num_private, num_constraints);
let candidate_bits_le = candidate.to_bits_le();
assert_eq!(1012, candidate_bits_le.len());
let expected_bits = expected.to_fields().unwrap().to_bits_le();
for (expected_bit, candidate_bit) in expected_bits.iter().zip_eq(&candidate_bits_le) {
assert_eq!(*expected_bit, candidate_bit.eject_value());
}
});
CurrentAleo::reset();
}
}
#[test]
fn test_signature_to_fields_constant() {
let mut rng = TestRng::default();
check_to_fields(Mode::Constant, &mut rng, 0, 0, 0, 0);
}
#[test]
fn test_signature_to_fields_public() {
let mut rng = TestRng::default();
check_to_fields(Mode::Public, &mut rng, 0, 0, 0, 0);
}
#[test]
fn test_signature_to_fields_private() {
let mut rng = TestRng::default();
check_to_fields(Mode::Private, &mut rng, 0, 0, 0, 0);
}
}