Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with the main repo #15

Merged
merged 14 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/script/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ enum : uint32_t {

// Making unknown public key versions (in BIP 342 scripts) non-standard
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20),

// Constants to point to the highest flag in use. Add new flags above this line.
//
SCRIPT_VERIFY_END_MARKER
};

bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
Expand Down
3 changes: 2 additions & 1 deletion src/test/fuzz/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
BanMan ban_man_read{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ 0};
banmap_t banmap_read;
ban_man_read.GetBanned(banmap_read);
assert(banmap == banmap_read);
// Temporarily disabled to allow the remainder of the fuzz test to run while a fix is being worked on:
// assert(banmap == banmap_read);
}
}
fs::remove(banlist_file.string() + ".dat");
Expand Down
6 changes: 5 additions & 1 deletion src/test/fuzz/prevector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ class prevector_tester

FUZZ_TARGET(prevector)
{
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
// inputs.
int limit_max_ops{3000};

FuzzedDataProvider prov(buffer.data(), buffer.size());
prevector_tester<8, int> test;

while (prov.remaining_bytes()) {
while (--limit_max_ops >= 0 && prov.remaining_bytes()) {
switch (prov.ConsumeIntegralInRange<int>(0, 13 + 3 * (test.size() > 0))) {
case 0:
test.insert(prov.ConsumeIntegralInRange<size_t>(0, test.size()), prov.ConsumeIntegral<int>());
Expand Down
17 changes: 9 additions & 8 deletions src/test/fuzz/rolling_bloom_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

FUZZ_TARGET(rolling_bloom_filter)
{
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
// inputs.
int limit_max_ops{3000};

FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());

CRollingBloomFilter rolling_bloom_filter{
fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, 1000),
0.999 / fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, std::numeric_limits<unsigned int>::max())};
while (fuzzed_data_provider.remaining_bytes() > 0) {
while (--limit_max_ops >= 0 && fuzzed_data_provider.remaining_bytes() > 0) {
CallOneOf(
fuzzed_data_provider,
[&] {
Expand All @@ -32,13 +36,10 @@ FUZZ_TARGET(rolling_bloom_filter)
assert(present);
},
[&] {
const std::optional<uint256> u256 = ConsumeDeserializable<uint256>(fuzzed_data_provider);
if (!u256) {
return;
}
(void)rolling_bloom_filter.contains(*u256);
rolling_bloom_filter.insert(*u256);
const bool present = rolling_bloom_filter.contains(*u256);
const uint256 u256{ConsumeUInt256(fuzzed_data_provider)};
(void)rolling_bloom_filter.contains(u256);
rolling_bloom_filter.insert(u256);
const bool present = rolling_bloom_filter.contains(u256);
assert(present);
},
[&] {
Expand Down
12 changes: 10 additions & 2 deletions src/test/fuzz/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chain

FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
{
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
// inputs.
int limit_max_ops{300};

FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
const auto& node = g_setup->m_node;
auto& chainstate = node.chainman->ActiveChainstate();
Expand Down Expand Up @@ -142,7 +146,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
return c.out.nValue;
};

while (fuzzed_data_provider.ConsumeBool()) {
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
{
// Total supply is the mempool fee + all outpoints
CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())};
Expand Down Expand Up @@ -285,6 +289,10 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)

FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
{
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
// inputs.
int limit_max_ops{300};

FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
const auto& node = g_setup->m_node;
auto& chainstate = node.chainman->ActiveChainstate();
Expand All @@ -305,7 +313,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
CTxMemPool tx_pool_{/* estimator */ nullptr, /* check_ratio */ 1};
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);

while (fuzzed_data_provider.ConsumeBool()) {
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);

if (fuzzed_data_provider.ConsumeBool()) {
Expand Down
11 changes: 8 additions & 3 deletions src/test/txvalidationcache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache, CCoinsViewCache& active_coins_tip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
PrecomputedTransactionData txdata;
// If we add many more flags, this loop can get too expensive, but we can
// rewrite in the future to randomly pick a set of flags to evaluate.
for (uint32_t test_flags=0; test_flags < (1U << 16); test_flags += 1) {

FastRandomContext insecure_rand(true);

for (int count = 0; count < 10000; ++count) {
TxValidationState state;

// Randomly selects flag combinations
uint32_t test_flags = (uint32_t) insecure_rand.randrange((SCRIPT_VERIFY_END_MARKER - 1) << 1);

// Filter out incompatible flag choices
if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) {
// CLEANSTACK requires P2SH and WITNESS, see VerifyScript() in
Expand Down
6 changes: 5 additions & 1 deletion test/get_previous_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def download_binary(tag, args) -> int:
tarballHash = hasher.hexdigest()

if tarballHash not in SHA256_SUMS or SHA256_SUMS[tarballHash] != tarball:
print("Checksum did not match")
if tarball in SHA256_SUMS.values():
print("Checksum did not match")
return 1

print("Checksum for given version doesn't exist")
return 1
print("Checksum matched")

Expand Down