Skip to content

Commit

Permalink
Auto merge of zcash#1399 - ebfull:write-r1cs, r=ebfull
Browse files Browse the repository at this point in the history
Write R1CS output to file in GenerateParams.

Not urgent. This is how the constraint system is communicated to the MPC.
  • Loading branch information
zkbot committed Nov 4, 2016
2 parents de9ca8e + 0a958ae commit c73122d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/zcash/GenerateParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ int main(int argc, char **argv)
return 1;
}

if(argc != 3) {
std::cerr << "Usage: " << argv[0] << " provingKeyFileName verificationKeyFileName" << std::endl;
if(argc != 4) {
std::cerr << "Usage: " << argv[0] << " provingKeyFileName verificationKeyFileName r1csFileName" << std::endl;
return 1;
}

std::string pkFile = argv[1];
std::string vkFile = argv[2];
std::string r1csFile = argv[3];

auto p = ZCJoinSplit::Generate();

p->saveProvingKey(pkFile);
p->saveVerifyingKey(vkFile);
p->saveR1CS(r1csFile);

delete p;

Expand Down
13 changes: 11 additions & 2 deletions src/zcash/JoinSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,23 @@ class JoinSplitCircuit : public JoinSplit<NumInputs, NumOutputs> {
throw std::runtime_error("cannot save verifying key; key doesn't exist");
}
}
void saveR1CS(std::string path) {
auto r1cs = generate_r1cs();

void generate() {
saveToFile(path, r1cs);
}

r1cs_constraint_system<FieldT> generate_r1cs() {
protoboard<FieldT> pb;

joinsplit_gadget<FieldT, NumInputs, NumOutputs> g(pb);
g.generate_r1cs_constraints();

const r1cs_constraint_system<FieldT> constraint_system = pb.get_constraint_system();
return pb.get_constraint_system();
}

void generate() {
const r1cs_constraint_system<FieldT> constraint_system = generate_r1cs();
r1cs_ppzksnark_keypair<ppzksnark_ppT> keypair = r1cs_ppzksnark_generator<ppzksnark_ppT>(constraint_system);

pk = keypair.pk;
Expand Down
1 change: 1 addition & 0 deletions src/zcash/JoinSplit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class JoinSplit {
virtual void saveProvingKey(std::string path) = 0;
virtual void loadVerifyingKey(std::string path) = 0;
virtual void saveVerifyingKey(std::string path) = 0;
virtual void saveR1CS(std::string path) = 0;

virtual ZCProof prove(
const boost::array<JSInput, NumInputs>& inputs,
Expand Down

0 comments on commit c73122d

Please sign in to comment.