Browse Source

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

pull/145/head
Sean Bowe 8 years ago
parent
commit
9285bba885
  1. 4
      configure.ac
  2. 2
      depends/packages/libsnark.mk
  3. 2
      src/Makefile.am
  4. 2
      src/Makefile.gtest.include
  5. 2
      src/gtest/test_joinsplit.cpp
  6. 2
      src/primitives/transaction.h
  7. 8
      src/test/sighash_tests.cpp
  8. 15
      src/zcash/JoinSplit.cpp
  9. 4
      src/zcash/JoinSplit.hpp
  10. 2
      src/zcash/Zcash.h

4
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])

2
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

2
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

2
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

2
src/gtest/test_joinsplit.cpp

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

2
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<unsigned char, ZKSNARK_PROOF_SIZE> proof;
CPourTx(): vpub_old(0), vpub_new(0) { }

8
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<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);
}

15
src/zcash/JoinSplit.cpp

@ -126,7 +126,7 @@ public:
JoinSplitCircuit() {}
bool verify(
const std::string& proof,
const boost::array<unsigned char, ZKSNARK_PROOF_SIZE>& proof,
const uint256& pubKeyHash,
const uint256& randomSeed,
const boost::array<uint256, NumInputs>& macs,
@ -142,7 +142,8 @@ public:
r1cs_ppzksnark_proof<ppzksnark_ppT> 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<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<JSOutput, NumOutputs>& outputs,
boost::array<Note, NumOutputs>& out_notes,
@ -266,8 +267,14 @@ public:
std::stringstream ss;
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;
}
};

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

2
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_

Loading…
Cancel
Save