Auto merge of #3340 - Eirik0:rename-merkle-typedefs, r=str4d
Rename merkle tree typedefs to include Sprout This is to be consistent with the naming convention we have been using to distinguish Sprout/Sapling.
This commit is contained in:
@@ -42,8 +42,8 @@ bool CCoins::Spend(uint32_t nPos)
|
|||||||
Cleanup();
|
Cleanup();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool CCoinsView::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return false; }
|
bool CCoinsView::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return false; }
|
||||||
bool CCoinsView::GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const { return false; }
|
bool CCoinsView::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return false; }
|
||||||
bool CCoinsView::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return false; }
|
bool CCoinsView::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return false; }
|
||||||
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
|
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
|
||||||
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
|
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
|
||||||
@@ -62,8 +62,8 @@ bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
|
|||||||
|
|
||||||
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
|
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
|
||||||
|
|
||||||
bool CCoinsViewBacked::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return base->GetSproutAnchorAt(rt, tree); }
|
bool CCoinsViewBacked::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return base->GetSproutAnchorAt(rt, tree); }
|
||||||
bool CCoinsViewBacked::GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const { return base->GetSaplingAnchorAt(rt, tree); }
|
bool CCoinsViewBacked::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return base->GetSaplingAnchorAt(rt, tree); }
|
||||||
bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return base->GetNullifier(nullifier, type); }
|
bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return base->GetNullifier(nullifier, type); }
|
||||||
bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); }
|
bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); }
|
||||||
bool CCoinsViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); }
|
bool CCoinsViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); }
|
||||||
@@ -117,7 +117,7 @@ CCoinsMap::const_iterator CCoinsViewCache::FetchCoins(const uint256 &txid) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
|
||||||
CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt);
|
CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt);
|
||||||
if (it != cacheSproutAnchors.end()) {
|
if (it != cacheSproutAnchors.end()) {
|
||||||
if (it->second.entered) {
|
if (it->second.entered) {
|
||||||
@@ -140,7 +140,7 @@ bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCoinsViewCache::GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
bool CCoinsViewCache::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const {
|
||||||
CAnchorsSaplingMap::const_iterator it = cacheSaplingAnchors.find(rt);
|
CAnchorsSaplingMap::const_iterator it = cacheSaplingAnchors.find(rt);
|
||||||
if (it != cacheSaplingAnchors.end()) {
|
if (it != cacheSaplingAnchors.end()) {
|
||||||
if (it->second.entered) {
|
if (it->second.entered) {
|
||||||
@@ -222,9 +222,9 @@ void CCoinsViewCache::AbstractPushAnchor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void CCoinsViewCache::PushAnchor(const ZCIncrementalMerkleTree &tree)
|
template<> void CCoinsViewCache::PushAnchor(const SproutMerkleTree &tree)
|
||||||
{
|
{
|
||||||
AbstractPushAnchor<ZCIncrementalMerkleTree, CAnchorsSproutMap, CAnchorsSproutMap::iterator, CAnchorsSproutCacheEntry>(
|
AbstractPushAnchor<SproutMerkleTree, CAnchorsSproutMap, CAnchorsSproutMap::iterator, CAnchorsSproutCacheEntry>(
|
||||||
tree,
|
tree,
|
||||||
SPROUT,
|
SPROUT,
|
||||||
cacheSproutAnchors,
|
cacheSproutAnchors,
|
||||||
@@ -232,9 +232,9 @@ template<> void CCoinsViewCache::PushAnchor(const ZCIncrementalMerkleTree &tree)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void CCoinsViewCache::PushAnchor(const ZCSaplingIncrementalMerkleTree &tree)
|
template<> void CCoinsViewCache::PushAnchor(const SaplingMerkleTree &tree)
|
||||||
{
|
{
|
||||||
AbstractPushAnchor<ZCSaplingIncrementalMerkleTree, CAnchorsSaplingMap, CAnchorsSaplingMap::iterator, CAnchorsSaplingCacheEntry>(
|
AbstractPushAnchor<SaplingMerkleTree, CAnchorsSaplingMap, CAnchorsSaplingMap::iterator, CAnchorsSaplingCacheEntry>(
|
||||||
tree,
|
tree,
|
||||||
SAPLING,
|
SAPLING,
|
||||||
cacheSaplingAnchors,
|
cacheSaplingAnchors,
|
||||||
@@ -245,7 +245,7 @@ template<> void CCoinsViewCache::PushAnchor(const ZCSaplingIncrementalMerkleTree
|
|||||||
template<>
|
template<>
|
||||||
void CCoinsViewCache::BringBestAnchorIntoCache(
|
void CCoinsViewCache::BringBestAnchorIntoCache(
|
||||||
const uint256 ¤tRoot,
|
const uint256 ¤tRoot,
|
||||||
ZCIncrementalMerkleTree &tree
|
SproutMerkleTree &tree
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
assert(GetSproutAnchorAt(currentRoot, tree));
|
assert(GetSproutAnchorAt(currentRoot, tree));
|
||||||
@@ -254,7 +254,7 @@ void CCoinsViewCache::BringBestAnchorIntoCache(
|
|||||||
template<>
|
template<>
|
||||||
void CCoinsViewCache::BringBestAnchorIntoCache(
|
void CCoinsViewCache::BringBestAnchorIntoCache(
|
||||||
const uint256 ¤tRoot,
|
const uint256 ¤tRoot,
|
||||||
ZCSaplingIncrementalMerkleTree &tree
|
SaplingMerkleTree &tree
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
assert(GetSaplingAnchorAt(currentRoot, tree));
|
assert(GetSaplingAnchorAt(currentRoot, tree));
|
||||||
@@ -295,7 +295,7 @@ void CCoinsViewCache::AbstractPopAnchor(
|
|||||||
void CCoinsViewCache::PopAnchor(const uint256 &newrt, ShieldedType type) {
|
void CCoinsViewCache::PopAnchor(const uint256 &newrt, ShieldedType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPROUT:
|
case SPROUT:
|
||||||
AbstractPopAnchor<ZCIncrementalMerkleTree, CAnchorsSproutMap, CAnchorsSproutCacheEntry>(
|
AbstractPopAnchor<SproutMerkleTree, CAnchorsSproutMap, CAnchorsSproutCacheEntry>(
|
||||||
newrt,
|
newrt,
|
||||||
SPROUT,
|
SPROUT,
|
||||||
cacheSproutAnchors,
|
cacheSproutAnchors,
|
||||||
@@ -303,7 +303,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt, ShieldedType type) {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
AbstractPopAnchor<ZCSaplingIncrementalMerkleTree, CAnchorsSaplingMap, CAnchorsSaplingCacheEntry>(
|
AbstractPopAnchor<SaplingMerkleTree, CAnchorsSaplingMap, CAnchorsSaplingCacheEntry>(
|
||||||
newrt,
|
newrt,
|
||||||
SAPLING,
|
SAPLING,
|
||||||
cacheSaplingAnchors,
|
cacheSaplingAnchors,
|
||||||
@@ -555,7 +555,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
|
|||||||
|
|
||||||
bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
|
bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
|
||||||
{
|
{
|
||||||
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
|
boost::unordered_map<uint256, SproutMerkleTree, CCoinsKeyHasher> intermediates;
|
||||||
|
|
||||||
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit)
|
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit)
|
||||||
{
|
{
|
||||||
@@ -568,7 +568,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
auto it = intermediates.find(joinsplit.anchor);
|
auto it = intermediates.find(joinsplit.anchor);
|
||||||
if (it != intermediates.end()) {
|
if (it != intermediates.end()) {
|
||||||
tree = it->second;
|
tree = it->second;
|
||||||
@@ -588,7 +588,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
|
|||||||
if (GetNullifier(spendDescription.nullifier, SAPLING)) // Prevent double spends
|
if (GetNullifier(spendDescription.nullifier, SAPLING)) // Prevent double spends
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) {
|
if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/coins.h
16
src/coins.h
@@ -276,7 +276,7 @@ struct CCoinsCacheEntry
|
|||||||
struct CAnchorsSproutCacheEntry
|
struct CAnchorsSproutCacheEntry
|
||||||
{
|
{
|
||||||
bool entered; // This will be false if the anchor is removed from the cache
|
bool entered; // This will be false if the anchor is removed from the cache
|
||||||
ZCIncrementalMerkleTree tree; // The tree itself
|
SproutMerkleTree tree; // The tree itself
|
||||||
unsigned char flags;
|
unsigned char flags;
|
||||||
|
|
||||||
enum Flags {
|
enum Flags {
|
||||||
@@ -289,7 +289,7 @@ struct CAnchorsSproutCacheEntry
|
|||||||
struct CAnchorsSaplingCacheEntry
|
struct CAnchorsSaplingCacheEntry
|
||||||
{
|
{
|
||||||
bool entered; // This will be false if the anchor is removed from the cache
|
bool entered; // This will be false if the anchor is removed from the cache
|
||||||
ZCSaplingIncrementalMerkleTree tree; // The tree itself
|
SaplingMerkleTree tree; // The tree itself
|
||||||
unsigned char flags;
|
unsigned char flags;
|
||||||
|
|
||||||
enum Flags {
|
enum Flags {
|
||||||
@@ -341,10 +341,10 @@ class CCoinsView
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Retrieve the tree (Sprout) at a particular anchored root in the chain
|
//! Retrieve the tree (Sprout) at a particular anchored root in the chain
|
||||||
virtual bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
|
virtual bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
|
||||||
|
|
||||||
//! Retrieve the tree (Sapling) at a particular anchored root in the chain
|
//! Retrieve the tree (Sapling) at a particular anchored root in the chain
|
||||||
virtual bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const;
|
virtual bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
|
||||||
|
|
||||||
//! Determine whether a nullifier is spent or not
|
//! Determine whether a nullifier is spent or not
|
||||||
virtual bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
virtual bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
||||||
@@ -389,8 +389,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CCoinsViewBacked(CCoinsView *viewIn);
|
CCoinsViewBacked(CCoinsView *viewIn);
|
||||||
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
|
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
|
||||||
bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const;
|
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
|
||||||
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
||||||
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
||||||
bool HaveCoins(const uint256 &txid) const;
|
bool HaveCoins(const uint256 &txid) const;
|
||||||
@@ -460,8 +460,8 @@ public:
|
|||||||
~CCoinsViewCache();
|
~CCoinsViewCache();
|
||||||
|
|
||||||
// Standard CCoinsView methods
|
// Standard CCoinsView methods
|
||||||
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
|
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
|
||||||
bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const;
|
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
|
||||||
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
|
||||||
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
||||||
bool HaveCoins(const uint256 &txid) const;
|
bool HaveCoins(const uint256 &txid) const;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ bool test_merkle_gadget(
|
|||||||
mgadget1.generate_r1cs_constraints();
|
mgadget1.generate_r1cs_constraints();
|
||||||
mgadget2.generate_r1cs_constraints();
|
mgadget2.generate_r1cs_constraints();
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
uint256 commitment1_data = uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c");
|
uint256 commitment1_data = uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c");
|
||||||
uint256 commitment2_data = uint256S("59d2cde5e65c1414c32ba54f0fe4bdb3d67618125286e6a191317917c812c6d7");
|
uint256 commitment2_data = uint256S("59d2cde5e65c1414c32ba54f0fe4bdb3d67618125286e6a191317917c812c6d7");
|
||||||
tree.append(commitment1_data);
|
tree.append(commitment1_data);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void test_full_api(ZCJoinSplit* js)
|
|||||||
SproutPaymentAddress recipient_addr = recipient_key.address();
|
SproutPaymentAddress recipient_addr = recipient_key.address();
|
||||||
|
|
||||||
// Create the commitment tree
|
// Create the commitment tree
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
|
|
||||||
// Set up a JoinSplit description
|
// Set up a JoinSplit description
|
||||||
uint64_t vpub_old = 10;
|
uint64_t vpub_old = 10;
|
||||||
@@ -106,7 +106,7 @@ void test_full_api(ZCJoinSplit* js)
|
|||||||
// Run tests using both phgr and groth as basis for field values
|
// Run tests using both phgr and groth as basis for field values
|
||||||
for (auto jsdesc : jsdescs)
|
for (auto jsdesc : jsdescs)
|
||||||
{
|
{
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
SproutProofs jsdescs2;
|
SproutProofs jsdescs2;
|
||||||
// Recipient should decrypt
|
// Recipient should decrypt
|
||||||
// Now the recipient should spend the money again
|
// Now the recipient should spend the money again
|
||||||
@@ -327,12 +327,12 @@ for test_input in TEST_VECTORS:
|
|||||||
|
|
||||||
void increment_note_witnesses(
|
void increment_note_witnesses(
|
||||||
const uint256& element,
|
const uint256& element,
|
||||||
std::vector<ZCIncrementalWitness>& witnesses,
|
std::vector<SproutWitness>& witnesses,
|
||||||
ZCIncrementalMerkleTree& tree
|
SproutMerkleTree& tree
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
tree.append(element);
|
tree.append(element);
|
||||||
for (ZCIncrementalWitness& w : witnesses) {
|
for (SproutWitness& w : witnesses) {
|
||||||
w.append(element);
|
w.append(element);
|
||||||
}
|
}
|
||||||
witnesses.push_back(tree.witness());
|
witnesses.push_back(tree.witness());
|
||||||
@@ -341,8 +341,8 @@ void increment_note_witnesses(
|
|||||||
TEST(joinsplit, full_api_test)
|
TEST(joinsplit, full_api_test)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::vector<ZCIncrementalWitness> witnesses;
|
std::vector<SproutWitness> witnesses;
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
increment_note_witnesses(uint256(), witnesses, tree);
|
increment_note_witnesses(uint256(), witnesses, tree);
|
||||||
SproutSpendingKey sk = SproutSpendingKey::random();
|
SproutSpendingKey sk = SproutSpendingKey::random();
|
||||||
SproutPaymentAddress addr = sk.address();
|
SproutPaymentAddress addr = sk.address();
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ class FakeCoinsViewDB : public CCoinsView {
|
|||||||
public:
|
public:
|
||||||
FakeCoinsViewDB() {}
|
FakeCoinsViewDB() {}
|
||||||
|
|
||||||
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ using namespace std;
|
|||||||
using namespace libsnark;
|
using namespace libsnark;
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void expect_deser_same(const ZCTestingIncrementalWitness& expected)
|
void expect_deser_same(const SproutTestingWitness& expected)
|
||||||
{
|
{
|
||||||
// Cannot check this; IncrementalWitness cannot be
|
// Cannot check this; IncrementalWitness cannot be
|
||||||
// deserialized because it can only be constructed by
|
// deserialized because it can only be constructed by
|
||||||
@@ -195,7 +195,7 @@ TEST(merkletree, vectors) {
|
|||||||
UniValue path_tests = read_json(MAKE_STRING(json_tests::merkle_path));
|
UniValue path_tests = read_json(MAKE_STRING(json_tests::merkle_path));
|
||||||
UniValue commitment_tests = read_json(MAKE_STRING(json_tests::merkle_commitments));
|
UniValue commitment_tests = read_json(MAKE_STRING(json_tests::merkle_commitments));
|
||||||
|
|
||||||
test_tree<ZCTestingIncrementalMerkleTree, ZCTestingIncrementalWitness>(
|
test_tree<SproutTestingMerkleTree, SproutTestingWitness>(
|
||||||
commitment_tests,
|
commitment_tests,
|
||||||
root_tests,
|
root_tests,
|
||||||
ser_tests,
|
ser_tests,
|
||||||
@@ -212,7 +212,7 @@ TEST(merkletree, SaplingVectors) {
|
|||||||
UniValue path_tests = read_json(MAKE_STRING(json_tests::merkle_path_sapling));
|
UniValue path_tests = read_json(MAKE_STRING(json_tests::merkle_path_sapling));
|
||||||
UniValue commitment_tests = read_json(MAKE_STRING(json_tests::merkle_commitments_sapling));
|
UniValue commitment_tests = read_json(MAKE_STRING(json_tests::merkle_commitments_sapling));
|
||||||
|
|
||||||
test_tree<ZCSaplingTestingIncrementalMerkleTree, ZCSaplingTestingIncrementalWitness>(
|
test_tree<SaplingTestingMerkleTree, SaplingTestingWitness>(
|
||||||
commitment_tests,
|
commitment_tests,
|
||||||
root_tests,
|
root_tests,
|
||||||
ser_tests,
|
ser_tests,
|
||||||
@@ -254,7 +254,7 @@ TEST(merkletree, emptyroot) {
|
|||||||
// an integer which converted to little-endian internally.
|
// an integer which converted to little-endian internally.
|
||||||
uint256 expected = uint256S("59d2cde5e65c1414c32ba54f0fe4bdb3d67618125286e6a191317917c812c6d7");
|
uint256 expected = uint256S("59d2cde5e65c1414c32ba54f0fe4bdb3d67618125286e6a191317917c812c6d7");
|
||||||
|
|
||||||
ASSERT_TRUE(ZCIncrementalMerkleTree::empty_root() == expected);
|
ASSERT_TRUE(SproutMerkleTree::empty_root() == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(merkletree, EmptyrootSapling) {
|
TEST(merkletree, EmptyrootSapling) {
|
||||||
@@ -263,13 +263,13 @@ TEST(merkletree, EmptyrootSapling) {
|
|||||||
// an integer which converted to little-endian internally.
|
// an integer which converted to little-endian internally.
|
||||||
uint256 expected = uint256S("3e49b5f954aa9d3545bc6c37744661eea48d7c34e3000d82b7f0010c30f4c2fb");
|
uint256 expected = uint256S("3e49b5f954aa9d3545bc6c37744661eea48d7c34e3000d82b7f0010c30f4c2fb");
|
||||||
|
|
||||||
ASSERT_TRUE(ZCSaplingIncrementalMerkleTree::empty_root() == expected);
|
ASSERT_TRUE(SaplingMerkleTree::empty_root() == expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(merkletree, deserializeInvalid) {
|
TEST(merkletree, deserializeInvalid) {
|
||||||
// attempt to deserialize a small tree from a serialized large tree
|
// attempt to deserialize a small tree from a serialized large tree
|
||||||
// (exceeds depth well-formedness check)
|
// (exceeds depth well-formedness check)
|
||||||
ZCIncrementalMerkleTree newTree;
|
SproutMerkleTree newTree;
|
||||||
|
|
||||||
for (size_t i = 0; i < 16; i++) {
|
for (size_t i = 0; i < 16; i++) {
|
||||||
newTree.append(uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"));
|
newTree.append(uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"));
|
||||||
@@ -280,7 +280,7 @@ TEST(merkletree, deserializeInvalid) {
|
|||||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
ss << newTree;
|
ss << newTree;
|
||||||
|
|
||||||
ZCTestingIncrementalMerkleTree newTreeSmall;
|
SproutTestingMerkleTree newTreeSmall;
|
||||||
ASSERT_THROW({ss >> newTreeSmall;}, std::ios_base::failure);
|
ASSERT_THROW({ss >> newTreeSmall;}, std::ios_base::failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ TEST(merkletree, deserializeInvalid2) {
|
|||||||
PROTOCOL_VERSION
|
PROTOCOL_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ TEST(merkletree, deserializeInvalid3) {
|
|||||||
PROTOCOL_VERSION
|
PROTOCOL_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,15 +316,15 @@ TEST(merkletree, deserializeInvalid4) {
|
|||||||
PROTOCOL_VERSION
|
PROTOCOL_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
ASSERT_THROW(ss >> tree, std::ios_base::failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(merkletree, testZeroElements) {
|
TEST(merkletree, testZeroElements) {
|
||||||
for (int start = 0; start < 20; start++) {
|
for (int start = 0; start < 20; start++) {
|
||||||
ZCIncrementalMerkleTree newTree;
|
SproutMerkleTree newTree;
|
||||||
|
|
||||||
ASSERT_TRUE(newTree.root() == ZCIncrementalMerkleTree::empty_root());
|
ASSERT_TRUE(newTree.root() == SproutMerkleTree::empty_root());
|
||||||
|
|
||||||
for (int i = start; i > 0; i--) {
|
for (int i = start; i > 0; i--) {
|
||||||
newTree.append(uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"));
|
newTree.append(uint256S("54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c"));
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ extern int GenMax(int n);
|
|||||||
|
|
||||||
TEST(Transaction, JSDescriptionRandomized) {
|
TEST(Transaction, JSDescriptionRandomized) {
|
||||||
// construct a merkle tree
|
// construct a merkle tree
|
||||||
ZCIncrementalMerkleTree merkleTree;
|
SproutMerkleTree merkleTree;
|
||||||
|
|
||||||
libzcash::SproutSpendingKey k = libzcash::SproutSpendingKey::random();
|
libzcash::SproutSpendingKey k = libzcash::SproutSpendingKey::random();
|
||||||
libzcash::SproutPaymentAddress addr = k.address();
|
libzcash::SproutPaymentAddress addr = k.address();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ TEST(TransactionBuilder, Invoke)
|
|||||||
auto maybe_note = maybe_pt.get().note(ivk);
|
auto maybe_note = maybe_pt.get().note(ivk);
|
||||||
ASSERT_EQ(static_cast<bool>(maybe_note), true);
|
ASSERT_EQ(static_cast<bool>(maybe_note), true);
|
||||||
auto note = maybe_note.get();
|
auto note = maybe_note.get();
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
tree.append(tx1.vShieldedOutput[0].cm);
|
tree.append(tx1.vShieldedOutput[0].cm);
|
||||||
auto anchor = tree.root();
|
auto anchor = tree.root();
|
||||||
auto witness = tree.witness();
|
auto witness = tree.witness();
|
||||||
@@ -145,7 +145,7 @@ TEST(TransactionBuilder, FailsWithNegativeChange)
|
|||||||
// Generate dummy Sapling note
|
// Generate dummy Sapling note
|
||||||
libzcash::SaplingNote note(pk, 59999);
|
libzcash::SaplingNote note(pk, 59999);
|
||||||
auto cm = note.cm().value();
|
auto cm = note.cm().value();
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
tree.append(cm);
|
tree.append(cm);
|
||||||
auto anchor = tree.root();
|
auto anchor = tree.root();
|
||||||
auto witness = tree.witness();
|
auto witness = tree.witness();
|
||||||
@@ -191,7 +191,7 @@ TEST(TransactionBuilder, ChangeOutput)
|
|||||||
// Generate dummy Sapling note
|
// Generate dummy Sapling note
|
||||||
libzcash::SaplingNote note(pk, 25000);
|
libzcash::SaplingNote note(pk, 25000);
|
||||||
auto cm = note.cm().value();
|
auto cm = note.cm().value();
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
tree.append(cm);
|
tree.append(cm);
|
||||||
auto anchor = tree.root();
|
auto anchor = tree.root();
|
||||||
auto witness = tree.witness();
|
auto witness = tree.witness();
|
||||||
@@ -289,7 +289,7 @@ TEST(TransactionBuilder, SetFee)
|
|||||||
// Generate dummy Sapling note
|
// Generate dummy Sapling note
|
||||||
libzcash::SaplingNote note(pk, 50000);
|
libzcash::SaplingNote note(pk, 50000);
|
||||||
auto cm = note.cm().value();
|
auto cm = note.cm().value();
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
tree.append(cm);
|
tree.append(cm);
|
||||||
auto anchor = tree.root();
|
auto anchor = tree.root();
|
||||||
auto witness = tree.witness();
|
auto witness = tree.witness();
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ class FakeCoinsViewDB : public CCoinsView {
|
|||||||
public:
|
public:
|
||||||
FakeCoinsViewDB() {}
|
FakeCoinsViewDB() {}
|
||||||
|
|
||||||
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/main.cpp
16
src/main.cpp
@@ -2269,7 +2269,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||||||
if (NetworkUpgradeActive(pindex->pprev->nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
if (NetworkUpgradeActive(pindex->pprev->nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) {
|
||||||
view.PopAnchor(pindex->pprev->hashFinalSaplingRoot, SAPLING);
|
view.PopAnchor(pindex->pprev->hashFinalSaplingRoot, SAPLING);
|
||||||
} else {
|
} else {
|
||||||
view.PopAnchor(ZCSaplingIncrementalMerkleTree::empty_root(), SAPLING);
|
view.PopAnchor(SaplingMerkleTree::empty_root(), SAPLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// move best block pointer to prevout block
|
// move best block pointer to prevout block
|
||||||
@@ -2414,7 +2414,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
if (!fJustCheck) {
|
if (!fJustCheck) {
|
||||||
view.SetBestBlock(pindex->GetBlockHash());
|
view.SetBestBlock(pindex->GetBlockHash());
|
||||||
// Before the genesis block, there was an empty tree
|
// Before the genesis block, there was an empty tree
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
pindex->hashSproutAnchor = tree.root();
|
pindex->hashSproutAnchor = tree.root();
|
||||||
// The genesis block contained no JoinSplits
|
// The genesis block contained no JoinSplits
|
||||||
pindex->hashFinalSproutRoot = pindex->hashSproutAnchor;
|
pindex->hashFinalSproutRoot = pindex->hashSproutAnchor;
|
||||||
@@ -2455,7 +2455,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
if (!fJustCheck) {
|
if (!fJustCheck) {
|
||||||
pindex->hashSproutAnchor = old_sprout_tree_root;
|
pindex->hashSproutAnchor = old_sprout_tree_root;
|
||||||
}
|
}
|
||||||
ZCIncrementalMerkleTree sprout_tree;
|
SproutMerkleTree sprout_tree;
|
||||||
// This should never fail: we should always be able to get the root
|
// This should never fail: we should always be able to get the root
|
||||||
// that is on the tip of our chain
|
// that is on the tip of our chain
|
||||||
assert(view.GetSproutAnchorAt(old_sprout_tree_root, sprout_tree));
|
assert(view.GetSproutAnchorAt(old_sprout_tree_root, sprout_tree));
|
||||||
@@ -2466,7 +2466,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
assert(sprout_tree.root() == old_sprout_tree_root);
|
assert(sprout_tree.root() == old_sprout_tree_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZCSaplingIncrementalMerkleTree sapling_tree;
|
SaplingMerkleTree sapling_tree;
|
||||||
assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree));
|
assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree));
|
||||||
|
|
||||||
// Grab the consensus branch ID for the block's height
|
// Grab the consensus branch ID for the block's height
|
||||||
@@ -2836,8 +2836,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
|||||||
// Update chainActive and related variables.
|
// Update chainActive and related variables.
|
||||||
UpdateTip(pindexDelete->pprev);
|
UpdateTip(pindexDelete->pprev);
|
||||||
// Get the current commitment tree
|
// Get the current commitment tree
|
||||||
ZCIncrementalMerkleTree newSproutTree;
|
SproutMerkleTree newSproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree newSaplingTree;
|
SaplingMerkleTree newSaplingTree;
|
||||||
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), newSproutTree));
|
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), newSproutTree));
|
||||||
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), newSaplingTree));
|
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), newSaplingTree));
|
||||||
// Let wallets know transactions went from 1-confirmed to
|
// Let wallets know transactions went from 1-confirmed to
|
||||||
@@ -2872,8 +2872,8 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
|
|||||||
pblock = █
|
pblock = █
|
||||||
}
|
}
|
||||||
// Get the current commitment tree
|
// Get the current commitment tree
|
||||||
ZCIncrementalMerkleTree oldSproutTree;
|
SproutMerkleTree oldSproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree oldSaplingTree;
|
SaplingMerkleTree oldSaplingTree;
|
||||||
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree));
|
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree));
|
||||||
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree));
|
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree));
|
||||||
// Apply the block atomically to the chain state.
|
// Apply the block atomically to the chain state.
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||||
CCoinsViewCache view(pcoinsTip);
|
CCoinsViewCache view(pcoinsTip);
|
||||||
|
|
||||||
ZCSaplingIncrementalMerkleTree sapling_tree;
|
SaplingMerkleTree sapling_tree;
|
||||||
assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree));
|
assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree));
|
||||||
|
|
||||||
// Priority order to process transactions
|
// Priority order to process transactions
|
||||||
|
|||||||
@@ -775,7 +775,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
|||||||
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
|
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
|
||||||
obj.push_back(Pair("pruned", fPruneMode));
|
obj.push_back(Pair("pruned", fPruneMode));
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree);
|
pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree);
|
||||||
obj.push_back(Pair("commitments", static_cast<uint64_t>(tree.size())));
|
obj.push_back(Pair("commitments", static_cast<uint64_t>(tree.size())));
|
||||||
|
|
||||||
|
|||||||
@@ -28,25 +28,25 @@ class CCoinsViewTest : public CCoinsView
|
|||||||
uint256 hashBestSproutAnchor_;
|
uint256 hashBestSproutAnchor_;
|
||||||
uint256 hashBestSaplingAnchor_;
|
uint256 hashBestSaplingAnchor_;
|
||||||
std::map<uint256, CCoins> map_;
|
std::map<uint256, CCoins> map_;
|
||||||
std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_;
|
std::map<uint256, SproutMerkleTree> mapSproutAnchors_;
|
||||||
std::map<uint256, ZCSaplingIncrementalMerkleTree> mapSaplingAnchors_;
|
std::map<uint256, SaplingMerkleTree> mapSaplingAnchors_;
|
||||||
std::map<uint256, bool> mapSproutNullifiers_;
|
std::map<uint256, bool> mapSproutNullifiers_;
|
||||||
std::map<uint256, bool> mapSaplingNullifiers_;
|
std::map<uint256, bool> mapSaplingNullifiers_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCoinsViewTest() {
|
CCoinsViewTest() {
|
||||||
hashBestSproutAnchor_ = ZCIncrementalMerkleTree::empty_root();
|
hashBestSproutAnchor_ = SproutMerkleTree::empty_root();
|
||||||
hashBestSaplingAnchor_ = ZCSaplingIncrementalMerkleTree::empty_root();
|
hashBestSaplingAnchor_ = SaplingMerkleTree::empty_root();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSproutAnchorAt(const uint256& rt, ZCIncrementalMerkleTree &tree) const {
|
bool GetSproutAnchorAt(const uint256& rt, SproutMerkleTree &tree) const {
|
||||||
if (rt == ZCIncrementalMerkleTree::empty_root()) {
|
if (rt == SproutMerkleTree::empty_root()) {
|
||||||
ZCIncrementalMerkleTree new_tree;
|
SproutMerkleTree new_tree;
|
||||||
tree = new_tree;
|
tree = new_tree;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint256, ZCIncrementalMerkleTree>::const_iterator it = mapSproutAnchors_.find(rt);
|
std::map<uint256, SproutMerkleTree>::const_iterator it = mapSproutAnchors_.find(rt);
|
||||||
if (it == mapSproutAnchors_.end()) {
|
if (it == mapSproutAnchors_.end()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -55,14 +55,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSaplingAnchorAt(const uint256& rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
bool GetSaplingAnchorAt(const uint256& rt, SaplingMerkleTree &tree) const {
|
||||||
if (rt == ZCSaplingIncrementalMerkleTree::empty_root()) {
|
if (rt == SaplingMerkleTree::empty_root()) {
|
||||||
ZCSaplingIncrementalMerkleTree new_tree;
|
SaplingMerkleTree new_tree;
|
||||||
tree = new_tree;
|
tree = new_tree;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint256, ZCSaplingIncrementalMerkleTree>::const_iterator it = mapSaplingAnchors_.find(rt);
|
std::map<uint256, SaplingMerkleTree>::const_iterator it = mapSaplingAnchors_.find(rt);
|
||||||
if (it == mapSaplingAnchors_.end()) {
|
if (it == mapSaplingAnchors_.end()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -174,8 +174,8 @@ public:
|
|||||||
mapCoins.erase(it++);
|
mapCoins.erase(it++);
|
||||||
}
|
}
|
||||||
|
|
||||||
BatchWriteAnchors<ZCIncrementalMerkleTree, CAnchorsSproutMap>(mapSproutAnchors, mapSproutAnchors_);
|
BatchWriteAnchors<SproutMerkleTree, CAnchorsSproutMap>(mapSproutAnchors, mapSproutAnchors_);
|
||||||
BatchWriteAnchors<ZCSaplingIncrementalMerkleTree, CAnchorsSaplingMap>(mapSaplingAnchors, mapSaplingAnchors_);
|
BatchWriteAnchors<SaplingMerkleTree, CAnchorsSaplingMap>(mapSaplingAnchors, mapSaplingAnchors_);
|
||||||
|
|
||||||
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
|
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
|
||||||
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
|
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
|
||||||
@@ -240,7 +240,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 appendRandomSproutCommitment(ZCIncrementalMerkleTree &tree)
|
uint256 appendRandomSproutCommitment(SproutMerkleTree &tree)
|
||||||
{
|
{
|
||||||
libzcash::SproutSpendingKey k = libzcash::SproutSpendingKey::random();
|
libzcash::SproutSpendingKey k = libzcash::SproutSpendingKey::random();
|
||||||
libzcash::SproutPaymentAddress addr = k.address();
|
libzcash::SproutPaymentAddress addr = k.address();
|
||||||
@@ -253,8 +253,8 @@ uint256 appendRandomSproutCommitment(ZCIncrementalMerkleTree &tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Tree> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, Tree &tree);
|
template<typename Tree> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, Tree &tree);
|
||||||
template<> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, ZCIncrementalMerkleTree &tree) { return cache.GetSproutAnchorAt(rt, tree); }
|
template<> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, SproutMerkleTree &tree) { return cache.GetSproutAnchorAt(rt, tree); }
|
||||||
template<> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) { return cache.GetSaplingAnchorAt(rt, tree); }
|
template<> bool GetAnchorAt(const CCoinsViewCacheTest &cache, const uint256 &rt, SaplingMerkleTree &tree) { return cache.GetSaplingAnchorAt(rt, tree); }
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup)
|
||||||
|
|
||||||
@@ -433,10 +433,10 @@ template<typename Tree> void anchorPopRegressionTestImpl(ShieldedType type)
|
|||||||
BOOST_AUTO_TEST_CASE(anchor_pop_regression_test)
|
BOOST_AUTO_TEST_CASE(anchor_pop_regression_test)
|
||||||
{
|
{
|
||||||
BOOST_TEST_CONTEXT("Sprout") {
|
BOOST_TEST_CONTEXT("Sprout") {
|
||||||
anchorPopRegressionTestImpl<ZCIncrementalMerkleTree>(SPROUT);
|
anchorPopRegressionTestImpl<SproutMerkleTree>(SPROUT);
|
||||||
}
|
}
|
||||||
BOOST_TEST_CONTEXT("Sapling") {
|
BOOST_TEST_CONTEXT("Sapling") {
|
||||||
anchorPopRegressionTestImpl<ZCSaplingIncrementalMerkleTree>(SAPLING);
|
anchorPopRegressionTestImpl<SaplingMerkleTree>(SAPLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,10 +525,10 @@ template<typename Tree> void anchorRegressionTestImpl(ShieldedType type)
|
|||||||
BOOST_AUTO_TEST_CASE(anchor_regression_test)
|
BOOST_AUTO_TEST_CASE(anchor_regression_test)
|
||||||
{
|
{
|
||||||
BOOST_TEST_CONTEXT("Sprout") {
|
BOOST_TEST_CONTEXT("Sprout") {
|
||||||
anchorRegressionTestImpl<ZCIncrementalMerkleTree>(SPROUT);
|
anchorRegressionTestImpl<SproutMerkleTree>(SPROUT);
|
||||||
}
|
}
|
||||||
BOOST_TEST_CONTEXT("Sapling") {
|
BOOST_TEST_CONTEXT("Sapling") {
|
||||||
anchorRegressionTestImpl<ZCSaplingIncrementalMerkleTree>(SAPLING);
|
anchorRegressionTestImpl<SaplingMerkleTree>(SAPLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,10 +588,10 @@ template<typename Tree> void anchorsFlushImpl(ShieldedType type)
|
|||||||
BOOST_AUTO_TEST_CASE(anchors_flush_test)
|
BOOST_AUTO_TEST_CASE(anchors_flush_test)
|
||||||
{
|
{
|
||||||
BOOST_TEST_CONTEXT("Sprout") {
|
BOOST_TEST_CONTEXT("Sprout") {
|
||||||
anchorsFlushImpl<ZCIncrementalMerkleTree>(SPROUT);
|
anchorsFlushImpl<SproutMerkleTree>(SPROUT);
|
||||||
}
|
}
|
||||||
BOOST_TEST_CONTEXT("Sapling") {
|
BOOST_TEST_CONTEXT("Sapling") {
|
||||||
anchorsFlushImpl<ZCSaplingIncrementalMerkleTree>(SAPLING);
|
anchorsFlushImpl<SaplingMerkleTree>(SAPLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,7 +601,7 @@ BOOST_AUTO_TEST_CASE(chained_joinsplits)
|
|||||||
CCoinsViewTest base;
|
CCoinsViewTest base;
|
||||||
CCoinsViewCacheTest cache(&base);
|
CCoinsViewCacheTest cache(&base);
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
|
|
||||||
JSDescription js1;
|
JSDescription js1;
|
||||||
js1.anchor = tree.root();
|
js1.anchor = tree.root();
|
||||||
@@ -746,10 +746,10 @@ template<typename Tree> void anchorsTestImpl(ShieldedType type)
|
|||||||
BOOST_AUTO_TEST_CASE(anchors_test)
|
BOOST_AUTO_TEST_CASE(anchors_test)
|
||||||
{
|
{
|
||||||
BOOST_TEST_CONTEXT("Sprout") {
|
BOOST_TEST_CONTEXT("Sprout") {
|
||||||
anchorsTestImpl<ZCIncrementalMerkleTree>(SPROUT);
|
anchorsTestImpl<SproutMerkleTree>(SPROUT);
|
||||||
}
|
}
|
||||||
BOOST_TEST_CONTEXT("Sapling") {
|
BOOST_TEST_CONTEXT("Sapling") {
|
||||||
anchorsTestImpl<ZCSaplingIncrementalMerkleTree>(SAPLING);
|
anchorsTestImpl<SaplingMerkleTree>(SAPLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1204,7 +1204,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
|
|||||||
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
|
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
|
||||||
|
|
||||||
AsyncJoinSplitInfo info;
|
AsyncJoinSplitInfo info;
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional < SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
try {
|
try {
|
||||||
proxy.perform_joinsplit(info, witnesses, anchor);
|
proxy.perform_joinsplit(info, witnesses, anchor);
|
||||||
@@ -1740,7 +1740,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals)
|
|||||||
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
|
static_cast<AsyncRPCOperation_sendmany *>(operation.get())->testmode = true;
|
||||||
|
|
||||||
MergeToAddressJSInfo info;
|
MergeToAddressJSInfo info;
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional < SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
try {
|
try {
|
||||||
proxy.perform_joinsplit(info, witnesses, anchor);
|
proxy.perform_joinsplit(info, witnesses, anchor);
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
|
|||||||
// integrity of the scheme through its own tests.
|
// integrity of the scheme through its own tests.
|
||||||
|
|
||||||
// construct a merkle tree
|
// construct a merkle tree
|
||||||
ZCIncrementalMerkleTree merkleTree;
|
SproutMerkleTree merkleTree;
|
||||||
|
|
||||||
auto k = libzcash::SproutSpendingKey::random();
|
auto k = libzcash::SproutSpendingKey::random();
|
||||||
auto addr = k.address();
|
auto addr = k.address();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ SpendDescriptionInfo::SpendDescriptionInfo(
|
|||||||
libzcash::SaplingExpandedSpendingKey expsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness)
|
SaplingWitness witness) : expsk(expsk), note(note), anchor(anchor), witness(witness)
|
||||||
{
|
{
|
||||||
librustzcash_sapling_generate_r(alpha.begin());
|
librustzcash_sapling_generate_r(alpha.begin());
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ bool TransactionBuilder::AddSaplingSpend(
|
|||||||
libzcash::SaplingExpandedSpendingKey expsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness)
|
SaplingWitness witness)
|
||||||
{
|
{
|
||||||
// Consistency check: all anchors must equal the first one
|
// Consistency check: all anchors must equal the first one
|
||||||
if (!spends.empty()) {
|
if (!spends.empty()) {
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ struct SpendDescriptionInfo {
|
|||||||
libzcash::SaplingNote note;
|
libzcash::SaplingNote note;
|
||||||
uint256 alpha;
|
uint256 alpha;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
ZCSaplingIncrementalWitness witness;
|
SaplingWitness witness;
|
||||||
|
|
||||||
SpendDescriptionInfo(
|
SpendDescriptionInfo(
|
||||||
libzcash::SaplingExpandedSpendingKey expsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness);
|
SaplingWitness witness);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OutputDescriptionInfo {
|
struct OutputDescriptionInfo {
|
||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
libzcash::SaplingExpandedSpendingKey expsk,
|
libzcash::SaplingExpandedSpendingKey expsk,
|
||||||
libzcash::SaplingNote note,
|
libzcash::SaplingNote note,
|
||||||
uint256 anchor,
|
uint256 anchor,
|
||||||
ZCSaplingIncrementalWitness witness);
|
SaplingWitness witness);
|
||||||
|
|
||||||
void AddSaplingOutput(
|
void AddSaplingOutput(
|
||||||
libzcash::SaplingFullViewingKey from,
|
libzcash::SaplingFullViewingKey from,
|
||||||
|
|||||||
24
src/txdb.cpp
24
src/txdb.cpp
@@ -44,9 +44,9 @@ CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(Get
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CCoinsViewDB::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
bool CCoinsViewDB::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
|
||||||
if (rt == ZCIncrementalMerkleTree::empty_root()) {
|
if (rt == SproutMerkleTree::empty_root()) {
|
||||||
ZCIncrementalMerkleTree new_tree;
|
SproutMerkleTree new_tree;
|
||||||
tree = new_tree;
|
tree = new_tree;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -56,9 +56,9 @@ bool CCoinsViewDB::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree
|
|||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCoinsViewDB::GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
bool CCoinsViewDB::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const {
|
||||||
if (rt == ZCSaplingIncrementalMerkleTree::empty_root()) {
|
if (rt == SaplingMerkleTree::empty_root()) {
|
||||||
ZCSaplingIncrementalMerkleTree new_tree;
|
SaplingMerkleTree new_tree;
|
||||||
tree = new_tree;
|
tree = new_tree;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,11 @@ uint256 CCoinsViewDB::GetBestAnchor(ShieldedType type) const {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case SPROUT:
|
case SPROUT:
|
||||||
if (!db.Read(DB_BEST_SPROUT_ANCHOR, hashBestAnchor))
|
if (!db.Read(DB_BEST_SPROUT_ANCHOR, hashBestAnchor))
|
||||||
return ZCIncrementalMerkleTree::empty_root();
|
return SproutMerkleTree::empty_root();
|
||||||
break;
|
break;
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
if (!db.Read(DB_BEST_SAPLING_ANCHOR, hashBestAnchor))
|
if (!db.Read(DB_BEST_SAPLING_ANCHOR, hashBestAnchor))
|
||||||
return ZCSaplingIncrementalMerkleTree::empty_root();
|
return SaplingMerkleTree::empty_root();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw runtime_error("Unknown shielded type");
|
throw runtime_error("Unknown shielded type");
|
||||||
@@ -176,17 +176,17 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
|
|||||||
mapCoins.erase(itOld);
|
mapCoins.erase(itOld);
|
||||||
}
|
}
|
||||||
|
|
||||||
::BatchWriteAnchors<CAnchorsSproutMap, CAnchorsSproutMap::iterator, CAnchorsSproutCacheEntry, ZCIncrementalMerkleTree>(batch, mapSproutAnchors, DB_SPROUT_ANCHOR);
|
::BatchWriteAnchors<CAnchorsSproutMap, CAnchorsSproutMap::iterator, CAnchorsSproutCacheEntry, SproutMerkleTree>(batch, mapSproutAnchors, DB_SPROUT_ANCHOR);
|
||||||
::BatchWriteAnchors<CAnchorsSaplingMap, CAnchorsSaplingMap::iterator, CAnchorsSaplingCacheEntry, ZCSaplingIncrementalMerkleTree>(batch, mapSaplingAnchors, DB_SAPLING_ANCHOR);
|
::BatchWriteAnchors<CAnchorsSaplingMap, CAnchorsSaplingMap::iterator, CAnchorsSaplingCacheEntry, SaplingMerkleTree>(batch, mapSaplingAnchors, DB_SAPLING_ANCHOR);
|
||||||
|
|
||||||
::BatchWriteNullifiers(batch, mapSproutNullifiers, DB_NULLIFIER);
|
::BatchWriteNullifiers(batch, mapSproutNullifiers, DB_NULLIFIER);
|
||||||
::BatchWriteNullifiers(batch, mapSaplingNullifiers, DB_SAPLING_NULLIFIER);
|
::BatchWriteNullifiers(batch, mapSaplingNullifiers, DB_SAPLING_NULLIFIER);
|
||||||
|
|
||||||
if (!hashBlock.IsNull())
|
if (!hashBlock.IsNull())
|
||||||
batch.Write(DB_BEST_BLOCK, hashBlock);
|
batch.Write(DB_BEST_BLOCK, hashBlock);
|
||||||
if (!hashSproutAnchor.IsNull() && hashSproutAnchor != ZCIncrementalMerkleTree::empty_root())
|
if (!hashSproutAnchor.IsNull() && hashSproutAnchor != SproutMerkleTree::empty_root())
|
||||||
batch.Write(DB_BEST_SPROUT_ANCHOR, hashSproutAnchor);
|
batch.Write(DB_BEST_SPROUT_ANCHOR, hashSproutAnchor);
|
||||||
if (!hashSaplingAnchor.IsNull() && hashSaplingAnchor != ZCSaplingIncrementalMerkleTree::empty_root())
|
if (!hashSaplingAnchor.IsNull() && hashSaplingAnchor != SaplingMerkleTree::empty_root())
|
||||||
batch.Write(DB_BEST_SAPLING_ANCHOR, hashSaplingAnchor);
|
batch.Write(DB_BEST_SAPLING_ANCHOR, hashSaplingAnchor);
|
||||||
|
|
||||||
LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
|
LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||||
|
|
||||||
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
|
bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
|
||||||
bool GetSaplingAnchorAt(const uint256 &rt, ZCSaplingIncrementalMerkleTree &tree) const;
|
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
|
||||||
bool GetNullifier(const uint256 &nf, ShieldedType type) const;
|
bool GetNullifier(const uint256 &nf, ShieldedType type) const;
|
||||||
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
bool GetCoins(const uint256 &txid, CCoins &coins) const;
|
||||||
bool HaveCoins(const uint256 &txid) const;
|
bool HaveCoins(const uint256 &txid) const;
|
||||||
|
|||||||
@@ -405,14 +405,14 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
|
boost::unordered_map<uint256, SproutMerkleTree, CCoinsKeyHasher> intermediates;
|
||||||
|
|
||||||
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
|
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
|
||||||
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
|
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
|
||||||
assert(!pcoins->GetNullifier(nf, SPROUT));
|
assert(!pcoins->GetNullifier(nf, SPROUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
auto it = intermediates.find(joinsplit.anchor);
|
auto it = intermediates.find(joinsplit.anchor);
|
||||||
if (it != intermediates.end()) {
|
if (it != intermediates.end()) {
|
||||||
tree = it->second;
|
tree = it->second;
|
||||||
@@ -428,7 +428,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
|
|||||||
intermediates.insert(std::make_pair(tree.root(), tree));
|
intermediates.insert(std::make_pair(tree.root(), tree));
|
||||||
}
|
}
|
||||||
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
||||||
ZCSaplingIncrementalMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
|
|
||||||
assert(pcoins->GetSaplingAnchorAt(spendDescription.anchor, tree));
|
assert(pcoins->GetSaplingAnchorAt(spendDescription.anchor, tree));
|
||||||
assert(!pcoins->GetNullifier(spendDescription.nullifier, SAPLING));
|
assert(!pcoins->GetNullifier(spendDescription.nullifier, SAPLING));
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ CWalletTx GetValidSpend(ZCJoinSplit& params,
|
|||||||
mtx.joinSplitPubKey = joinSplitPubKey;
|
mtx.joinSplitPubKey = joinSplitPubKey;
|
||||||
|
|
||||||
// Fake tree for the unused witness
|
// Fake tree for the unused witness
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
|
|
||||||
libzcash::JSOutput dummyout;
|
libzcash::JSOutput dummyout;
|
||||||
libzcash::JSInput dummyin;
|
libzcash::JSInput dummyin;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ protected:
|
|||||||
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
|
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
|
||||||
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
|
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
|
||||||
virtual void EraseFromWallet(const uint256 &hash) {}
|
virtual void EraseFromWallet(const uint256 &hash) {}
|
||||||
virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree sproutTree, ZCSaplingIncrementalMerkleTree saplingTree, bool added) {}
|
virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, SproutMerkleTree sproutTree, SaplingMerkleTree saplingTree, bool added) {}
|
||||||
virtual void SetBestChain(const CBlockLocator &locator) {}
|
virtual void SetBestChain(const CBlockLocator &locator) {}
|
||||||
virtual void UpdatedTransaction(const uint256 &hash) {}
|
virtual void UpdatedTransaction(const uint256 &hash) {}
|
||||||
virtual void Inventory(const uint256 &hash) {}
|
virtual void Inventory(const uint256 &hash) {}
|
||||||
@@ -55,7 +55,7 @@ struct CMainSignals {
|
|||||||
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
|
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
|
||||||
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
|
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
|
||||||
/** Notifies listeners of a change to the tip of the active block chain. */
|
/** Notifies listeners of a change to the tip of the active block chain. */
|
||||||
boost::signals2::signal<void (const CBlockIndex *, const CBlock *, ZCIncrementalMerkleTree, ZCSaplingIncrementalMerkleTree, bool)> ChainTip;
|
boost::signals2::signal<void (const CBlockIndex *, const CBlock *, SproutMerkleTree, SaplingMerkleTree, bool)> ChainTip;
|
||||||
/** Notifies listeners of a new active block chain. */
|
/** Notifies listeners of a new active block chain. */
|
||||||
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
|
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
|
||||||
/** Notifies listeners about an inventory item being seen on the network. */
|
/** Notifies listeners about an inventory item being seen on the network. */
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
JSOutPoint jso = std::get<0>(t);
|
JSOutPoint jso = std::get<0>(t);
|
||||||
std::vector<JSOutPoint> vOutPoints = {jso};
|
std::vector<JSOutPoint> vOutPoints = {jso};
|
||||||
uint256 inputAnchor;
|
uint256 inputAnchor;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
|
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
|
||||||
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
|
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
|
||||||
jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor};
|
jsopWitnessAnchorMap[jso.ToString()] = MergeToAddressWitnessAnchorData{vInputWitnesses[0], inputAnchor};
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of treestate within this transaction
|
// Keep track of treestate within this transaction
|
||||||
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
|
boost::unordered_map<uint256, SproutMerkleTree, CCoinsKeyHasher> intermediates;
|
||||||
std::vector<uint256> previousCommitments;
|
std::vector<uint256> previousCommitments;
|
||||||
|
|
||||||
while (!vpubNewProcessed) {
|
while (!vpubNewProcessed) {
|
||||||
@@ -406,7 +406,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
|
|
||||||
CAmount jsInputValue = 0;
|
CAmount jsInputValue = 0;
|
||||||
uint256 jsAnchor;
|
uint256 jsAnchor;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
|
|
||||||
JSDescription prevJoinSplit;
|
JSDescription prevJoinSplit;
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
// Update tree state with previous joinsplit
|
// Update tree state with previous joinsplit
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
auto it = intermediates.find(prevJoinSplit.anchor);
|
auto it = intermediates.find(prevJoinSplit.anchor);
|
||||||
if (it != intermediates.end()) {
|
if (it != intermediates.end()) {
|
||||||
tree = it->second;
|
tree = it->second;
|
||||||
@@ -437,7 +437,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(changeOutputIndex != -1);
|
assert(changeOutputIndex != -1);
|
||||||
boost::optional<ZCIncrementalWitness> changeWitness;
|
boost::optional<SproutWitness> changeWitness;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (const uint256& commitment : prevJoinSplit.commitments) {
|
for (const uint256& commitment : prevJoinSplit.commitments) {
|
||||||
tree.append(commitment);
|
tree.append(commitment);
|
||||||
@@ -487,7 +487,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
std::vector<SproutNote> vInputNotes;
|
std::vector<SproutNote> vInputNotes;
|
||||||
std::vector<SproutSpendingKey> vInputZKeys;
|
std::vector<SproutSpendingKey> vInputZKeys;
|
||||||
std::vector<JSOutPoint> vOutPoints;
|
std::vector<JSOutPoint> vOutPoints;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
|
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
|
||||||
uint256 inputAnchor;
|
uint256 inputAnchor;
|
||||||
int numInputsNeeded = (jsChange > 0) ? 1 : 0;
|
int numInputsNeeded = (jsChange > 0) ? 1 : 0;
|
||||||
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
|
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
|
||||||
@@ -544,7 +544,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
|||||||
if (!optionalWitness) {
|
if (!optionalWitness) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
|
||||||
}
|
}
|
||||||
ZCIncrementalWitness w = *optionalWitness; // could use .get();
|
SproutWitness w = *optionalWitness; // could use .get();
|
||||||
if (jsChange > 0) {
|
if (jsChange > 0) {
|
||||||
for (const uint256& commitment : previousCommitments) {
|
for (const uint256& commitment : previousCommitments) {
|
||||||
w.append(commitment);
|
w.append(commitment);
|
||||||
@@ -695,7 +695,7 @@ void AsyncRPCOperation_mergetoaddress::sign_send_raw_transaction(UniValue obj)
|
|||||||
|
|
||||||
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info)
|
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info)
|
||||||
{
|
{
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@@ -707,7 +707,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
|
|||||||
|
|
||||||
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& outPoints)
|
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInfo& info, std::vector<JSOutPoint>& outPoints)
|
||||||
{
|
{
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@@ -718,7 +718,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(MergeToAddressJSInf
|
|||||||
|
|
||||||
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
|
UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
|
||||||
MergeToAddressJSInfo& info,
|
MergeToAddressJSInfo& info,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||||
uint256 anchor)
|
uint256 anchor)
|
||||||
{
|
{
|
||||||
if (anchor.IsNull()) {
|
if (anchor.IsNull()) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct MergeToAddressJSInfo {
|
|||||||
|
|
||||||
// A struct to help us track the witness and anchor for a given JSOutPoint
|
// A struct to help us track the witness and anchor for a given JSOutPoint
|
||||||
struct MergeToAddressWitnessAnchorData {
|
struct MergeToAddressWitnessAnchorData {
|
||||||
boost::optional<ZCIncrementalWitness> witness;
|
boost::optional<SproutWitness> witness;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ private:
|
|||||||
// JoinSplit where you have the witnesses and anchor
|
// JoinSplit where you have the witnesses and anchor
|
||||||
UniValue perform_joinsplit(
|
UniValue perform_joinsplit(
|
||||||
MergeToAddressJSInfo& info,
|
MergeToAddressJSInfo& info,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||||
uint256 anchor);
|
uint256 anchor);
|
||||||
|
|
||||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||||
@@ -172,7 +172,7 @@ public:
|
|||||||
|
|
||||||
UniValue perform_joinsplit(
|
UniValue perform_joinsplit(
|
||||||
MergeToAddressJSInfo& info,
|
MergeToAddressJSInfo& info,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional<SproutWitness>> witnesses,
|
||||||
uint256 anchor)
|
uint256 anchor)
|
||||||
{
|
{
|
||||||
return delegate->perform_joinsplit(info, witnesses, anchor);
|
return delegate->perform_joinsplit(info, witnesses, anchor);
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
JSOutPoint jso = std::get<0>(t);
|
JSOutPoint jso = std::get<0>(t);
|
||||||
std::vector<JSOutPoint> vOutPoints = { jso };
|
std::vector<JSOutPoint> vOutPoints = { jso };
|
||||||
uint256 inputAnchor;
|
uint256 inputAnchor;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
|
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
|
||||||
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
|
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
|
||||||
jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor };
|
jsopWitnessAnchorMap[ jso.ToString() ] = WitnessAnchorData{ vInputWitnesses[0], inputAnchor };
|
||||||
}
|
}
|
||||||
@@ -516,7 +516,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of treestate within this transaction
|
// Keep track of treestate within this transaction
|
||||||
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
|
boost::unordered_map<uint256, SproutMerkleTree, CCoinsKeyHasher> intermediates;
|
||||||
std::vector<uint256> previousCommitments;
|
std::vector<uint256> previousCommitments;
|
||||||
|
|
||||||
while (!vpubNewProcessed) {
|
while (!vpubNewProcessed) {
|
||||||
@@ -526,7 +526,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
|
|
||||||
CAmount jsInputValue = 0;
|
CAmount jsInputValue = 0;
|
||||||
uint256 jsAnchor;
|
uint256 jsAnchor;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
|
|
||||||
JSDescription prevJoinSplit;
|
JSDescription prevJoinSplit;
|
||||||
|
|
||||||
@@ -548,7 +548,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
// Update tree state with previous joinsplit
|
// Update tree state with previous joinsplit
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
auto it = intermediates.find(prevJoinSplit.anchor);
|
auto it = intermediates.find(prevJoinSplit.anchor);
|
||||||
if (it != intermediates.end()) {
|
if (it != intermediates.end()) {
|
||||||
tree = it->second;
|
tree = it->second;
|
||||||
@@ -557,7 +557,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(changeOutputIndex != -1);
|
assert(changeOutputIndex != -1);
|
||||||
boost::optional<ZCIncrementalWitness> changeWitness;
|
boost::optional<SproutWitness> changeWitness;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (const uint256& commitment : prevJoinSplit.commitments) {
|
for (const uint256& commitment : prevJoinSplit.commitments) {
|
||||||
tree.append(commitment);
|
tree.append(commitment);
|
||||||
@@ -606,7 +606,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
//
|
//
|
||||||
std::vector<SproutNote> vInputNotes;
|
std::vector<SproutNote> vInputNotes;
|
||||||
std::vector<JSOutPoint> vOutPoints;
|
std::vector<JSOutPoint> vOutPoints;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> vInputWitnesses;
|
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
|
||||||
uint256 inputAnchor;
|
uint256 inputAnchor;
|
||||||
int numInputsNeeded = (jsChange>0) ? 1 : 0;
|
int numInputsNeeded = (jsChange>0) ? 1 : 0;
|
||||||
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
|
while (numInputsNeeded++ < ZC_NUM_JS_INPUTS && zInputsDeque.size() > 0) {
|
||||||
@@ -663,7 +663,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
if (!optionalWitness) {
|
if (!optionalWitness) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Witness for note commitment is null");
|
||||||
}
|
}
|
||||||
ZCIncrementalWitness w = *optionalWitness; // could use .get();
|
SproutWitness w = *optionalWitness; // could use .get();
|
||||||
if (jsChange > 0) {
|
if (jsChange > 0) {
|
||||||
for (const uint256& commitment : previousCommitments) {
|
for (const uint256& commitment : previousCommitments) {
|
||||||
w.append(commitment);
|
w.append(commitment);
|
||||||
@@ -920,7 +920,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
|
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional < SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@@ -931,7 +931,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
|
|||||||
|
|
||||||
|
|
||||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
|
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional < SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@@ -942,7 +942,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info
|
|||||||
|
|
||||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
|
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||||
AsyncJoinSplitInfo & info,
|
AsyncJoinSplitInfo & info,
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional < SproutWitness>> witnesses,
|
||||||
uint256 anchor)
|
uint256 anchor)
|
||||||
{
|
{
|
||||||
if (anchor.IsNull()) {
|
if (anchor.IsNull()) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct AsyncJoinSplitInfo
|
|||||||
|
|
||||||
// A struct to help us track the witness and anchor for a given JSOutPoint
|
// A struct to help us track the witness and anchor for a given JSOutPoint
|
||||||
struct WitnessAnchorData {
|
struct WitnessAnchorData {
|
||||||
boost::optional<ZCIncrementalWitness> witness;
|
boost::optional<SproutWitness> witness;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ private:
|
|||||||
// JoinSplit where you have the witnesses and anchor
|
// JoinSplit where you have the witnesses and anchor
|
||||||
UniValue perform_joinsplit(
|
UniValue perform_joinsplit(
|
||||||
AsyncJoinSplitInfo & info,
|
AsyncJoinSplitInfo & info,
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional < SproutWitness>> witnesses,
|
||||||
uint256 anchor);
|
uint256 anchor);
|
||||||
|
|
||||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||||
@@ -173,7 +173,7 @@ public:
|
|||||||
|
|
||||||
UniValue perform_joinsplit(
|
UniValue perform_joinsplit(
|
||||||
AsyncJoinSplitInfo & info,
|
AsyncJoinSplitInfo & info,
|
||||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
std::vector<boost::optional < SproutWitness>> witnesses,
|
||||||
uint256 anchor)
|
uint256 anchor)
|
||||||
{
|
{
|
||||||
return delegate->perform_joinsplit(info, witnesses, anchor);
|
return delegate->perform_joinsplit(info, witnesses, anchor);
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public:
|
|||||||
|
|
||||||
void IncrementNoteWitnesses(const CBlockIndex* pindex,
|
void IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||||
const CBlock* pblock,
|
const CBlock* pblock,
|
||||||
ZCIncrementalMerkleTree& sproutTree,
|
SproutMerkleTree& sproutTree,
|
||||||
ZCSaplingIncrementalMerkleTree& saplingTree) {
|
SaplingMerkleTree& saplingTree) {
|
||||||
CWallet::IncrementNoteWitnesses(pindex, pblock, sproutTree, saplingTree);
|
CWallet::IncrementNoteWitnesses(pindex, pblock, sproutTree, saplingTree);
|
||||||
}
|
}
|
||||||
void DecrementNoteWitnesses(const CBlockIndex* pindex) {
|
void DecrementNoteWitnesses(const CBlockIndex* pindex) {
|
||||||
@@ -97,8 +97,8 @@ std::pair<JSOutPoint, SaplingOutPoint> CreateValidBlock(TestWallet& wallet,
|
|||||||
const libzcash::SproutSpendingKey& sk,
|
const libzcash::SproutSpendingKey& sk,
|
||||||
const CBlockIndex& index,
|
const CBlockIndex& index,
|
||||||
CBlock& block,
|
CBlock& block,
|
||||||
ZCIncrementalMerkleTree& sproutTree,
|
SproutMerkleTree& sproutTree,
|
||||||
ZCSaplingIncrementalMerkleTree& saplingTree) {
|
SaplingMerkleTree& saplingTree) {
|
||||||
auto wtx = GetValidReceive(sk, 50, true, 4);
|
auto wtx = GetValidReceive(sk, 50, true, 4);
|
||||||
auto note = GetNote(sk, wtx, 0, 1);
|
auto note = GetNote(sk, wtx, 0, 1);
|
||||||
auto nullifier = note.nullifier(sk);
|
auto nullifier = note.nullifier(sk);
|
||||||
@@ -120,8 +120,8 @@ std::pair<JSOutPoint, SaplingOutPoint> CreateValidBlock(TestWallet& wallet,
|
|||||||
std::pair<uint256, uint256> GetWitnessesAndAnchors(TestWallet& wallet,
|
std::pair<uint256, uint256> GetWitnessesAndAnchors(TestWallet& wallet,
|
||||||
std::vector<JSOutPoint>& sproutNotes,
|
std::vector<JSOutPoint>& sproutNotes,
|
||||||
std::vector<SaplingOutPoint>& saplingNotes,
|
std::vector<SaplingOutPoint>& saplingNotes,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>>& sproutWitnesses,
|
std::vector<boost::optional<SproutWitness>>& sproutWitnesses,
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& saplingWitnesses) {
|
std::vector<boost::optional<SaplingWitness>>& saplingWitnesses) {
|
||||||
sproutWitnesses.clear();
|
sproutWitnesses.clear();
|
||||||
saplingWitnesses.clear();
|
saplingWitnesses.clear();
|
||||||
uint256 sproutAnchor;
|
uint256 sproutAnchor;
|
||||||
@@ -147,7 +147,7 @@ TEST(wallet_tests, note_data_serialisation) {
|
|||||||
mapSproutNoteData_t noteData;
|
mapSproutNoteData_t noteData;
|
||||||
JSOutPoint jsoutpt {wtx.GetHash(), 0, 1};
|
JSOutPoint jsoutpt {wtx.GetHash(), 0, 1};
|
||||||
SproutNoteData nd {sk.address(), nullifier};
|
SproutNoteData nd {sk.address(), nullifier};
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
nd.witnesses.push_front(tree.witness());
|
nd.witnesses.push_front(tree.witness());
|
||||||
noteData[jsoutpt] = nd;
|
noteData[jsoutpt] = nd;
|
||||||
|
|
||||||
@@ -585,8 +585,8 @@ TEST(wallet_tests, cached_witnesses_empty_chain) {
|
|||||||
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
|
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
|
||||||
std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
|
std::vector<SaplingOutPoint> saplingNotes = SetSaplingNoteData(wtx);
|
||||||
|
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
|
|
||||||
@@ -605,8 +605,8 @@ TEST(wallet_tests, cached_witnesses_empty_chain) {
|
|||||||
CBlock block;
|
CBlock block;
|
||||||
block.vtx.push_back(wtx);
|
block.vtx.push_back(wtx);
|
||||||
CBlockIndex index(block);
|
CBlockIndex index(block);
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
wallet.IncrementNoteWitnesses(&index, &block, sproutTree, saplingTree);
|
wallet.IncrementNoteWitnesses(&index, &block, sproutTree, saplingTree);
|
||||||
|
|
||||||
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
::GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
@@ -624,8 +624,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
TestWallet wallet;
|
TestWallet wallet;
|
||||||
std::pair<uint256, uint256> anchors1;
|
std::pair<uint256, uint256> anchors1;
|
||||||
CBlock block1;
|
CBlock block1;
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
|
|
||||||
auto sk = libzcash::SproutSpendingKey::random();
|
auto sk = libzcash::SproutSpendingKey::random();
|
||||||
wallet.AddSpendingKey(sk);
|
wallet.AddSpendingKey(sk);
|
||||||
@@ -639,8 +639,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
// Called to fetch anchor
|
// Called to fetch anchor
|
||||||
std::vector<JSOutPoint> sproutNotes {outpts.first};
|
std::vector<JSOutPoint> sproutNotes {outpts.first};
|
||||||
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
|
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
anchors1 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
EXPECT_NE(anchors1.first, anchors1.second);
|
EXPECT_NE(anchors1.first, anchors1.second);
|
||||||
@@ -661,8 +661,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
wallet.AddToWallet(wtx, true, NULL);
|
wallet.AddToWallet(wtx, true, NULL);
|
||||||
|
|
||||||
std::vector<JSOutPoint> sproutNotes {jsoutpt};
|
std::vector<JSOutPoint> sproutNotes {jsoutpt};
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
|
|
||||||
@@ -675,8 +675,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
block2.vtx.push_back(wtx);
|
block2.vtx.push_back(wtx);
|
||||||
CBlockIndex index2(block2);
|
CBlockIndex index2(block2);
|
||||||
index2.nHeight = 2;
|
index2.nHeight = 2;
|
||||||
ZCIncrementalMerkleTree sproutTree2 {sproutTree};
|
SproutMerkleTree sproutTree2 {sproutTree};
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree2 {saplingTree};
|
SaplingMerkleTree saplingTree2 {saplingTree};
|
||||||
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree2, saplingTree2);
|
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree2, saplingTree2);
|
||||||
|
|
||||||
auto anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
auto anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
@@ -709,8 +709,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
|
|
||||||
// Incrementing with the same block again should not change the cache
|
// Incrementing with the same block again should not change the cache
|
||||||
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree);
|
wallet.IncrementNoteWitnesses(&index2, &block2, sproutTree, saplingTree);
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses5;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses5;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses5;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses5;
|
||||||
|
|
||||||
auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5);
|
auto anchors5 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses5, saplingWitnesses5);
|
||||||
EXPECT_NE(anchors5.first, anchors5.second);
|
EXPECT_NE(anchors5.first, anchors5.second);
|
||||||
@@ -724,8 +724,8 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
|
|||||||
|
|
||||||
TEST(wallet_tests, CachedWitnessesDecrementFirst) {
|
TEST(wallet_tests, CachedWitnessesDecrementFirst) {
|
||||||
TestWallet wallet;
|
TestWallet wallet;
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
|
|
||||||
auto sk = libzcash::SproutSpendingKey::random();
|
auto sk = libzcash::SproutSpendingKey::random();
|
||||||
wallet.AddSpendingKey(sk);
|
wallet.AddSpendingKey(sk);
|
||||||
@@ -750,8 +750,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
|
|||||||
// Called to fetch anchor
|
// Called to fetch anchor
|
||||||
std::vector<JSOutPoint> sproutNotes {outpts.first};
|
std::vector<JSOutPoint> sproutNotes {outpts.first};
|
||||||
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
|
std::vector<SaplingOutPoint> saplingNotes {outpts.second};
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
anchors2 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,8 +770,8 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
|
|||||||
wallet.AddToWallet(wtx, true, NULL);
|
wallet.AddToWallet(wtx, true, NULL);
|
||||||
|
|
||||||
std::vector<JSOutPoint> sproutNotes {jsoutpt};
|
std::vector<JSOutPoint> sproutNotes {jsoutpt};
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
auto anchors3 = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
|
|
||||||
@@ -810,12 +810,12 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) {
|
|||||||
std::vector<SaplingOutPoint> saplingNotes;
|
std::vector<SaplingOutPoint> saplingNotes;
|
||||||
std::vector<uint256> sproutAnchors;
|
std::vector<uint256> sproutAnchors;
|
||||||
std::vector<uint256> saplingAnchors;
|
std::vector<uint256> saplingAnchors;
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCIncrementalMerkleTree sproutRiTree = sproutTree;
|
SproutMerkleTree sproutRiTree = sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingRiTree = saplingTree;
|
SaplingMerkleTree saplingRiTree = saplingTree;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
auto sk = libzcash::SproutSpendingKey::random();
|
auto sk = libzcash::SproutSpendingKey::random();
|
||||||
wallet.AddSpendingKey(sk);
|
wallet.AddSpendingKey(sk);
|
||||||
@@ -846,8 +846,8 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) {
|
|||||||
// Now pretend we are reindexing: the chain is cleared, and each block is
|
// Now pretend we are reindexing: the chain is cleared, and each block is
|
||||||
// used to increment witnesses again.
|
// used to increment witnesses again.
|
||||||
for (size_t i = 0; i < numBlocks; i++) {
|
for (size_t i = 0; i < numBlocks; i++) {
|
||||||
ZCIncrementalMerkleTree sproutRiPrevTree {sproutRiTree};
|
SproutMerkleTree sproutRiPrevTree {sproutRiTree};
|
||||||
ZCSaplingIncrementalMerkleTree saplingRiPrevTree {saplingRiTree};
|
SaplingMerkleTree saplingRiPrevTree {saplingRiTree};
|
||||||
wallet.IncrementNoteWitnesses(&(indices[i]), &(blocks[i]), sproutRiTree, saplingRiTree);
|
wallet.IncrementNoteWitnesses(&(indices[i]), &(blocks[i]), sproutRiTree, saplingRiTree);
|
||||||
|
|
||||||
auto anchors = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
auto anchors = GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
@@ -909,12 +909,12 @@ TEST(wallet_tests, ClearNoteWitnessCache) {
|
|||||||
auto saplingNotes = SetSaplingNoteData(wtx);
|
auto saplingNotes = SetSaplingNoteData(wtx);
|
||||||
|
|
||||||
// Pretend we mined the tx by adding a fake witness
|
// Pretend we mined the tx by adding a fake witness
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
wtx.mapSproutNoteData[jsoutpt].witnesses.push_front(sproutTree.witness());
|
wtx.mapSproutNoteData[jsoutpt].witnesses.push_front(sproutTree.witness());
|
||||||
wtx.mapSproutNoteData[jsoutpt].witnessHeight = 1;
|
wtx.mapSproutNoteData[jsoutpt].witnessHeight = 1;
|
||||||
wallet.nWitnessCacheSize = 1;
|
wallet.nWitnessCacheSize = 1;
|
||||||
|
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
wtx.mapSaplingNoteData[saplingNotes[0]].witnesses.push_front(saplingTree.witness());
|
wtx.mapSaplingNoteData[saplingNotes[0]].witnesses.push_front(saplingTree.witness());
|
||||||
wtx.mapSaplingNoteData[saplingNotes[0]].witnessHeight = 1;
|
wtx.mapSaplingNoteData[saplingNotes[0]].witnessHeight = 1;
|
||||||
wallet.nWitnessCacheSize = 2;
|
wallet.nWitnessCacheSize = 2;
|
||||||
@@ -922,8 +922,8 @@ TEST(wallet_tests, ClearNoteWitnessCache) {
|
|||||||
wallet.AddToWallet(wtx, true, NULL);
|
wallet.AddToWallet(wtx, true, NULL);
|
||||||
|
|
||||||
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
|
std::vector<JSOutPoint> sproutNotes {jsoutpt, jsoutpt2};
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> sproutWitnesses;
|
std::vector<boost::optional<SproutWitness>> sproutWitnesses;
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>> saplingWitnesses;
|
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
|
||||||
|
|
||||||
// Before clearing, we should have a witness for one note
|
// Before clearing, we should have a witness for one note
|
||||||
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
GetWitnessesAndAnchors(wallet, sproutNotes, saplingNotes, sproutWitnesses, saplingWitnesses);
|
||||||
@@ -1081,7 +1081,7 @@ TEST(wallet_tests, UpdatedNoteData) {
|
|||||||
wtx.SetSproutNoteData(noteData);
|
wtx.SetSproutNoteData(noteData);
|
||||||
|
|
||||||
// Pretend we mined the tx by adding a fake witness
|
// Pretend we mined the tx by adding a fake witness
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
wtx.mapSproutNoteData[jsoutpt].witnesses.push_front(tree.witness());
|
wtx.mapSproutNoteData[jsoutpt].witnesses.push_front(tree.witness());
|
||||||
wtx.mapSproutNoteData[jsoutpt].witnessHeight = 100;
|
wtx.mapSproutNoteData[jsoutpt].witnessHeight = 100;
|
||||||
|
|
||||||
|
|||||||
@@ -2646,7 +2646,7 @@ UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp)
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
uint256 joinSplitPubKey;
|
uint256 joinSplitPubKey;
|
||||||
uint256 anchor = ZCIncrementalMerkleTree().root();
|
uint256 anchor = SproutMerkleTree().root();
|
||||||
JSDescription samplejoinsplit(true,
|
JSDescription samplejoinsplit(true,
|
||||||
*pzcashParams,
|
*pzcashParams,
|
||||||
joinSplitPubKey,
|
joinSplitPubKey,
|
||||||
@@ -2846,7 +2846,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
|
|||||||
SproutNote decrypted_note = npt.note(payment_addr);
|
SproutNote decrypted_note = npt.note(payment_addr);
|
||||||
|
|
||||||
assert(pwalletMain != NULL);
|
assert(pwalletMain != NULL);
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
uint256 commitment = decrypted_note.cm();
|
uint256 commitment = decrypted_note.cm();
|
||||||
pwalletMain->WitnessNoteCommitment(
|
pwalletMain->WitnessNoteCommitment(
|
||||||
@@ -2947,7 +2947,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint256 anchor;
|
uint256 anchor;
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>> witnesses;
|
std::vector<boost::optional<SproutWitness>> witnesses;
|
||||||
pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor);
|
pwalletMain->WitnessNoteCommitment(commitments, witnesses, anchor);
|
||||||
|
|
||||||
assert(witnesses.size() == notes.size());
|
assert(witnesses.size() == notes.size());
|
||||||
|
|||||||
@@ -451,8 +451,8 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
|
|||||||
|
|
||||||
void CWallet::ChainTip(const CBlockIndex *pindex,
|
void CWallet::ChainTip(const CBlockIndex *pindex,
|
||||||
const CBlock *pblock,
|
const CBlock *pblock,
|
||||||
ZCIncrementalMerkleTree sproutTree,
|
SproutMerkleTree sproutTree,
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree,
|
SaplingMerkleTree saplingTree,
|
||||||
bool added)
|
bool added)
|
||||||
{
|
{
|
||||||
if (added) {
|
if (added) {
|
||||||
@@ -847,8 +847,8 @@ void UpdateWitnessHeights(NoteDataMap& noteDataMap, int indexHeight, int64_t nWi
|
|||||||
|
|
||||||
void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||||
const CBlock* pblockIn,
|
const CBlock* pblockIn,
|
||||||
ZCIncrementalMerkleTree& sproutTree,
|
SproutMerkleTree& sproutTree,
|
||||||
ZCSaplingIncrementalMerkleTree& saplingTree)
|
SaplingMerkleTree& saplingTree)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||||
@@ -1470,7 +1470,7 @@ bool CWallet::IsFromMe(const uint256& nullifier) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
|
void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SproutWitness>>& witnesses,
|
||||||
uint256 &final_anchor)
|
uint256 &final_anchor)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
@@ -1497,7 +1497,7 @@ void CWallet::GetSproutNoteWitnesses(std::vector<JSOutPoint> notes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::GetSaplingNoteWitnesses(std::vector<SaplingOutPoint> notes,
|
void CWallet::GetSaplingNoteWitnesses(std::vector<SaplingOutPoint> notes,
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SaplingWitness>>& witnesses,
|
||||||
uint256 &final_anchor)
|
uint256 &final_anchor)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
@@ -1888,12 +1888,12 @@ bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
|
void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SproutWitness>>& witnesses,
|
||||||
uint256 &final_anchor)
|
uint256 &final_anchor)
|
||||||
{
|
{
|
||||||
witnesses.resize(commitments.size());
|
witnesses.resize(commitments.size());
|
||||||
CBlockIndex* pindex = chainActive.Genesis();
|
CBlockIndex* pindex = chainActive.Genesis();
|
||||||
ZCIncrementalMerkleTree tree;
|
SproutMerkleTree tree;
|
||||||
|
|
||||||
while (pindex) {
|
while (pindex) {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
@@ -1907,7 +1907,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
|
|||||||
{
|
{
|
||||||
tree.append(note_commitment);
|
tree.append(note_commitment);
|
||||||
|
|
||||||
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) {
|
BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
|
||||||
if (wit) {
|
if (wit) {
|
||||||
wit->append(note_commitment);
|
wit->append(note_commitment);
|
||||||
}
|
}
|
||||||
@@ -1928,7 +1928,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
|
|||||||
|
|
||||||
// Consistency check: we should be able to find the current tree
|
// Consistency check: we should be able to find the current tree
|
||||||
// in our CCoins view.
|
// in our CCoins view.
|
||||||
ZCIncrementalMerkleTree dummy_tree;
|
SproutMerkleTree dummy_tree;
|
||||||
assert(pcoinsTip->GetSproutAnchorAt(current_anchor, dummy_tree));
|
assert(pcoinsTip->GetSproutAnchorAt(current_anchor, dummy_tree));
|
||||||
|
|
||||||
pindex = chainActive.Next(pindex);
|
pindex = chainActive.Next(pindex);
|
||||||
@@ -1937,7 +1937,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
|
|||||||
// TODO: #93; Select a root via some heuristic.
|
// TODO: #93; Select a root via some heuristic.
|
||||||
final_anchor = tree.root();
|
final_anchor = tree.root();
|
||||||
|
|
||||||
BOOST_FOREACH(boost::optional<ZCIncrementalWitness>& wit, witnesses) {
|
BOOST_FOREACH(boost::optional<SproutWitness>& wit, witnesses) {
|
||||||
if (wit) {
|
if (wit) {
|
||||||
assert(final_anchor == wit->root());
|
assert(final_anchor == wit->root());
|
||||||
}
|
}
|
||||||
@@ -1980,8 +1980,8 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
// This should never fail: we should always be able to get the tree
|
// This should never fail: we should always be able to get the tree
|
||||||
// state on the path to the tip of our chain
|
// state on the path to the tip of our chain
|
||||||
assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, sproutTree));
|
assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, sproutTree));
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public:
|
|||||||
* Cached incremental witnesses for spendable Notes.
|
* Cached incremental witnesses for spendable Notes.
|
||||||
* Beginning of the list is the most recent witness.
|
* Beginning of the list is the most recent witness.
|
||||||
*/
|
*/
|
||||||
std::list<ZCIncrementalWitness> witnesses;
|
std::list<SproutWitness> witnesses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block height corresponding to the most current witness.
|
* Block height corresponding to the most current witness.
|
||||||
@@ -272,7 +272,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
SaplingNoteData() : witnessHeight {-1} { }
|
SaplingNoteData() : witnessHeight {-1} { }
|
||||||
|
|
||||||
std::list<ZCSaplingIncrementalWitness> witnesses;
|
std::list<SaplingWitness> witnesses;
|
||||||
int witnessHeight;
|
int witnessHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -737,8 +737,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void IncrementNoteWitnesses(const CBlockIndex* pindex,
|
void IncrementNoteWitnesses(const CBlockIndex* pindex,
|
||||||
const CBlock* pblock,
|
const CBlock* pblock,
|
||||||
ZCIncrementalMerkleTree& sproutTree,
|
SproutMerkleTree& sproutTree,
|
||||||
ZCSaplingIncrementalMerkleTree& saplingTree);
|
SaplingMerkleTree& saplingTree);
|
||||||
/**
|
/**
|
||||||
* pindex is the old tip being disconnected.
|
* pindex is the old tip being disconnected.
|
||||||
*/
|
*/
|
||||||
@@ -1033,7 +1033,7 @@ public:
|
|||||||
void EraseFromWallet(const uint256 &hash);
|
void EraseFromWallet(const uint256 &hash);
|
||||||
void WitnessNoteCommitment(
|
void WitnessNoteCommitment(
|
||||||
std::vector<uint256> commitments,
|
std::vector<uint256> commitments,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SproutWitness>>& witnesses,
|
||||||
uint256 &final_anchor);
|
uint256 &final_anchor);
|
||||||
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
||||||
void ReacceptWalletTransactions();
|
void ReacceptWalletTransactions();
|
||||||
@@ -1077,11 +1077,11 @@ public:
|
|||||||
bool IsFromMe(const uint256& nullifier) const;
|
bool IsFromMe(const uint256& nullifier) const;
|
||||||
void GetSproutNoteWitnesses(
|
void GetSproutNoteWitnesses(
|
||||||
std::vector<JSOutPoint> notes,
|
std::vector<JSOutPoint> notes,
|
||||||
std::vector<boost::optional<ZCIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SproutWitness>>& witnesses,
|
||||||
uint256 &final_anchor);
|
uint256 &final_anchor);
|
||||||
void GetSaplingNoteWitnesses(
|
void GetSaplingNoteWitnesses(
|
||||||
std::vector<SaplingOutPoint> notes,
|
std::vector<SaplingOutPoint> notes,
|
||||||
std::vector<boost::optional<ZCSaplingIncrementalWitness>>& witnesses,
|
std::vector<boost::optional<SaplingWitness>>& witnesses,
|
||||||
uint256 &final_anchor);
|
uint256 &final_anchor);
|
||||||
|
|
||||||
isminetype IsMine(const CTxIn& txin) const;
|
isminetype IsMine(const CTxIn& txin) const;
|
||||||
@@ -1096,7 +1096,7 @@ public:
|
|||||||
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
|
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
|
||||||
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
|
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
|
||||||
CAmount GetChange(const CTransaction& tx) const;
|
CAmount GetChange(const CTransaction& tx) const;
|
||||||
void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree sproutTree, ZCSaplingIncrementalMerkleTree saplingTree, bool added);
|
void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, SproutMerkleTree sproutTree, SaplingMerkleTree saplingTree, bool added);
|
||||||
/** Saves witness caches and best block locator to disk. */
|
/** Saves witness caches and best block locator to disk. */
|
||||||
void SetBestChain(const CBlockLocator& loc);
|
void SetBestChain(const CBlockLocator& loc);
|
||||||
std::set<std::pair<libzcash::PaymentAddress, uint256>> GetNullifiersForAddresses(const std::set<libzcash::PaymentAddress> & addresses);
|
std::set<std::pair<libzcash::PaymentAddress, uint256>> GetNullifiersForAddresses(const std::set<libzcash::PaymentAddress> & addresses);
|
||||||
|
|||||||
@@ -248,16 +248,16 @@ EmptyMerkleRoots<Depth, Hash> IncrementalMerkleTree<Depth, Hash>::emptyroots;
|
|||||||
|
|
||||||
} // end namespace `libzcash`
|
} // end namespace `libzcash`
|
||||||
|
|
||||||
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> ZCIncrementalMerkleTree;
|
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> SproutMerkleTree;
|
||||||
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalMerkleTree;
|
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> SproutTestingMerkleTree;
|
||||||
|
|
||||||
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> ZCIncrementalWitness;
|
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::SHA256Compress> SproutWitness;
|
||||||
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> ZCTestingIncrementalWitness;
|
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::SHA256Compress> SproutTestingWitness;
|
||||||
|
|
||||||
typedef libzcash::IncrementalMerkleTree<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> ZCSaplingIncrementalMerkleTree;
|
typedef libzcash::IncrementalMerkleTree<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> SaplingMerkleTree;
|
||||||
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalMerkleTree;
|
typedef libzcash::IncrementalMerkleTree<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> SaplingTestingMerkleTree;
|
||||||
|
|
||||||
typedef libzcash::IncrementalWitness<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> ZCSaplingIncrementalWitness;
|
typedef libzcash::IncrementalWitness<SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash> SaplingWitness;
|
||||||
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> ZCSaplingTestingIncrementalWitness;
|
typedef libzcash::IncrementalWitness<INCREMENTAL_MERKLE_TREE_DEPTH_TESTING, libzcash::PedersenHash> SaplingTestingWitness;
|
||||||
|
|
||||||
#endif /* ZC_INCREMENTALMERKLETREE_H_ */
|
#endif /* ZC_INCREMENTALMERKLETREE_H_ */
|
||||||
|
|||||||
@@ -428,10 +428,10 @@ JSOutput::JSOutput() : addr(uint256(), uint256()), value(0) {
|
|||||||
addr = a_sk.address();
|
addr = a_sk.address();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSInput::JSInput() : witness(ZCIncrementalMerkleTree().witness()),
|
JSInput::JSInput() : witness(SproutMerkleTree().witness()),
|
||||||
key(SproutSpendingKey::random()) {
|
key(SproutSpendingKey::random()) {
|
||||||
note = SproutNote(key.address().a_pk, 0, random_uint256(), random_uint256());
|
note = SproutNote(key.address().a_pk, 0, random_uint256(), random_uint256());
|
||||||
ZCIncrementalMerkleTree dummy_tree;
|
SproutMerkleTree dummy_tree;
|
||||||
dummy_tree.append(note.cm());
|
dummy_tree.append(note.cm());
|
||||||
witness = dummy_tree.witness();
|
witness = dummy_tree.witness();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ typedef boost::variant<PHGRProof, GrothProof> SproutProof;
|
|||||||
|
|
||||||
class JSInput {
|
class JSInput {
|
||||||
public:
|
public:
|
||||||
ZCIncrementalWitness witness;
|
SproutWitness witness;
|
||||||
SproutNote note;
|
SproutNote note;
|
||||||
SproutSpendingKey key;
|
SproutSpendingKey key;
|
||||||
|
|
||||||
JSInput();
|
JSInput();
|
||||||
JSInput(ZCIncrementalWitness witness,
|
JSInput(SproutWitness witness,
|
||||||
SproutNote note,
|
SproutNote note,
|
||||||
SproutSpendingKey key) : witness(witness), note(note), key(key) { }
|
SproutSpendingKey key) : witness(witness), note(note), key(key) { }
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ double benchmark_create_joinsplit()
|
|||||||
uint256 joinSplitPubKey;
|
uint256 joinSplitPubKey;
|
||||||
|
|
||||||
/* Get the anchor of an empty commitment tree. */
|
/* Get the anchor of an empty commitment tree. */
|
||||||
uint256 anchor = ZCIncrementalMerkleTree().root();
|
uint256 anchor = SproutMerkleTree().root();
|
||||||
|
|
||||||
struct timeval tv_start;
|
struct timeval tv_start;
|
||||||
timer_start(tv_start);
|
timer_start(tv_start);
|
||||||
@@ -298,8 +298,8 @@ double benchmark_try_decrypt_notes(size_t nAddrs)
|
|||||||
double benchmark_increment_note_witnesses(size_t nTxs)
|
double benchmark_increment_note_witnesses(size_t nTxs)
|
||||||
{
|
{
|
||||||
CWallet wallet;
|
CWallet wallet;
|
||||||
ZCIncrementalMerkleTree sproutTree;
|
SproutMerkleTree sproutTree;
|
||||||
ZCSaplingIncrementalMerkleTree saplingTree;
|
SaplingMerkleTree saplingTree;
|
||||||
|
|
||||||
auto sk = libzcash::SproutSpendingKey::random();
|
auto sk = libzcash::SproutSpendingKey::random();
|
||||||
wallet.AddSpendingKey(sk);
|
wallet.AddSpendingKey(sk);
|
||||||
@@ -355,12 +355,12 @@ double benchmark_increment_note_witnesses(size_t nTxs)
|
|||||||
// Fake the input of a given block
|
// Fake the input of a given block
|
||||||
class FakeCoinsViewDB : public CCoinsViewDB {
|
class FakeCoinsViewDB : public CCoinsViewDB {
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
ZCIncrementalMerkleTree t;
|
SproutMerkleTree t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FakeCoinsViewDB(std::string dbName, uint256& hash) : CCoinsViewDB(dbName, 100, false, false), hash(hash) {}
|
FakeCoinsViewDB(std::string dbName, uint256& hash) : CCoinsViewDB(dbName, 100, false, false), hash(hash) {}
|
||||||
|
|
||||||
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
|
bool GetAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
|
||||||
if (rt == t.root()) {
|
if (rt == t.root()) {
|
||||||
tree = t;
|
tree = t;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user