# TODO: rename to libzcash
LIBZCASH_H = \
zcash/IncrementalMerkleTree.h \
- zerocash/utils/util.h \
zcash/NoteEncryption.hpp \
zcash/Address.hpp \
zcash/JoinSplit.hpp \
# zerocash protocol primitives #
libzcash_a_SOURCES = \
zcash/IncrementalMerkleTree.cpp \
- zerocash/utils/util.cpp \
zcash/NoteEncryption.cpp \
zcash/Address.cpp \
zcash/JoinSplit.cpp \
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
bin_PROGRAMS += \
- zcash/GenerateParams \
- zerocash/tests/utilTest
+ zcash/GenerateParams
# tool for generating our public parameters
zcash_GenerateParams_SOURCES = zcash/GenerateParams.cpp
$(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)
#include <gtest/gtest.h>
#include "uint256.h"
-#include "zerocash/utils/util.h"
#include "zcash/util.h"
#include <boost/foreach.hpp>
#include "libsnark/gadgetlib1/gadgets/merkle_tree/merkle_tree_check_read_gadget.hpp"
using namespace libsnark;
-using namespace libzerocash;
#include "zcash/circuit/utils.tcc"
--- /dev/null
+#include <gtest/gtest.h>
+#include "zcash/util.h"
+
+TEST(libzcash_utils, convertBytesVectorToVector)
+{
+ std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF};
+ std::vector<bool> 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<bool>(100)), std::length_error);
+
+ {
+ std::vector<bool> v(63, 1);
+ ASSERT_TRUE(convertVectorToInt(v) == 0x7fffffffffffffff);
+ }
+
+ {
+ std::vector<bool> v(64, 1);
+ ASSERT_TRUE(convertVectorToInt(v) == 0xffffffffffffffff);
+ }
+}
#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"
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;
std::vector<bool> commitment_bv;
{
std::vector<unsigned char> 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);
{
uint256 witroot = wit.root();
std::vector<unsigned char> 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));
#include "zcash/IncrementalMerkleTree.hpp"
#include "crypto/sha256.h"
-#include "zerocash/utils/util.h" // TODO: remove these utilities
+#include "zcash/util.h"
namespace libzcash {
BOOST_FOREACH(Hash b, path)
{
std::vector<unsigned char> hashv(b.begin(), b.end());
- std::vector<bool> 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());
#include "prf.h"
#include "sodium.h"
-#include "zerocash/utils/util.h"
#include "zcash/util.h"
#include <memory>
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);
template<typename T>
std::vector<bool> to_bool_vector(T input) {
std::vector<unsigned char> input_v(input.begin(), input.end());
- std::vector<bool> output_bv(256, 0);
- libzerocash::convertBytesVectorToVector(
- input_v,
- output_bv
- );
- return output_bv;
+ return convertBytesVectorToVector(input_v);
}
std::vector<bool> uint256_to_bool_vector(uint256 input) {
std::vector<bool> uint64_to_bool_vector(uint64_t input) {
auto num_bv = convertIntToVectorLE(input);
- std::vector<bool> num_v(64, 0);
- libzerocash::convertBytesVectorToVector(num_bv, num_v);
-
- return num_v;
+
+ return convertBytesVectorToVector(num_bv);
}
void insert_uint256(std::vector<bool>& into, uint256 from) {
#include "zcash/util.h"
#include <algorithm>
+#include <stdexcept>
std::vector<unsigned char> convertIntToVectorLE(const uint64_t val_int) {
std::vector<unsigned char> bytes;
return bytes;
}
+
+// Convert bytes into boolean vector. (MSB to LSB)
+std::vector<bool> convertBytesVectorToVector(const std::vector<unsigned char>& bytes) {
+ std::vector<bool> 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<bool>& 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<v.size();i++) {
+ if (v.at(i)) {
+ result |= (uint64_t)1 << ((v.size() - 1) - i);
+ }
+ }
+
+ return result;
+}
#include <cstdint>
std::vector<unsigned char> convertIntToVectorLE(const uint64_t val_int);
+std::vector<bool> convertBytesVectorToVector(const std::vector<unsigned char>& bytes);
+uint64_t convertVectorToInt(const std::vector<bool>& v);
#endif // __ZCASH_UTIL_H
+++ /dev/null
-*.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
+++ /dev/null
-Eli Ben-Sasson
-Alessandro Chiesa
-Christina Garman
-Matthew Green
-Ian Miers
-Eran Tromer
-Madars Virza
+++ /dev/null
-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.
+++ /dev/null
-#!/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
+++ /dev/null
-/** @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 <stdio.h>
-#include <sys/time.h>
-
-#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 */
+++ /dev/null
-/** @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 <string>
-
-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_ */
-
+++ /dev/null
-
-#define BOOST_TEST_MODULE utilTest
-#include <boost/test/included/unit_test.hpp>
-
-#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<bool>(100)), std::length_error);
-
- {
- std::vector<bool> v(63, 1);
- BOOST_CHECK(libzerocash::convertVectorToInt(v) == 0x7fffffffffffffff);
- }
-
- {
- std::vector<bool> v(64, 1);
- BOOST_CHECK(libzerocash::convertVectorToInt(v) == 0xffffffffffffffff);
- }
-}
-
-BOOST_AUTO_TEST_CASE( testConvertBytesVectorToVector ) {
- std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF};
- std::vector<bool> 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<bool> actual_bits;
- libzerocash::convertBytesVectorToVector(bytes, actual_bits);
- BOOST_CHECK(actual_bits == expected_bits);
-}
-
+++ /dev/null
-#include <string>
-#include <iostream>
-#include <fstream>
-#include <exception>
-#include <cstring>
-#include <iomanip>
-#include <algorithm>
-
-#include <sodium.h>
-
-#include "util.h"
-
-namespace libzerocash {
-
-void convertBytesVectorToVector(const std::vector<unsigned char>& bytes, std::vector<bool>& 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<bool>& 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<v.size();i++) {
- if (v.at(i)) {
- result |= (uint64_t)1 << ((v.size() - 1) - i);
- }
- }
-
- return result;
-}
-
-} /* namespace libzerocash */
-
+++ /dev/null
-#ifndef UTIL_H_
-#define UTIL_H_
-
-#include <string>
-#include <stdexcept>
-#include <vector>
-#include <cstdint>
-
-#include "crypto/sha256.h"
-
-namespace libzerocash {
-
-void convertBytesVectorToVector(const std::vector<unsigned char>& bytes, std::vector<bool>& v);
-
-uint64_t convertVectorToInt(const std::vector<bool>& v);
-
-} /* namespace libzerocash */
-#endif /* UTIL_H_ */
-
-