diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp index bc84a0b95..2a18d42ce 100644 --- a/src/test/DoS_tests.cpp +++ b/src/test/DoS_tests.cpp @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) CTransaction RandomOrphan() { std::map::iterator it; - it = mapOrphanTransactions.lower_bound(GetRandHash()); + it = mapOrphanTransactions.lower_bound(insecure_rand256()); if (it == mapOrphanTransactions.end()) it = mapOrphanTransactions.begin(); return it->second.tx; @@ -141,7 +141,7 @@ BOOST_DATA_TEST_CASE(DoS_mapOrphans, boost::unit_test::data::xrange(static_cast< CMutableTransaction tx; tx.vin.resize(1); tx.vin[0].prevout.n = 0; - tx.vin[0].prevout.hash = GetRandHash(); + tx.vin[0].prevout.hash = insecure_rand256(); tx.vin[0].scriptSig << OP_1; tx.vout.resize(1); tx.vout[0].nValue = 1*CENT; diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index e889f739e..58b05b85d 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) static std::vector RandomData() { - uint256 r = GetRandHash(); + uint256 r = insecure_rand256(); return std::vector(r.begin(), r.end()); } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 9c41b7272..9d2ce5465 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -161,7 +161,7 @@ void Correct_Queue_range(std::vector range) FakeCheckCheckCompletion::n_calls = 0; CCheckQueueControl control(small_queue.get()); while (total) { - vChecks.resize(std::min(total, (size_t) GetRand(10))); + vChecks.resize(std::min(total, (size_t) insecure_randrange(10))); total -= vChecks.size(); control.Add(vChecks); } @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) { std::vector range; range.reserve(100000/1000); - for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)GetRand(std::min((size_t)1000, ((size_t)100000) - i)))) + for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)insecure_randrange(std::min((size_t)1000, ((size_t)100000) - i)))) range.push_back(i); Correct_Queue_range(range); } @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) CCheckQueueControl control(fail_queue.get()); size_t remaining = i; while (remaining) { - size_t r = GetRand(10); + size_t r = insecure_randrange(10); std::vector vChecks; vChecks.reserve(r); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) { CCheckQueueControl control(queue.get()); while (total) { - size_t r = GetRand(10); + size_t r = insecure_randrange(10); std::vector vChecks; for (size_t k = 0; k < r && total; k++) vChecks.emplace_back(--total); @@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) { CCheckQueueControl control(queue.get()); while (total) { - size_t r = GetRand(10); + size_t r = insecure_randrange(10); std::vector vChecks; for (size_t k = 0; k < r && total; k++) { total--; diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 666a1e42f..8a067a070 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -143,7 +143,7 @@ public: return false; } coins = it->second; - if (coins.IsPruned() && insecure_rand() % 2 == 0) { + if (coins.IsPruned() && insecure_randrange(2) == 0) { // Randomly return false in case of an empty entry. return false; } @@ -209,7 +209,7 @@ public: if (it->second.flags & CCoinsCacheEntry::DIRTY) { // Same optimization used in CCoinsViewDB is to only write dirty entries. map_[it->first] = it->second.coins; - if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) { + if (it->second.coins.IsPruned() && insecure_randrange(3) == 0) { // Randomly delete empty entries on write. map_.erase(it->first); } @@ -275,12 +275,12 @@ public: { CMutableTransaction mutableTx; - sproutNullifier = GetRandHash(); + sproutNullifier = insecure_rand256(); JSDescription jsd; jsd.nullifiers[0] = sproutNullifier; mutableTx.vJoinSplit.emplace_back(jsd); - saplingNullifier = GetRandHash(); + saplingNullifier = insecure_rand256(); SpendDescription sd; sd.nullifier = saplingNullifier; mutableTx.vShieldedSpend.push_back(sd); @@ -312,8 +312,8 @@ uint256 appendRandomSproutCommitment(SproutMerkleTree &tree) } template void AppendRandomLeaf(Tree &tree); -template<> void AppendRandomLeaf(SproutMerkleTree &tree) { tree.append(GetRandHash()); } -template<> void AppendRandomLeaf(SaplingMerkleTree &tree) { tree.append(GetRandHash()); } +template<> void AppendRandomLeaf(SproutMerkleTree &tree) { tree.append(insecure_rand256()); } +template<> void AppendRandomLeaf(SaplingMerkleTree &tree) { tree.append(insecure_rand256()); } template<> void AppendRandomLeaf(OrchardMerkleFrontier &tree) { // OrchardMerkleFrontier only has APIs to append entire bundles, but // fortunately the tests only require that the tree root change. @@ -462,7 +462,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) std::vector txids; txids.resize(NUM_SIMULATION_ITERATIONS / 8); for (unsigned int i = 0; i < txids.size(); i++) { - txids[i] = GetRandHash(); + txids[i] = insecure_rand256(); } for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { @@ -472,7 +472,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) CCoins& coins = result[txid]; CCoinsModifier entry = stack.back()->ModifyCoins(txid); BOOST_CHECK(coins == *entry); - if (insecure_rand() % 5 == 0 || coins.IsPruned()) { + if (insecure_randrange(5) == 0 || coins.IsPruned()) { if (coins.IsPruned()) { added_an_entry = true; } else { @@ -490,7 +490,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) } // Once every 1000 iterations and at the end, verify the full cache. - if (insecure_rand() % 1000 == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { + if (insecure_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { for (std::map::iterator it = result.begin(); it != result.end(); it++) { const CCoins* coins = stack.back()->AccessCoins(it->first); if (coins) { @@ -506,14 +506,14 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test) } } - if (insecure_rand() % 100 == 0) { + if (insecure_randrange(100) == 0) { // Every 100 iterations, change the cache stack. - if (stack.size() > 0 && insecure_rand() % 2 == 0) { + if (stack.size() > 0 && insecure_randrange(2) == 0) { stack.back()->Flush(); delete stack.back(); stack.pop_back(); } - if (stack.size() == 0 || (stack.size() < 4 && insecure_rand() % 2)) { + if (stack.size() == 0 || (stack.size() < 4 && insecure_randrange(2))) { CCoinsView* tip = &base; if (stack.size() > 0) { tip = stack.back(); @@ -614,7 +614,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test) unsigned int height = insecure_rand(); // 1/10 times create a coinbase - if (insecure_rand() % 10 == 0 || coinbaseids.size() < 10) { + if (insecure_randrange(10) == 0 || coinbaseids.size() < 10) { coinbaseids[tx.GetHash()] = tx.vout[0].nValue; assert(CTransaction(tx).IsCoinBase()); } @@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test) else { uint256 prevouthash; // equally likely to spend coinbase or non coinbase - std::set::iterator txIt = alltxids.lower_bound(GetRandHash()); + std::set::iterator txIt = alltxids.lower_bound(insecure_rand256()); if (txIt == alltxids.end()) { txIt = alltxids.begin(); } @@ -652,7 +652,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test) } // Once every 1000 iterations and at the end, verify the full cache. - if (insecure_rand() % 1000 == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { + if (insecure_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { for (std::map::iterator it = result.begin(); it != result.end(); it++) { const CCoins* coins = stack.back()->AccessCoins(it->first); if (coins) { @@ -663,14 +663,14 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test) } } - if (insecure_rand() % 100 == 0) { + if (insecure_randrange(100) == 0) { // Every 100 iterations, change the cache stack. - if (stack.size() > 0 && insecure_rand() % 2 == 0) { + if (stack.size() > 0 && insecure_randrange(2) == 0) { stack.back()->Flush(); delete stack.back(); stack.pop_back(); } - if (stack.size() == 0 || (stack.size() < 4 && insecure_rand() % 2)) { + if (stack.size() == 0 || (stack.size() < 4 && insecure_randrange(2))) { CCoinsView* tip = &base; if (stack.size() > 0) { tip = stack.back(); diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 79cc47617..ad2c60236 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper) path ph = temp_directory_path() / unique_path(); CDBWrapper dbw(ph, (1 << 20), true, false); char key = 'k'; - uint256 in = GetRandHash(); + uint256 in = insecure_rand256(); uint256 res; BOOST_CHECK(dbw.Write(key, in)); @@ -51,11 +51,11 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch) CDBWrapper dbw(ph, (1 << 20), true, false); char key = 'i'; - uint256 in = GetRandHash(); + uint256 in = insecure_rand256(); char key2 = 'j'; - uint256 in2 = GetRandHash(); + uint256 in2 = insecure_rand256(); char key3 = 'k'; - uint256 in3 = GetRandHash(); + uint256 in3 = insecure_rand256(); uint256 res; CDBBatch batch(dbw); @@ -87,10 +87,10 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator) // The two keys are intentionally chosen for ordering char key = 'j'; - uint256 in = GetRandHash(); + uint256 in = insecure_rand256(); BOOST_CHECK(dbw.Write(key, in)); char key2 = 'k'; - uint256 in2 = GetRandHash(); + uint256 in2 = insecure_rand256(); BOOST_CHECK(dbw.Write(key2, in2)); boost::scoped_ptr it(const_cast(&dbw)->NewIterator()); diff --git a/src/test/merkle_tests.cpp b/src/test/merkle_tests.cpp index 0acb67228..3001eb6fd 100644 --- a/src/test/merkle_tests.cpp +++ b/src/test/merkle_tests.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(merkle_test) { for (int i = 0; i < 32; i++) { // Try 32 block sizes: all sizes from 0 to 16 inclusive, and then 15 random sizes. - int ntx = (i <= 16) ? i : 17 + (insecure_rand() % 4000); + int ntx = (i <= 16) ? i : 17 + (insecure_randrange(4000)); // Try up to 3 mutations. for (int mutate = 0; mutate <= 3; mutate++) { int duplicate1 = mutate >= 1 ? 1 << ctz(ntx) : 0; // The last how many transactions to duplicate first. diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp index d6c5541ed..3175aba99 100644 --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -25,7 +25,7 @@ public: // flip one bit in one of the hashes - this should break the authentication void Damage() { unsigned int n = insecure_rand() % vHash.size(); - int bit = insecure_rand() % 256; + int bit = insecure_randrange(256); *(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7); } }; diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index 7feb42103..5137b102c 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -144,9 +144,9 @@ void GetBlockProofEquivalentTimeImpl(const Consensus::Params& params) { } for (int j = 0; j < 1000; j++) { - CBlockIndex *p1 = &blocks[GetRand(10000)]; - CBlockIndex *p2 = &blocks[GetRand(10000)]; - CBlockIndex *p3 = &blocks[GetRand(10000)]; + CBlockIndex *p1 = &blocks[insecure_randrange(10000)]; + CBlockIndex *p2 = &blocks[insecure_randrange(10000)]; + CBlockIndex *p3 = &blocks[insecure_randrange(10000)]; int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params); BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime()); diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index b3f401661..e615ab178 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -195,14 +195,14 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt) test.erase(insecure_rand() % test.size()); } if (((r >> 4) % 8) == 2) { - int new_size = std::max(0, std::min(30, test.size() + (insecure_rand() % 5) - 2)); + int new_size = std::max(0, std::min(30, test.size() + (insecure_randrange(5)) - 2)); test.resize(new_size); } if (((r >> 7) % 8) == 3) { - test.insert(insecure_rand() % (test.size() + 1), 1 + (insecure_rand() % 2), insecure_rand()); + test.insert(insecure_rand() % (test.size() + 1), 1 + (insecure_randrange(2)), insecure_rand()); } if (((r >> 10) % 8) == 4) { - int del = std::min(test.size(), 1 + (insecure_rand() % 2)); + int del = std::min(test.size(), 1 + (insecure_randrange(2))); int beg = insecure_rand() % (test.size() + 1 - del); test.erase(beg, beg + del); } @@ -214,20 +214,20 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt) } if (((r >> 21) % 32) == 7) { int values[4]; - int num = 1 + (insecure_rand() % 4); + int num = 1 + (insecure_randrange(4)); for (int i = 0; i < num; i++) { values[i] = insecure_rand(); } test.insert_range(insecure_rand() % (test.size() + 1), values, values + num); } if (((r >> 26) % 32) == 8) { - int del = std::min(test.size(), 1 + (insecure_rand() % 4)); + int del = std::min(test.size(), 1 + (insecure_randrange(4))); int beg = insecure_rand() % (test.size() + 1 - del); test.erase(beg, beg + del); } r = insecure_rand(); if (r % 32 == 9) { - test.reserve(insecure_rand() % 32); + test.reserve(insecure_randrange(32)); } if ((r >> 5) % 64 == 10) { test.shrink_to_fit(); @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt) test.clear(); } if (((r >> 21) % 512) == 12) { - test.assign(insecure_rand() % 32, insecure_rand()); + test.assign(insecure_randrange(32), insecure_rand()); } if (((r >> 15) % 64) == 3) { test.swap(); diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index dc2411ee5..8791fcacf 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -90,7 +90,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un void static RandomScript(CScript &script) { static const opcodetype oplist[] = {OP_FALSE, OP_1, OP_2, OP_3, OP_CHECKSIG, OP_IF, OP_VERIF, OP_RETURN}; script = CScript(); - int ops = (insecure_rand() % 10); + int ops = (insecure_randrange(10)); for (int i=0; i sapling_version_dist( CTransaction::SAPLING_MAX_CURRENT_VERSION); void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t consensusBranchId) { - tx.fOverwintered = insecure_rand() % 2; + tx.fOverwintered = insecure_randrange(2); if (tx.fOverwintered) { - if (insecure_rand() % 2) { + if (insecure_randrange(2)) { tx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; tx.nVersion = sapling_version_dist(rng); } else { tx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; tx.nVersion = overwinter_version_dist(rng); } - tx.nExpiryHeight = (insecure_rand() % 2) ? insecure_rand() % TX_EXPIRY_HEIGHT_THRESHOLD : 0; + tx.nExpiryHeight = (insecure_randrange(2)) ? insecure_rand() % TX_EXPIRY_HEIGHT_THRESHOLD : 0; } else { tx.nVersion = insecure_rand() & 0x7FFFFFFF; } @@ -126,33 +126,33 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co tx.vShieldedSpend.clear(); tx.vShieldedOutput.clear(); tx.vJoinSplit.clear(); - tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0; - int ins = (insecure_rand() % 4) + 1; - int outs = fSingle ? ins : (insecure_rand() % 4) + 1; - int shielded_spends = (insecure_rand() % 4) + 1; - int shielded_outs = (insecure_rand() % 4) + 1; - int joinsplits = (insecure_rand() % 4); + tx.nLockTime = (insecure_randrange(2)) ? insecure_rand() : 0; + int ins = (insecure_randrange(4)) + 1; + int outs = fSingle ? ins : (insecure_randrange(4)) + 1; + int shielded_spends = (insecure_randrange(4)) + 1; + int shielded_outs = (insecure_randrange(4)) + 1; + int joinsplits = (insecure_randrange(4)); for (int in = 0; in < ins; in++) { tx.vin.push_back(CTxIn()); CTxIn &txin = tx.vin.back(); - txin.prevout.hash = GetRandHash(); - txin.prevout.n = insecure_rand() % 4; + txin.prevout.hash = insecure_rand256(); + txin.prevout.n = insecure_randrange(4); RandomScript(txin.scriptSig); - txin.nSequence = (insecure_rand() % 2) ? insecure_rand() : (unsigned int)-1; + txin.nSequence = (insecure_randrange(2)) ? insecure_rand() : (unsigned int)-1; } for (int out = 0; out < outs; out++) { tx.vout.push_back(CTxOut()); CTxOut &txout = tx.vout.back(); - txout.nValue = insecure_rand() % 100000000; + txout.nValue = insecure_randrange(100000000); RandomScript(txout.scriptPubKey); } if (tx.nVersionGroupId == SAPLING_VERSION_GROUP_ID) { - tx.valueBalanceSapling = insecure_rand() % 100000000; + tx.valueBalanceSapling = insecure_randrange(100000000); for (int spend = 0; spend < shielded_spends; spend++) { SpendDescription sdesc; zcash_test_harness_random_jubjub_point(sdesc.cv.begin()); zcash_test_harness_random_jubjub_base(sdesc.anchor.begin()); - sdesc.nullifier = GetRandHash(); + sdesc.nullifier = insecure_rand256(); zcash_test_harness_random_jubjub_point(sdesc.rk.begin()); GetRandBytes(sdesc.zkproof.begin(), sdesc.zkproof.size()); tx.vShieldedSpend.push_back(sdesc); @@ -172,17 +172,17 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co if (tx.fOverwintered && tx.nVersion >= SAPLING_TX_VERSION) { for (int js = 0; js < joinsplits; js++) { JSDescription jsdesc; - if (insecure_rand() % 2 == 0) { - jsdesc.vpub_old = insecure_rand() % 100000000; + if (insecure_randrange(2) == 0) { + jsdesc.vpub_old = insecure_randrange(100000000); } else { - jsdesc.vpub_new = insecure_rand() % 100000000; + jsdesc.vpub_new = insecure_randrange(100000000); } - jsdesc.anchor = GetRandHash(); - jsdesc.nullifiers[0] = GetRandHash(); - jsdesc.nullifiers[1] = GetRandHash(); - jsdesc.ephemeralKey = GetRandHash(); - jsdesc.randomSeed = GetRandHash(); + jsdesc.anchor = insecure_rand256(); + jsdesc.nullifiers[0] = insecure_rand256(); + jsdesc.nullifiers[1] = insecure_rand256(); + jsdesc.ephemeralKey = insecure_rand256(); + jsdesc.randomSeed = insecure_rand256(); GetRandBytes(jsdesc.ciphertexts[0].begin(), jsdesc.ciphertexts[0].size()); GetRandBytes(jsdesc.ciphertexts[1].begin(), jsdesc.ciphertexts[1].size()); { @@ -190,8 +190,8 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co GetRandBytes(zkproof.begin(), zkproof.size()); jsdesc.proof = zkproof; } - jsdesc.macs[0] = GetRandHash(); - jsdesc.macs[1] = GetRandHash(); + jsdesc.macs[0] = insecure_rand256(); + jsdesc.macs[1] = insecure_rand256(); tx.vJoinSplit.push_back(jsdesc); } diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp index 99cf9df55..7fc690966 100644 --- a/src/test/skiplist_tests.cpp +++ b/src/test/skiplist_tests.cpp @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test) // Test 100 random starting points for locators. for (int n=0; n<100; n++) { - int r = insecure_rand() % 150000; + int r = insecure_randrange(150000); CBlockIndex* tip = (r < 100000) ? &vBlocksMain[r] : &vBlocksSide[r - 100000]; CBlockLocator locator = chain.GetLocator(tip); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 58dfc74bd..bd6d26ad8 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -110,7 +110,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha orig_current_path = fs::current_path(); ClearDatadirCache(); - pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); + pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(insecure_randrange(100000))); fs::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); pblocktree = new CBlockTreeDB(1 << 20, true); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 1cb7a12b1..551c36d42 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -310,7 +310,7 @@ void test_simple_sapling_invalidity(uint32_t consensusBranchId, CMutableTransact CValidationState state; newTx.vShieldedSpend.push_back(SpendDescription()); - newTx.vShieldedSpend[0].nullifier = GetRandHash(); + newTx.vShieldedSpend[0].nullifier = insecure_rand256(); BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state)); BOOST_CHECK(state.GetRejectReason() == "bad-txns-no-sink-of-funds"); @@ -321,7 +321,7 @@ void test_simple_sapling_invalidity(uint32_t consensusBranchId, CMutableTransact CValidationState state; newTx.vShieldedSpend.push_back(SpendDescription()); - newTx.vShieldedSpend[0].nullifier = GetRandHash(); + newTx.vShieldedSpend[0].nullifier = insecure_rand256(); newTx.vShieldedOutput.push_back(OutputDescription()); @@ -331,7 +331,7 @@ void test_simple_sapling_invalidity(uint32_t consensusBranchId, CMutableTransact BOOST_CHECK(!CheckTransactionWithoutProofVerification(newTx, state)); BOOST_CHECK(state.GetRejectReason() == "bad-spend-description-nullifiers-duplicate"); - newTx.vShieldedSpend[1].nullifier = GetRandHash(); + newTx.vShieldedSpend[1].nullifier = insecure_rand256(); BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state)); } @@ -382,8 +382,8 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa newTx.vJoinSplit.push_back(JSDescription()); JSDescription *jsdesc = &newTx.vJoinSplit[0]; - jsdesc->nullifiers[0] = GetRandHash(); - jsdesc->nullifiers[1] = GetRandHash(); + jsdesc->nullifiers[0] = insecure_rand256(); + jsdesc->nullifiers[1] = insecure_rand256(); // Fake coins being spent. std::vector allPrevOutputs; @@ -474,19 +474,19 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa newTx.vJoinSplit.push_back(JSDescription()); JSDescription *jsdesc = &newTx.vJoinSplit[0]; - jsdesc->nullifiers[0] = GetRandHash(); + jsdesc->nullifiers[0] = insecure_rand256(); jsdesc->nullifiers[1] = jsdesc->nullifiers[0]; BOOST_CHECK(!CheckTransaction(newTx, state, verifier)); BOOST_CHECK(state.GetRejectReason() == "bad-joinsplits-nullifiers-duplicate"); - jsdesc->nullifiers[1] = GetRandHash(); + jsdesc->nullifiers[1] = insecure_rand256(); newTx.vJoinSplit.push_back(JSDescription()); jsdesc = &newTx.vJoinSplit[0]; // Fixes #2026. Related PR #2078. JSDescription *jsdesc2 = &newTx.vJoinSplit[1]; - jsdesc2->nullifiers[0] = GetRandHash(); + jsdesc2->nullifiers[0] = insecure_rand256(); jsdesc2->nullifiers[1] = jsdesc->nullifiers[0]; BOOST_CHECK(!CheckTransaction(newTx, state, verifier)); @@ -499,8 +499,8 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa newTx.vJoinSplit.push_back(JSDescription()); JSDescription *jsdesc = &newTx.vJoinSplit[0]; - jsdesc->nullifiers[0] = GetRandHash(); - jsdesc->nullifiers[1] = GetRandHash(); + jsdesc->nullifiers[0] = insecure_rand256(); + jsdesc->nullifiers[1] = insecure_rand256(); newTx.vin.push_back(CTxIn(uint256(), -1));