semaphore_rs_proof/
ark.rs

1use super::Proof;
2use ark_bn254::Config;
3use ark_ec::bn::Bn;
4use ark_groth16::Proof as ArkProof;
5
6impl From<ArkProof<Bn<Config>>> for Proof {
7    fn from(proof: ArkProof<Bn<Config>>) -> Self {
8        let proof = semaphore_rs_ark_circom::ethereum::Proof::from(proof);
9        let (a, b, c) = proof.as_tuple();
10        Self(a, b, c)
11    }
12}
13
14impl From<Proof> for ArkProof<Bn<Config>> {
15    fn from(proof: Proof) -> Self {
16        let eth_proof = semaphore_rs_ark_circom::ethereum::Proof {
17            a: semaphore_rs_ark_circom::ethereum::G1 {
18                x: proof.0 .0,
19                y: proof.0 .1,
20            },
21            #[rustfmt::skip] // Rustfmt inserts some confusing spaces
22            b: semaphore_rs_ark_circom::ethereum::G2 {
23                // The order of coefficients is flipped.
24                x: [proof.1.0[1], proof.1.0[0]],
25                y: [proof.1.1[1], proof.1.1[0]],
26            },
27            c: semaphore_rs_ark_circom::ethereum::G1 {
28                x: proof.2 .0,
29                y: proof.2 .1,
30            },
31        };
32        eth_proof.into()
33    }
34}