Major updates integration from all upstreams
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "sodium.h"
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@@ -30,6 +31,7 @@
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
@@ -339,12 +341,12 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
|
||||
// integrity of the scheme through its own tests.
|
||||
|
||||
// construct a merkle tree
|
||||
ZCIncrementalMerkleTree merkleTree;
|
||||
SproutMerkleTree merkleTree;
|
||||
|
||||
libzcash::SpendingKey k = libzcash::SpendingKey::random();
|
||||
libzcash::PaymentAddress addr = k.address();
|
||||
auto k = libzcash::SproutSpendingKey::random();
|
||||
auto addr = k.address();
|
||||
|
||||
libzcash::Note note(addr.a_pk, 100, uint256(), uint256());
|
||||
libzcash::SproutNote note(addr.a_pk, 100, uint256(), uint256());
|
||||
|
||||
// commitment from coin
|
||||
uint256 commitment = note.cm();
|
||||
@@ -358,12 +360,12 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
|
||||
auto witness = merkleTree.witness();
|
||||
|
||||
// create JSDescription
|
||||
uint256 pubKeyHash;
|
||||
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
|
||||
uint256 joinSplitPubKey;
|
||||
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
|
||||
libzcash::JSInput(witness, note, k),
|
||||
libzcash::JSInput() // dummy input of zero value
|
||||
};
|
||||
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs = {
|
||||
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs = {
|
||||
libzcash::JSOutput(addr, 50),
|
||||
libzcash::JSOutput(addr, 50)
|
||||
};
|
||||
@@ -371,8 +373,8 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
|
||||
auto verifier = libzcash::ProofVerifier::Strict();
|
||||
|
||||
{
|
||||
JSDescription jsdesc(*pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 0);
|
||||
BOOST_CHECK(jsdesc.Verify(*pzcashParams, verifier, pubKeyHash));
|
||||
JSDescription jsdesc(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 0);
|
||||
BOOST_CHECK(jsdesc.Verify(*pzcashParams, verifier, joinSplitPubKey));
|
||||
|
||||
CDataStream ss(SER_DISK, CLIENT_VERSION);
|
||||
ss << jsdesc;
|
||||
@@ -381,29 +383,89 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
|
||||
ss >> jsdesc_deserialized;
|
||||
|
||||
BOOST_CHECK(jsdesc_deserialized == jsdesc);
|
||||
BOOST_CHECK(jsdesc_deserialized.Verify(*pzcashParams, verifier, pubKeyHash));
|
||||
BOOST_CHECK(jsdesc_deserialized.Verify(*pzcashParams, verifier, joinSplitPubKey));
|
||||
}
|
||||
|
||||
{
|
||||
// Ensure that the balance equation is working.
|
||||
BOOST_CHECK_THROW(JSDescription(*pzcashParams, pubKeyHash, rt, inputs, outputs, 10, 0), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(JSDescription(*pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 10), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 10, 0), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 10), std::invalid_argument);
|
||||
}
|
||||
|
||||
{
|
||||
// Ensure that it won't verify if the root is changed.
|
||||
auto test = JSDescription(*pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 0);
|
||||
auto test = JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 0);
|
||||
test.anchor = GetRandHash();
|
||||
BOOST_CHECK(!test.Verify(*pzcashParams, verifier, pubKeyHash));
|
||||
BOOST_CHECK(!test.Verify(*pzcashParams, verifier, joinSplitPubKey));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_simple_joinsplit_invalidity)
|
||||
void test_simple_sapling_invalidity(uint32_t consensusBranchId, CMutableTransaction tx)
|
||||
{
|
||||
{
|
||||
CMutableTransaction newTx(tx);
|
||||
CValidationState state;
|
||||
|
||||
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-vin-empty");
|
||||
}
|
||||
{
|
||||
CMutableTransaction newTx(tx);
|
||||
CValidationState state;
|
||||
|
||||
newTx.vShieldedSpend.push_back(SpendDescription());
|
||||
newTx.vShieldedSpend[0].nullifier = GetRandHash();
|
||||
|
||||
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-vout-empty");
|
||||
}
|
||||
{
|
||||
// Ensure that nullifiers are never duplicated within a transaction.
|
||||
CMutableTransaction newTx(tx);
|
||||
CValidationState state;
|
||||
|
||||
newTx.vShieldedSpend.push_back(SpendDescription());
|
||||
newTx.vShieldedSpend[0].nullifier = GetRandHash();
|
||||
|
||||
newTx.vShieldedOutput.push_back(OutputDescription());
|
||||
|
||||
newTx.vShieldedSpend.push_back(SpendDescription());
|
||||
newTx.vShieldedSpend[1].nullifier = newTx.vShieldedSpend[0].nullifier;
|
||||
|
||||
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-spend-description-nullifiers-duplicate");
|
||||
|
||||
newTx.vShieldedSpend[1].nullifier = GetRandHash();
|
||||
|
||||
BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state));
|
||||
}
|
||||
{
|
||||
CMutableTransaction newTx(tx);
|
||||
CValidationState state;
|
||||
|
||||
// Create a coinbase transaction
|
||||
CTxIn vin;
|
||||
vin.prevout = COutPoint();
|
||||
newTx.vin.push_back(vin);
|
||||
CTxOut vout;
|
||||
vout.nValue = 1;
|
||||
newTx.vout.push_back(vout);
|
||||
|
||||
newTx.vShieldedOutput.push_back(OutputDescription());
|
||||
|
||||
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-cb-has-output-description");
|
||||
|
||||
newTx.vShieldedSpend.push_back(SpendDescription());
|
||||
|
||||
BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-cb-has-spend-description");
|
||||
}
|
||||
}
|
||||
|
||||
void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransaction tx)
|
||||
{
|
||||
uint32_t consensusBranchId = SPROUT_BRANCH_ID;
|
||||
auto verifier = libzcash::ProofVerifier::Strict();
|
||||
CMutableTransaction tx;
|
||||
tx.nVersion = 2;
|
||||
{
|
||||
// Ensure that empty vin/vout remain invalid without
|
||||
// joinsplits.
|
||||
@@ -531,9 +593,42 @@ BOOST_AUTO_TEST_CASE(test_simple_joinsplit_invalidity)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_Get)
|
||||
BOOST_AUTO_TEST_CASE(test_simple_joinsplit_invalidity_driver) {
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
mtx.nVersion = 2;
|
||||
test_simple_joinsplit_invalidity(SPROUT_BRANCH_ID, mtx);
|
||||
}
|
||||
{
|
||||
// Switch to regtest parameters so we can activate Overwinter
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
|
||||
CMutableTransaction mtx;
|
||||
mtx.fOverwintered = true;
|
||||
mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
|
||||
mtx.nVersion = OVERWINTER_TX_VERSION;
|
||||
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
|
||||
test_simple_joinsplit_invalidity(NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId, mtx);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
|
||||
// Test Sapling things
|
||||
mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID;
|
||||
mtx.nVersion = SAPLING_TX_VERSION;
|
||||
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
|
||||
test_simple_sapling_invalidity(NetworkUpgradeInfo[Consensus::UPGRADE_SAPLING].nBranchId, mtx);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
|
||||
// Switch back to mainnet parameters as originally selected in test fixture
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
}
|
||||
}
|
||||
|
||||
// Parameterized testing over consensus branch ids
|
||||
BOOST_DATA_TEST_CASE(test_Get, boost::unit_test::data::xrange(static_cast<int>(Consensus::MAX_NETWORK_UPGRADES)))
|
||||
{
|
||||
uint32_t consensusBranchId = SPROUT_BRANCH_ID;
|
||||
uint32_t consensusBranchId = NetworkUpgradeInfo[sample].nBranchId;
|
||||
|
||||
CBasicKeyStore keystore;
|
||||
CCoinsView coinsDummy;
|
||||
@@ -570,7 +665,7 @@ BOOST_AUTO_TEST_CASE(test_big_overwinter_transaction) {
|
||||
uint32_t consensusBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId;
|
||||
CMutableTransaction mtx;
|
||||
mtx.fOverwintered = true;
|
||||
mtx.nVersion = 3;
|
||||
mtx.nVersion = OVERWINTER_TX_VERSION;
|
||||
mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
|
||||
|
||||
CKey key;
|
||||
|
||||
Reference in New Issue
Block a user