Browse Source

Rename CPourTx to JSDescription.

metaverse
Sean Bowe 8 years ago
parent
commit
a8c68ffe99
  1. 2
      src/coins.cpp
  2. 4
      src/gtest/test_checktransaction.cpp
  3. 14
      src/main.cpp
  4. 12
      src/primitives/transaction.cpp
  5. 16
      src/primitives/transaction.h
  6. 2
      src/rpcrawtransaction.cpp
  7. 8
      src/test/coins_tests.cpp
  8. 2
      src/test/sighash_tests.cpp
  9. 36
      src/test/transaction_tests.cpp
  10. 10
      src/txmempool.cpp
  11. 18
      src/wallet/rpcwallet.cpp
  12. 2
      src/wallet/wallet.cpp
  13. 4
      src/zcbenchmarks.cpp
  14. 2
      src/zcbenchmarks.h

2
src/coins.cpp

@ -394,7 +394,7 @@ bool CCoinsViewCache::HavePourRequirements(const CTransaction& tx) const
{
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
BOOST_FOREACH(const CPourTx &pour, tx.vpour)
BOOST_FOREACH(const JSDescription &pour, tx.vpour)
{
BOOST_FOREACH(const uint256& serial, pour.serials)
{

4
src/gtest/test_checktransaction.cpp

@ -15,9 +15,9 @@ TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
CMutableTransaction newTx(tx);
CValidationState state;
newTx.vpour.push_back(CPourTx());
newTx.vpour.push_back(JSDescription());
CPourTx *pourtx = &newTx.vpour[0];
JSDescription *pourtx = &newTx.vpour[0];
pourtx->vpub_old = 1;
pourtx->vpub_new = 1;

14
src/main.cpp

@ -876,7 +876,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
return false;
} else {
// Ensure that zk-SNARKs verify
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
if (!pour.Verify(*pzcashParams, tx.joinSplitPubKey)) {
return state.DoS(100, error("CheckTransaction(): pour does not verify"),
REJECT_INVALID, "bad-txns-pour-verification-failed");
@ -921,7 +921,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
}
// Ensure that pour values are well-formed
BOOST_FOREACH(const CPourTx& pour, tx.vpour)
BOOST_FOREACH(const JSDescription& pour, tx.vpour)
{
if (pour.vpub_old < 0) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_old negative"),
@ -968,7 +968,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
// Check for duplicate pour serials in this transaction
set<uint256> vPourSerials;
BOOST_FOREACH(const CPourTx& pour, tx.vpour)
BOOST_FOREACH(const JSDescription& pour, tx.vpour)
{
BOOST_FOREACH(const uint256& serial, pour.serials)
{
@ -1104,7 +1104,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
return false;
}
}
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
if (pool.mapSerials.count(serial))
{
@ -1586,7 +1586,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
}
// spend serials
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
inputs.SetSerial(serial, true);
}
@ -1908,7 +1908,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
}
// unspend serials
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
view.SetSerial(serial, false);
}
@ -2157,7 +2157,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &bucket_commitment, pour.commitments) {
// Insert the bucket commitments into our temporary tree.

12
src/primitives/transaction.cpp

@ -9,7 +9,7 @@
#include "tinyformat.h"
#include "utilstrencodings.h"
CPourTx::CPourTx(ZCJoinSplit& params,
JSDescription::JSDescription(ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& anchor,
const boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
@ -37,7 +37,7 @@ CPourTx::CPourTx(ZCJoinSplit& params,
);
}
bool CPourTx::Verify(
bool JSDescription::Verify(
ZCJoinSplit& params,
const uint256& pubKeyHash
) const {
@ -54,7 +54,7 @@ bool CPourTx::Verify(
);
}
uint256 CPourTx::h_sig(ZCJoinSplit& params, const uint256& pubKeyHash) const
uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& pubKeyHash) const
{
return params.h_sig(randomSeed, serials, pubKeyHash);
}
@ -139,7 +139,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
*const_cast<std::vector<CTxIn>*>(&vin) = tx.vin;
*const_cast<std::vector<CTxOut>*>(&vout) = tx.vout;
*const_cast<unsigned int*>(&nLockTime) = tx.nLockTime;
*const_cast<std::vector<CPourTx>*>(&vpour) = tx.vpour;
*const_cast<std::vector<JSDescription>*>(&vpour) = tx.vpour;
*const_cast<uint256*>(&joinSplitPubKey) = tx.joinSplitPubKey;
*const_cast<joinsplit_sig_t*>(&joinSplitSig) = tx.joinSplitSig;
*const_cast<uint256*>(&hash) = tx.hash;
@ -156,7 +156,7 @@ CAmount CTransaction::GetValueOut() const
throw std::runtime_error("CTransaction::GetValueOut(): value out of range");
}
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
for (std::vector<JSDescription>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
{
// NB: vpub_old "takes" money from the value pool just as outputs do
nValueOut += it->vpub_old;
@ -170,7 +170,7 @@ CAmount CTransaction::GetValueOut() const
CAmount CTransaction::GetPourValueIn() const
{
CAmount nValue = 0;
for (std::vector<CPourTx>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
for (std::vector<JSDescription>::const_iterator it(vpour.begin()); it != vpour.end(); ++it)
{
// NB: vpub_new "gives" money to the value pool just as inputs do
nValue += it->vpub_new;

16
src/primitives/transaction.h

@ -17,7 +17,7 @@
#include "zcash/Zcash.h"
#include "zcash/JoinSplit.hpp"
class CPourTx
class JSDescription
{
public:
// These values 'enter from' and 'exit to' the value
@ -65,9 +65,9 @@ public:
// This is a zk-SNARK which ensures that this pour is valid.
boost::array<unsigned char, ZKSNARK_PROOF_SIZE> proof;
CPourTx(): vpub_old(0), vpub_new(0) { }
JSDescription(): vpub_old(0), vpub_new(0) { }
CPourTx(ZCJoinSplit& params,
JSDescription(ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& rt,
const boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
@ -98,7 +98,7 @@ public:
READWRITE(proof);
}
friend bool operator==(const CPourTx& a, const CPourTx& b)
friend bool operator==(const JSDescription& a, const JSDescription& b)
{
return (
a.vpub_old == b.vpub_old &&
@ -114,7 +114,7 @@ public:
);
}
friend bool operator!=(const CPourTx& a, const CPourTx& b)
friend bool operator!=(const JSDescription& a, const JSDescription& b)
{
return !(a == b);
}
@ -303,7 +303,7 @@ public:
const std::vector<CTxIn> vin;
const std::vector<CTxOut> vout;
const uint32_t nLockTime;
const std::vector<CPourTx> vpour;
const std::vector<JSDescription> vpour;
const uint256 joinSplitPubKey;
const joinsplit_sig_t joinSplitSig;
@ -325,7 +325,7 @@ public:
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
READWRITE(*const_cast<uint32_t*>(&nLockTime));
if (nVersion >= 2) {
READWRITE(*const_cast<std::vector<CPourTx>*>(&vpour));
READWRITE(*const_cast<std::vector<JSDescription>*>(&vpour));
if (vpour.size() > 0) {
READWRITE(*const_cast<uint256*>(&joinSplitPubKey));
READWRITE(*const_cast<joinsplit_sig_t*>(&joinSplitSig));
@ -382,7 +382,7 @@ struct CMutableTransaction
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
uint32_t nLockTime;
std::vector<CPourTx> vpour;
std::vector<JSDescription> vpour;
uint256 joinSplitPubKey;
CTransaction::joinsplit_sig_t joinSplitSig;

2
src/rpcrawtransaction.cpp

@ -92,7 +92,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
Array vpour;
for (unsigned int i = 0; i < tx.vpour.size(); i++) {
const CPourTx& pourtx = tx.vpour[i];
const JSDescription& pourtx = tx.vpour[i];
Object pour;
pour.push_back(Pair("anchor", pourtx.anchor.GetHex()));

8
src/test/coins_tests.cpp

@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(chained_pours)
ZCIncrementalMerkleTree tree;
CPourTx ptx1;
JSDescription ptx1;
ptx1.anchor = tree.root();
ptx1.commitments[0] = appendRandomCommitment(tree);
ptx1.commitments[1] = appendRandomCommitment(tree);
@ -232,13 +232,13 @@ BOOST_AUTO_TEST_CASE(chained_pours)
// Although it's not possible given our assumptions, if
// two pours create the same treestate twice, we should
// still be able to anchor to it.
CPourTx ptx1b;
JSDescription ptx1b;
ptx1b.anchor = tree.root();
ptx1b.commitments[0] = ptx1.commitments[0];
ptx1b.commitments[1] = ptx1.commitments[1];
CPourTx ptx2;
CPourTx ptx3;
JSDescription ptx2;
JSDescription ptx3;
ptx2.anchor = tree.root();
ptx3.anchor = tree.root();

2
src/test/sighash_tests.cpp

@ -122,7 +122,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
}
if (tx.nVersion >= 2) {
for (int pour = 0; pour < pours; pour++) {
CPourTx pourtx;
JSDescription pourtx;
if (insecure_rand() % 2 == 0) {
pourtx.vpub_old = insecure_rand() % 100000000;
} else {

36
src/test/transaction_tests.cpp

@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(test_basic_pour_verification)
auto witness = merkleTree.witness();
// create CPourTx
// create JSDescription
uint256 pubKeyHash;
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
libzcash::JSInput(witness, note, k),
@ -342,13 +342,13 @@ BOOST_AUTO_TEST_CASE(test_basic_pour_verification)
};
{
CPourTx pourtx(*p, pubKeyHash, rt, inputs, outputs, 0, 0);
JSDescription pourtx(*p, pubKeyHash, rt, inputs, outputs, 0, 0);
BOOST_CHECK(pourtx.Verify(*p, pubKeyHash));
CDataStream ss(SER_DISK, CLIENT_VERSION);
ss << pourtx;
CPourTx pourtx_deserialized;
JSDescription pourtx_deserialized;
ss >> pourtx_deserialized;
BOOST_CHECK(pourtx_deserialized == pourtx);
@ -357,13 +357,13 @@ BOOST_AUTO_TEST_CASE(test_basic_pour_verification)
{
// Ensure that the balance equation is working.
BOOST_CHECK_THROW(CPourTx(*p, pubKeyHash, rt, inputs, outputs, 10, 0), std::invalid_argument);
BOOST_CHECK_THROW(CPourTx(*p, pubKeyHash, rt, inputs, outputs, 0, 10), std::invalid_argument);
BOOST_CHECK_THROW(JSDescription(*p, pubKeyHash, rt, inputs, outputs, 10, 0), std::invalid_argument);
BOOST_CHECK_THROW(JSDescription(*p, pubKeyHash, rt, inputs, outputs, 0, 10), std::invalid_argument);
}
{
// Ensure that it won't verify if the root is changed.
auto test = CPourTx(*p, pubKeyHash, rt, inputs, outputs, 0, 0);
auto test = JSDescription(*p, pubKeyHash, rt, inputs, outputs, 0, 0);
test.anchor = GetRandHash();
BOOST_CHECK(!test.Verify(*p, pubKeyHash));
}
@ -393,8 +393,8 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
BOOST_CHECK(state.GetRejectReason() == "bad-txns-vout-empty");
newTx.vpour.push_back(CPourTx());
CPourTx *pourtx = &newTx.vpour[0];
newTx.vpour.push_back(JSDescription());
JSDescription *pourtx = &newTx.vpour[0];
pourtx->serials[0] = GetRandHash();
pourtx->serials[1] = GetRandHash();
@ -422,9 +422,9 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
CMutableTransaction newTx(tx);
CValidationState state;
newTx.vpour.push_back(CPourTx());
newTx.vpour.push_back(JSDescription());
CPourTx *pourtx = &newTx.vpour[0];
JSDescription *pourtx = &newTx.vpour[0];
pourtx->vpub_old = -1;
BOOST_CHECK(!CheckTransaction(newTx, state));
@ -448,9 +448,9 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
pourtx->vpub_new = (MAX_MONEY / 2) + 10;
newTx.vpour.push_back(CPourTx());
newTx.vpour.push_back(JSDescription());
CPourTx *pourtx2 = &newTx.vpour[1];
JSDescription *pourtx2 = &newTx.vpour[1];
pourtx2->vpub_new = (MAX_MONEY / 2) + 10;
BOOST_CHECK(!CheckTransaction(newTx, state));
@ -461,8 +461,8 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
CMutableTransaction newTx(tx);
CValidationState state;
newTx.vpour.push_back(CPourTx());
CPourTx *pourtx = &newTx.vpour[0];
newTx.vpour.push_back(JSDescription());
JSDescription *pourtx = &newTx.vpour[0];
pourtx->serials[0] = GetRandHash();
pourtx->serials[1] = pourtx->serials[0];
@ -472,8 +472,8 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
pourtx->serials[1] = GetRandHash();
newTx.vpour.push_back(CPourTx());
CPourTx *pourtx2 = &newTx.vpour[1];
newTx.vpour.push_back(JSDescription());
JSDescription *pourtx2 = &newTx.vpour[1];
pourtx2->serials[0] = GetRandHash();
pourtx2->serials[1] = pourtx->serials[0];
@ -486,8 +486,8 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
CMutableTransaction newTx(tx);
CValidationState state;
newTx.vpour.push_back(CPourTx());
CPourTx *pourtx = &newTx.vpour[0];
newTx.vpour.push_back(JSDescription());
JSDescription *pourtx = &newTx.vpour[0];
pourtx->serials[0] = GetRandHash();
pourtx->serials[1] = GetRandHash();

10
src/txmempool.cpp

@ -99,7 +99,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
const CTransaction& tx = mapTx[hash].GetTx();
for (unsigned int i = 0; i < tx.vin.size(); i++)
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
mapSerials[serial] = &tx;
}
@ -148,7 +148,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
}
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapNextTx.erase(txin.prevout);
BOOST_FOREACH(const CPourTx& pour, tx.vpour) {
BOOST_FOREACH(const JSDescription& pour, tx.vpour) {
BOOST_FOREACH(const uint256& serial, pour.serials) {
mapSerials.erase(serial);
}
@ -200,7 +200,7 @@ void CTxMemPool::removeWithAnchor(const uint256 &invalidRoot)
for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
const CTransaction& tx = it->second.GetTx();
BOOST_FOREACH(const CPourTx& pour, tx.vpour) {
BOOST_FOREACH(const JSDescription& pour, tx.vpour) {
if (pour.anchor == invalidRoot) {
transactionsToRemove.push_back(tx);
break;
@ -230,7 +230,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
}
}
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
std::map<uint256, const CTransaction*>::iterator it = mapSerials.find(serial);
if (it != mapSerials.end()) {
@ -317,7 +317,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
BOOST_FOREACH(const JSDescription &pour, tx.vpour) {
BOOST_FOREACH(const uint256 &serial, pour.serials) {
assert(!pcoins->GetSerial(serial));
}

18
src/wallet/rpcwallet.cpp

@ -2393,18 +2393,18 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
pzcashParams->loadProvingKey();
}
CPourTx* samplejoinsplit = NULL;
JSDescription* samplejoinsplit = NULL;
if (benchmarktype == "verifyjoinsplit") {
uint256 pubKeyHash;
uint256 anchor = ZCIncrementalMerkleTree().root();
samplejoinsplit = new CPourTx(*pzcashParams,
pubKeyHash,
anchor,
{JSInput(), JSInput()},
{JSOutput(), JSOutput()},
0,
0);
samplejoinsplit = new JSDescription(*pzcashParams,
pubKeyHash,
anchor,
{JSInput(), JSInput()},
{JSOutput(), JSOutput()},
0,
0);
}
for (int i = 0; i < samplecount; i++) {
@ -2644,7 +2644,7 @@ Value zc_raw_pour(const json_spirit::Array& params, bool fHelp)
mtx.nVersion = 2;
mtx.joinSplitPubKey = joinSplitPubKey;
CPourTx pourtx(*pzcashParams,
JSDescription pourtx(*pzcashParams,
joinSplitPubKey,
anchor,
{vpourin[0], vpourin[1]},

2
src/wallet/wallet.cpp

@ -1065,7 +1065,7 @@ void CWallet::WitnessBucketCommitment(std::vector<uint256> commitments,
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
BOOST_FOREACH(const CPourTx& pour, tx.vpour)
BOOST_FOREACH(const JSDescription& pour, tx.vpour)
{
BOOST_FOREACH(const uint256 &bucket_commitment, pour.commitments)
{

4
src/zcbenchmarks.cpp

@ -76,7 +76,7 @@ double benchmark_create_joinsplit()
uint256 anchor = ZCIncrementalMerkleTree().root();
timer_start();
CPourTx pourtx(*pzcashParams,
JSDescription pourtx(*pzcashParams,
pubKeyHash,
anchor,
{JSInput(), JSInput()},
@ -89,7 +89,7 @@ double benchmark_create_joinsplit()
return ret;
}
double benchmark_verify_joinsplit(const CPourTx &joinsplit)
double benchmark_verify_joinsplit(const JSDescription &joinsplit)
{
timer_start();
uint256 pubKeyHash;

2
src/zcbenchmarks.h

@ -8,7 +8,7 @@ extern double benchmark_sleep();
extern double benchmark_parameter_loading();
extern double benchmark_create_joinsplit();
extern double benchmark_solve_equihash();
extern double benchmark_verify_joinsplit(const CPourTx &joinsplit);
extern double benchmark_verify_joinsplit(const JSDescription &joinsplit);
extern double benchmark_verify_equihash();
extern double benchmark_large_tx();

Loading…
Cancel
Save