semaphore_rs_proof/
lib.rs1use ruint::aliases::U256;
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "ark")]
5mod ark;
6
7pub mod compression;
8
9pub mod packing;
10
11pub type G1 = (U256, U256);
13
14pub type G2 = ([U256; 2], [U256; 2]);
16
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
19pub struct Proof(pub G1, pub G2, pub G1);
20
21impl Proof {
22 pub const fn from_flat(flat: [U256; 8]) -> Self {
23 let [x0, x1, x2, x3, x4, x5, x6, x7] = flat;
24 Self((x0, x1), ([x2, x3], [x4, x5]), (x6, x7))
25 }
26
27 pub const fn flatten(self) -> [U256; 8] {
28 let Self((a0, a1), ([bx0, bx1], [by0, by1]), (c0, c1)) = self;
29 [a0, a1, bx0, bx1, by0, by1, c0, c1]
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn deser() {
39 let s = r#"[["0x1","0x2"],[["0x3","0x4"],["0x5","0x6"]],["0x7","0x8"]]"#;
40
41 let deserialized: Proof = serde_json::from_str(s).unwrap();
42 let reserialized = serde_json::to_string(&deserialized).unwrap();
43
44 assert_eq!(s, reserialized);
45 }
46}