diff --git a/src/zcash/GenerateParams.cpp b/src/zcash/GenerateParams.cpp index 9e27047ab..eadfe7b18 100644 --- a/src/zcash/GenerateParams.cpp +++ b/src/zcash/GenerateParams.cpp @@ -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; diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 719564523..b9e72f1c2 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -111,14 +111,23 @@ public: 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 generate_r1cs() { protoboard pb; joinsplit_gadget g(pb); g.generate_r1cs_constraints(); - const r1cs_constraint_system constraint_system = pb.get_constraint_system(); + return pb.get_constraint_system(); + } + + void generate() { + const r1cs_constraint_system constraint_system = generate_r1cs(); r1cs_ppzksnark_keypair keypair = r1cs_ppzksnark_generator(constraint_system); pk = keypair.pk; diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index 6acfc2a25..8f17a4c46 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -62,6 +62,7 @@ public: 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& inputs,