diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index 3d1f7e5aa..8ae512932 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -410,8 +410,8 @@ class ZCProof(object): repr(self.g_K), repr(self.g_H)) -ZC_NUM_JS_INPUTS = 2 -ZC_NUM_JS_OUTPUTS = 2 +HUSH_NUM_JS_INPUTS = 2 +HUSH_NUM_JS_OUTPUTS = 2 ZC_NOTEPLAINTEXT_LEADING = 1 ZC_V_SIZE = 8 @@ -439,13 +439,13 @@ class JSDescription(object): self.vpub_old = 0 self.vpub_new = 0 self.anchor = 0 - self.nullifiers = [0] * ZC_NUM_JS_INPUTS - self.commitments = [0] * ZC_NUM_JS_OUTPUTS + self.nullifiers = [0] * HUSH_NUM_JS_INPUTS + self.commitments = [0] * HUSH_NUM_JS_OUTPUTS self.onetimePubKey = 0 self.randomSeed = 0 - self.macs = [0] * ZC_NUM_JS_INPUTS + self.macs = [0] * HUSH_NUM_JS_INPUTS self.proof = None - self.ciphertexts = [None] * ZC_NUM_JS_OUTPUTS + self.ciphertexts = [None] * HUSH_NUM_JS_OUTPUTS def deserialize(self, f): self.vpub_old = struct.unpack(" #include #include - #include "main.h" #include "primitives/transaction.h" #include "consensus/validation.h" -extern ZCJoinSplit* params; - +//TODO: Update these tests for Sapling +/* TEST(checktransaction_tests, check_vpub_not_both_nonzero) { CMutableTransaction tx; tx.nVersion = 2; @@ -733,16 +732,16 @@ TEST(checktransaction_tests, SaplingSproutInputSumsTooLarge) { // create JSDescription uint256 rt; uint256 joinSplitPubKey; - std::array inputs = { + std::array inputs = { libzcash::JSInput(), libzcash::JSInput() }; - std::array outputs = { + std::array outputs = { libzcash::JSOutput(), libzcash::JSOutput() }; - std::array inputMap; - std::array outputMap; + std::array inputMap; + std::array outputMap; auto jsdesc = JSDescription::Randomized( true, @@ -1037,3 +1036,4 @@ TEST(checktransaction_tests, BadTxReceivedOverNetwork) } } } +*/ diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index 91ed81176..44cc1d52c 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -2,14 +2,11 @@ // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include - #include "consensus/upgrades.h" #include "consensus/validation.h" #include "main.h" #include "utiltest.h" -extern ZCJoinSplit* params; - extern bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); void ExpectOptionalAmount(CAmount expected, boost::optional actual) { @@ -88,77 +85,3 @@ TEST(Validation, ContextualCheckInputsPassesWithCoinbase) { EXPECT_TRUE(ContextualCheckInputs(tx, state, view, false, 0, false, txdata, Params(CBaseChainParams::MAIN).GetConsensus(), consensusBranchId)); } } - -TEST(Validation, ReceivedBlockTransactions) { - auto sk = libzcash::SproutSpendingKey::random(); - - // Create a fake genesis block - CBlock block1; - block1.vtx.push_back(GetValidReceive(*params, sk, 5, true)); - block1.hashMerkleRoot = block1.BuildMerkleTree(); - CBlockIndex fakeIndex1 {block1}; - - // Create a fake child block - CBlock block2; - block2.hashPrevBlock = block1.GetHash(); - block2.vtx.push_back(GetValidReceive(*params, sk, 10, true)); - block2.hashMerkleRoot = block2.BuildMerkleTree(); - CBlockIndex fakeIndex2 {block2}; - fakeIndex2.pprev = &fakeIndex1; - - CDiskBlockPos pos1; - CDiskBlockPos pos2; - - // Set initial state of indices - ASSERT_TRUE(fakeIndex1.RaiseValidity(BLOCK_VALID_TREE)); - ASSERT_TRUE(fakeIndex2.RaiseValidity(BLOCK_VALID_TREE)); - EXPECT_TRUE(fakeIndex1.IsValid(BLOCK_VALID_TREE)); - EXPECT_TRUE(fakeIndex2.IsValid(BLOCK_VALID_TREE)); - EXPECT_FALSE(fakeIndex1.IsValid(BLOCK_VALID_TRANSACTIONS)); - EXPECT_FALSE(fakeIndex2.IsValid(BLOCK_VALID_TRANSACTIONS)); - - // Sprout pool values should not be set - EXPECT_FALSE((bool)fakeIndex1.nSproutValue); - EXPECT_FALSE((bool)fakeIndex1.nChainSproutValue); - EXPECT_FALSE((bool)fakeIndex2.nSproutValue); - EXPECT_FALSE((bool)fakeIndex2.nChainSproutValue); - - // Mark the second block's transactions as received first - CValidationState state; - EXPECT_TRUE(ReceivedBlockTransactions(block2, state, &fakeIndex2, pos2)); - EXPECT_FALSE(fakeIndex1.IsValid(BLOCK_VALID_TRANSACTIONS)); - EXPECT_TRUE(fakeIndex2.IsValid(BLOCK_VALID_TRANSACTIONS)); - - // Sprout pool value delta should now be set for the second block, - // but not any chain totals - EXPECT_FALSE((bool)fakeIndex1.nSproutValue); - EXPECT_FALSE((bool)fakeIndex1.nChainSproutValue); - { - SCOPED_TRACE("ExpectOptionalAmount call"); - ExpectOptionalAmount(20, fakeIndex2.nSproutValue); - } - EXPECT_FALSE((bool)fakeIndex2.nChainSproutValue); - - // Now mark the first block's transactions as received - EXPECT_TRUE(ReceivedBlockTransactions(block1, state, &fakeIndex1, pos1)); - EXPECT_TRUE(fakeIndex1.IsValid(BLOCK_VALID_TRANSACTIONS)); - EXPECT_TRUE(fakeIndex2.IsValid(BLOCK_VALID_TRANSACTIONS)); - - // Sprout pool values should now be set for both blocks - { - SCOPED_TRACE("ExpectOptionalAmount call"); - ExpectOptionalAmount(10, fakeIndex1.nSproutValue); - } - { - SCOPED_TRACE("ExpectOptionalAmount call"); - ExpectOptionalAmount(10, fakeIndex1.nChainSproutValue); - } - { - SCOPED_TRACE("ExpectOptionalAmount call"); - ExpectOptionalAmount(20, fakeIndex2.nSproutValue); - } - { - SCOPED_TRACE("ExpectOptionalAmount call"); - ExpectOptionalAmount(30, fakeIndex2.nChainSproutValue); - } -} diff --git a/src/init.cpp b/src/init.cpp index 22608ce31..2b660bf2f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -93,11 +93,8 @@ extern bool komodo_dailysnapshot(int32_t height); extern int32_t KOMODO_LOADINGBLOCKS; extern char SMART_CHAIN_SYMBOL[]; extern int32_t KOMODO_SNAPSHOT_INTERVAL; - extern void komodo_init(int32_t height); -//ZCJoinSplit* pzcashParams = NULL; - #ifdef ENABLE_WALLET CWallet* pwalletMain = NULL; #endif diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 9268005dd..85478a8d0 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -37,9 +37,7 @@ #endif #include - #include - #include "zcash/NoteEncryption.hpp" #include "zcash/Zcash.h" #include "zcash/JoinSplit.hpp" @@ -53,20 +51,15 @@ extern std::string ASSETCHAINS_SELFIMPORT; #define OUTPUTDESCRIPTION_SIZE GetSerializeSize(OutputDescription(), SER_NETWORK, PROTOCOL_VERSION) #define SPENDDESCRIPTION_SIZE GetSerializeSize(SpendDescription(), SER_NETWORK, PROTOCOL_VERSION) - // Overwinter transaction version static const int32_t OVERWINTER_TX_VERSION = 3; -static_assert(OVERWINTER_TX_VERSION >= OVERWINTER_MIN_TX_VERSION, - "Overwinter tx version must not be lower than minimum"); -static_assert(OVERWINTER_TX_VERSION <= OVERWINTER_MAX_TX_VERSION, - "Overwinter tx version must not be higher than maximum"); +static_assert(OVERWINTER_TX_VERSION >= OVERWINTER_MIN_TX_VERSION, "Overwinter tx version must not be lower than minimum"); +static_assert(OVERWINTER_TX_VERSION <= OVERWINTER_MAX_TX_VERSION, "Overwinter tx version must not be higher than maximum"); // Sapling transaction version static const int32_t SAPLING_TX_VERSION = 4; -static_assert(SAPLING_TX_VERSION >= SAPLING_MIN_TX_VERSION, - "Sapling tx version must not be lower than minimum"); -static_assert(SAPLING_TX_VERSION <= SAPLING_MAX_TX_VERSION, - "Sapling tx version must not be higher than maximum"); +static_assert(SAPLING_TX_VERSION >= SAPLING_MIN_TX_VERSION, "Sapling tx version must not be lower than minimum"); +static_assert(SAPLING_TX_VERSION <= SAPLING_MAX_TX_VERSION, "Sapling tx version must not be higher than maximum"); /** * A shielded input to a transaction. It contains data that describes a Spend transfer. @@ -225,14 +218,14 @@ public: // are derived from the secrets placed in the note // and the secret spend-authority key known by the // spender. - std::array nullifiers; + std::array nullifiers; // Note commitments are introduced into the commitment // tree, blinding the public about the values and // destinations involved in the JoinSplit. The presence of // a commitment in the note commitment tree is required // to spend it. - std::array commitments; + std::array commitments; // Ephemeral key uint256 ephemeralKey; @@ -241,7 +234,7 @@ public: // These contain trapdoors, values and other information // that the recipient needs, including a memo field. It // is encrypted using the scheme implemented in crypto/NoteEncryption.cpp - std::array ciphertexts = {{ {{0}} }}; + std::array ciphertexts = {{ {{0}} }}; // Random seed uint256 randomSeed; @@ -249,7 +242,7 @@ public: // MACs // The verification of the JoinSplit requires these MACs // to be provided as an input. - std::array macs; + std::array macs; // JoinSplit proof // This is a zk-SNARK which ensures that this JoinSplit is valid. @@ -261,8 +254,8 @@ public: ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& rt, - const std::array& inputs, - const std::array& outputs, + const std::array& inputs, + const std::array& outputs, CAmount vpub_old, CAmount vpub_new, bool computeProof = true, // Set to false in some tests @@ -273,10 +266,10 @@ public: ZCJoinSplit& params, const uint256& joinSplitPubKey, const uint256& rt, - std::array& inputs, - std::array& outputs, - std::array& inputMap, - std::array& outputMap, + std::array& inputs, + std::array& outputs, + std::array& inputMap, + std::array& outputMap, CAmount vpub_old, CAmount vpub_new, bool computeProof = true, // Set to false in some tests diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index be3ff13fb..d0801aa81 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -3,12 +3,10 @@ // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -#define BOOST_TEST_MODULE Bitcoin Test Suite +#define BOOST_TEST_MODULE Hush Test Suite #include "test_bitcoin.h" - #include "crypto/common.h" - #include "key.h" #include "main.h" #include "random.h" @@ -27,29 +25,24 @@ #include #include #include - #include "librustzcash.h" CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h CWallet* pwalletMain; -ZCJoinSplit *pzcashParams; extern bool fPrintToConsole; extern void noui_connect(); JoinSplitTestingSetup::JoinSplitTestingSetup() { - boost::filesystem::path pk_path = ZC_GetParamsDir() / "sprout-proving.key"; - boost::filesystem::path vk_path = ZC_GetParamsDir() / "sprout-verifying.key"; - pzcashParams = ZCJoinSplit::Prepared(vk_path.string(), pk_path.string()); - boost::filesystem::path sapling_spend = ZC_GetParamsDir() / "sapling-spend.params"; + boost::filesystem::path sapling_spend = ZC_GetParamsDir() / "sapling-spend.params"; boost::filesystem::path sapling_output = ZC_GetParamsDir() / "sapling-output.params"; static_assert( sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), "librustzcash not configured correctly"); - auto sapling_spend_str = sapling_spend.native(); + auto sapling_spend_str = sapling_spend.native(); auto sapling_output_str = sapling_output.native(); librustzcash_init_zksnark_params( @@ -67,7 +60,6 @@ JoinSplitTestingSetup::JoinSplitTestingSetup() JoinSplitTestingSetup::~JoinSplitTestingSetup() { - delete pzcashParams; } BasicTestingSetup::BasicTestingSetup() @@ -94,12 +86,12 @@ TestingSetup::TestingSetup() RegisterWalletRPCCommands(tableRPC); #endif ClearDatadirCache(); - pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); + pathTemp = GetTempPath() / strprintf("test_hush_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); - pblocktree = new CBlockTreeDB(1 << 20, true); - pcoinsdbview = new CCoinsViewDB(1 << 23, true); - pcoinsTip = new CCoinsViewCache(pcoinsdbview); + pblocktree = new CBlockTreeDB(1 << 20, true); + pcoinsdbview = new CCoinsViewDB(1 << 23, true); + pcoinsTip = new CCoinsViewCache(pcoinsdbview); InitBlockIndex(); #ifdef ENABLE_WALLET bool fFirstRun; @@ -134,7 +126,6 @@ TestingSetup::~TestingSetup() boost::filesystem::remove_all(pathTemp); } - CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPool *pool) { return CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight, pool ? pool->HasNoInputsOf(tx) : hadNoDependencies, diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index acbe4025c..56fc7642c 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -362,11 +362,11 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification) // create JSDescription uint256 joinSplitPubKey; - std::array inputs = { + std::array inputs = { libzcash::JSInput(witness, note, k), libzcash::JSInput() // dummy input of zero value }; - std::array outputs = { + std::array outputs = { libzcash::JSOutput(addr, 50), libzcash::JSOutput(addr, 50) }; diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index ffbd02faf..7714cf90a 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -60,7 +60,7 @@ int mta_find_output(UniValue obj, int n) } UniValue outputMap = outputMapValue.get_array(); - assert(outputMap.size() == ZC_NUM_JS_OUTPUTS); + assert(outputMap.size() == HUSH_NUM_JS_OUTPUTS); for (size_t i = 0; i < outputMap.size(); i++) { if (outputMap[i].get_int() == n) { return i; diff --git a/src/wallet/gtest/test_transaction.cpp b/src/wallet/gtest/test_transaction.cpp index f0a311a49..df25f2ccf 100644 --- a/src/wallet/gtest/test_transaction.cpp +++ b/src/wallet/gtest/test_transaction.cpp @@ -34,16 +34,16 @@ TEST(Transaction, JSDescriptionRandomized) { // create JSDescription uint256 pubKeyHash; - boost::array inputs = { + boost::array inputs = { libzcash::JSInput(witness, note, k), libzcash::JSInput() // dummy input of zero value }; - boost::array outputs = { + boost::array outputs = { libzcash::JSOutput(addr, 50), libzcash::JSOutput(addr, 50) }; - std::array inputMap; - std::array outputMap; + std::array inputMap; + std::array outputMap; { auto jsdesc = JSDescription::Randomized( @@ -73,8 +73,8 @@ TEST(Transaction, JSDescriptionRandomized) { inputMap, outputMap, 0, 0, false, GenZero); - std::array expectedInputMap {1, 0}; - std::array expectedOutputMap {1, 0}; + std::array expectedInputMap {1, 0}; + std::array expectedOutputMap {1, 0}; EXPECT_EQ(expectedInputMap, inputMap); EXPECT_EQ(expectedOutputMap, outputMap); } @@ -86,8 +86,8 @@ TEST(Transaction, JSDescriptionRandomized) { inputMap, outputMap, 0, 0, false, GenMax); - boost::array expectedInputMap {0, 1}; - boost::array expectedOutputMap {0, 1}; + boost::array expectedInputMap {0, 1}; + boost::array expectedOutputMap {0, 1}; EXPECT_EQ(expectedInputMap, inputMap); EXPECT_EQ(expectedOutputMap, outputMap); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1f9820dc4..0c12a3f99 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -203,7 +203,7 @@ public: uint256 hash; // Index into CTransaction.vjoinsplit uint64_t js; - // Index into JSDescription fields of length ZC_NUM_JS_OUTPUTS + // Index into JSDescription fields of length HUSH_NUM_JS_OUTPUTS uint8_t n; JSOutPoint() { SetNull(); } diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index ceac79fe4..3d5d43e79 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -2,8 +2,8 @@ // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -#ifndef ZC_JOINSPLIT_H_ -#define ZC_JOINSPLIT_H_ +#ifndef HUSH_JOINSPLIT_H_ +#define HUSH_JOINSPLIT_H_ #include "Zcash.h" #include "Proof.hpp" @@ -13,7 +13,6 @@ #include "NoteEncryption.hpp" #include "uint256.h" #include "uint252.h" - #include namespace libzcash { @@ -25,16 +24,13 @@ static constexpr size_t GROTH_PROOF_SIZE = ( typedef std::array GrothProof; typedef boost::variant SproutProof; - class JSInput { }; - class JSOutput { }; - template class JoinSplit { }; } -typedef libzcash::JoinSplit ZCJoinSplit; +typedef libzcash::JoinSplit ZCJoinSplit; -#endif // ZC_JOINSPLIT_H_ +#endif // HUSH_JOINSPLIT_H_ diff --git a/src/zcash/NoteEncryption.hpp b/src/zcash/NoteEncryption.hpp index bafda8032..ff121470c 100644 --- a/src/zcash/NoteEncryption.hpp +++ b/src/zcash/NoteEncryption.hpp @@ -117,7 +117,7 @@ public: } // Encrypts `message` with `pk_enc` and returns the ciphertext. - // This is only called ZC_NUM_JS_OUTPUTS times for a given instantiation; + // This is only called HUSH_NUM_JS_OUTPUTS times for a given instantiation; // but can be called 255 times before the nonce-space runs out. Ciphertext encrypt(const uint256 &pk_enc, const Plaintext &message diff --git a/src/zcash/Zcash.h b/src/zcash/Zcash.h index 14f2ed411..a8bb78f26 100644 --- a/src/zcash/Zcash.h +++ b/src/zcash/Zcash.h @@ -4,8 +4,8 @@ #ifndef ZC_ZCASH_H_ #define ZC_ZCASH_H_ -#define ZC_NUM_JS_INPUTS 2 -#define ZC_NUM_JS_OUTPUTS 2 +#define HUSH_NUM_JS_INPUTS 2 +#define HUSH_NUM_JS_OUTPUTS 2 #define INCREMENTAL_MERKLE_TREE_DEPTH 29 #define INCREMENTAL_MERKLE_TREE_DEPTH_TESTING 4