1pub mod bn256_grumpkin;
4pub mod hyperkzg;
5pub mod ipa_pc;
6pub mod keccak;
7pub mod mercury;
8pub mod msm;
9pub mod pasta;
10pub mod pedersen;
11pub mod poseidon;
12pub mod secp_secq;
13pub mod traits;
14
15#[cfg(feature = "blitzar")]
16pub mod blitzar;
17#[cfg(feature = "io")]
18pub mod ptau;
19
20use crate::{
21 provider::{
22 bn256_grumpkin::{bn256, grumpkin},
23 hyperkzg::CommitmentEngine as HyperKZGCommitmentEngine,
24 keccak::Keccak256Transcript,
25 pasta::{pallas, vesta},
26 pedersen::CommitmentEngine as PedersenCommitmentEngine,
27 poseidon::{PoseidonRO, PoseidonROCircuit},
28 secp_secq::{secp256k1, secq256k1},
29 },
30 traits::Engine,
31};
32#[cfg(feature = "io")]
33pub use ptau::{check_sanity_of_ptau_file, read_ptau, write_ptau};
34use serde::{Deserialize, Serialize};
35
36#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
38pub struct Bn256EngineKZG;
39
40#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
42pub struct GrumpkinEngine;
43
44#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
46pub struct Bn256EngineIPA;
47
48impl Engine for Bn256EngineKZG {
49 type Base = bn256::Base;
50 type Scalar = bn256::Scalar;
51 type GE = bn256::Point;
52 type RO = PoseidonRO<Self::Base>;
53 type ROCircuit = PoseidonROCircuit<Self::Base>;
54 type RO2 = PoseidonRO<Self::Scalar>;
55 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
56 type TE = Keccak256Transcript<Self>;
57 type CE = HyperKZGCommitmentEngine<Self>;
58}
59
60impl Engine for Bn256EngineIPA {
61 type Base = bn256::Base;
62 type Scalar = bn256::Scalar;
63 type GE = bn256::Point;
64 type RO = PoseidonRO<Self::Base>;
65 type ROCircuit = PoseidonROCircuit<Self::Base>;
66 type RO2 = PoseidonRO<Self::Scalar>;
67 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
68 type TE = Keccak256Transcript<Self>;
69 type CE = PedersenCommitmentEngine<Self>;
70}
71
72impl Engine for GrumpkinEngine {
73 type Base = grumpkin::Base;
74 type Scalar = grumpkin::Scalar;
75 type GE = grumpkin::Point;
76 type RO = PoseidonRO<Self::Base>;
77 type ROCircuit = PoseidonROCircuit<Self::Base>;
78 type RO2 = PoseidonRO<Self::Scalar>;
79 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
80 type TE = Keccak256Transcript<Self>;
81 type CE = PedersenCommitmentEngine<Self>;
82}
83
84#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
86pub struct Secp256k1Engine;
87
88#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
90pub struct Secq256k1Engine;
91
92impl Engine for Secp256k1Engine {
93 type Base = secp256k1::Base;
94 type Scalar = secp256k1::Scalar;
95 type GE = secp256k1::Point;
96 type RO = PoseidonRO<Self::Base>;
97 type ROCircuit = PoseidonROCircuit<Self::Base>;
98 type RO2 = PoseidonRO<Self::Scalar>;
99 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
100 type TE = Keccak256Transcript<Self>;
101 type CE = PedersenCommitmentEngine<Self>;
102}
103
104impl Engine for Secq256k1Engine {
105 type Base = secq256k1::Base;
106 type Scalar = secq256k1::Scalar;
107 type GE = secq256k1::Point;
108 type RO = PoseidonRO<Self::Base>;
109 type ROCircuit = PoseidonROCircuit<Self::Base>;
110 type RO2 = PoseidonRO<Self::Scalar>;
111 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
112 type TE = Keccak256Transcript<Self>;
113 type CE = PedersenCommitmentEngine<Self>;
114}
115
116#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
118pub struct PallasEngine;
119
120#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
122pub struct VestaEngine;
123
124impl Engine for PallasEngine {
125 type Base = pallas::Base;
126 type Scalar = pallas::Scalar;
127 type GE = pallas::Point;
128 type RO = PoseidonRO<Self::Base>;
129 type ROCircuit = PoseidonROCircuit<Self::Base>;
130 type RO2 = PoseidonRO<Self::Scalar>;
131 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
132 type TE = Keccak256Transcript<Self>;
133 type CE = PedersenCommitmentEngine<Self>;
134}
135
136impl Engine for VestaEngine {
137 type Base = vesta::Base;
138 type Scalar = vesta::Scalar;
139 type GE = vesta::Point;
140 type RO = PoseidonRO<Self::Base>;
141 type ROCircuit = PoseidonROCircuit<Self::Base>;
142 type RO2 = PoseidonRO<Self::Scalar>;
143 type RO2Circuit = PoseidonROCircuit<Self::Scalar>;
144 type TE = Keccak256Transcript<Self>;
145 type CE = PedersenCommitmentEngine<Self>;
146}
147
148#[cfg(test)]
149mod tests {
150 use crate::provider::{
151 bn256_grumpkin::bn256, pasta::pallas, secp_secq::secp256k1, traits::DlogGroup,
152 };
153 use digest::{ExtendableOutput, Update};
154 use halo2curves::{group::Curve, CurveExt};
155 use sha3::Shake256;
156 use std::io::Read;
157
158 macro_rules! impl_cycle_pair_test {
159 ($curve:ident) => {
160 fn from_label_serial(label: &'static [u8], n: usize) -> Vec<$curve::Affine> {
161 let mut shake = Shake256::default();
162 shake.update(label);
163 let mut reader = shake.finalize_xof();
164 (0..n)
165 .map(|_| {
166 let mut uniform_bytes = [0u8; 32];
167 reader.read_exact(&mut uniform_bytes).unwrap();
168 let hash = $curve::Point::hash_to_curve("from_uniform_bytes");
169 hash(&uniform_bytes).to_affine()
170 })
171 .collect()
172 }
173
174 let label = b"test_from_label";
175 for n in [
176 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1021,
177 ] {
178 let ck_par = <$curve::Point as DlogGroup>::from_label(label, n);
179 let ck_ser = from_label_serial(label, n);
180 assert_eq!(ck_par.len(), n);
181 assert_eq!(ck_ser.len(), n);
182 assert_eq!(ck_par, ck_ser);
183 }
184 };
185 }
186
187 #[test]
188 fn test_bn256_from_label() {
189 impl_cycle_pair_test!(bn256);
190 }
191
192 #[test]
193 fn test_pallas_from_label() {
194 impl_cycle_pair_test!(pallas);
195 }
196
197 #[test]
198 fn test_secp256k1_from_label() {
199 impl_cycle_pair_test!(secp256k1);
200 }
201}