ark-point-to-bytes-example/src/lib.rs
src/lib.rsRaw
1#![allow(non_snake_case)]
2
3#[cfg(test)]
4mod tests {
5 use ark_pallas::{constraints::GVar, Fq, Projective};
6 use ark_r1cs_std::{alloc::AllocVar, R1CSVar, ToBytesGadget};
7 use ark_relations::r1cs::ConstraintSystem;
8 use ark_serialize::CanonicalSerialize;
9 use ark_std::UniformRand;
10
11 #[test]
12 fn test_point_to_bytes() {
13 let mut rng = ark_std::test_rng();
14 let cs = ConstraintSystem::<Fq>::new_ref();
15
16 let point = Projective::rand(&mut rng);
17 let pointVar = GVar::new_witness(cs.clone(), || Ok(point)).unwrap();
18
19 let mut point_bytes = Vec::new();
20 point.serialize_uncompressed(&mut point_bytes).unwrap();
21
22 let pointVar_bytes = pointVar.to_bytes().unwrap();
23
24 assert_eq!(pointVar_bytes.value().unwrap(), point_bytes);
25 // They differ in the last byte, the one used to indicate if is point at infinity.
26 }
27}