Skip to content

Commit

Permalink
Merge pull request #1399 from apoelstra/2025-02--fuzz-fixes
Browse files Browse the repository at this point in the history
various bugfixes for new fuzz test vectors
  • Loading branch information
delta1 authored Feb 11, 2025
2 parents 22089ac + 363c510 commit 99c2ee7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class CDiskBlockIndex : public CBlockIndex
bool RemoveDynaFedMaskOnSerialize(bool for_read) {
if (for_read) {
bool is_dyna = nVersion < 0;
nVersion = ~CBlockHeader::DYNAFED_HF_MASK & nVersion;
nVersion = (int32_t) (~CBlockHeader::DYNAFED_HF_MASK & (uint32_t)nVersion);
return is_dyna;
} else {
return is_dynafed_block();
Expand Down
2 changes: 1 addition & 1 deletion src/node/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct CTxMemPoolModifiedEntry {
nSigOpCostWithAncestors = entry->GetSigOpCostWithAncestors();
}

int64_t GetModifiedFee() const { return iter->GetModifiedFee(); }
CAmount GetModifiedFee() const { return iter->GetModifiedFee(); }
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
uint64_t GetDiscountSizeWithAncestors() const { return discountSizeWithAncestors; }
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
Expand Down
4 changes: 4 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,10 @@ static RPCHelpMan getcompactsketch()
CDataStream ssBlock(block_bytes, SER_NETWORK, PROTOCOL_VERSION);
ssBlock >> block;

if (block.vtx.empty()) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Cannot obtain sketch of empty block.");
}

CBlockHeaderAndShortTxIDs cmpctblock(block, true);

CDataStream ssCompactBlock(SER_NETWORK, PROTOCOL_VERSION);
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/witness_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FUZZ_TARGET_INIT(witness_program, initialize_witness_program)

CScriptWitness witness;
int fuzz_control;
int flags;
unsigned flags;
ds >> fuzz_control;
ds >> witness.stack;
ds >> flags;
Expand All @@ -64,7 +64,7 @@ FUZZ_TARGET_INIT(witness_program, initialize_witness_program)

if (fuzz_control & 1) {
unsigned char hash_program[32];
CSHA256().Write(&program[0], program.size()).Finalize(hash_program);
CSHA256().Write(program.data(), program.size()).Finalize(hash_program);
CScript scriptPubKey = CScript{} << OP_0 << std::vector<unsigned char>(hash_program, hash_program + sizeof(hash_program));
witness.stack.push_back(program);

Expand Down
16 changes: 3 additions & 13 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ struct update_ancestor_state
int64_t discountSize;
};

struct update_fee_delta
{
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }

void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }

private:
int64_t feeDelta;
};

bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
{
AssertLockHeld(cs_main);
Expand Down Expand Up @@ -108,7 +98,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
discountSizeWithAncestors{GetDiscountTxSize()},
setPeginsSpent(_setPeginsSpent) {}

void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta)
{
nModFeesWithDescendants += newFeeDelta - feeDelta;
nModFeesWithAncestors += newFeeDelta - feeDelta;
Expand Down Expand Up @@ -520,7 +510,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
CAmount delta{0};
ApplyDelta(entry.GetTx().GetHash(), delta);
if (delta) {
mapTx.modify(newit, update_fee_delta(delta));
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
}

// Update cachedInnerUsage to include contained transaction's usage.
Expand Down Expand Up @@ -1027,7 +1017,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
delta += nFeeDelta;
txiter it = mapTx.find(hash);
if (it != mapTx.end()) {
mapTx.modify(it, update_fee_delta(delta));
mapTx.modify(it, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
// Now update all ancestors' modified fees with descendants
setEntries setAncestors;
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
Expand Down
8 changes: 4 additions & 4 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CTxMemPoolEntry
const unsigned int entryHeight; //!< Chain height when entering the mempool
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
const int64_t sigOpCost; //!< Total sigop cost
int64_t feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
CAmount feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
LockPoints lockPoints; //!< Track the height and time at which tx was final

// Information about descendants of this transaction that are in the
Expand Down Expand Up @@ -135,7 +135,7 @@ class CTxMemPoolEntry
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
unsigned int GetHeight() const { return entryHeight; }
int64_t GetSigOpCost() const { return sigOpCost; }
int64_t GetModifiedFee() const { return nFee + feeDelta; }
CAmount GetModifiedFee() const { return nFee + feeDelta; }
size_t DynamicMemoryUsage() const { return nUsageSize; }
const LockPoints& GetLockPoints() const { return lockPoints; }

Expand All @@ -144,8 +144,8 @@ class CTxMemPoolEntry
// Adjusts the ancestor state
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps, int64_t discountSize);
// Updates the fee delta used for mining priority score, and the
// modified fees with descendants.
void UpdateFeeDelta(int64_t feeDelta);
// modified fees with descendants/ancestors.
void UpdateFeeDelta(CAmount newFeeDelta);
// Update the LockPoints after a reorg
void UpdateLockPoints(const LockPoints& lp);

Expand Down
2 changes: 2 additions & 0 deletions test/sanitizer_suppressions/ubsan
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ implicit-integer-sign-change:primitives/confidential.cpp
implicit-integer-sign-change:primitives/confidential.h
shift-base:simplicity/sha256.c
unsigned-integer-overflow:simplicity/sha256.c
# See comment in simplicity/primitive/elements/env.c line 303
unsigned-integer-overflow:simplicity/primitive/elements/env.c

0 comments on commit 99c2ee7

Please sign in to comment.