forked from jancarlsson/snarkfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSL_ppzk.hpp
143 lines (121 loc) · 3.7 KB
/
DSL_ppzk.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef _SNARKFRONT_DSL_PPZK_HPP_
#define _SNARKFRONT_DSL_PPZK_HPP_
#include <cstdint>
#include <memory>
#include "Alg.hpp"
#include "Alg_bool.hpp"
#include "DSL_base.hpp"
#include <PPZK_keypair.hpp> // snarklib
#include <PPZK_proof.hpp> // snarklib
#include <ProgressCallback.hpp> // snarklib
#include "R1C.hpp"
#include "TLsingleton.hpp"
namespace snarkfront {
////////////////////////////////////////////////////////////////////////////////
// zero knowledge proof management
//
template <typename PAIRING> using Keypair = snarklib::PPZK_Keypair<PAIRING>;
template <typename PAIRING> using Input = R1Cowitness<typename PAIRING::Fr>;
template <typename PAIRING> using Proof = snarklib::PPZK_Proof<PAIRING>;
typedef snarklib::ProgressCallback ProgressCallback;
template <typename PAIRING>
void reset()
{
TL<R1C<typename PAIRING::Fr>>::singleton()
->reset();
}
template <typename PAIRING>
void end_input()
{
TL<R1C<typename PAIRING::Fr>>::singleton()
->checkpointInput();
}
template <typename PAIRING>
std::size_t variable_count()
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->counterID();
}
template <typename PAIRING>
snarklib::PPZK_Keypair<PAIRING> keypair()
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->keypair<PAIRING>();
}
template <typename PAIRING>
snarklib::PPZK_Keypair<PAIRING> keypair(
snarklib::ProgressCallback& callback)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->keypair<PAIRING>(std::addressof(callback));
}
template <typename PAIRING>
const R1Cowitness<typename PAIRING::Fr>& input()
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->input();
}
template <typename PAIRING>
snarklib::PPZK_Proof<PAIRING> proof(
const snarklib::PPZK_Keypair<PAIRING>& keypair)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->proof(keypair, 0);
}
template <typename PAIRING>
snarklib::PPZK_Proof<PAIRING> proof(
const snarklib::PPZK_Keypair<PAIRING>& keypair,
snarklib::ProgressCallback& callback)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->proof(keypair, 0, std::addressof(callback));
}
template <typename PAIRING>
snarklib::PPZK_Proof<PAIRING> proof(
const snarklib::PPZK_Keypair<PAIRING>& keypair,
const std::size_t reserveTune,
snarklib::ProgressCallback& callback)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->proof(keypair, reserveTune, std::addressof(callback));
}
template <typename PAIRING>
bool verify(
const snarklib::PPZK_Keypair<PAIRING>& keypair,
const R1Cowitness<typename PAIRING::Fr>& input,
const snarklib::PPZK_Proof<PAIRING>& proof)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->verify(keypair, input, proof);
}
template <typename PAIRING>
bool verify(
const snarklib::PPZK_Keypair<PAIRING>& keypair,
const R1Cowitness<typename PAIRING::Fr>& input,
const snarklib::PPZK_Proof<PAIRING>& proof,
snarklib::ProgressCallback& callback)
{
return TL<R1C<typename PAIRING::Fr>>::singleton()
->verify(keypair, input, proof, std::addressof(callback));
}
////////////////////////////////////////////////////////////////////////////////
// terminate circuits, constrain final proof output
//
template <typename FR>
void assert_true(const AST_Var<Alg_bool<FR>>& x) {
TL<R1C<FR>>::singleton()->setTrue(x->r1Terms()[0]);
}
template <typename FR>
void assert_false(const AST_Var<Alg_bool<FR>>& x) {
TL<R1C<FR>>::singleton()->setFalse(x->r1Terms()[0]);
}
template <typename FR>
void assert_true(const AST_X<Alg_bool<FR>>& a) {
assert_true(bool_x<FR>(a));
}
template <typename FR>
void assert_false(const AST_X<Alg_bool<FR>>& a) {
assert_false(bool_x<FR>(a));
}
} // namespace snarkfront
#endif