Remove the rest of libzerocash.

This commit is contained in:
Sean Bowe
2016-06-28 10:08:50 -06:00
parent 658cdb15f7
commit 2668a1bc13
21 changed files with 94 additions and 303 deletions

View File

@@ -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<Depth, Hash>::path(std::deque<Hash> filler_hash
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());

View File

@@ -2,7 +2,6 @@
#include "prf.h"
#include "sodium.h"
#include "zerocash/utils/util.h"
#include "zcash/util.h"
#include <memory>

View File

@@ -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);

View File

@@ -22,13 +22,8 @@ std::vector<bool> trailing252(std::vector<bool> input) {
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) {
@@ -41,10 +36,8 @@ std::vector<bool> uint252_to_bool_vector(uint252 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) {

View File

@@ -1,5 +1,6 @@
#include "zcash/util.h"
#include <algorithm>
#include <stdexcept>
std::vector<unsigned char> convertIntToVectorLE(const uint64_t val_int) {
std::vector<unsigned char> bytes;
@@ -10,3 +11,35 @@ std::vector<unsigned char> convertIntToVectorLE(const uint64_t val_int) {
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;
}

View File

@@ -5,5 +5,7 @@
#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