scripted-diff: Use new naming style for insecure_rand* functions

-BEGIN VERIFY SCRIPT-
sed -i 's/\<insecure_randbits(/InsecureRandBits(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_randbool(/InsecureRandBool(/g' src/test/*.cpp src/test/*.h src/gtest/*.cpp src/wallet/test/*.cpp
sed -i 's/\<insecure_randrange(/InsecureRandRange(/g' src/test/*.cpp src/test/*.h src/gtest/*.cpp src/wallet/test/*.cpp
sed -i 's/\<insecure_randbytes(/InsecureRandBytes(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_rand256(/InsecureRand256(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<insecure_rand(/InsecureRand32(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
sed -i 's/\<seed_insecure_rand(/SeedInsecureRand(/g' src/test/*.cpp src/test/*.h src/wallet/test/*.cpp
-END VERIFY SCRIPT-

(cherry picked from commit bitcoin/bitcoin@e945848582)
This commit is contained in:
Pieter Wuille 2017-06-07 12:03:17 -07:00 committed by Jack Grigg
parent 3e6b2edc74
commit 101d19fe17
19 changed files with 135 additions and 135 deletions

View File

@ -146,7 +146,7 @@ public:
return false;
}
coins = it->second;
if (coins.IsPruned() && insecure_randbool() == 0) {
if (coins.IsPruned() && InsecureRandBool() == 0) {
// Randomly return false in case of an empty entry.
return false;
}
@ -212,7 +212,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_randrange(3) == 0) {
if (it->second.coins.IsPruned() && InsecureRandRange(3) == 0) {
// Randomly delete empty entries on write.
map_.erase(it->first);
}

View File

@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
CTransaction RandomOrphan()
{
std::map<uint256, COrphanTx>::iterator it;
it = mapOrphanTransactions.lower_bound(insecure_rand256());
it = mapOrphanTransactions.lower_bound(InsecureRand256());
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 = insecure_rand256();
tx.vin[0].prevout.hash = InsecureRand256();
tx.vin[0].scriptSig << OP_1;
tx.vout.resize(1);
tx.vout[0].nValue = 1*CENT;

View File

@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none)
static std::vector<unsigned char> RandomData()
{
uint256 r = insecure_rand256();
uint256 r = InsecureRand256();
return std::vector<unsigned char>(r.begin(), r.end());
}

View File

@ -161,7 +161,7 @@ void Correct_Queue_range(std::vector<size_t> range)
FakeCheckCheckCompletion::n_calls = 0;
CCheckQueueControl<FakeCheckCheckCompletion> control(small_queue.get());
while (total) {
vChecks.resize(std::min(total, (size_t) insecure_randrange(10)));
vChecks.resize(std::min(total, (size_t) InsecureRandRange(10)));
total -= vChecks.size();
control.Add(vChecks);
}
@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random)
{
std::vector<size_t> range;
range.reserve(100000/1000);
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))))
for (size_t i = 2; i < 100000; i += std::max((size_t)1, (size_t)InsecureRandRange(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<FailingCheck> control(fail_queue.get());
size_t remaining = i;
while (remaining) {
size_t r = insecure_randrange(10);
size_t r = InsecureRandRange(10);
std::vector<FailingCheck> vChecks;
vChecks.reserve(r);
@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
{
CCheckQueueControl<UniqueCheck> control(queue.get());
while (total) {
size_t r = insecure_randrange(10);
size_t r = InsecureRandRange(10);
std::vector<UniqueCheck> 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<MemoryCheck> control(queue.get());
while (total) {
size_t r = insecure_randrange(10);
size_t r = InsecureRandRange(10);
std::vector<MemoryCheck> vChecks;
for (size_t k = 0; k < r && total; k++) {
total--;

View File

@ -143,7 +143,7 @@ public:
return false;
}
coins = it->second;
if (coins.IsPruned() && insecure_randbool() == 0) {
if (coins.IsPruned() && InsecureRandBool() == 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_randrange(3) == 0) {
if (it->second.coins.IsPruned() && InsecureRandRange(3) == 0) {
// Randomly delete empty entries on write.
map_.erase(it->first);
}
@ -275,12 +275,12 @@ public:
{
CMutableTransaction mutableTx;
sproutNullifier = insecure_rand256();
sproutNullifier = InsecureRand256();
JSDescription jsd;
jsd.nullifiers[0] = sproutNullifier;
mutableTx.vJoinSplit.emplace_back(jsd);
saplingNullifier = insecure_rand256();
saplingNullifier = InsecureRand256();
SpendDescription sd;
sd.nullifier = saplingNullifier;
mutableTx.vShieldedSpend.push_back(sd);
@ -312,8 +312,8 @@ uint256 appendRandomSproutCommitment(SproutMerkleTree &tree)
}
template<typename Tree> void AppendRandomLeaf(Tree &tree);
template<> void AppendRandomLeaf(SproutMerkleTree &tree) { tree.append(insecure_rand256()); }
template<> void AppendRandomLeaf(SaplingMerkleTree &tree) { tree.append(insecure_rand256()); }
template<> void AppendRandomLeaf(SproutMerkleTree &tree) { tree.append(InsecureRand256()); }
template<> void AppendRandomLeaf(SaplingMerkleTree &tree) { tree.append(InsecureRand256()); }
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,25 +462,25 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
std::vector<uint256> txids;
txids.resize(NUM_SIMULATION_ITERATIONS / 8);
for (unsigned int i = 0; i < txids.size(); i++) {
txids[i] = insecure_rand256();
txids[i] = InsecureRand256();
}
for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) {
// Do a random modification.
{
uint256 txid = txids[insecure_randrange(txids.size())]; // txid we're going to modify in this iteration.
uint256 txid = txids[InsecureRandRange(txids.size())]; // txid we're going to modify in this iteration.
CCoins& coins = result[txid];
CCoinsModifier entry = stack.back()->ModifyCoins(txid);
BOOST_CHECK(coins == *entry);
if (insecure_randrange(5) == 0 || coins.IsPruned()) {
if (InsecureRandRange(5) == 0 || coins.IsPruned()) {
if (coins.IsPruned()) {
added_an_entry = true;
} else {
updated_an_entry = true;
}
coins.nVersion = insecure_rand();
coins.nVersion = InsecureRand32();
coins.vout.resize(1);
coins.vout[0].nValue = insecure_rand();
coins.vout[0].nValue = InsecureRand32();
*entry = coins;
} else {
coins.Clear();
@ -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_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
if (InsecureRandRange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
for (std::map<uint256, CCoins>::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_randrange(100) == 0) {
if (InsecureRandRange(100) == 0) {
// Every 100 iterations, change the cache stack.
if (stack.size() > 0 && insecure_randbool() == 0) {
if (stack.size() > 0 && InsecureRandBool() == 0) {
stack.back()->Flush();
delete stack.back();
stack.pop_back();
}
if (stack.size() == 0 || (stack.size() < 4 && insecure_randbool())) {
if (stack.size() == 0 || (stack.size() < 4 && InsecureRandBool())) {
CCoinsView* tip = &base;
if (stack.size() > 0) {
tip = stack.back();
@ -611,10 +611,10 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
tx.vin.resize(1);
tx.vout.resize(1);
tx.vout[0].nValue = i; //Keep txs unique
unsigned int height = insecure_rand();
unsigned int height = InsecureRand32();
// 1/10 times create a coinbase
if (insecure_randrange(10) == 0 || coinbaseids.size() < 10) {
if (InsecureRandRange(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<uint256>::iterator txIt = alltxids.lower_bound(insecure_rand256());
std::set<uint256>::iterator txIt = alltxids.lower_bound(InsecureRand256());
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_randrange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
if (InsecureRandRange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) {
for (std::map<uint256, CCoins>::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_randrange(100) == 0) {
if (InsecureRandRange(100) == 0) {
// Every 100 iterations, change the cache stack.
if (stack.size() > 0 && insecure_randbool() == 0) {
if (stack.size() > 0 && InsecureRandBool() == 0) {
stack.back()->Flush();
delete stack.back();
stack.pop_back();
}
if (stack.size() == 0 || (stack.size() < 4 && insecure_randbool())) {
if (stack.size() == 0 || (stack.size() < 4 && InsecureRandBool())) {
CCoinsView* tip = &base;
if (stack.size() > 0) {
tip = stack.back();

View File

@ -36,7 +36,7 @@ void TestVector(const Hasher &h, const In &in, const Out &out) {
Hasher hasher(h);
size_t pos = 0;
while (pos < in.size()) {
size_t len = insecure_randrange((in.size() - pos + 1) / 2 + 1);
size_t len = InsecureRandRange((in.size() - pos + 1) / 2 + 1);
hasher.Write((unsigned char*)&in[pos], len);
pos += len;
if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {

View File

@ -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 = insecure_rand256();
uint256 in = InsecureRand256();
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 = insecure_rand256();
uint256 in = InsecureRand256();
char key2 = 'j';
uint256 in2 = insecure_rand256();
uint256 in2 = InsecureRand256();
char key3 = 'k';
uint256 in3 = insecure_rand256();
uint256 in3 = InsecureRand256();
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 = insecure_rand256();
uint256 in = InsecureRand256();
BOOST_CHECK(dbw.Write(key, in));
char key2 = 'k';
uint256 in2 = insecure_rand256();
uint256 in2 = InsecureRand256();
BOOST_CHECK(dbw.Write(key2, in2));
boost::scoped_ptr<CDBIterator> it(const_cast<CDBWrapper*>(&dbw)->NewIterator());

View File

@ -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_randrange(4000));
int ntx = (i <= 16) ? i : 17 + (InsecureRandRange(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.
@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(merkle_test)
// If ntx <= 16, try all branches. Otherise, try 16 random ones.
int mtx = loop;
if (ntx > 16) {
mtx = insecure_randrange(ntx);
mtx = InsecureRandRange(ntx);
}
std::vector<uint256> newBranch = BlockMerkleBranch(block, mtx);
std::vector<uint256> oldBranch = BlockGetMerkleBranch(block, merkleTree, mtx);

View File

@ -24,8 +24,8 @@ class CPartialMerkleTreeTester : public CPartialMerkleTree
public:
// flip one bit in one of the hashes - this should break the authentication
void Damage() {
unsigned int n = insecure_randrange(vHash.size());
int bit = insecure_randbits(8);
unsigned int n = InsecureRandRange(vHash.size());
int bit = InsecureRandBits(8);
*(vHash[n].begin() + (bit>>3)) ^= 1<<(bit&7);
}
};
@ -34,7 +34,7 @@ BOOST_FIXTURE_TEST_SUITE(pmt_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(pmt_test1)
{
seed_insecure_rand(false);
SeedInsecureRand(false);
static const unsigned int nTxCounts[] = {1, 4, 7, 17, 56, 100, 127, 256, 312, 513, 1000, 4095};
for (int n = 0; n < 12; n++) {
@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
std::vector<bool> vMatch(nTx, false);
std::vector<uint256> vMatchTxid1;
for (unsigned int j=0; j<nTx; j++) {
bool fInclude = insecure_randbits(att / 2) == 0;
bool fInclude = InsecureRandBits(att / 2) == 0;
vMatch[j] = fInclude;
if (fInclude)
vMatchTxid1.push_back(vTxid[j]);

View File

@ -144,9 +144,9 @@ void GetBlockProofEquivalentTimeImpl(const Consensus::Params& params) {
}
for (int j = 0; j < 1000; j++) {
CBlockIndex *p1 = &blocks[insecure_randrange(10000)];
CBlockIndex *p2 = &blocks[insecure_randrange(10000)];
CBlockIndex *p3 = &blocks[insecure_randrange(10000)];
CBlockIndex *p1 = &blocks[InsecureRandRange(10000)];
CBlockIndex *p2 = &blocks[InsecureRandRange(10000)];
CBlockIndex *p3 = &blocks[InsecureRandRange(10000)];
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params);
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());

View File

@ -176,7 +176,7 @@ public:
}
prevector_tester() {
seed_insecure_rand();
SeedInsecureRand();
rand_seed = insecure_rand_seed;
rand_cache = insecure_rand_ctx;
}
@ -187,59 +187,59 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
for (int j = 0; j < 64; j++) {
prevector_tester<8, int> test;
for (int i = 0; i < 2048; i++) {
if (insecure_randbits(2) == 0) {
test.insert(insecure_randrange(test.size() + 1), insecure_rand());
if (InsecureRandBits(2) == 0) {
test.insert(InsecureRandRange(test.size() + 1), InsecureRand32());
}
if (test.size() > 0 && insecure_randbits(2) == 1) {
test.erase(insecure_randrange(test.size()));
if (test.size() > 0 && InsecureRandBits(2) == 1) {
test.erase(InsecureRandRange(test.size()));
}
if (insecure_randbits(3) == 2) {
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (insecure_randrange(5)) - 2));
if (InsecureRandBits(3) == 2) {
int new_size = std::max<int>(0, std::min<int>(30, test.size() + (InsecureRandRange(5)) - 2));
test.resize(new_size);
}
if (insecure_randbits(3) == 3) {
test.insert(insecure_randrange(test.size() + 1), 1 + insecure_randbool(), insecure_rand());
if (InsecureRandBits(3) == 3) {
test.insert(InsecureRandRange(test.size() + 1), 1 + InsecureRandBool(), InsecureRand32());
}
if (insecure_randbits(3) == 4) {
int del = std::min<int>(test.size(), 1 + (insecure_randbool()));
int beg = insecure_randrange(test.size() + 1 - del);
if (InsecureRandBits(3) == 4) {
int del = std::min<int>(test.size(), 1 + (InsecureRandBool()));
int beg = InsecureRandRange(test.size() + 1 - del);
test.erase(beg, beg + del);
}
if (insecure_randbits(4) == 5) {
test.push_back(insecure_rand());
if (InsecureRandBits(4) == 5) {
test.push_back(InsecureRand32());
}
if (test.size() > 0 && insecure_randbits(4) == 6) {
if (test.size() > 0 && InsecureRandBits(4) == 6) {
test.pop_back();
}
if (insecure_randbits(5) == 7) {
if (InsecureRandBits(5) == 7) {
int values[4];
int num = 1 + (insecure_randbits(2));
int num = 1 + (InsecureRandBits(2));
for (int i = 0; i < num; i++) {
values[i] = insecure_rand();
values[i] = InsecureRand32();
}
test.insert_range(insecure_randrange(test.size() + 1), values, values + num);
test.insert_range(InsecureRandRange(test.size() + 1), values, values + num);
}
if (insecure_randbits(5) == 8) {
int del = std::min<int>(test.size(), 1 + (insecure_randbits(2)));
int beg = insecure_randrange(test.size() + 1 - del);
if (InsecureRandBits(5) == 8) {
int del = std::min<int>(test.size(), 1 + (InsecureRandBits(2)));
int beg = InsecureRandRange(test.size() + 1 - del);
test.erase(beg, beg + del);
}
if (insecure_randbits(5) == 9) {
test.reserve(insecure_randbits(5));
if (InsecureRandBits(5) == 9) {
test.reserve(InsecureRandBits(5));
}
if (insecure_randbits(6) == 10) {
if (InsecureRandBits(6) == 10) {
test.shrink_to_fit();
}
if (test.size() > 0) {
test.update(insecure_randrange(test.size()), insecure_rand());
test.update(InsecureRandRange(test.size()), InsecureRand32());
}
if (insecure_randbits(10) == 11) {
if (InsecureRandBits(10) == 11) {
test.clear();
}
if (insecure_randbits(9) == 12) {
test.assign(insecure_randbits(5), insecure_rand());
if (InsecureRandBits(9) == 12) {
test.assign(InsecureRandBits(5), InsecureRand32());
}
if (insecure_randbits(3) == 3) {
if (InsecureRandBits(3) == 3) {
test.swap();
}
}

View File

@ -90,9 +90,9 @@ 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_randrange(10));
int ops = (InsecureRandRange(10));
for (int i=0; i<ops; i++)
script << oplist[insecure_randrange(sizeof(oplist)/sizeof(oplist[0]))];
script << oplist[InsecureRandRange(sizeof(oplist)/sizeof(oplist[0]))];
}
// Overwinter tx version numbers are selected randomly from current version range.
@ -108,51 +108,51 @@ std::uniform_int_distribution<int> sapling_version_dist(
CTransaction::SAPLING_MAX_CURRENT_VERSION);
void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t consensusBranchId) {
tx.fOverwintered = insecure_randbool();
tx.fOverwintered = InsecureRandBool();
if (tx.fOverwintered) {
if (insecure_randbool()) {
if (InsecureRandBool()) {
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_randbool()) ? insecure_randrange(TX_EXPIRY_HEIGHT_THRESHOLD) : 0;
tx.nExpiryHeight = (InsecureRandBool()) ? InsecureRandRange(TX_EXPIRY_HEIGHT_THRESHOLD) : 0;
} else {
tx.nVersion = insecure_randbits(31);
tx.nVersion = InsecureRandBits(31);
}
tx.vin.clear();
tx.vout.clear();
tx.vShieldedSpend.clear();
tx.vShieldedOutput.clear();
tx.vJoinSplit.clear();
tx.nLockTime = (insecure_randbool()) ? insecure_rand() : 0;
int ins = (insecure_randbits(2)) + 1;
int outs = fSingle ? ins : (insecure_randbits(2)) + 1;
int shielded_spends = (insecure_randbits(2)) + 1;
int shielded_outs = (insecure_randbits(2)) + 1;
int joinsplits = (insecure_randbits(2));
tx.nLockTime = (InsecureRandBool()) ? InsecureRand32() : 0;
int ins = (InsecureRandBits(2)) + 1;
int outs = fSingle ? ins : (InsecureRandBits(2)) + 1;
int shielded_spends = (InsecureRandBits(2)) + 1;
int shielded_outs = (InsecureRandBits(2)) + 1;
int joinsplits = (InsecureRandBits(2));
for (int in = 0; in < ins; in++) {
tx.vin.push_back(CTxIn());
CTxIn &txin = tx.vin.back();
txin.prevout.hash = insecure_rand256();
txin.prevout.n = insecure_randbits(2);
txin.prevout.hash = InsecureRand256();
txin.prevout.n = InsecureRandBits(2);
RandomScript(txin.scriptSig);
txin.nSequence = (insecure_randbool()) ? insecure_rand() : (unsigned int)-1;
txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : (unsigned int)-1;
}
for (int out = 0; out < outs; out++) {
tx.vout.push_back(CTxOut());
CTxOut &txout = tx.vout.back();
txout.nValue = insecure_randrange(100000000);
txout.nValue = InsecureRandRange(100000000);
RandomScript(txout.scriptPubKey);
}
if (tx.nVersionGroupId == SAPLING_VERSION_GROUP_ID) {
tx.valueBalanceSapling = insecure_randrange(100000000);
tx.valueBalanceSapling = InsecureRandRange(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 = insecure_rand256();
sdesc.nullifier = InsecureRand256();
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_randbool() == 0) {
jsdesc.vpub_old = insecure_randrange(100000000);
if (InsecureRandBool() == 0) {
jsdesc.vpub_old = InsecureRandRange(100000000);
} else {
jsdesc.vpub_new = insecure_randrange(100000000);
jsdesc.vpub_new = InsecureRandRange(100000000);
}
jsdesc.anchor = insecure_rand256();
jsdesc.nullifiers[0] = insecure_rand256();
jsdesc.nullifiers[1] = insecure_rand256();
jsdesc.ephemeralKey = insecure_rand256();
jsdesc.randomSeed = insecure_rand256();
jsdesc.anchor = InsecureRand256();
jsdesc.nullifiers[0] = InsecureRand256();
jsdesc.nullifiers[1] = InsecureRand256();
jsdesc.ephemeralKey = InsecureRand256();
jsdesc.randomSeed = InsecureRand256();
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] = insecure_rand256();
jsdesc.macs[1] = insecure_rand256();
jsdesc.macs[0] = InsecureRand256();
jsdesc.macs[1] = InsecureRand256();
tx.vJoinSplit.push_back(jsdesc);
}
@ -217,7 +217,7 @@ BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(sighash_test)
{
uint32_t overwinterBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId;
seed_insecure_rand(false);
SeedInsecureRand(false);
#if defined(PRINT_SIGHASH_JSON)
std::cout << "[\n";
@ -229,14 +229,14 @@ BOOST_AUTO_TEST_CASE(sighash_test)
nRandomTests = 500;
#endif
for (int i=0; i<nRandomTests; i++) {
int nHashType = insecure_rand();
int nHashType = InsecureRand32();
// Exclude ZFUTURE as its branch ID can't be represented as a JSON int32
uint32_t consensusBranchId = NetworkUpgradeInfo[insecure_randrange(Consensus::MAX_NETWORK_UPGRADES - 1)].nBranchId;
uint32_t consensusBranchId = NetworkUpgradeInfo[InsecureRandRange(Consensus::MAX_NETWORK_UPGRADES - 1)].nBranchId;
CMutableTransaction txTo;
RandomTransaction(txTo, (nHashType & 0x1f) == SIGHASH_SINGLE, consensusBranchId);
CScript scriptCode;
RandomScript(scriptCode);
int nIn = insecure_randrange(txTo.vin.size());
int nIn = InsecureRandRange(txTo.vin.size());
// We don't generate v5 transactions here; we have separate ZIP 244 test vectors.
const PrecomputedTransactionData txdata(txTo, {});

View File

@ -35,8 +35,8 @@ BOOST_AUTO_TEST_CASE(skiplist_test)
}
for (int i=0; i < 1000; i++) {
int from = insecure_randrange(SKIPLIST_LENGTH - 1);
int to = insecure_randrange(from + 1);
int from = InsecureRandRange(SKIPLIST_LENGTH - 1);
int to = InsecureRandRange(from + 1);
BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]);
BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]);
@ -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_randrange(150000);
int r = InsecureRandRange(150000);
CBlockIndex* tip = (r < 100000) ? &vBlocksMain[r] : &vBlocksSide[r - 100000];
CBlockLocator locator = chain.GetLocator(tip);

View File

@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
{
// Make this test deterministic.
seed_insecure_rand(true);
SeedInsecureRand(true);
for (int rep = 0; rep < 500; ++rep) {
FILE* file = fopen("streams_test_tmp", "w+b");

View File

@ -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)(insecure_randrange(100000)));
pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000)));
fs::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string();
pblocktree = new CBlockTreeDB(1 << 20, true);

View File

@ -14,7 +14,7 @@
extern uint256 insecure_rand_seed;
extern FastRandomContext insecure_rand_ctx;
static inline void seed_insecure_rand(bool fDeterministic = false)
static inline void SeedInsecureRand(bool fDeterministic = false)
{
if (fDeterministic) {
insecure_rand_seed = uint256();
@ -24,12 +24,12 @@ static inline void seed_insecure_rand(bool fDeterministic = false)
insecure_rand_ctx = FastRandomContext(insecure_rand_seed);
}
static inline uint32_t insecure_rand() { return insecure_rand_ctx.rand32(); }
static inline uint256 insecure_rand256() { return insecure_rand_ctx.rand256(); }
static inline uint64_t insecure_randbits(int bits) { return insecure_rand_ctx.randbits(bits); }
static inline uint64_t insecure_randrange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
static inline bool insecure_randbool() { return insecure_rand_ctx.randbool(); }
static inline std::vector<unsigned char> insecure_randbytes(size_t len) { return insecure_rand_ctx.randbytes(len); }
static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); }
static inline uint256 InsecureRand256() { return insecure_rand_ctx.rand256(); }
static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.randbits(bits); }
static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); }
static inline std::vector<unsigned char> InsecureRandBytes(size_t len) { return insecure_rand_ctx.randbytes(len); }
/** Basic testing setup.
* This just configures logging and chain parameters.

View File

@ -310,7 +310,7 @@ void test_simple_sapling_invalidity(uint32_t consensusBranchId, CMutableTransact
CValidationState state;
newTx.vShieldedSpend.push_back(SpendDescription());
newTx.vShieldedSpend[0].nullifier = insecure_rand256();
newTx.vShieldedSpend[0].nullifier = InsecureRand256();
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 = insecure_rand256();
newTx.vShieldedSpend[0].nullifier = InsecureRand256();
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 = insecure_rand256();
newTx.vShieldedSpend[1].nullifier = InsecureRand256();
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] = insecure_rand256();
jsdesc->nullifiers[1] = insecure_rand256();
jsdesc->nullifiers[0] = InsecureRand256();
jsdesc->nullifiers[1] = InsecureRand256();
// Fake coins being spent.
std::vector<CTxOut> 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] = insecure_rand256();
jsdesc->nullifiers[0] = InsecureRand256();
jsdesc->nullifiers[1] = jsdesc->nullifiers[0];
BOOST_CHECK(!CheckTransaction(newTx, state, verifier));
BOOST_CHECK(state.GetRejectReason() == "bad-joinsplits-nullifiers-duplicate");
jsdesc->nullifiers[1] = insecure_rand256();
jsdesc->nullifiers[1] = InsecureRand256();
newTx.vJoinSplit.push_back(JSDescription());
jsdesc = &newTx.vJoinSplit[0]; // Fixes #2026. Related PR #2078.
JSDescription *jsdesc2 = &newTx.vJoinSplit[1];
jsdesc2->nullifiers[0] = insecure_rand256();
jsdesc2->nullifiers[0] = InsecureRand256();
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] = insecure_rand256();
jsdesc->nullifiers[1] = insecure_rand256();
jsdesc->nullifiers[0] = InsecureRand256();
jsdesc->nullifiers[1] = InsecureRand256();
newTx.vin.push_back(CTxIn(uint256(), -1));

View File

@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(util_IsHex)
BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
{
seed_insecure_rand(true);
SeedInsecureRand(true);
for (int mod=2;mod<11;mod++)
{
int mask = 1;
@ -248,7 +248,7 @@ BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
for (int i = 0; i < 10000; i++) {
uint32_t rval;
do{
rval=insecure_rand()&mask;
rval=InsecureRand32()&mask;
}while(rval>=(uint32_t)mod);
count += rval==0;
}

View File

@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(passphrase) {
std::string hash(GetRandHash().ToString());
std::vector<unsigned char> vchSalt(8);
GetRandBytes(&vchSalt[0], vchSalt.size());
uint32_t rounds = insecure_rand();
uint32_t rounds = InsecureRand32();
if (rounds > 30000)
rounds = 30000;
TestCrypter::TestPassphrase(vchSalt, SecureString(hash.begin(), hash.end()), rounds);