1#![cfg_attr(not(feature = "std"), no_std)]
2use ark_std::collections::BTreeMap;
3
4use ark_crypto_primitives::Error;
5use ark_ec::PairingEngine;
6use ark_ff::{PrimeField, SquareRootField};
7use ark_std::{
8 rand::{CryptoRng, RngCore},
9 vec::Vec,
10};
11
12pub use arkworks_utils::Curve;
13use common::{AnchorProof, Leaf, MixerProof, VAnchorProof};
14use utxo::Utxo;
15
16#[cfg(feature = "aead")]
17pub mod aead;
18
19pub mod common;
20pub mod keypair;
21pub mod utxo;
22
23#[cfg(feature = "r1cs")]
24pub mod r1cs;
25
26#[cfg(feature = "plonk")]
27pub mod plonk;
28
29pub trait MixerProver<E: PairingEngine, const HEIGHT: usize> {
30 fn create_leaf_with_privates(
33 curve: Curve,
34 secret: Vec<u8>,
35 nullifier: Vec<u8>,
36 ) -> Result<Leaf, Error>;
37 fn create_random_leaf<R: RngCore + CryptoRng>(curve: Curve, rng: &mut R)
39 -> Result<Leaf, Error>;
40 fn create_proof<R: RngCore + CryptoRng>(
42 curve: Curve,
43 secret: Vec<u8>,
44 nullifier: Vec<u8>,
45 leaves: Vec<Vec<u8>>,
46 index: u64,
47 recipient: Vec<u8>,
48 relayer: Vec<u8>,
49 fee: u128,
50 refund: u128,
51 pk: Vec<u8>,
52 default_leaf: [u8; 32],
53 rng: &mut R,
54 ) -> Result<MixerProof, Error>;
55}
56
57pub trait AnchorProver<E: PairingEngine, const HEIGHT: usize, const ANCHOR_CT: usize> {
58 fn create_leaf_with_privates(
61 curve: Curve,
62 chain_id: u64,
63 secret: Vec<u8>,
64 nullifier: Vec<u8>,
65 ) -> Result<Leaf, Error>;
66 fn create_random_leaf<R: RngCore + CryptoRng>(
68 curve: Curve,
69 chain_id: u64,
70 rng: &mut R,
71 ) -> Result<Leaf, Error>;
72 fn create_proof<R: RngCore + CryptoRng>(
74 curve: Curve,
75 chain_id: u64,
76 secret: Vec<u8>,
77 nullifier: Vec<u8>,
78 leaves: Vec<Vec<u8>>,
79 index: u64,
80 root_set: [Vec<u8>; ANCHOR_CT],
81 recipient: Vec<u8>,
82 relayer: Vec<u8>,
83 fee: u128,
84 refund: u128,
85 commitment: Vec<u8>,
86 pk: Vec<u8>,
87 default_leaf: [u8; 32],
88 rng: &mut R,
89 ) -> Result<AnchorProof, Error>;
90}
91
92pub trait VAnchorProver<
93 E: PairingEngine,
94 const HEIGHT: usize,
95 const ANCHOR_CT: usize,
96 const INS: usize,
97 const OUTS: usize,
98> where
99 <E as PairingEngine>::Fr: PrimeField + SquareRootField + From<i128>,
100{
101 fn create_leaf_with_privates(
102 curve: Curve,
103 chain_id: u64,
104 amount: u128,
105 index: Option<u64>,
106 private_key: Vec<u8>,
107 blinding: Vec<u8>,
108 ) -> Result<Utxo<E::Fr>, Error> {
109 Self::create_utxo(curve, chain_id, amount, index, private_key, blinding)
110 }
111 fn create_random_leaf<R: RngCore + CryptoRng>(
113 curve: Curve,
114 chain_id: u64,
115 amount: u128,
116 index: Option<u64>,
117 rng: &mut R,
118 ) -> Result<Utxo<E::Fr>, Error> {
119 Self::create_random_utxo(curve, chain_id, amount, index, rng)
120 }
121 fn create_utxo(
123 curve: Curve,
124 chain_id: u64,
125 amount: u128,
126 index: Option<u64>,
127 private_key: Vec<u8>,
128 blinding: Vec<u8>,
129 ) -> Result<Utxo<E::Fr>, Error>;
130 fn create_random_utxo<R: RngCore + CryptoRng>(
132 curve: Curve,
133 chain_id: u64,
134 amount: u128,
135 index: Option<u64>,
136 rng: &mut R,
137 ) -> Result<Utxo<E::Fr>, Error>;
138 fn create_public_utxo(
140 curve: Curve,
141 chain_id: u64,
142 amount: u128,
143 blinding: Vec<u8>,
144 public_key: Vec<u8>,
145 index: Option<u64>,
146 ) -> Result<Utxo<E::Fr>, Error>;
147 fn create_proof<R: RngCore + CryptoRng>(
149 curve: Curve,
150 chain_id: u64,
151 public_amount: i128,
153 ext_data_hash: Vec<u8>,
154 in_root_set: [Vec<u8>; ANCHOR_CT],
155 in_indices: [u64; INS],
156 in_leaves: BTreeMap<u64, Vec<Vec<u8>>>,
157 in_utxos: [Utxo<E::Fr>; INS],
159 out_utxos: [Utxo<E::Fr>; OUTS],
161 pk: Vec<u8>,
162 default_leaf: [u8; 32],
163 rng: &mut R,
164 ) -> Result<VAnchorProof, Error>;
165}