Enable binary serializations of proofs and r1cs keys, and make the CPourTx proof field fixed-size.

This commit is contained in:
Sean Bowe
2016-05-23 09:47:23 -06:00
parent 9cf13a3e85
commit 9285bba885
10 changed files with 22 additions and 21 deletions

View File

@@ -39,10 +39,8 @@ else
CXXFLAGS_overridden=no CXXFLAGS_overridden=no
fi fi
# Zerocash requries C++11 compatibility; set it early: # Zcash requries C++11 compatibility; set it early:
CXXFLAGS="-std=c++11 $CXXFLAGS" CXXFLAGS="-std=c++11 $CXXFLAGS"
# Zerocash uses this libsnark curve:
CPPFLAGS="-DCURVE_ALT_BN128 $CPPFLAGS"
AC_PROG_CXX AC_PROG_CXX
m4_ifdef([AC_PROG_OBJCXX],[AC_PROG_OBJCXX]) m4_ifdef([AC_PROG_OBJCXX],[AC_PROG_OBJCXX])

View File

@@ -15,7 +15,7 @@ define $(package)_preprocess_cmds
endef endef
define $(package)_build_cmds 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 endef
define $(package)_stage_cmds define $(package)_stage_cmds

View File

@@ -415,7 +415,7 @@ libzcash_a_SOURCES = \
zcash/prf.cpp \ zcash/prf.cpp \
zcash/util.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 # # bitcoinconsensus library #
if BUILD_BITCOIN_LIBS if BUILD_BITCOIN_LIBS

View File

@@ -11,6 +11,8 @@ zcash_gtest_SOURCES = \
gtest/test_merkletree.cpp \ gtest/test_merkletree.cpp \
gtest/test_circuit.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) \ 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) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1)
if ENABLE_WALLET if ENABLE_WALLET

View File

@@ -33,7 +33,7 @@ void test_full_api(ZCJoinSplit* js)
boost::array<uint256, 2> commitments; boost::array<uint256, 2> commitments;
uint256 rt = tree.root(); uint256 rt = tree.root();
boost::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts; boost::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts;
std::string proof; boost::array<unsigned char, ZKSNARK_PROOF_SIZE> proof;
{ {
boost::array<JSInput, 2> inputs = { boost::array<JSInput, 2> inputs = {

View File

@@ -63,7 +63,7 @@ public:
// Pour proof // Pour proof
// This is a zk-SNARK which ensures that this pour is valid. // This is a zk-SNARK which ensures that this pour is valid.
std::string proof; boost::array<unsigned char, ZKSNARK_PROOF_SIZE> proof;
CPourTx(): vpub_old(0), vpub_new(0) { } CPourTx(): vpub_old(0), vpub_new(0) { }

View File

@@ -135,14 +135,6 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
randombytes_buf(pourtx.ciphertexts[1].begin(), pourtx.ciphertexts[1].size()); randombytes_buf(pourtx.ciphertexts[1].begin(), pourtx.ciphertexts[1].size());
pourtx.macs[0] = GetRandHash(); pourtx.macs[0] = GetRandHash();
pourtx.macs[1] = GetRandHash(); pourtx.macs[1] = GetRandHash();
{
std::vector<unsigned char> 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); tx.vpour.push_back(pourtx);
} }

View File

@@ -126,7 +126,7 @@ public:
JoinSplitCircuit() {} JoinSplitCircuit() {}
bool verify( bool verify(
const std::string& proof, const boost::array<unsigned char, ZKSNARK_PROOF_SIZE>& proof,
const uint256& pubKeyHash, const uint256& pubKeyHash,
const uint256& randomSeed, const uint256& randomSeed,
const boost::array<uint256, NumInputs>& macs, const boost::array<uint256, NumInputs>& macs,
@@ -142,7 +142,8 @@ public:
r1cs_ppzksnark_proof<ppzksnark_ppT> r1cs_proof; r1cs_ppzksnark_proof<ppzksnark_ppT> r1cs_proof;
std::stringstream ss; std::stringstream ss;
ss.str(proof); std::string proof_str(proof.begin(), proof.end());
ss.str(proof_str);
ss >> r1cs_proof; ss >> r1cs_proof;
uint256 h_sig = this->h_sig(randomSeed, nullifiers, pubKeyHash); uint256 h_sig = this->h_sig(randomSeed, nullifiers, pubKeyHash);
@@ -160,7 +161,7 @@ public:
return r1cs_ppzksnark_verifier_strong_IC<ppzksnark_ppT>(*vk, witness, r1cs_proof); return r1cs_ppzksnark_verifier_strong_IC<ppzksnark_ppT>(*vk, witness, r1cs_proof);
} }
std::string prove( boost::array<unsigned char, ZKSNARK_PROOF_SIZE> prove(
const boost::array<JSInput, NumInputs>& inputs, const boost::array<JSInput, NumInputs>& inputs,
const boost::array<JSOutput, NumOutputs>& outputs, const boost::array<JSOutput, NumOutputs>& outputs,
boost::array<Note, NumOutputs>& out_notes, boost::array<Note, NumOutputs>& out_notes,
@@ -266,8 +267,14 @@ public:
std::stringstream ss; std::stringstream ss;
ss << proof; ss << proof;
std::string serialized_proof = ss.str();
return ss.str(); boost::array<unsigned char, ZKSNARK_PROOF_SIZE> 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;
} }
}; };

View File

@@ -58,7 +58,7 @@ public:
virtual void loadVerifyingKey(std::string path) = 0; virtual void loadVerifyingKey(std::string path) = 0;
virtual void saveVerifyingKey(std::string path) = 0; virtual void saveVerifyingKey(std::string path) = 0;
virtual std::string prove( virtual boost::array<unsigned char, ZKSNARK_PROOF_SIZE> prove(
const boost::array<JSInput, NumInputs>& inputs, const boost::array<JSInput, NumInputs>& inputs,
const boost::array<JSOutput, NumOutputs>& outputs, const boost::array<JSOutput, NumOutputs>& outputs,
boost::array<Note, NumOutputs>& out_notes, boost::array<Note, NumOutputs>& out_notes,
@@ -75,7 +75,7 @@ public:
) = 0; ) = 0;
virtual bool verify( virtual bool verify(
const std::string& proof, const boost::array<unsigned char, ZKSNARK_PROOF_SIZE>& proof,
const uint256& pubKeyHash, const uint256& pubKeyHash,
const uint256& randomSeed, const uint256& randomSeed,
const boost::array<uint256, NumInputs>& hmacs, const boost::array<uint256, NumInputs>& hmacs,

View File

@@ -12,4 +12,6 @@
#define ZC_R_SIZE 32 #define ZC_R_SIZE 32
#define ZC_MEMO_SIZE 128 #define ZC_MEMO_SIZE 128
#define ZKSNARK_PROOF_SIZE 584
#endif // _ZCCONSTANTS_H_ #endif // _ZCCONSTANTS_H_