1
+ #include < stdlib.h>
2
+ #include < iostream>
3
+
4
+ #include " libff/algebra/fields/field_utils.hpp"
5
+ #include " libsnark/zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.hpp"
6
+ #include " libsnark/common/default_types/r1cs_ppzksnark_pp.hpp"
7
+ #include " libsnark/gadgetlib1/pb_variable.hpp"
8
+
9
+ #include " gadget.hpp"
10
+
11
+ using namespace libsnark ;
12
+ using namespace std ;
13
+
14
+ int main ()
15
+ {
16
+ // Initialize the curve parameters.
17
+ default_r1cs_ppzksnark_pp::init_public_params ();
18
+
19
+ typedef libff::Fr<default_r1cs_ppzksnark_pp> FieldT;
20
+
21
+ // Create protoboard
22
+
23
+ protoboard<FieldT> pb;
24
+ pb_variable<FieldT> out;
25
+ pb_variable<FieldT> x;
26
+
27
+ // Allocate variables
28
+
29
+ out.allocate (pb, " out" );
30
+ x.allocate (pb, " x" );
31
+
32
+ // This sets up the protoboard variables
33
+ // so that the first one (out) represents the public
34
+ // input and the rest is private input
35
+
36
+ pb.set_input_sizes (1 );
37
+
38
+ test_gadget<FieldT> g (pb, out, x);
39
+ g.generate_r1cs_constraints ();
40
+
41
+ cout << " Number of variables: " << pb.num_variables () << endl;
42
+
43
+ // Add witness values
44
+
45
+ pb.val (out) = 35 ;
46
+ pb.val (x) = 3 ;
47
+
48
+ g.generate_r1cs_witness ();
49
+
50
+ if (pb.is_satisfied ()) {
51
+ cout << " Constraint system is satisfied." << endl;
52
+ }
53
+ else {
54
+ cout << " Constraint system is not satisfied." << endl;
55
+ }
56
+
57
+ cout << " primary (public) input: " << pb.primary_input () << endl;
58
+ cout << " auxiliary (private) input: " << pb.auxiliary_input () << endl;
59
+
60
+ const r1cs_constraint_system<FieldT> constraint_system = pb.get_constraint_system ();
61
+
62
+ cout << " Number of R1CS constraints: " << constraint_system.num_constraints () << endl;
63
+
64
+ r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp> keypair = r1cs_ppzksnark_generator<default_r1cs_ppzksnark_pp>(constraint_system);
65
+
66
+ r1cs_ppzksnark_proof<default_r1cs_ppzksnark_pp> proof = r1cs_ppzksnark_prover<default_r1cs_ppzksnark_pp>(keypair.pk , pb.primary_input (), pb.auxiliary_input ());
67
+
68
+ bool verified = r1cs_ppzksnark_verifier_strong_IC<default_r1cs_ppzksnark_pp>(keypair.vk , pb.primary_input (), proof);
69
+
70
+ cout << " Primary (public) input: " << pb.primary_input () << endl;
71
+ cout << " Auxiliary (private) input: " << pb.auxiliary_input () << endl;
72
+
73
+ cout << " Verification status: " << verified << endl;
74
+
75
+ return 0 ;
76
+ }
0 commit comments