Skip to content

Commit 2d0866c

Browse files
committed
Correct init of curve variables. Now test works.
1 parent 1fc176d commit 2d0866c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/test.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ int main()
1616
{
1717

1818
typedef Fr<default_r1cs_ppzksnark_pp> FieldT;
19+
20+
// Initialize the curve parameters.
21+
default_r1cs_ppzksnark_pp::init_public_params();
1922

2023
// Create protoboard
2124

@@ -24,20 +27,27 @@ int main()
2427
// Define variables
2528

2629
pb_variable<FieldT> x;
27-
pb_variable<FieldT> out;
2830
pb_variable<FieldT> sym_1;
2931
pb_variable<FieldT> y;
3032
pb_variable<FieldT> sym_2;
33+
pb_variable<FieldT> out;
3134

3235
// Allocate variables to protoboard
3336
// The strings (like "x") are only for debugging purposes
3437

35-
x.allocate(pb, "x");
3638
out.allocate(pb, "out");
39+
x.allocate(pb, "x");
3740
sym_1.allocate(pb, "sym_1");
3841
y.allocate(pb, "y");
3942
sym_2.allocate(pb, "sym_2");
4043

44+
// This sets up the protoboard variables
45+
// so that the first one (out) represents the public
46+
// input and the rest is private input
47+
pb.set_input_sizes(1);
48+
49+
cout << "Number of variables: " << pb.num_variables() << endl;
50+
4151
// Add R1CS constraints to protoboard
4252

4353
// x*x = sym_1
@@ -60,36 +70,27 @@ int main()
6070
pb.val(y) = 27;
6171
pb.val(sym_2) = 30;
6272

63-
6473
if (pb.is_satisfied()) {
6574
cout << "Constraint system is satisfied." << endl;
6675
}
6776
else {
6877
cout << "Constraint system is not satisfied." << endl;
6978
}
7079

71-
// This is not working for some reason
72-
cout << "Value of x: " << pb.val(x) << endl;
73-
7480
const r1cs_constraint_system<FieldT> constraint_system = pb.get_constraint_system();
7581

7682
cout << "Number of R1CS constraints: " << constraint_system.num_constraints() << endl;
77-
cout << "Number of variables: " << pb.num_variables() << endl;
78-
79-
// Initialize the curve parameters.
80-
default_r1cs_ppzksnark_pp::init_public_params();
8183

8284
r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp> keypair = r1cs_ppzksnark_generator<default_r1cs_ppzksnark_pp>(constraint_system);
8385

8486
r1cs_ppzksnark_proof<default_r1cs_ppzksnark_pp> proof = r1cs_ppzksnark_prover<default_r1cs_ppzksnark_pp>(keypair.pk, pb.primary_input(), pb.auxiliary_input());
85-
86-
vector<FieldT> empty;
8787

88-
bool verified = r1cs_ppzksnark_verifier_strong_IC<default_r1cs_ppzksnark_pp>(keypair.vk, empty, proof);
88+
bool verified = r1cs_ppzksnark_verifier_strong_IC<default_r1cs_ppzksnark_pp>(keypair.vk, pb.primary_input(), proof);
8989

90-
cout << "Verification status: " << verified << endl;
90+
cout << "Primary (public) input: " << pb.primary_input() << endl;
91+
cout << "Auxiliary (private) input: " << pb.auxiliary_input() << endl;
9192

92-
cout << "made it here" << endl;
93+
cout << "Verification status: " << verified << endl;
9394

9495
return 0;
9596
}

0 commit comments

Comments
 (0)