Skip to content

Commit

Permalink
NoteEncryption implementation and integration, removal of ECIES and c…
Browse files Browse the repository at this point in the history
…rypto++ dependencies.
  • Loading branch information
ebfull committed Apr 28, 2016
1 parent b2cf9ba commit 6c36a9f
Show file tree
Hide file tree
Showing 23 changed files with 1,206 additions and 735 deletions.
8 changes: 1 addition & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,6 @@ AC_CHECK_LIB([gmp],[[__gmpn_sub_n]],GMP_LIBS=-lgmp, [AC_MSG_ERROR(libgmp missing
AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing))
AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)])

AC_CHECK_HEADER([cryptopp/eccrypto.h],,AC_MSG_ERROR(libcryptopp headers missing))
# We link against "main" as a stop-gap; crypto++ is full of template
# classes whose library symbols are mangled by some black alchemy.
AC_CHECK_LIB([cryptopp],[main],CRYPTOPP_LIBS=-lcryptopp, [AC_MSG_ERROR(libcryptopp missing)])

# libsnark header layout is broken unless cpp's -I is passed with the
# libsnark directory, so for now we use this hideous workaround:
echo 'Hunting for libsnark include directory...'
Expand All @@ -720,7 +715,7 @@ CPPFLAGS="-I$LIBSNARK_INCDIR $CPPFLAGS"
AC_CHECK_HEADER([libsnark/gadgetlib1/gadget.hpp],,AC_MSG_ERROR(libsnark headers missing))
AC_CHECK_LIB([snark],[main],LIBSNARK_LIBS=-lsnark, [AC_MSG_ERROR(libsnark missing)], [-lgmpxx])

LIBZEROCASH_LIBS="-lsnark -lcryptopp -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium"
LIBZEROCASH_LIBS="-lsnark -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium"

AC_CHECK_LIB([crypto],[RAND_egd],[],[
AC_ARG_WITH([libressl],
Expand Down Expand Up @@ -929,7 +924,6 @@ AC_SUBST(MINIUPNPC_CPPFLAGS)
AC_SUBST(MINIUPNPC_LIBS)
AC_SUBST(GMP_LIBS)
AC_SUBST(GMPXX_LIBS)
AC_SUBST(CRYPTOPP_LIBS)
AC_SUBST(LIBSNARK_LIBS)
AC_SUBST(LIBZEROCASH_LIBS)
AC_CONFIG_FILES([Makefile src/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py])
Expand Down
20 changes: 0 additions & 20 deletions depends/packages/crypto++.mk

This file was deleted.

2 changes: 1 addition & 1 deletion depends/packages/packages.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zerocash_packages := libsnark crypto++ libgmp libsodium
zerocash_packages := libsnark libgmp libsodium
packages := boost openssl $(zerocash_packages) googletest
native_packages := native_ccache native_comparisontool

Expand Down
9 changes: 6 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ LIBZEROCASH_H = \
zerocash/Zerocash.h \
zerocash/ZerocashParams.h \
zerocash/zerocash_pour_params.hpp \
zerocash/utils/util.h
zerocash/utils/util.h \
zcash/NoteEncryption.hpp \
zcash/prf.h

.PHONY: FORCE
# bitcoin core #
Expand Down Expand Up @@ -400,7 +402,6 @@ bitcoin_tx_LDADD = \
$(LIBBITCOIN_UNIVALUE) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(LIBSECP256K1) \
$(LIBZEROCASH) \
$(LIBBITCOIN_CRYPTO) \
Expand All @@ -421,7 +422,9 @@ libzerocash_a_SOURCES = \
zerocash/PourProver.cpp \
zerocash/PourTransaction.cpp \
zerocash/ZerocashParams.cpp \
zerocash/utils/util.cpp
zerocash/utils/util.cpp \
zcash/NoteEncryption.cpp \
zcash/prf.cpp

libzerocash_a_CPPFLAGS = -fPIC -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -std=c++11 -pipe -O2 -O0 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ BITCOIN_TESTS =\
test/miner_tests.cpp \
test/mruset_tests.cpp \
test/multisig_tests.cpp \
test/noteencryption_tests.cpp \
test/netbase_tests.cpp \
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.zcash.include
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ zerocash_tests_zerocashTest_SOURCES = \
zerocash_tests_zerocashTest_LDADD = \
$(BOOST_LIBS) \
$(LIBZEROCASH) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZEROCASH_LIBS)

Expand All @@ -47,6 +48,7 @@ zerocash_tests_test_zerocash_pour_ppzksnark_SOURCES = zerocash/tests/test_zeroca
zerocash_tests_test_zerocash_pour_ppzksnark_LDADD = \
$(BOOST_LIBS) \
$(LIBZEROCASH) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZEROCASH_LIBS)

5 changes: 1 addition & 4 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ CPourTx::CPourTx(ZerocashParams& params,
boost::array<std::vector<unsigned char>, NUM_POUR_INPUTS> serials_bv;
boost::array<std::vector<unsigned char>, NUM_POUR_OUTPUTS> commitments_bv;
boost::array<std::vector<unsigned char>, NUM_POUR_INPUTS> macs_bv;
boost::array<std::string, NUM_POUR_OUTPUTS> ciphertexts_bv;

proof = pourtx.unpack(serials_bv, commitments_bv, macs_bv, ciphertexts_bv);
proof = pourtx.unpack(serials_bv, commitments_bv, macs_bv, ciphertexts, ephemeralKey);
serials = unsigned_char_vector_array_to_uint256_array(serials_bv);
commitments = unsigned_char_vector_array_to_uint256_array(commitments_bv);
macs = unsigned_char_vector_array_to_uint256_array(macs_bv);

ciphertexts = ciphertexts_bv;
}

bool CPourTx::Verify(ZerocashParams& params) const {
Expand Down
19 changes: 12 additions & 7 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "zerocash/PourInput.h"
#include "zerocash/PourOutput.h"

#include "zcash/NoteEncryption.hpp"

using namespace libzerocash;

static const unsigned int NUM_POUR_INPUTS = 2;
Expand Down Expand Up @@ -58,10 +60,13 @@ class CPourTx
boost::array<uint256, NUM_POUR_OUTPUTS> commitments;

// Ciphertexts
// These are encrypted using ECIES. They are used to
// transfer metadata and seeds to generate trapdoors
// for the recipient to spend the value.
boost::array<std::string, NUM_POUR_OUTPUTS> ciphertexts;
// These contain trapdoors, values and other information
// that the recipient needs, including a memo field. It
// is encrypted using the scheme implemented in crypto/NoteEncryption.cpp
boost::array<ZCNoteEncryption::Ciphertext, NUM_POUR_OUTPUTS> ciphertexts;

// Ephemeral key
uint256 ephemeralKey;

// MACs
// The verification of the pour requires these MACs
Expand All @@ -72,9 +77,7 @@ class CPourTx
// This is a zk-SNARK which ensures that this pour is valid.
std::string proof;

CPourTx(): vpub_old(0), vpub_new(0), scriptPubKey(), scriptSig(), anchor(), serials(), commitments(), ciphertexts(), macs(), proof() {

}
CPourTx(): vpub_old(0), vpub_new(0) { }

CPourTx(ZerocashParams& params,
const CScript& scriptPubKey,
Expand All @@ -100,6 +103,7 @@ class CPourTx
READWRITE(serials);
READWRITE(commitments);
READWRITE(ciphertexts);
READWRITE(ephemeralKey);
READWRITE(macs);
READWRITE(proof);
}
Expand All @@ -115,6 +119,7 @@ class CPourTx
a.serials == b.serials &&
a.commitments == b.commitments &&
a.ciphertexts == b.ciphertexts &&
a.ephemeralKey == b.ephemeralKey &&
a.macs == b.macs &&
a.proof == b.proof
);
Expand Down
Loading

0 comments on commit 6c36a9f

Please sign in to comment.