From 2668a1bc1328a87a53bfe97a1486561d210cd37b Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Tue, 28 Jun 2016 10:08:50 -0600 Subject: [PATCH] Remove the rest of libzerocash. --- src/Makefile.am | 2 -- src/Makefile.gtest.include | 3 +- src/Makefile.zcash.include | 12 +------ src/gtest/test_circuit.cpp | 2 -- src/gtest/test_libzcash_utils.cpp | 44 +++++++++++++++++++++++ src/gtest/test_merkletree.cpp | 13 ++++--- src/zcash/IncrementalMerkleTree.cpp | 7 ++-- src/zcash/JoinSplit.cpp | 1 - src/zcash/circuit/merkle.tcc | 2 +- src/zcash/circuit/utils.tcc | 13 ++----- src/zcash/util.cpp | 33 +++++++++++++++++ src/zcash/util.h | 2 ++ src/zerocash/.gitignore | 16 --------- src/zerocash/AUTHORS | 7 ---- src/zerocash/LICENSE | 19 ---------- src/zerocash/tests/full-test-suite.sh | 31 ---------------- src/zerocash/tests/timer.cpp | 48 ------------------------- src/zerocash/tests/timer.h | 28 --------------- src/zerocash/tests/utilTest.cpp | 52 --------------------------- src/zerocash/utils/util.cpp | 42 ---------------------- src/zerocash/utils/util.h | 20 ----------- 21 files changed, 94 insertions(+), 303 deletions(-) create mode 100644 src/gtest/test_libzcash_utils.cpp delete mode 100644 src/zerocash/.gitignore delete mode 100644 src/zerocash/AUTHORS delete mode 100644 src/zerocash/LICENSE delete mode 100755 src/zerocash/tests/full-test-suite.sh delete mode 100644 src/zerocash/tests/timer.cpp delete mode 100644 src/zerocash/tests/timer.h delete mode 100644 src/zerocash/tests/utilTest.cpp delete mode 100644 src/zerocash/utils/util.cpp delete mode 100644 src/zerocash/utils/util.h diff --git a/src/Makefile.am b/src/Makefile.am index f4613c27c..1a9ca90aa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -72,7 +72,6 @@ endif # TODO: rename to libzcash LIBZCASH_H = \ zcash/IncrementalMerkleTree.h \ - zerocash/utils/util.h \ zcash/NoteEncryption.hpp \ zcash/Address.hpp \ zcash/JoinSplit.hpp \ @@ -408,7 +407,6 @@ bitcoin_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS) # zerocash protocol primitives # libzcash_a_SOURCES = \ zcash/IncrementalMerkleTree.cpp \ - zerocash/utils/util.cpp \ zcash/NoteEncryption.cpp \ zcash/Address.cpp \ zcash/JoinSplit.cpp \ diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 1a76f8463..7369f9431 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -9,7 +9,8 @@ zcash_gtest_SOURCES = \ gtest/test_joinsplit.cpp \ gtest/test_noteencryption.cpp \ gtest/test_merkletree.cpp \ - gtest/test_circuit.cpp + gtest/test_circuit.cpp \ + gtest/test_libzcash_utils.cpp zcash_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC diff --git a/src/Makefile.zcash.include b/src/Makefile.zcash.include index 45c944ea1..341ba2736 100644 --- a/src/Makefile.zcash.include +++ b/src/Makefile.zcash.include @@ -1,6 +1,5 @@ bin_PROGRAMS += \ - zcash/GenerateParams \ - zerocash/tests/utilTest + zcash/GenerateParams # tool for generating our public parameters zcash_GenerateParams_SOURCES = zcash/GenerateParams.cpp @@ -10,12 +9,3 @@ zcash_GenerateParams_LDADD = \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CRYPTO) \ $(LIBZCASH_LIBS) - -# tests for utilities that come with zerocash -zerocash_tests_utilTest_SOURCES = zerocash/tests/utilTest.cpp -zerocash_tests_utilTest_LDADD = \ - $(BOOST_LIBS) \ - $(LIBZCASH) \ - $(LIBBITCOIN_UTIL) \ - $(LIBBITCOIN_CRYPTO) \ - $(LIBZCASH_LIBS) diff --git a/src/gtest/test_circuit.cpp b/src/gtest/test_circuit.cpp index 26004e045..612a72886 100644 --- a/src/gtest/test_circuit.cpp +++ b/src/gtest/test_circuit.cpp @@ -1,7 +1,6 @@ #include #include "uint256.h" -#include "zerocash/utils/util.h" #include "zcash/util.h" #include @@ -14,7 +13,6 @@ #include "libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.hpp" using namespace libsnark; -using namespace libzerocash; #include "zcash/circuit/utils.tcc" diff --git a/src/gtest/test_libzcash_utils.cpp b/src/gtest/test_libzcash_utils.cpp new file mode 100644 index 000000000..ff84608bc --- /dev/null +++ b/src/gtest/test_libzcash_utils.cpp @@ -0,0 +1,44 @@ +#include +#include "zcash/util.h" + +TEST(libzcash_utils, convertBytesVectorToVector) +{ + std::vector bytes = {0x00, 0x01, 0x03, 0x12, 0xFF}; + std::vector expected_bits = { + // 0x00 + 0, 0, 0, 0, 0, 0, 0, 0, + // 0x01 + 0, 0, 0, 0, 0, 0, 0, 1, + // 0x03 + 0, 0, 0, 0, 0, 0, 1, 1, + // 0x12 + 0, 0, 0, 1, 0, 0, 1, 0, + // 0xFF + 1, 1, 1, 1, 1, 1, 1, 1 + }; + ASSERT_TRUE(convertBytesVectorToVector(bytes) == expected_bits); +} + +TEST(libzcash_utils, convertVectorToInt) +{ + ASSERT_TRUE(convertVectorToInt({0}) == 0); + ASSERT_TRUE(convertVectorToInt({1}) == 1); + ASSERT_TRUE(convertVectorToInt({0,1}) == 1); + ASSERT_TRUE(convertVectorToInt({1,0}) == 2); + ASSERT_TRUE(convertVectorToInt({1,1}) == 3); + ASSERT_TRUE(convertVectorToInt({1,0,0}) == 4); + ASSERT_TRUE(convertVectorToInt({1,0,1}) == 5); + ASSERT_TRUE(convertVectorToInt({1,1,0}) == 6); + + ASSERT_THROW(convertVectorToInt(std::vector(100)), std::length_error); + + { + std::vector v(63, 1); + ASSERT_TRUE(convertVectorToInt(v) == 0x7fffffffffffffff); + } + + { + std::vector v(64, 1); + ASSERT_TRUE(convertVectorToInt(v) == 0xffffffffffffffff); + } +} diff --git a/src/gtest/test_merkletree.cpp b/src/gtest/test_merkletree.cpp index 04374f6de..b5c1bb4c6 100644 --- a/src/gtest/test_merkletree.cpp +++ b/src/gtest/test_merkletree.cpp @@ -15,6 +15,9 @@ #include "serialize.h" #include "streams.h" +#include "zcash/IncrementalMerkleTree.hpp" +#include "zcash/util.h" + #include "libsnark/common/default_types/r1cs_ppzksnark_pp.hpp" #include "libsnark/zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.hpp" #include "libsnark/gadgetlib1/gadgets/hashes/sha256/sha256_gadget.hpp" @@ -40,13 +43,9 @@ read_json(const std::string& jsondata) return v.get_array(); } -#include "zcash/IncrementalMerkleTree.hpp" -#include "zerocash/utils/util.h" - //#define PRINT_JSON 1 using namespace std; -using namespace libzerocash; using namespace libsnark; @@ -178,10 +177,10 @@ void test_tree(Array root_tests, Array ser_tests, Array witness_ser_tests, Array std::vector commitment_bv; { std::vector commitment_v(test_commitment.begin(), test_commitment.end()); - convertBytesVectorToVector(commitment_v, commitment_bv); + commitment_bv = convertBytesVectorToVector(commitment_v); } - size_t path_index = libzerocash::convertVectorToInt(path.index); + size_t path_index = convertVectorToInt(path.index); commitment.bits.fill_with_bits(pb, bit_vector(commitment_bv)); positions.fill_with_bits_of_ulong(pb, path_index); @@ -193,7 +192,7 @@ void test_tree(Array root_tests, Array ser_tests, Array witness_ser_tests, Array { uint256 witroot = wit.root(); std::vector root_v(witroot.begin(), witroot.end()); - convertBytesVectorToVector(root_v, root_bv); + root_bv = convertBytesVectorToVector(root_v); } root.bits.fill_with_bits(pb, bit_vector(root_bv)); diff --git a/src/zcash/IncrementalMerkleTree.cpp b/src/zcash/IncrementalMerkleTree.cpp index bae82f275..3a6501555 100644 --- a/src/zcash/IncrementalMerkleTree.cpp +++ b/src/zcash/IncrementalMerkleTree.cpp @@ -4,7 +4,7 @@ #include "zcash/IncrementalMerkleTree.hpp" #include "crypto/sha256.h" -#include "zerocash/utils/util.h" // TODO: remove these utilities +#include "zcash/util.h" namespace libzcash { @@ -244,11 +244,8 @@ MerklePath IncrementalMerkleTree::path(std::deque filler_hash BOOST_FOREACH(Hash b, path) { std::vector hashv(b.begin(), b.end()); - std::vector tmp_b; - libzerocash::convertBytesVectorToVector(hashv, tmp_b); - - merkle_path.push_back(tmp_b); + merkle_path.push_back(convertBytesVectorToVector(hashv)); } std::reverse(merkle_path.begin(), merkle_path.end()); diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 04cb7e000..22ec0d17c 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -2,7 +2,6 @@ #include "prf.h" #include "sodium.h" -#include "zerocash/utils/util.h" #include "zcash/util.h" #include diff --git a/src/zcash/circuit/merkle.tcc b/src/zcash/circuit/merkle.tcc index 3ec420b91..ca89adbed 100644 --- a/src/zcash/circuit/merkle.tcc +++ b/src/zcash/circuit/merkle.tcc @@ -50,7 +50,7 @@ public: void generate_r1cs_witness(const MerklePath& path) { // TODO: Change libsnark so that it doesn't require this goofy // number thing in its API. - size_t path_index = libzerocash::convertVectorToInt(path.index); + size_t path_index = convertVectorToInt(path.index); positions.fill_with_bits_of_ulong(this->pb, path_index); diff --git a/src/zcash/circuit/utils.tcc b/src/zcash/circuit/utils.tcc index c54abc56b..fa7ae324a 100644 --- a/src/zcash/circuit/utils.tcc +++ b/src/zcash/circuit/utils.tcc @@ -22,13 +22,8 @@ std::vector trailing252(std::vector input) { template std::vector to_bool_vector(T input) { std::vector input_v(input.begin(), input.end()); - std::vector output_bv(256, 0); - libzerocash::convertBytesVectorToVector( - input_v, - output_bv - ); - return output_bv; + return convertBytesVectorToVector(input_v); } std::vector uint256_to_bool_vector(uint256 input) { @@ -41,10 +36,8 @@ std::vector uint252_to_bool_vector(uint252 input) { std::vector uint64_to_bool_vector(uint64_t input) { auto num_bv = convertIntToVectorLE(input); - std::vector num_v(64, 0); - libzerocash::convertBytesVectorToVector(num_bv, num_v); - - return num_v; + + return convertBytesVectorToVector(num_bv); } void insert_uint256(std::vector& into, uint256 from) { diff --git a/src/zcash/util.cpp b/src/zcash/util.cpp index b4f33d774..6f32bf79a 100644 --- a/src/zcash/util.cpp +++ b/src/zcash/util.cpp @@ -1,5 +1,6 @@ #include "zcash/util.h" #include +#include std::vector convertIntToVectorLE(const uint64_t val_int) { std::vector bytes; @@ -10,3 +11,35 @@ std::vector convertIntToVectorLE(const uint64_t val_int) { return bytes; } + +// Convert bytes into boolean vector. (MSB to LSB) +std::vector convertBytesVectorToVector(const std::vector& bytes) { + std::vector ret; + ret.resize(bytes.size() * 8); + + unsigned char c; + for (size_t i = 0; i < bytes.size(); i++) { + c = bytes.at(i); + for (size_t j = 0; j < 8; j++) { + ret.at((i*8)+j) = (c >> (7-j)) & 1; + } + } + + return ret; +} + +// Convert boolean vector (big endian) to integer +uint64_t convertVectorToInt(const std::vector& v) { + if (v.size() > 64) { + throw std::length_error ("boolean vector can't be larger than 64 bits"); + } + + uint64_t result = 0; + for (size_t i=0; i std::vector convertIntToVectorLE(const uint64_t val_int); +std::vector convertBytesVectorToVector(const std::vector& bytes); +uint64_t convertVectorToInt(const std::vector& v); #endif // __ZCASH_UTIL_H diff --git a/src/zerocash/.gitignore b/src/zerocash/.gitignore deleted file mode 100644 index f4620b0fe..000000000 --- a/src/zerocash/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -*.o -*.d -depinst/ -depsrc/ - -libzerocash.a -libzerocash.so - -zerocash_pour_ppzksnark/tests/test_zerocash_pour_ppzksnark -zerocash_pour_ppzksnark/profiling/profile_zerocash_pour_gadget -tests/zerocashTest -tests/merkleTest -tests/utilTest -libzerocash/GenerateParamsForFiles -zerocashTest-proving-key -zerocashTest-verification-key diff --git a/src/zerocash/AUTHORS b/src/zerocash/AUTHORS deleted file mode 100644 index 3a23e189a..000000000 --- a/src/zerocash/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -Eli Ben-Sasson -Alessandro Chiesa -Christina Garman -Matthew Green -Ian Miers -Eran Tromer -Madars Virza diff --git a/src/zerocash/LICENSE b/src/zerocash/LICENSE deleted file mode 100644 index 72dc60d84..000000000 --- a/src/zerocash/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/src/zerocash/tests/full-test-suite.sh b/src/zerocash/tests/full-test-suite.sh deleted file mode 100755 index e721a9c71..000000000 --- a/src/zerocash/tests/full-test-suite.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -eu - -SUITE_EXIT_STATUS=0 -REPOROOT="$(readlink -f "$(dirname "$0")"/../)" - -function run_test_phase -{ - echo "===== BEGIN: $*" - set +e - eval "$@" - if [ $? -eq 0 ] - then - echo "===== PASSED: $*" - else - echo "===== FAILED: $*" - SUITE_EXIT_STATUS=1 - fi - set -e -} - -cd "${REPOROOT}" - -# Test phases: -run_test_phase "${REPOROOT}/tests/utilTest" -run_test_phase "${REPOROOT}/tests/zerocashTest" -run_test_phase "${REPOROOT}/tests/merkleTest" -run_test_phase "${REPOROOT}/zerocash_pour_ppzksnark/tests/test_zerocash_pour_ppzksnark" - -exit $SUITE_EXIT_STATUS diff --git a/src/zerocash/tests/timer.cpp b/src/zerocash/tests/timer.cpp deleted file mode 100644 index b5642f681..000000000 --- a/src/zerocash/tests/timer.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/** @file - ***************************************************************************** - - Implementation of interfaces for a timer to profile executions. - - ***************************************************************************** - * @author This file is part of libzerocash, developed by the Zerocash - * project and contributors (see AUTHORS). - * @copyright MIT license (see LICENSE file) - *****************************************************************************/ - -#include -#include - -#include "zerocash/tests/timer.h" - -namespace libzerocash { - -struct timeval tv_start; -struct timeval tv_end; - -void timer_start() { - printf("%s\n", "Starting Timer"); - gettimeofday(&tv_start, 0); -} - -void timer_stop() { - float elapsed; - gettimeofday(&tv_end, 0); - - elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000); - printf("%s [%fs]\n\n", "Stopping Timer", elapsed); -} - -void timer_start(const std::string location) { - printf("%s %s\n", "(enter)", location.c_str()); - gettimeofday(&tv_start, 0); -} - -void timer_stop(const std::string location) { - float elapsed; - gettimeofday(&tv_end, 0); - - elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000); - printf("%s %s [%fs]\n\n", "(leave)", location.c_str(), elapsed); -} - -} /* namespace libzerocash */ diff --git a/src/zerocash/tests/timer.h b/src/zerocash/tests/timer.h deleted file mode 100644 index ad9aef8d8..000000000 --- a/src/zerocash/tests/timer.h +++ /dev/null @@ -1,28 +0,0 @@ -/** @file - ***************************************************************************** - - Declaration of interfaces for a timer to profile executions. - - ***************************************************************************** - * @author This file is part of libzerocash, developed by the Zerocash - * project and contributors (see AUTHORS). - * @copyright MIT license (see LICENSE file) - *****************************************************************************/ - -#ifndef TIMER_H_ -#define TIMER_H_ - -#include - -namespace libzerocash { - -void timer_start(); -void timer_stop(); - -void timer_start(const std::string location); -void timer_stop(const std::string location); - -} /* namespace libzerocash */ - -#endif /* TIMER_H_ */ - diff --git a/src/zerocash/tests/utilTest.cpp b/src/zerocash/tests/utilTest.cpp deleted file mode 100644 index 4bb6622aa..000000000 --- a/src/zerocash/tests/utilTest.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -#define BOOST_TEST_MODULE utilTest -#include - -#include "zerocash/utils/util.h" -#include "crypto/sha256.h" - -#include "uint256.h" -#include "utilstrencodings.h" - -BOOST_AUTO_TEST_CASE( testConvertVectorToInt ) { - BOOST_CHECK(libzerocash::convertVectorToInt({0}) == 0); - BOOST_CHECK(libzerocash::convertVectorToInt({1}) == 1); - BOOST_CHECK(libzerocash::convertVectorToInt({0,1}) == 1); - BOOST_CHECK(libzerocash::convertVectorToInt({1,0}) == 2); - BOOST_CHECK(libzerocash::convertVectorToInt({1,1}) == 3); - BOOST_CHECK(libzerocash::convertVectorToInt({1,0,0}) == 4); - BOOST_CHECK(libzerocash::convertVectorToInt({1,0,1}) == 5); - BOOST_CHECK(libzerocash::convertVectorToInt({1,1,0}) == 6); - - BOOST_CHECK_THROW(libzerocash::convertVectorToInt(std::vector(100)), std::length_error); - - { - std::vector v(63, 1); - BOOST_CHECK(libzerocash::convertVectorToInt(v) == 0x7fffffffffffffff); - } - - { - std::vector v(64, 1); - BOOST_CHECK(libzerocash::convertVectorToInt(v) == 0xffffffffffffffff); - } -} - -BOOST_AUTO_TEST_CASE( testConvertBytesVectorToVector ) { - std::vector bytes = {0x00, 0x01, 0x03, 0x12, 0xFF}; - std::vector expected_bits = { - // 0x00 - 0, 0, 0, 0, 0, 0, 0, 0, - // 0x01 - 0, 0, 0, 0, 0, 0, 0, 1, - // 0x03 - 0, 0, 0, 0, 0, 0, 1, 1, - // 0x12 - 0, 0, 0, 1, 0, 0, 1, 0, - // 0xFF - 1, 1, 1, 1, 1, 1, 1, 1 - }; - std::vector actual_bits; - libzerocash::convertBytesVectorToVector(bytes, actual_bits); - BOOST_CHECK(actual_bits == expected_bits); -} - diff --git a/src/zerocash/utils/util.cpp b/src/zerocash/utils/util.cpp deleted file mode 100644 index 53a5d3ee0..000000000 --- a/src/zerocash/utils/util.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "util.h" - -namespace libzerocash { - -void convertBytesVectorToVector(const std::vector& bytes, std::vector& v) { - v.resize(bytes.size() * 8); - unsigned char c; - for (size_t i = 0; i < bytes.size(); i++) { - c = bytes.at(i); - for (size_t j = 0; j < 8; j++) { - v.at((i*8)+j) = (c >> (7-j)) & 1; - } - } -} - -uint64_t convertVectorToInt(const std::vector& v) { - if (v.size() > 64) { - throw std::length_error ("boolean vector can't be larger than 64 bits"); - } - - uint64_t result = 0; - for (size_t i=0; i -#include -#include -#include - -#include "crypto/sha256.h" - -namespace libzerocash { - -void convertBytesVectorToVector(const std::vector& bytes, std::vector& v); - -uint64_t convertVectorToInt(const std::vector& v); - -} /* namespace libzerocash */ -#endif /* UTIL_H_ */ - -