]> Git Repo - VerusCoin.git/commitdiff
Deprecate the old tree and remove old tree tests from the test suite.
authorSean Bowe <[email protected]>
Sun, 3 Apr 2016 22:05:08 +0000 (16:05 -0600)
committerSean Bowe <[email protected]>
Thu, 28 Apr 2016 22:07:52 +0000 (16:07 -0600)
12 files changed:
qa/zcash/full-test-suite.sh
src/Makefile.zcash.include
src/coins.h
src/test/transaction_tests.cpp
src/txdb.h
src/wallet/rpcwallet.cpp
src/wallet/wallet.cpp
src/wallet/wallet.h
src/zerocash/PourInput.cpp
src/zerocash/PourInput.h
src/zerocash/tests/merkleTest.cpp [deleted file]
src/zerocash/tests/zerocashTest.cpp

index 9c809d7fbd74a0727351b50ddf4a9eed408e9661..85387ff07e2fa9be0d6b31bec9f213fe856689b4 100755 (executable)
@@ -27,7 +27,6 @@ cd "${REPOROOT}"
 
 # Test phases:
 run_test_phase "${REPOROOT}/qa/zcash/ensure-no-dot-so-in-depends.py"
-run_test_phase "${REPOROOT}/src/zerocash/tests/merkleTest"
 run_test_phase "${REPOROOT}/src/zerocash/tests/utilTest"
 
 # If make check fails, show test-suite.log as part of our run_test_phase
index 68b0c69aac87f98349d2e56a03e8ef75c36b36e0..7455ffff1b3b1d8393a7ca7fee6b421469e4d227 100644 (file)
@@ -1,6 +1,5 @@
 bin_PROGRAMS += \
   zerocash/GenerateParamsForFiles \
-  zerocash/tests/merkleTest \
   zerocash/tests/utilTest \
   zerocash/tests/zerocashTest \
   zerocash/tests/test_zerocash_pour_ppzksnark
@@ -13,14 +12,6 @@ zerocash_GenerateParamsForFiles_LDADD = \
   $(LIBBITCOIN_CRYPTO) \
   $(LIBZEROCASH_LIBS)
 
-# tests for our incremental merkle tree
-zerocash_tests_merkleTest_SOURCES = zerocash/tests/merkleTest.cpp
-zerocash_tests_merkleTest_LDADD = \
-  $(BOOST_LIBS) \
-  $(LIBZEROCASH) \
-  $(LIBBITCOIN_CRYPTO) \
-  $(LIBZEROCASH_LIBS)
-
 # tests for utilities that come with zerocash
 zerocash_tests_utilTest_SOURCES = zerocash/tests/utilTest.cpp
 zerocash_tests_utilTest_LDADD = \
@@ -38,6 +29,7 @@ zerocash_tests_zerocashTest_SOURCES = \
 zerocash_tests_zerocashTest_LDADD = \
   $(BOOST_LIBS) \
   $(LIBZEROCASH) \
+  $(LIBBITCOIN_UTIL) \
   $(LIBBITCOIN_CRYPTO) \
   $(LIBZEROCASH_LIBS)
 
index 4e547d52568c467e08baae7a99997e5da5707ec0..2dffc31771050b2cd218eafd2291391bb991aad3 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <boost/foreach.hpp>
 #include <boost/unordered_map.hpp>
-#include "zerocash/IncrementalMerkleTree.h"
 #include "zcash/IncrementalMerkleTree.hpp"
 
 /** 
index c869e37ff9ecdce0476e1b7b8b14f2db6aba4dfc..6192a2652fd14c275e35f3052973ee730548a00e 100644 (file)
@@ -26,7 +26,6 @@
 #include "json/json_spirit_writer_template.h"
 
 #include "zerocash/ZerocashParams.h"
-#include "zerocash/IncrementalMerkleTree.h"
 #include "zerocash/PourInput.h"
 #include "zerocash/PourOutput.h"
 #include "zerocash/Address.h"
@@ -311,44 +310,35 @@ BOOST_AUTO_TEST_CASE(test_basic_pour_verification)
     // Also, it's generally libzerocash's job to ensure
     // the integrity of the scheme through its own tests.
 
-    static const unsigned int TEST_TREE_DEPTH = 3;
-
     // construct the r1cs keypair
-    auto keypair = ZerocashParams::GenerateNewKeyPair(TEST_TREE_DEPTH);
+    auto keypair = ZerocashParams::GenerateNewKeyPair(INCREMENTAL_MERKLE_TREE_DEPTH);
     ZerocashParams p(
-        TEST_TREE_DEPTH,
+        INCREMENTAL_MERKLE_TREE_DEPTH,
         &keypair
     );
 
     // construct a merkle tree
-    IncrementalMerkleTree merkleTree(TEST_TREE_DEPTH);
+    ZCIncrementalMerkleTree merkleTree;
     Address addr = Address::CreateNewRandomAddress();
     Coin coin(addr.getPublicAddress(), 100);
 
     // commitment from coin
-    std::vector<bool> commitment(ZC_CM_SIZE * 8);
-    convertBytesVectorToVector(coin.getCoinCommitment().getCommitmentValue(), commitment);
+    uint256 commitment(coin.getCoinCommitment().getCommitmentValue());
 
     // insert commitment into the merkle tree
-    std::vector<bool> index;
-    merkleTree.insertElement(commitment, index);
+    merkleTree.append(commitment);
 
     // compute the merkle root we will be working with
-    vector<unsigned char> rt(ZC_ROOT_SIZE);
-    {
-        vector<bool> root_bv(ZC_ROOT_SIZE * 8);
-        merkleTree.getRootValue(root_bv);
-        convertVectorToBytesVector(root_bv, rt);
-    }
+    uint256 rt = merkleTree.root();
 
-    merkle_authentication_path path(TEST_TREE_DEPTH);
-    merkleTree.getWitness(index, path);
+    auto witness = merkleTree.witness();
+    auto path = witness.path();
 
     // create CPourTx
     CScript scriptPubKey;
     boost::array<PourInput, NUM_POUR_INPUTS> inputs = {
-        PourInput(coin, addr, convertVectorToInt(index), path),
-        PourInput(TEST_TREE_DEPTH) // dummy input of zero value
+        PourInput(coin, addr, path),
+        PourInput(INCREMENTAL_MERKLE_TREE_DEPTH) // dummy input of zero value
     };
     boost::array<PourOutput, NUM_POUR_OUTPUTS> outputs = {
         PourOutput(50),
index 0e20b0d9be708b7f61cbe7f2f74055f21fcfc83f..8e6782141be089f65ea0267e2b334ce5b566a333 100644 (file)
@@ -14,8 +14,6 @@
 #include <utility>
 #include <vector>
 
-#include "zerocash/IncrementalMerkleTree.h"
-
 class CBlockFileInfo;
 class CBlockIndex;
 struct CDiskTxPos;
index bc82ffc79cc047f5ced2a9aa7f537d5afceeb7b4..8d2aea04f801a3c46c734e05cb71015465222795 100644 (file)
@@ -2480,10 +2480,9 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
     uint256 commitment = uint256(commitment_v);
 
     assert(pwalletMain != NULL);
-    libsnark::merkle_authentication_path path(INCREMENTAL_MERKLE_TREE_DEPTH); // We don't care during receive... yet! :)
-    size_t path_index = 0;
+    libzcash::MerklePath path;
     uint256 anchor;
-    auto found_in_chain = pwalletMain->WitnessBucketCommitment(commitment, path, path_index, anchor);
+    auto found_in_chain = pwalletMain->WitnessBucketCommitment(commitment, path, anchor);
 
     CAmount value_of_bucket = decrypted_bucket.getValue();
 
@@ -2587,14 +2586,13 @@ Value zc_raw_pour(const json_spirit::Array& params, bool fHelp)
         std::vector<unsigned char> commitment_v = input_coin.getCoinCommitment().getCommitmentValue();
         uint256 commitment = uint256(commitment_v);
 
-        libsnark::merkle_authentication_path path(INCREMENTAL_MERKLE_TREE_DEPTH);
-        size_t path_index = 0;
+        libzcash::MerklePath path;
         assert(pwalletMain != NULL);
-        if (!pwalletMain->WitnessBucketCommitment(commitment, path, path_index, anchor)) {
+        if (!pwalletMain->WitnessBucketCommitment(commitment, path, anchor)) {
             throw std::runtime_error("Couldn't find bucket in the blockchain");
         }
 
-        vpourin.push_back(PourInput(input_coin, zcaddress, path_index, path));
+        vpourin.push_back(PourInput(input_coin, zcaddress, path));
     }
 
     while (vpourin.size() < NUM_POUR_INPUTS) {
index 7c48c025bb735c2abe3af9a232c23b3ae2c8d5a8..fbdbb25a8aa178aded826bcf9960350d6696040e 100644 (file)
@@ -1052,15 +1052,12 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
 }
 
 bool CWallet::WitnessBucketCommitment(uint256 &commitment,
-                                      libsnark::merkle_authentication_path& path,
-                                      size_t &path_index,
+                                      libzcash::MerklePath &path,
                                       uint256 &final_anchor)
 {
-    bool res = false;
-    std::vector<bool> commitment_index;
-
     CBlockIndex* pindex = chainActive.Genesis();
-    libzerocash::IncrementalMerkleTree tree(INCREMENTAL_MERKLE_TREE_DEPTH);
+    ZCIncrementalMerkleTree tree;
+    boost::optional<ZCIncrementalWitness> witness = boost::none;
     uint256 current_anchor;
 
     while (pindex) {
@@ -1073,25 +1070,23 @@ bool CWallet::WitnessBucketCommitment(uint256 &commitment,
             {
                 BOOST_FOREACH(const uint256 &bucket_commitment, pour.commitments)
                 {
-                    std::vector<bool> commitment_bv(ZC_CM_SIZE * 8);
-                    std::vector<bool> index;
-                    std::vector<unsigned char> commitment_value(bucket_commitment.begin(), bucket_commitment.end());
-                    libzerocash::convertBytesVectorToVector(commitment_value, commitment_bv);
-                    assert(tree.insertElement(commitment_bv, index));
-
-                    if (bucket_commitment == commitment) {
-                        // We've found it! Now, we construct a witness.
-                        res = true;
-                        commitment_index = index;
+                    if (witness) {
+                        witness->append(bucket_commitment);
+                    } else {
+                        tree.append(bucket_commitment);
+
+                        if (bucket_commitment == commitment) {
+                            witness = tree.witness();
+                        }
                     }
                 }
             }
         }
 
-        {
-            std::vector<unsigned char> newrt_v(32);
-            tree.getRootValue(newrt_v);
-            current_anchor = uint256(newrt_v);
+        if (witness) {
+            current_anchor = witness->root();
+        } else {
+            current_anchor = tree.root();
         }
 
         // Consistency check: we should be able to find the current tree
@@ -1102,14 +1097,14 @@ bool CWallet::WitnessBucketCommitment(uint256 &commitment,
         pindex = chainActive.Next(pindex);
     }
 
-    if (res) {
-        assert(tree.getWitness(commitment_index, path));
-    }
+    if (witness) {
+        path = witness->path();
+        final_anchor = current_anchor;
 
-    path_index = libzerocash::convertVectorToInt(commitment_index);
-    final_anchor = current_anchor;
+        return true;
+    }
 
-    return res;
+    return false;
 }
 
 /**
index c5385c785b6ae5f284abbd95f7601378a3061b4d..3d908ea2545949b44090dd72ed36699bb503dc7f 100644 (file)
@@ -616,7 +616,7 @@ public:
     void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
     bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
     void EraseFromWallet(const uint256 &hash);
-    bool WitnessBucketCommitment(uint256 &commitment, libsnark::merkle_authentication_path& path, size_t &path_index, uint256 &final_anchor);
+    bool WitnessBucketCommitment(uint256 &commitment, libzcash::MerklePath& path, uint256 &final_anchor);
     int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
     void ReacceptWalletTransactions();
     void ResendWalletTransactions(int64_t nBestBlockTime);
index 7601001d06227dd375fd304bce4ee8b2724ce517..eeb087f0dd386a06eb6676583783e04d52e02907 100644 (file)
@@ -11,7 +11,6 @@
  * @copyright  MIT license (see LICENSE file)
  *****************************************************************************/
 
-#include "IncrementalMerkleTree.h"
 #include "PourInput.h"
 
 namespace libzerocash {
@@ -21,27 +20,20 @@ PourInput::PourInput(int tree_depth): old_coin(), merkle_index(), path() {
 
        this->old_coin = Coin(this->old_address.getPublicAddress(), 0);
 
-       // dummy merkle tree
-       IncrementalMerkleTree merkleTree(tree_depth);
+       ZCIncrementalMerkleTree merkleTree;
+       merkleTree.append(uint256(this->old_coin.getCoinCommitment().getCommitmentValue()));
 
-       // commitment from coin
-       std::vector<bool> commitment(ZC_CM_SIZE * 8);
-       convertBytesVectorToVector(this->old_coin.getCoinCommitment().getCommitmentValue(), commitment);
+       auto witness = merkleTree.witness();
+       auto merkle_path = witness.path();
 
-       // insert commitment into the merkle tree
-       std::vector<bool> index;
-       merkleTree.insertElement(commitment, index);
-
-       merkleTree.getWitness(index, this->path);
-
-       this->merkle_index = 1;
+       this->path = merkle_path.authentication_path;
+       this->merkle_index = convertVectorToInt(merkle_path.index);
 }
 
 PourInput::PourInput(Coin old_coin,
           Address old_address,
-          size_t merkle_index,
-          merkle_authentication_path path) : old_coin(old_coin), merkle_index(merkle_index), path(path) {
-               this->old_address = old_address;
+          const libzcash::MerklePath &path) : old_address(old_address), old_coin(old_coin), path(path.authentication_path) {
+               this->merkle_index = convertVectorToInt(path.index);
 };
 
 } /* namespace libzerocash */
\ No newline at end of file
index 2bb924c79fc2b35ef6a4bf8f08dc8b541fd3b0a7..6da31e9d32f07daf6053c621731e84fc09a1e044 100644 (file)
@@ -15,6 +15,8 @@
 #include "Coin.h"
 #include "ZerocashParams.h"
 
+#include "zcash/IncrementalMerkleTree.hpp"
+
 namespace libzerocash {
 
 class PourInput {
@@ -23,8 +25,7 @@ public:
 
     PourInput(Coin old_coin,
               Address old_address,
-              size_t merkle_index,
-              merkle_authentication_path path);
+              const libzcash::MerklePath& path);
 
     Coin old_coin;
     Address old_address;
diff --git a/src/zerocash/tests/merkleTest.cpp b/src/zerocash/tests/merkleTest.cpp
deleted file mode 100644 (file)
index 9be66cc..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/** @file
- *****************************************************************************
-
- Test for Merkle tree.
-
- *****************************************************************************
- * @author     This file is part of libzerocash, developed by the Zerocash
- *             project and contributors (see AUTHORS).
- * @copyright  MIT license (see LICENSE file)
- *****************************************************************************/
-
-#include "zerocash/IncrementalMerkleTree.h"
-
-#include <iostream>
-#include <vector>
-
-#define BOOST_TEST_MODULE merkleTest
-#include <boost/test/included/unit_test.hpp>
-
-using namespace libzerocash;
-using namespace std;
-
-void constructNonzeroTestVector(std::vector< std::vector<bool> > &values, uint32_t size)
-{
-    values.resize(0);
-    std::vector<bool> dummy;
-    dummy.resize(256);
-    dummy[0] = true;
-
-    for (uint32_t i = 0; i < size; i++)
-    {
-        values.push_back(dummy);
-    }
-}
-
-void constructZeroTestVector(std::vector< std::vector<bool> > &values, uint32_t size)
-{
-    values.resize(0);
-    std::vector<bool> dummy;
-    dummy.resize(256);
-
-    for (uint32_t i = 0; i < size; i++)
-    {
-        values.push_back(dummy);
-    }
-}
-
-BOOST_AUTO_TEST_CASE( testRootOfTreeOfZerosIsZero ) {
-    IncrementalMerkleTree incTree;
-    std::vector< std::vector<bool> > values;
-    std::vector<bool> actual_root;
-
-    constructZeroTestVector(values, 2);
-
-    // Create an IncrementalMerkleTree over the values.
-    if (incTree.insertVector(values) == false) {
-        BOOST_ERROR("Could not insert into the tree.");
-    }
-    incTree.prune();
-    incTree.getRootValue(actual_root);
-
-    std::vector<bool> expected_root(32*8, 0);
-    BOOST_CHECK( expected_root == actual_root );
-}
-
-void add_values_to_reference(IncrementalMerkleTree &tree, std::vector< std::vector<bool> > &values) {
-    IncrementalMerkleTree newtree(20);
-
-    if (newtree.insertVector(values) == false) {
-        BOOST_ERROR("Could not insert into the tree.");
-    }
-
-    tree.setTo(newtree);
-}
-
-BOOST_AUTO_TEST_CASE( test_add_values_to_reference ) {
-    IncrementalMerkleTree incTree(20);
-    IncrementalMerkleTree incTree2(20);
-
-    std::vector< std::vector<bool> > values;
-    constructNonzeroTestVector(values, 2);
-
-    if (incTree.insertVector(values) == false) {
-        BOOST_ERROR("Could not insert into the tree.");
-    }
-
-    add_values_to_reference(incTree2, values);
-
-    {
-        std::vector<bool> root1, root2;
-        incTree.getRootValue(root1);
-        incTree2.getRootValue(root2);
-
-        BOOST_CHECK(root1 == root2);
-    }
-}
-
-BOOST_AUTO_TEST_CASE( testRootOfTreeOfNonZeroIsNonZero ) {
-    IncrementalMerkleTree incTree;
-    std::vector< std::vector<bool> > values;
-    std::vector<bool> actual_root;
-
-    constructNonzeroTestVector(values, 2);
-
-    // Create an IncrementalMerkleTree over the values.
-    if (incTree.insertVector(values) == false) {
-        BOOST_ERROR("Could not insert into the tree.");
-    }
-    incTree.prune();
-    incTree.getRootValue(actual_root);
-
-    std::vector<bool> expected_root(32*8, 0);
-    BOOST_CHECK( expected_root != actual_root );
-}
-
-BOOST_AUTO_TEST_CASE( testSerializationEdgeCase ) {
-
-}
-
-BOOST_AUTO_TEST_CASE( testCompactRepresentation ) {
-    for (uint32_t num_entries = 0; num_entries < 100; num_entries++) {
-        size_t test_depth = 64;
-
-        if (num_entries == 2) {
-            // This is a particular failure I'm testing with weird
-            // padding caused by this depth.
-            test_depth = 20;
-        }
-
-        std::vector< std::vector<bool> > values;
-        std::vector<bool> root1, root2;
-        IncrementalMerkleTree incTree(test_depth);
-
-        constructNonzeroTestVector(values, num_entries);
-
-        BOOST_REQUIRE( incTree.insertVector(values) );
-        BOOST_REQUIRE( incTree.prune() );
-
-        IncrementalMerkleTreeCompact compact = incTree.getCompactRepresentation();
-
-        BOOST_REQUIRE( compact.getTreeHeight() == test_depth );
-
-        // Calculate what the path to the next-added element should be.
-        std::vector<unsigned char> path_bytes(8);
-        std::vector<bool> path_bits;
-        libzerocash::convertIntToBytesVector(num_entries, path_bytes);
-        libzerocash::convertBytesVectorToVector(path_bytes, path_bits);
-
-        if (test_depth == 64) {
-            // Make sure the paths match.
-            BOOST_REQUIRE( compact.getHashList() == path_bits );
-        }
-
-        // Make sure there's a hash for every '1' bit down the path.
-        BOOST_REQUIRE( compact.getHashVec().size() == libzerocash::countOnes(path_bits) );
-
-        /* Test serializing and deserializing. */
-        std::vector<unsigned char> serializedCompact = compact.serialize();
-        IncrementalMerkleTreeCompact deserializedCompact = IncrementalMerkleTreeCompact::deserialize(serializedCompact);
-        BOOST_REQUIRE(compact.getTreeHeight() == deserializedCompact.getTreeHeight());
-        BOOST_REQUIRE(compact.getHashList() == deserializedCompact.getHashList());
-        BOOST_REQUIRE(compact.getHashVec() == deserializedCompact.getHashVec());
-
-        // Make sure 'restoring' the tree results in the same root.
-        IncrementalMerkleTree newTree(compact);
-        incTree.getRootValue(root1);
-        incTree.getRootValue(root2);
-        BOOST_REQUIRE( root1 == root2 );
-    }
-}
-
-BOOST_AUTO_TEST_CASE( testCompactDeserializationFailures ) {
-    IncrementalMerkleTree incTree(64);
-    std::vector< std::vector<bool> > values;
-    constructNonzeroTestVector(values, 5);
-    BOOST_REQUIRE( incTree.insertVector(values) );
-    BOOST_REQUIRE( incTree.prune() );
-    IncrementalMerkleTreeCompact compact = incTree.getCompactRepresentation();
-
-    /* Base the following tests off of this valid serialization. */
-    std::vector<unsigned char> serialized = compact.serialize();
-
-    /* Should fail if we truncate any number of bytes off the end. */
-    for (size_t trunc_len = 0; trunc_len < serialized.size(); trunc_len++) {
-        std::vector<unsigned char> truncated(serialized.begin(), serialized.begin() + trunc_len);
-        BOOST_CHECK_THROW(
-            IncrementalMerkleTreeCompact::deserialize(truncated),
-            std::out_of_range
-        );
-    }
-
-    /* Should fail if we append any number of extra bytes on the end. */
-    std::vector<unsigned char> extra_byte = serialized;
-    extra_byte.push_back(0x00);
-    BOOST_CHECK_THROW(
-        IncrementalMerkleTreeCompact::deserialize(extra_byte),
-        std::runtime_error
-    );
-}
index 912759eaa520295e366fccd815a3c5cf7557d64e..6770ccb63abad26866ff73632a31c1583486e9b0 100644 (file)
 #include "zerocash/PourOutput.h"
 #include "zerocash/utils/util.h"
 
+#include "uint256.h"
+
 using namespace std;
 using namespace libsnark;
 
-#define TEST_TREE_DEPTH 4
-
 BOOST_AUTO_TEST_CASE( SaveAndLoadKeysFromFiles ) {
     cout << "\nSaveAndLoadKeysFromFiles TEST\n" << endl;
 
     cout << "Creating Params...\n" << endl;
 
     libzerocash::timer_start("Param Generation");
-    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(TEST_TREE_DEPTH);
+    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::ZerocashParams p(
-        TEST_TREE_DEPTH,
+        INCREMENTAL_MERKLE_TREE_DEPTH,
         &keypair
     );
     libzerocash::timer_stop("Param Generation");
@@ -72,11 +72,11 @@ BOOST_AUTO_TEST_CASE( SaveAndLoadKeysFromFiles ) {
     libzerocash::timer_stop("Saving Verification Key");
 
     libzerocash::timer_start("Loading Proving Key");
-    auto pk_loaded = libzerocash::ZerocashParams::LoadProvingKeyFromFile(pk_path, TEST_TREE_DEPTH);
+    auto pk_loaded = libzerocash::ZerocashParams::LoadProvingKeyFromFile(pk_path, INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::timer_stop("Loading Proving Key");
 
     libzerocash::timer_start("Loading Verification Key");
-    auto vk_loaded = libzerocash::ZerocashParams::LoadVerificationKeyFromFile(vk_path, TEST_TREE_DEPTH);
+    auto vk_loaded = libzerocash::ZerocashParams::LoadVerificationKeyFromFile(vk_path, INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::timer_stop("Loading Verification Key");
 
     cout << "Comparing Proving and Verification key.\n" << endl;
@@ -107,19 +107,19 @@ BOOST_AUTO_TEST_CASE( SaveAndLoadKeysFromFiles ) {
     }
 
     cout << "Creating Merkle Tree...\n" << endl;
-    libzerocash::IncrementalMerkleTree merkleTree(coinValues, TEST_TREE_DEPTH);
+    libzerocash::IncrementalMerkleTree merkleTree(coinValues, INCREMENTAL_MERKLE_TREE_DEPTH);
     cout << "Successfully created Merkle Tree.\n" << endl;
 
     std::vector<bool> index;
 
     cout << "Creating Witness 1...\n" << endl;
-    merkle_authentication_path witness_1(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_1(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::convertIntToVector(1, index);
     merkleTree.getWitness(index, witness_1);
     cout << "Successfully created Witness 1.\n" << endl;
 
     cout << "Creating Witness 2...\n" << endl;
-    merkle_authentication_path witness_2(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_2(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::convertIntToVector(3, index);
     merkleTree.getWitness(index, witness_2);
     cout << "Successfully created Witness 2.\n" << endl;
@@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE( SaveAndLoadKeysFromFiles ) {
 BOOST_AUTO_TEST_CASE( PourInputOutputTest ) {
     // dummy input
     {
-        libzerocash::PourInput input(TEST_TREE_DEPTH);
+        libzerocash::PourInput input(INCREMENTAL_MERKLE_TREE_DEPTH);
 
         BOOST_CHECK(input.old_coin.getValue() == 0);
         BOOST_CHECK(input.old_address.getPublicAddress() == input.old_coin.getPublicAddress());
@@ -192,10 +192,10 @@ void test_pour(libzerocash::ZerocashParams& p,
           std::vector<uint64_t> inputs, // values of the inputs (max 2)
           std::vector<uint64_t> outputs) // values of the outputs (max 2)
 {
-    using pour_input_state = std::tuple<libzerocash::Address, libzerocash::Coin, std::vector<bool>>;
+    using pour_input_state = std::tuple<libzerocash::Address, libzerocash::Coin, ZCIncrementalWitness>;
 
     // Construct incremental merkle tree
-    libzerocash::IncrementalMerkleTree merkleTree(TEST_TREE_DEPTH);
+    ZCIncrementalMerkleTree merkleTree;
 
     // Dummy sig_pk
     vector<unsigned char> as(ZC_SIG_PK_SIZE, 'a');
@@ -210,33 +210,30 @@ void test_pour(libzerocash::ZerocashParams& p,
         libzerocash::Coin coin(addr.getPublicAddress(), *it);
 
         // commitment from coin
-        std::vector<bool> commitment(ZC_CM_SIZE * 8);
-        libzerocash::convertBytesVectorToVector(coin.getCoinCommitment().getCommitmentValue(), commitment);
+        uint256 commitment(coin.getCoinCommitment().getCommitmentValue());
 
         // insert commitment into the merkle tree
-        std::vector<bool> index;
-        merkleTree.insertElement(commitment, index);
+        merkleTree.append(commitment);
+
+        // and append to any witnesses
+        for(vector<pour_input_state>::iterator wit = input_state.begin(); wit != input_state.end(); ++wit) {
+            std::get<2>(*wit).append(commitment);
+        }
 
         // store the state temporarily
-        input_state.push_back(std::make_tuple(addr, coin, index));
+        input_state.push_back(std::make_tuple(addr, coin, merkleTree.witness()));
     }
 
     // compute the merkle root we will be working with
-    vector<unsigned char> rt(ZC_ROOT_SIZE);
-    {
-        vector<bool> root_bv(ZC_ROOT_SIZE * 8);
-        merkleTree.getRootValue(root_bv);
-        libzerocash::convertVectorToBytesVector(root_bv, rt);
-    }
+    auto rt_u = merkleTree.root();
+    std::vector<unsigned char> rt(rt_u.begin(), rt_u.end());
 
     // get witnesses for all the input coins and construct the pours
     for(vector<pour_input_state>::iterator it = input_state.begin(); it != input_state.end(); ++it) {
-        merkle_authentication_path path(TEST_TREE_DEPTH);
-
-        auto index = std::get<2>(*it);
-        merkleTree.getWitness(index, path);
+        auto witness = std::get<2>(*it);
+        auto path = witness.path();
 
-        pour_inputs.push_back(libzerocash::PourInput(std::get<1>(*it), std::get<0>(*it), libzerocash::convertVectorToInt(index), path));
+        pour_inputs.push_back(libzerocash::PourInput(std::get<1>(*it), std::get<0>(*it), path));
     }
 
     // construct dummy outputs with the given values
@@ -250,9 +247,9 @@ void test_pour(libzerocash::ZerocashParams& p,
 }
 
 BOOST_AUTO_TEST_CASE( PourVpubInTest ) {
-    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(TEST_TREE_DEPTH);
+    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::ZerocashParams p(
-        TEST_TREE_DEPTH,
+        INCREMENTAL_MERKLE_TREE_DEPTH,
         &keypair
     );
 
@@ -331,9 +328,9 @@ BOOST_AUTO_TEST_CASE( PourTxTest ) {
     cout << "Creating Params...\n" << endl;
 
     libzerocash::timer_start("Param Generation");
-    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(TEST_TREE_DEPTH);
+    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::ZerocashParams p(
-        TEST_TREE_DEPTH,
+        INCREMENTAL_MERKLE_TREE_DEPTH,
         &keypair
     );
     libzerocash::timer_stop("Param Generation");
@@ -363,12 +360,12 @@ BOOST_AUTO_TEST_CASE( PourTxTest ) {
     cout << "Creating Merkle Tree...\n" << endl;
 
     libzerocash::timer_start("Merkle Tree");
-    libzerocash::IncrementalMerkleTree merkleTree(coinValues, TEST_TREE_DEPTH);
+    libzerocash::IncrementalMerkleTree merkleTree(coinValues, INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::timer_stop("Merkle Tree");
 
     cout << "Successfully created Merkle Tree.\n" << endl;
 
-    merkle_authentication_path witness_1(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_1(INCREMENTAL_MERKLE_TREE_DEPTH);
 
     libzerocash::timer_start("Witness");
     std::vector<bool> index;
@@ -384,7 +381,7 @@ BOOST_AUTO_TEST_CASE( PourTxTest ) {
     }
     cout << "\n" << endl;
 
-    merkle_authentication_path witness_2(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_2(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::convertIntToVector(3, index);
     if (merkleTree.getWitness(index, witness_2) == false) {
                cout << "Could not get witness" << endl;
@@ -539,9 +536,9 @@ BOOST_AUTO_TEST_CASE( SimpleTxTest ) {
     cout << "\nSIMPLE TRANSACTION TEST\n" << endl;
 
     libzerocash::timer_start("Param Generation");
-    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(TEST_TREE_DEPTH);
+    auto keypair = libzerocash::ZerocashParams::GenerateNewKeyPair(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::ZerocashParams p(
-        TEST_TREE_DEPTH,
+        INCREMENTAL_MERKLE_TREE_DEPTH,
         &keypair
     );
     libzerocash::timer_stop("Param Generation");
@@ -571,13 +568,13 @@ BOOST_AUTO_TEST_CASE( SimpleTxTest ) {
     }
 
     cout << "Creating Merkle Tree...\n" << endl;
-    libzerocash::IncrementalMerkleTree merkleTree(coinValues, TEST_TREE_DEPTH);
+    libzerocash::IncrementalMerkleTree merkleTree(coinValues, INCREMENTAL_MERKLE_TREE_DEPTH);
     cout << "Successfully created Merkle Tree.\n" << endl;
 
     std::vector<bool> index;
 
     cout << "Creating Witness 1...\n" << endl;
-    merkle_authentication_path witness_1(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_1(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::convertIntToVector(1, index);
     if (merkleTree.getWitness(index, witness_1) == false) {
                BOOST_ERROR("Could not get witness");
@@ -585,7 +582,7 @@ BOOST_AUTO_TEST_CASE( SimpleTxTest ) {
     cout << "Successfully created Witness 1.\n" << endl;
 
     cout << "Creating Witness 2...\n" << endl;
-    merkle_authentication_path witness_2(TEST_TREE_DEPTH);
+    merkle_authentication_path witness_2(INCREMENTAL_MERKLE_TREE_DEPTH);
     libzerocash::convertIntToVector(3, index);
     if (merkleTree.getWitness(index, witness_2) == false) {
                cout << "Could not get witness" << endl;
This page took 0.059386 seconds and 4 git commands to generate.