diff --git a/src/bench/bls.cpp b/src/bench/bls.cpp index 4e4cf76bda47..15deecc1a47c 100644 --- a/src/bench/bls.cpp +++ b/src/bench/bls.cpp @@ -327,10 +327,10 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench) blsWorker.Start(llmq::DEFAULT_WORKER_COUNT); // Benchmark. + size_t i = 0; bench.minEpochIterations(bench.output() ? 1000 : 1).run([&] { if (futures.size() < 100) { while (futures.size() < 10000) { - size_t i = 0; auto f = blsWorker.AsyncVerifySig(sigs[i], pubKeys[i], msgHashes[i], cancelCond); futures.emplace_back(i, std::move(f)); i = (i + 1) % pubKeys.size(); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index a8290fd5cd7e..a5c587f2c92b 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -308,6 +308,9 @@ static RPCHelpMan masternode_winners() if (!request.params[0].isNull()) { nCount = request.params[0].getInt(); + if (nCount < 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); + } } if (!request.params[1].isNull()) { diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index 7d16a4618d62..f837cf248d99 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -1340,7 +1340,9 @@ static RPCHelpMan verifyislock() } } - CHECK_NONFATAL(pBlockIndex != nullptr); + if (pBlockIndex == nullptr) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + } CBLSSignature sig; const bool use_bls_legacy{!DeploymentActiveAfter(pBlockIndex, chainman.GetConsensus(), Consensus::DEPLOYMENT_V19)}; diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index c8a8de622f1c..047b2e29721d 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -41,6 +42,9 @@ namespace { struct RPCFuzzTestingSetup : public TestingSetup { RPCFuzzTestingSetup(const ChainType chain_type, const std::vector& extra_args) : TestingSetup{chain_type, extra_args} { + m_node.govman = std::make_unique(m_args.GetDataDirNet(), *m_node.mn_metaman, + *m_node.chainman, *m_node.sbman, *m_node.dmnman, + *m_node.mn_sync, /*collateral=*/nullptr); } void CallRPC(const std::string& rpc_method, const std::vector& arguments) @@ -49,7 +53,15 @@ struct RPCFuzzTestingSetup : public TestingSetup { request.context = m_node; request.strMethod = rpc_method; try { - request.params = RPCConvertValues(rpc_method, arguments); + const auto subcommand_pos = rpc_method.find(' '); + if (subcommand_pos == std::string::npos) { + request.params = RPCConvertValues(rpc_method, arguments); + } else { + request.strMethod = rpc_method.substr(0, subcommand_pos); + std::vector subcommand_arguments{rpc_method.substr(subcommand_pos + 1)}; + subcommand_arguments.insert(subcommand_arguments.end(), arguments.begin(), arguments.end()); + request.params = RPCConvertValues(request.strMethod, subcommand_arguments); + } } catch (const std::runtime_error&) { return; } @@ -72,25 +84,42 @@ const std::vector RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{ "addconnection", // avoid DNS lookups "addnode", // avoid DNS lookups "addpeeraddress", // avoid DNS lookups + "debug", // changes global log categories "dumptxoutset", // avoid writing to disk "dumpwallet", // avoid writing to disk "enumeratesigners", "echoipc", // avoid assertion failure (Assertion `"EnsureAnyNodeContext(request.context).init" && check' failed.) + "evodb repair", // avoid repairing/rewriting EvoDB state "generatetoaddress", // avoid prohibitively slow execution (when `num_blocks` is large) "generatetodescriptor", // avoid prohibitively slow execution (when `nblocks` is large) "gettxoutproof", // avoid prohibitively slow execution + "gobject", // may dispatch to gobject submit + "gobject submit", // changes governance state "importmempool", // avoid reading from disk "importwallet", // avoid reading from disk "loadwallet", // avoid reading from disk + "masternode", // may dispatch to masternode connect + "masternode connect", // avoid network activity / DNS lookups + "mnauth", // changes peer authentication state + "mnsync", // changes masternode sync state + "quorum", // may dispatch to quorum dkgsimerror + "quorum dkgsimerror", // changes global DKG error rates "savemempool", // disabled as a precautionary measure: may take a file path argument in the future "setban", // avoid DNS lookups + "sporkupdate", // changes spork state "stop", // avoid shutdown state + "submitchainlock", // changes ChainLock state + "voteraw", // changes governance votes }; // RPC commands which are safe for fuzzing. const std::vector RPC_COMMANDS_SAFE_FOR_FUZZING{ "analyzepsbt", + "bls", + "bls fromsecret", + "bls generate", "clearbanned", + "cleardiscouraged", "combinepsbt", "combinerawtransaction", "converttopsbt", @@ -107,33 +136,49 @@ const std::vector RPC_COMMANDS_SAFE_FOR_FUZZING{ "echojson", "estimaterawfee", "estimatesmartfee", + "evodb verify", "finalizepsbt", "generate", "generateblock", "getaddednodeinfo", + "getaddressbalance", + "getaddressdeltas", + "getaddressmempool", + "getaddresstxids", + "getaddressutxos", "getaddrmaninfo", + "getassetunlockstatuses", "getbestblockhash", + "getbestchainlock", "getblock", "getblockchaininfo", "getblockcount", "getblockfilter", + "getblockfrompeer", "getblockhash", + "getblockhashes", "getblockheader", + "getblockheaders", "getblockstats", "getblocktemplate", + "getchainlockbyheight", "getchaintips", "getchaintxstats", + "getcoinjoininfo", "getconnectioncount", + "getcreditpoolinfo", "getdeploymentinfo", "getdescriptorinfo", "getdifficulty", + "getgovernanceinfo", "getindexinfo", + "getislocks", "getmemoryinfo", "getmempoolancestors", "getmempooldescendants", "getmempoolentry", - "gettxspendingprevout", "getmempoolinfo", + "getmerkleblocks", "getmininginfo", "getnettotals", "getnetworkhashps", @@ -141,23 +186,62 @@ const std::vector RPC_COMMANDS_SAFE_FOR_FUZZING{ "getnodeaddresses", "getpeerinfo", "getprioritisedtransactions", + "getquorumproofchain", "getrawaddrman", "getrawmempool", "getrawtransaction", + "getrawtransactionmulti", "getrpcinfo", + "getspecialtxes", + "getspentinfo", + "getsuperblockbudget", + "gettxchainlocks", "gettxout", "gettxoutsetinfo", "gettxspendingprevout", + "gobject check", + "gobject count", + "gobject deserialize", + "gobject diff", + "gobject get", + "gobject getcurrentvotes", + "gobject list", "help", "invalidateblock", "joinpsbts", "listbanned", "logging", + "masternode count", + "masternode list", + "masternode payments", + "masternode status", + "masternode winners", + "masternodelist", "mockscheduler", "ping", "preciousblock", "prioritisetransaction", + "protx", + "protx diff", + "protx info", + "protx list", + "protx listdiff", "pruneblockchain", + "quorum dkginfo", + "quorum dkgstatus", + "quorum getdata", + "quorum getrecsig", + "quorum hasrecsig", + "quorum info", + "quorum isconflicting", + "quorum list", + "quorum listextended", + "quorum memberof", + "quorum platformsign", + "quorum rotationinfo", + "quorum selectquorum", + "quorum sign", + "quorum verify", "reconsiderblock", "scanblocks", "scantxoutset", @@ -168,6 +252,7 @@ const std::vector RPC_COMMANDS_SAFE_FOR_FUZZING{ "setnetworkactive", "signmessagewithprivkey", "signrawtransactionwithkey", + "spork", "submitblock", "submitheader", "submitpackage", @@ -177,7 +262,10 @@ const std::vector RPC_COMMANDS_SAFE_FOR_FUZZING{ "utxoupdatepsbt", "validateaddress", "verifychain", + "verifychainlock", + "verifyislock", "verifymessage", + "verifyquorumproofchain", "verifytxoutproof", "waitforblock", "waitforblockheight", diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 176318a4a212..0bf6a31b6497 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -147,7 +147,7 @@ FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool) outpoints_rbf = outpoints_supply; // The sum of the values of all spendable outpoints - constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN}; + constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 500 * COIN}; SetMempoolConstraints(*node.args, fuzzed_data_provider); CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)}; @@ -166,8 +166,8 @@ FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool) LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300) { { - // Total supply is all outpoints - CAmount supply_now{0}; + // Total supply is the mempool fee + all outpoints + CAmount supply_now{WITH_LOCK(tx_pool.cs, return tx_pool.GetTotalFee())}; for (const auto& op : outpoints_supply) { supply_now += GetAmount(op); } diff --git a/test/functional/feature_llmq_evo.py b/test/functional/feature_llmq_evo.py index aa63a63478da..c417d4266acd 100755 --- a/test/functional/feature_llmq_evo.py +++ b/test/functional/feature_llmq_evo.py @@ -20,7 +20,7 @@ MasternodeInfo, ) from test_framework.util import ( - assert_equal, assert_greater_than_or_equal, + assert_equal, assert_greater_than_or_equal, assert_raises_rpc_error, ) @@ -180,6 +180,7 @@ def test_masternode_count(self, expected_mns_count, expected_evo_count): assert_equal(detailed_count['evo']['total'], expected_evo_count) def test_masternode_winners(self, mn_rr_active=False): + assert_raises_rpc_error(-8, "Negative count", self.nodes[0].masternode, 'winners', -1) # ignore recent winners, test future ones only # we get up to 21 entries here: tip + up to 20 future payees winners = self.nodes[0].masternode('winners', 0) diff --git a/test/functional/rpc_verifyislock.py b/test/functional/rpc_verifyislock.py index efdb3d73f9d1..2e65a8bdf7fd 100755 --- a/test/functional/rpc_verifyislock.py +++ b/test/functional/rpc_verifyislock.py @@ -52,6 +52,8 @@ def run_test(self): assert node.verifyislock(request_id, txid, rec_sig) # Not mined, should use maxHeight assert not node.verifyislock(request_id, txid, rec_sig, 1) + for height in (-2, node.getblockcount() + 1): + assert_raises_rpc_error(-8, "Block height out of range", node.verifyislock, request_id, txid, rec_sig, height) self.generate(node, 1, sync_fun=self.no_op) assert txid not in node.getrawmempool() # Mined but at higher height, should use maxHeight