semaphore_rs_proof/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use ruint::aliases::U256;
use serde::{Deserialize, Serialize};

#[cfg(feature = "ark")]
mod ark;

pub mod compression;
pub mod packing;

// Matches the private G1Tup type in ark-circom.
pub type G1 = (U256, U256);

// Matches the private G2Tup type in ark-circom.
pub type G2 = ([U256; 2], [U256; 2]);

/// Wrap a proof object so we have serde support
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Proof(pub G1, pub G2, pub G1);

impl Proof {
    pub const fn from_flat(flat: [U256; 8]) -> Self {
        let [x0, x1, x2, x3, x4, x5, x6, x7] = flat;
        Self((x0, x1), ([x2, x3], [x4, x5]), (x6, x7))
    }

    pub const fn flatten(self) -> [U256; 8] {
        let Self((a0, a1), ([bx0, bx1], [by0, by1]), (c0, c1)) = self;
        [a0, a1, bx0, bx1, by0, by1, c0, c1]
    }
}