From 685c0ab07fd90b244dac5e2cb1f069ac6151ec5c Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sat, 17 Nov 2018 15:47:35 -0700 Subject: [PATCH] Allow user to ask server to save the Sprout R1CS out during startup. --- src/init.cpp | 10 ++++++++++ src/zcash/JoinSplit.cpp | 10 ++++++++++ src/zcash/JoinSplit.hpp | 2 ++ 3 files changed, 22 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index add2fc1b1..8ce766e5c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -842,6 +842,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) return InitError(_("Payment disclosure requires -experimentalfeatures.")); } else if (mapArgs.count("-zmergetoaddress")) { return InitError(_("RPC method z_mergetoaddress requires -experimentalfeatures.")); + } else if (mapArgs.count("-savesproutr1cs")) { + return InitError(_("Saving the Sprout R1CS requires -experimentalfeatures.")); } } @@ -1221,6 +1223,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Initialize Zcash circuit parameters ZC_LoadParams(chainparams); + if (GetBoolArg("-savesproutr1cs", false)) { + boost::filesystem::path r1cs_path = ZC_GetParamsDir() / "r1cs"; + + LogPrintf("Saving Sprout R1CS to %s\n", r1cs_path.string()); + + pzcashParams->saveR1CS(r1cs_path.string()); + } + /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections * that the server is there and will be ready later). Warmup mode will diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 0772ecb67..669b5f63a 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -101,6 +101,16 @@ public: saveToFile(pkPath, keypair.pk); } + void saveR1CS(std::string path) + { + protoboard pb; + joinsplit_gadget g(pb); + g.generate_r1cs_constraints(); + r1cs_constraint_system r1cs = pb.get_constraint_system(); + + saveToFile(path, r1cs); + } + bool verify( const PHGRProof& proof, ProofVerifier& verifier, diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index c37926ede..2d3a61a6d 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -67,6 +67,8 @@ public: const uint256& joinSplitPubKey ); + virtual void saveR1CS(std::string path) = 0; + // Compute nullifiers, macs, note commitments & encryptions, and SNARK proof virtual SproutProof prove( bool makeGrothProof,