Browse Source

Fixes for indentation and local variable names.

pull/4/head
Sean Bowe 8 years ago
parent
commit
22de160219
  1. 4
      qa/rpc-tests/zcjoinsplit.py
  2. 30
      qa/rpc-tests/zcjoinsplitdoublespend.py
  3. 8
      src/rpcclient.cpp
  4. 4
      src/rpcrawtransaction.cpp
  5. 62
      src/test/coins_tests.cpp
  6. 34
      src/test/sighash_tests.cpp
  7. 14
      src/txdb.cpp
  8. 22
      src/txmempool.cpp
  9. 30
      src/wallet/rpcwallet.cpp
  10. 4
      src/wallet/wallet.cpp
  11. 16
      src/zcbenchmarks.cpp

4
qa/rpc-tests/zcjoinsplit.py

@ -11,7 +11,7 @@ import os
import shutil
import sys
class PourTxTest(BitcoinTestFramework):
class JoinSplitTest(BitcoinTestFramework):
def setup_network(self):
self.nodes = []
self.is_network_split = False
@ -47,4 +47,4 @@ class PourTxTest(BitcoinTestFramework):
assert_equal(receive_result["exists"], True)
if __name__ == '__main__':
PourTxTest().main()
JoinSplitTest().main()

30
qa/rpc-tests/zcjoinsplitdoublespend.py

@ -12,10 +12,10 @@ import shutil
import sys
import time
class PourTxTest(BitcoinTestFramework):
class JoinSplitTest(BitcoinTestFramework):
def setup_network(self):
# Start with split network:
return super(PourTxTest, self).setup_network(True)
return super(JoinSplitTest, self).setup_network(True)
def txid_in_mempool(self, node, txid):
exception_triggered = False
@ -89,27 +89,27 @@ class PourTxTest(BitcoinTestFramework):
blank_tx = self.nodes[0].createrawtransaction([], {})
# Create pour {A, B}->{*}
pour_AB = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[0] : zcsecretkey, pool[1] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
{pool[0] : zcsecretkey, pool[1] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
# Create pour {B, C}->{*}
pour_BC = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[1] : zcsecretkey, pool[2] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
{pool[1] : zcsecretkey, pool[2] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
# Create pour {C, D}->{*}
pour_CD = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[2] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
{pool[2] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
# Create pour {A, D}->{*}
pour_AD = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[0] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
{pool[0] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1},
0, 0.1)
# (a) Node 0 will spend pour AB, then attempt to
# double-spend it with BC. It should fail before and
@ -180,4 +180,4 @@ class PourTxTest(BitcoinTestFramework):
sync_blocks(self.nodes)
if __name__ == '__main__':
PourTxTest().main()
JoinSplitTest().main()

8
src/rpcclient.cpp

@ -91,10 +91,10 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "estimatepriority", 0 },
{ "prioritisetransaction", 1 },
{ "prioritisetransaction", 2 },
{ "zcrawpour", 1 },
{ "zcrawpour", 2 },
{ "zcrawpour", 3 },
{ "zcrawpour", 4 },
{ "zcrawjoinsplit", 1 },
{ "zcrawjoinsplit", 2 },
{ "zcrawjoinsplit", 3 },
{ "zcrawjoinsplit", 4 },
{ "zcbenchmark", 1 },
{ "getblocksubsidy", 0}
};

4
src/rpcrawtransaction.cpp

@ -99,8 +99,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
Array nullifiers;
BOOST_FOREACH(const uint256 serial, jsdescription.nullifiers) {
nullifiers.push_back(serial.GetHex());
BOOST_FOREACH(const uint256 nf, jsdescription.nullifiers) {
nullifiers.push_back(nf.GetHex());
}
joinsplit.push_back(Pair("nullifiers", nullifiers));
}

62
src/test/coins_tests.cpp

@ -217,78 +217,78 @@ BOOST_AUTO_TEST_CASE(anchors_flush_test)
}
}
BOOST_AUTO_TEST_CASE(chained_pours)
BOOST_AUTO_TEST_CASE(chained_joinsplits)
{
CCoinsViewTest base;
CCoinsViewCacheTest cache(&base);
ZCIncrementalMerkleTree tree;
JSDescription ptx1;
ptx1.anchor = tree.root();
ptx1.commitments[0] = appendRandomCommitment(tree);
ptx1.commitments[1] = appendRandomCommitment(tree);
JSDescription js1;
js1.anchor = tree.root();
js1.commitments[0] = appendRandomCommitment(tree);
js1.commitments[1] = appendRandomCommitment(tree);
// Although it's not possible given our assumptions, if
// two pours create the same treestate twice, we should
// two joinsplits create the same treestate twice, we should
// still be able to anchor to it.
JSDescription ptx1b;
ptx1b.anchor = tree.root();
ptx1b.commitments[0] = ptx1.commitments[0];
ptx1b.commitments[1] = ptx1.commitments[1];
JSDescription js1b;
js1b.anchor = tree.root();
js1b.commitments[0] = js1.commitments[0];
js1b.commitments[1] = js1.commitments[1];
JSDescription ptx2;
JSDescription ptx3;
JSDescription js2;
JSDescription js3;
ptx2.anchor = tree.root();
ptx3.anchor = tree.root();
js2.anchor = tree.root();
js3.anchor = tree.root();
ptx2.commitments[0] = appendRandomCommitment(tree);
ptx2.commitments[1] = appendRandomCommitment(tree);
js2.commitments[0] = appendRandomCommitment(tree);
js2.commitments[1] = appendRandomCommitment(tree);
ptx3.commitments[0] = appendRandomCommitment(tree);
ptx3.commitments[1] = appendRandomCommitment(tree);
js3.commitments[0] = appendRandomCommitment(tree);
js3.commitments[1] = appendRandomCommitment(tree);
{
CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx2);
mtx.vjoinsplit.push_back(js2);
BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx));
}
{
// ptx2 is trying to anchor to ptx1 but ptx1
// js2 is trying to anchor to js1 but js1
// appears afterwards -- not a permitted ordering
CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx2);
mtx.vjoinsplit.push_back(ptx1);
mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(js1);
BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx));
}
{
CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1);
mtx.vjoinsplit.push_back(ptx2);
mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(js2);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
}
{
CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1);
mtx.vjoinsplit.push_back(ptx2);
mtx.vjoinsplit.push_back(ptx3);
mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(js3);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
}
{
CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1);
mtx.vjoinsplit.push_back(ptx1b);
mtx.vjoinsplit.push_back(ptx2);
mtx.vjoinsplit.push_back(ptx3);
mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(js1b);
mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(js3);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
}

34
src/test/sighash_tests.cpp

@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
int ins = (insecure_rand() % 4) + 1;
int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
int pours = (insecure_rand() % 4);
int joinsplits = (insecure_rand() % 4);
for (int in = 0; in < ins; in++) {
tx.vin.push_back(CTxIn());
CTxIn &txin = tx.vin.back();
@ -121,26 +121,26 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
RandomScript(txout.scriptPubKey);
}
if (tx.nVersion >= 2) {
for (int pour = 0; pour < pours; pour++) {
JSDescription pourtx;
for (int js = 0; js < joinsplits; js++) {
JSDescription jsdesc;
if (insecure_rand() % 2 == 0) {
pourtx.vpub_old = insecure_rand() % 100000000;
jsdesc.vpub_old = insecure_rand() % 100000000;
} else {
pourtx.vpub_new = insecure_rand() % 100000000;
jsdesc.vpub_new = insecure_rand() % 100000000;
}
pourtx.anchor = GetRandHash();
pourtx.nullifiers[0] = GetRandHash();
pourtx.nullifiers[1] = GetRandHash();
pourtx.ephemeralKey = GetRandHash();
pourtx.randomSeed = GetRandHash();
randombytes_buf(pourtx.ciphertexts[0].begin(), pourtx.ciphertexts[0].size());
randombytes_buf(pourtx.ciphertexts[1].begin(), pourtx.ciphertexts[1].size());
randombytes_buf(pourtx.proof.begin(), pourtx.proof.size());
pourtx.macs[0] = GetRandHash();
pourtx.macs[1] = GetRandHash();
tx.vjoinsplit.push_back(pourtx);
jsdesc.anchor = GetRandHash();
jsdesc.nullifiers[0] = GetRandHash();
jsdesc.nullifiers[1] = GetRandHash();
jsdesc.ephemeralKey = GetRandHash();
jsdesc.randomSeed = GetRandHash();
randombytes_buf(jsdesc.ciphertexts[0].begin(), jsdesc.ciphertexts[0].size());
randombytes_buf(jsdesc.ciphertexts[1].begin(), jsdesc.ciphertexts[1].size());
randombytes_buf(jsdesc.proof.begin(), jsdesc.proof.size());
jsdesc.macs[0] = GetRandHash();
jsdesc.macs[1] = GetRandHash();
tx.vjoinsplit.push_back(jsdesc);
}
unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES];

14
src/txdb.cpp

@ -18,7 +18,7 @@
using namespace std;
static const char DB_ANCHOR = 'A';
static const char DB_SERIAL = 's';
static const char DB_NULLIFIER = 's';
static const char DB_COINS = 'c';
static const char DB_BLOCK_FILES = 'f';
static const char DB_TXINDEX = 't';
@ -43,11 +43,11 @@ void static BatchWriteAnchor(CLevelDBBatch &batch,
}
}
void static BatchWriteSerial(CLevelDBBatch &batch, const uint256 &serial, const bool &entered) {
void static BatchWriteNullifier(CLevelDBBatch &batch, const uint256 &nf, const bool &entered) {
if (!entered)
batch.Erase(make_pair(DB_SERIAL, serial));
batch.Erase(make_pair(DB_NULLIFIER, nf));
else
batch.Write(make_pair(DB_SERIAL, serial), true);
batch.Write(make_pair(DB_NULLIFIER, nf), true);
}
void static BatchWriteCoins(CLevelDBBatch &batch, const uint256 &hash, const CCoins &coins) {
@ -81,9 +81,9 @@ bool CCoinsViewDB::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree)
return read;
}
bool CCoinsViewDB::GetNullifier(const uint256 &serial) const {
bool CCoinsViewDB::GetNullifier(const uint256 &nf) const {
bool spent = false;
bool read = db.Read(make_pair(DB_SERIAL, serial), spent);
bool read = db.Read(make_pair(DB_NULLIFIER, nf), spent);
return read;
}
@ -139,7 +139,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
for (CNullifiersMap::iterator it = mapNullifiers.begin(); it != mapNullifiers.end();) {
if (it->second.flags & CNullifiersCacheEntry::DIRTY) {
BatchWriteSerial(batch, it->first, it->second.entered);
BatchWriteNullifier(batch, it->first, it->second.entered);
// TODO: changed++?
}
CNullifiersMap::iterator itOld = it++;

22
src/txmempool.cpp

@ -100,8 +100,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
for (unsigned int i = 0; i < tx.vin.size(); i++)
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) {
mapNullifiers[serial] = &tx;
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
mapNullifiers[nf] = &tx;
}
}
nTransactionsUpdated++;
@ -149,8 +149,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapNextTx.erase(txin.prevout);
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256& serial, joinsplit.nullifiers) {
mapNullifiers.erase(serial);
BOOST_FOREACH(const uint256& nf, joinsplit.nullifiers) {
mapNullifiers.erase(nf);
}
}
@ -231,8 +231,8 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
}
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) {
std::map<uint256, const CTransaction*>::iterator it = mapNullifiers.find(serial);
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
std::map<uint256, const CTransaction*>::iterator it = mapNullifiers.find(nf);
if (it != mapNullifiers.end()) {
const CTransaction &txConflict = *it->second;
if (txConflict != tx)
@ -318,8 +318,8 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) {
assert(!pcoins->GetNullifier(serial));
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
assert(!pcoins->GetNullifier(nf));
}
ZCIncrementalMerkleTree tree;
@ -484,11 +484,11 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
bool CCoinsViewMemPool::GetNullifier(const uint256 &serial) const {
if (mempool.mapNullifiers.count(serial))
bool CCoinsViewMemPool::GetNullifier(const uint256 &nf) const {
if (mempool.mapNullifiers.count(nf))
return true;
return base->GetNullifier(serial);
return base->GetNullifier(nf);
}
bool CCoinsViewMemPool::GetCoins(const uint256 &txid, CCoins &coins) const {

30
src/wallet/rpcwallet.cpp

@ -2644,17 +2644,17 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
mtx.nVersion = 2;
mtx.joinSplitPubKey = joinSplitPubKey;
JSDescription jsdescription(*pzcashParams,
joinSplitPubKey,
anchor,
{vjsin[0], vjsin[1]},
{vjsout[0], vjsout[1]},
vpub_old,
vpub_new);
JSDescription jsdesc(*pzcashParams,
joinSplitPubKey,
anchor,
{vjsin[0], vjsin[1]},
{vjsout[0], vjsout[1]},
vpub_old,
vpub_new);
assert(jsdescription.Verify(*pzcashParams, joinSplitPubKey));
assert(jsdesc.Verify(*pzcashParams, joinSplitPubKey));
mtx.vjoinsplit.push_back(jsdescription);
mtx.vjoinsplit.push_back(jsdesc);
// TODO: #966.
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
@ -2688,18 +2688,18 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
{
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
ss2 << ((unsigned char) 0x00);
ss2 << jsdescription.ephemeralKey;
ss2 << jsdescription.ciphertexts[0];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[0];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey);
encryptedNote1 = HexStr(ss2.begin(), ss2.end());
}
{
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
ss2 << ((unsigned char) 0x01);
ss2 << jsdescription.ephemeralKey;
ss2 << jsdescription.ciphertexts[1];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey);
ss2 << jsdesc.ephemeralKey;
ss2 << jsdesc.ciphertexts[1];
ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey);
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
}

4
src/wallet/wallet.cpp

@ -1065,9 +1065,9 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
BOOST_FOREACH(const JSDescription& pour, tx.vjoinsplit)
BOOST_FOREACH(const JSDescription& jsdesc, tx.vjoinsplit)
{
BOOST_FOREACH(const uint256 &note_commitment, pour.commitments)
BOOST_FOREACH(const uint256 &note_commitment, jsdesc.commitments)
{
tree.append(note_commitment);

16
src/zcbenchmarks.cpp

@ -76,16 +76,16 @@ double benchmark_create_joinsplit()
uint256 anchor = ZCIncrementalMerkleTree().root();
timer_start();
JSDescription jsdescription(*pzcashParams,
pubKeyHash,
anchor,
{JSInput(), JSInput()},
{JSOutput(), JSOutput()},
0,
0);
JSDescription jsdesc(*pzcashParams,
pubKeyHash,
anchor,
{JSInput(), JSInput()},
{JSOutput(), JSOutput()},
0,
0);
double ret = timer_stop();
assert(jsdescription.Verify(*pzcashParams, pubKeyHash));
assert(jsdesc.Verify(*pzcashParams, pubKeyHash));
return ret;
}

Loading…
Cancel
Save