Skip to main content

ysbell/groth16/
ext.rs

1use super::{create_proof_batch_priority, create_random_proof_batch_priority};
2use super::{ParameterSource, Proof};
3use crate::{Circuit, SynthesisError};
4use paired::Engine;
5use rand_core::RngCore;
6
7pub fn create_proof<E, C, P: ParameterSource<E>>(
8    circuit: C,
9    params: P,
10    r: E::Fr,
11    s: E::Fr,
12) -> Result<Proof<E>, SynthesisError>
13where
14    E: Engine,
15    C: Circuit<E> + Send,
16{
17    let proofs =
18        create_proof_batch_priority::<E, C, P>(vec![circuit], params, vec![r], vec![s], false)?;
19    Ok(proofs.into_iter().next().unwrap())
20}
21
22pub fn create_random_proof<E, C, R, P: ParameterSource<E>>(
23    circuit: C,
24    params: P,
25    rng: &mut R,
26) -> Result<Proof<E>, SynthesisError>
27where
28    E: Engine,
29    C: Circuit<E> + Send,
30    R: RngCore,
31{
32    let proofs =
33        create_random_proof_batch_priority::<E, C, R, P>(vec![circuit], params, rng, false)?;
34    Ok(proofs.into_iter().next().unwrap())
35}
36
37pub fn create_proof_batch<E, C, P: ParameterSource<E>>(
38    circuits: Vec<C>,
39    params: P,
40    r: Vec<E::Fr>,
41    s: Vec<E::Fr>,
42) -> Result<Vec<Proof<E>>, SynthesisError>
43where
44    E: Engine,
45    C: Circuit<E> + Send,
46{
47    create_proof_batch_priority::<E, C, P>(circuits, params, r, s, false)
48}
49
50pub fn create_random_proof_batch<E, C, R, P: ParameterSource<E>>(
51    circuits: Vec<C>,
52    params: P,
53    rng: &mut R,
54) -> Result<Vec<Proof<E>>, SynthesisError>
55where
56    E: Engine,
57    C: Circuit<E> + Send,
58    R: RngCore,
59{
60    create_random_proof_batch_priority::<E, C, R, P>(circuits, params, rng, false)
61}
62
63pub fn create_proof_in_priority<E, C, P: ParameterSource<E>>(
64    circuit: C,
65    params: P,
66    r: E::Fr,
67    s: E::Fr,
68) -> Result<Proof<E>, SynthesisError>
69where
70    E: Engine,
71    C: Circuit<E> + Send,
72{
73    let proofs =
74        create_proof_batch_priority::<E, C, P>(vec![circuit], params, vec![r], vec![s], true)?;
75    Ok(proofs.into_iter().next().unwrap())
76}
77
78pub fn create_random_proof_in_priority<E, C, R, P: ParameterSource<E>>(
79    circuit: C,
80    params: P,
81    rng: &mut R,
82) -> Result<Proof<E>, SynthesisError>
83where
84    E: Engine,
85    C: Circuit<E> + Send,
86    R: RngCore,
87{
88    let proofs =
89        create_random_proof_batch_priority::<E, C, R, P>(vec![circuit], params, rng, true)?;
90    Ok(proofs.into_iter().next().unwrap())
91}
92
93pub fn create_proof_batch_in_priority<E, C, P: ParameterSource<E>>(
94    circuits: Vec<C>,
95    params: P,
96    r: Vec<E::Fr>,
97    s: Vec<E::Fr>,
98) -> Result<Vec<Proof<E>>, SynthesisError>
99where
100    E: Engine,
101    C: Circuit<E> + Send,
102{
103    create_proof_batch_priority::<E, C, P>(circuits, params, r, s, true)
104}
105
106pub fn create_random_proof_batch_in_priority<E, C, R, P: ParameterSource<E>>(
107    circuits: Vec<C>,
108    params: P,
109    rng: &mut R,
110) -> Result<Vec<Proof<E>>, SynthesisError>
111where
112    E: Engine,
113    C: Circuit<E> + Send,
114    R: RngCore,
115{
116    create_random_proof_batch_priority::<E, C, R, P>(circuits, params, rng, true)
117}