ark_gm17/
data_structures.rs1use ark_ec::PairingEngine;
2use ark_ff::bytes::ToBytes;
3use ark_serialize::*;
4use ark_std::{
5 io::{self, Result as IoResult},
6 vec::Vec,
7};
8
9#[derive(PartialEq, Eq, Clone, Default, CanonicalSerialize, CanonicalDeserialize)]
11pub struct Proof<E: PairingEngine> {
12 #[doc(hidden)]
13 pub a: E::G1Affine,
14 #[doc(hidden)]
15 pub b: E::G2Affine,
16 #[doc(hidden)]
17 pub c: E::G1Affine,
18}
19
20impl<E: PairingEngine> ToBytes for Proof<E> {
21 #[inline]
22 fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
23 self.a.write(&mut writer)?;
24 self.b.write(&mut writer)?;
25 self.c.write(&mut writer)
26 }
27}
28
29#[derive(Eq, PartialEq, Clone, CanonicalSerialize, CanonicalDeserialize)]
31pub struct VerifyingKey<E: PairingEngine> {
32 #[doc(hidden)]
33 pub h_g2: E::G2Affine,
34 #[doc(hidden)]
35 pub g_alpha_g1: E::G1Affine,
36 #[doc(hidden)]
37 pub h_beta_g2: E::G2Affine,
38 #[doc(hidden)]
39 pub g_gamma_g1: E::G1Affine,
40 #[doc(hidden)]
41 pub h_gamma_g2: E::G2Affine,
42 #[doc(hidden)]
43 pub query: Vec<E::G1Affine>,
44}
45
46impl<E: PairingEngine> ToBytes for VerifyingKey<E> {
47 fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
48 self.h_g2.write(&mut writer)?;
49 self.g_alpha_g1.write(&mut writer)?;
50 self.h_beta_g2.write(&mut writer)?;
51 self.g_gamma_g1.write(&mut writer)?;
52 self.h_gamma_g2.write(&mut writer)?;
53 for q in &self.query {
54 q.write(&mut writer)?;
55 }
56 Ok(())
57 }
58}
59
60impl<E: PairingEngine> Default for VerifyingKey<E> {
61 fn default() -> Self {
62 Self {
63 h_g2: E::G2Affine::default(),
64 g_alpha_g1: E::G1Affine::default(),
65 h_beta_g2: E::G2Affine::default(),
66 g_gamma_g1: E::G1Affine::default(),
67 h_gamma_g2: E::G2Affine::default(),
68 query: Vec::new(),
69 }
70 }
71}
72
73#[derive(PartialEq, Eq, Clone)]
76pub struct PreparedVerifyingKey<E: PairingEngine> {
77 #[doc(hidden)]
78 pub vk: VerifyingKey<E>,
79 #[doc(hidden)]
80 pub g_alpha: E::G1Affine,
81 #[doc(hidden)]
82 pub h_beta: E::G2Affine,
83 #[doc(hidden)]
84 pub g_alpha_h_beta_ml: E::Fqk,
85 #[doc(hidden)]
86 pub g_gamma_pc: E::G1Prepared,
87 #[doc(hidden)]
88 pub h_gamma_pc: E::G2Prepared,
89 #[doc(hidden)]
90 pub h_pc: E::G2Prepared,
91 #[doc(hidden)]
92 pub query: Vec<E::G1Affine>,
93}
94
95impl<E: PairingEngine> Default for PreparedVerifyingKey<E> {
96 fn default() -> Self {
97 Self {
98 vk: VerifyingKey::default(),
99 g_alpha: E::G1Affine::default(),
100 h_beta: E::G2Affine::default(),
101 g_alpha_h_beta_ml: E::Fqk::default(),
102 g_gamma_pc: E::G1Prepared::default(),
103 h_gamma_pc: E::G2Prepared::default(),
104 h_pc: E::G2Prepared::default(),
105 query: Vec::new(),
106 }
107 }
108}
109
110impl<E: PairingEngine> From<PreparedVerifyingKey<E>> for VerifyingKey<E> {
111 fn from(other: PreparedVerifyingKey<E>) -> Self {
112 other.vk
113 }
114}
115
116impl<E: PairingEngine> From<VerifyingKey<E>> for PreparedVerifyingKey<E> {
117 fn from(other: VerifyingKey<E>) -> Self {
118 crate::prepare_verifying_key(&other)
119 }
120}
121
122impl<E: PairingEngine> ToBytes for PreparedVerifyingKey<E> {
123 fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
124 self.vk.write(&mut writer)?;
125 self.g_alpha.write(&mut writer)?;
126 self.h_beta.write(&mut writer)?;
127 self.g_alpha_h_beta_ml.write(&mut writer)?;
128 self.g_gamma_pc.write(&mut writer)?;
129 self.h_gamma_pc.write(&mut writer)?;
130 self.h_pc.write(&mut writer)?;
131 for q in &self.query {
132 q.write(&mut writer)?;
133 }
134 Ok(())
135 }
136}
137
138#[derive(PartialEq, Eq, Clone, CanonicalSerialize, CanonicalDeserialize)]
140pub struct ProvingKey<E: PairingEngine> {
141 #[doc(hidden)]
142 pub vk: VerifyingKey<E>,
143 #[doc(hidden)]
144 pub a_query: Vec<E::G1Affine>,
145 #[doc(hidden)]
146 pub b_query: Vec<E::G2Affine>,
147 #[doc(hidden)]
148 pub c_query_1: Vec<E::G1Affine>,
149 #[doc(hidden)]
150 pub c_query_2: Vec<E::G1Affine>,
151 #[doc(hidden)]
152 pub g_gamma_z: E::G1Affine,
153 #[doc(hidden)]
154 pub h_gamma_z: E::G2Affine,
155 #[doc(hidden)]
156 pub g_ab_gamma_z: E::G1Affine,
157 #[doc(hidden)]
158 pub g_gamma2_z2: E::G1Affine,
159 #[doc(hidden)]
160 pub g_gamma2_z_t: Vec<E::G1Affine>,
161}