diff --git a/configure.ac b/configure.ac index 1c8f5e168..5453418a7 100644 --- a/configure.ac +++ b/configure.ac @@ -39,10 +39,8 @@ else CXXFLAGS_overridden=no fi -# Zerocash requries C++11 compatibility; set it early: +# Zcash requries C++11 compatibility; set it early: CXXFLAGS="-std=c++11 $CXXFLAGS" -# Zerocash uses this libsnark curve: -CPPFLAGS="-DCURVE_ALT_BN128 $CPPFLAGS" AC_PROG_CXX m4_ifdef([AC_PROG_OBJCXX],[AC_PROG_OBJCXX]) diff --git a/depends/packages/libsnark.mk b/depends/packages/libsnark.mk index 7d5c8b1af..d40956b78 100644 --- a/depends/packages/libsnark.mk +++ b/depends/packages/libsnark.mk @@ -15,7 +15,7 @@ define $(package)_preprocess_cmds endef define $(package)_build_cmds - CXXFLAGS="-fPIC -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 + CXXFLAGS="-fPIC -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 endef define $(package)_stage_cmds diff --git a/src/Makefile.am b/src/Makefile.am index 6cb0f89b3..5f7f7f198 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -415,7 +415,7 @@ libzcash_a_SOURCES = \ zcash/prf.cpp \ zcash/util.cpp -libzcash_a_CPPFLAGS = -fPIC -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -std=c++11 -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) +libzcash_a_CPPFLAGS = -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) # bitcoinconsensus library # if BUILD_BITCOIN_LIBS diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 041a2fb83..aed865a7c 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -11,6 +11,8 @@ zcash_gtest_SOURCES = \ gtest/test_merkletree.cpp \ gtest/test_circuit.cpp +zcash_gtest_CPPFLAGS = -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC + zcash_gtest_LDADD = -lgtest $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) if ENABLE_WALLET diff --git a/src/gtest/test_joinsplit.cpp b/src/gtest/test_joinsplit.cpp index 96e887e77..2b5f95d0e 100644 --- a/src/gtest/test_joinsplit.cpp +++ b/src/gtest/test_joinsplit.cpp @@ -33,7 +33,7 @@ void test_full_api(ZCJoinSplit* js) boost::array commitments; uint256 rt = tree.root(); boost::array ciphertexts; - std::string proof; + boost::array proof; { boost::array inputs = { diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 79dbe8336..be134f147 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -63,7 +63,7 @@ public: // Pour proof // This is a zk-SNARK which ensures that this pour is valid. - std::string proof; + boost::array proof; CPourTx(): vpub_old(0), vpub_new(0) { } diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 4ff973c8b..15564ed90 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -135,14 +135,6 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) { randombytes_buf(pourtx.ciphertexts[1].begin(), pourtx.ciphertexts[1].size()); pourtx.macs[0] = GetRandHash(); pourtx.macs[1] = GetRandHash(); - { - std::vector txt; - int prooflen = insecure_rand() % 1000; - for (int i = 0; i < prooflen; i++) { - txt.push_back(insecure_rand() % 256); - } - pourtx.proof = std::string(txt.begin(), txt.end()); - } tx.vpour.push_back(pourtx); } diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 05da1e87a..2000ee4c9 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -126,7 +126,7 @@ public: JoinSplitCircuit() {} bool verify( - const std::string& proof, + const boost::array& proof, const uint256& pubKeyHash, const uint256& randomSeed, const boost::array& macs, @@ -142,7 +142,8 @@ public: r1cs_ppzksnark_proof r1cs_proof; std::stringstream ss; - ss.str(proof); + std::string proof_str(proof.begin(), proof.end()); + ss.str(proof_str); ss >> r1cs_proof; uint256 h_sig = this->h_sig(randomSeed, nullifiers, pubKeyHash); @@ -160,7 +161,7 @@ public: return r1cs_ppzksnark_verifier_strong_IC(*vk, witness, r1cs_proof); } - std::string prove( + boost::array prove( const boost::array& inputs, const boost::array& outputs, boost::array& out_notes, @@ -266,8 +267,14 @@ public: std::stringstream ss; ss << proof; + std::string serialized_proof = ss.str(); - return ss.str(); + boost::array result_proof; + //std::cout << "proof size in bytes when serialized: " << serialized_proof.size() << std::endl; + assert(serialized_proof.size() == ZKSNARK_PROOF_SIZE); + memcpy(&result_proof[0], &serialized_proof[0], ZKSNARK_PROOF_SIZE); + + return result_proof; } }; diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index bd06c7ecb..f80cf9168 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -58,7 +58,7 @@ public: virtual void loadVerifyingKey(std::string path) = 0; virtual void saveVerifyingKey(std::string path) = 0; - virtual std::string prove( + virtual boost::array prove( const boost::array& inputs, const boost::array& outputs, boost::array& out_notes, @@ -75,7 +75,7 @@ public: ) = 0; virtual bool verify( - const std::string& proof, + const boost::array& proof, const uint256& pubKeyHash, const uint256& randomSeed, const boost::array& hmacs, diff --git a/src/zcash/Zcash.h b/src/zcash/Zcash.h index b0d9fbb95..0c2d569a9 100644 --- a/src/zcash/Zcash.h +++ b/src/zcash/Zcash.h @@ -12,4 +12,6 @@ #define ZC_R_SIZE 32 #define ZC_MEMO_SIZE 128 +#define ZKSNARK_PROOF_SIZE 584 + #endif // _ZCCONSTANTS_H_