Skip to content

Commit 99c2ee7

Browse files
authored
Merge pull request #1399 from apoelstra/2025-02--fuzz-fixes
various bugfixes for new fuzz test vectors
2 parents 22089ac + 363c510 commit 99c2ee7

7 files changed

Lines changed: 17 additions & 21 deletions

File tree

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class CDiskBlockIndex : public CBlockIndex
469469
bool RemoveDynaFedMaskOnSerialize(bool for_read) {
470470
if (for_read) {
471471
bool is_dyna = nVersion < 0;
472-
nVersion = ~CBlockHeader::DYNAFED_HF_MASK & nVersion;
472+
nVersion = (int32_t) (~CBlockHeader::DYNAFED_HF_MASK & (uint32_t)nVersion);
473473
return is_dyna;
474474
} else {
475475
return is_dynafed_block();

src/node/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct CTxMemPoolModifiedEntry {
4646
nSigOpCostWithAncestors = entry->GetSigOpCostWithAncestors();
4747
}
4848

49-
int64_t GetModifiedFee() const { return iter->GetModifiedFee(); }
49+
CAmount GetModifiedFee() const { return iter->GetModifiedFee(); }
5050
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
5151
uint64_t GetDiscountSizeWithAncestors() const { return discountSizeWithAncestors; }
5252
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }

src/rpc/mining.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,10 @@ static RPCHelpMan getcompactsketch()
15271527
CDataStream ssBlock(block_bytes, SER_NETWORK, PROTOCOL_VERSION);
15281528
ssBlock >> block;
15291529

1530+
if (block.vtx.empty()) {
1531+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Cannot obtain sketch of empty block.");
1532+
}
1533+
15301534
CBlockHeaderAndShortTxIDs cmpctblock(block, true);
15311535

15321536
CDataStream ssCompactBlock(SER_NETWORK, PROTOCOL_VERSION);

src/test/fuzz/witness_program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ FUZZ_TARGET_INIT(witness_program, initialize_witness_program)
4545

4646
CScriptWitness witness;
4747
int fuzz_control;
48-
int flags;
48+
unsigned flags;
4949
ds >> fuzz_control;
5050
ds >> witness.stack;
5151
ds >> flags;
@@ -64,7 +64,7 @@ FUZZ_TARGET_INIT(witness_program, initialize_witness_program)
6464

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

src/txmempool.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ struct update_ancestor_state
6060
int64_t discountSize;
6161
};
6262

63-
struct update_fee_delta
64-
{
65-
explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
66-
67-
void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
68-
69-
private:
70-
int64_t feeDelta;
71-
};
72-
7363
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
7464
{
7565
AssertLockHeld(cs_main);
@@ -108,7 +98,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
10898
discountSizeWithAncestors{GetDiscountTxSize()},
10999
setPeginsSpent(_setPeginsSpent) {}
110100

111-
void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
101+
void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta)
112102
{
113103
nModFeesWithDescendants += newFeeDelta - feeDelta;
114104
nModFeesWithAncestors += newFeeDelta - feeDelta;
@@ -520,7 +510,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
520510
CAmount delta{0};
521511
ApplyDelta(entry.GetTx().GetHash(), delta);
522512
if (delta) {
523-
mapTx.modify(newit, update_fee_delta(delta));
513+
mapTx.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
524514
}
525515

526516
// Update cachedInnerUsage to include contained transaction's usage.
@@ -1027,7 +1017,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
10271017
delta += nFeeDelta;
10281018
txiter it = mapTx.find(hash);
10291019
if (it != mapTx.end()) {
1030-
mapTx.modify(it, update_fee_delta(delta));
1020+
mapTx.modify(it, [&delta](CTxMemPoolEntry& e) { e.UpdateFeeDelta(delta); });
10311021
// Now update all ancestors' modified fees with descendants
10321022
setEntries setAncestors;
10331023
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();

src/txmempool.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CTxMemPoolEntry
102102
const unsigned int entryHeight; //!< Chain height when entering the mempool
103103
const bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
104104
const int64_t sigOpCost; //!< Total sigop cost
105-
int64_t feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
105+
CAmount feeDelta{0}; //!< Used for determining the priority of the transaction for mining in a block
106106
LockPoints lockPoints; //!< Track the height and time at which tx was final
107107

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

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

test/sanitizer_suppressions/ubsan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ implicit-integer-sign-change:primitives/confidential.cpp
8181
implicit-integer-sign-change:primitives/confidential.h
8282
shift-base:simplicity/sha256.c
8383
unsigned-integer-overflow:simplicity/sha256.c
84+
# See comment in simplicity/primitive/elements/env.c line 303
85+
unsigned-integer-overflow:simplicity/primitive/elements/env.c

0 commit comments

Comments
 (0)