What changed, and why it matters
This is a small code-cleanup change in Bitcoin Core. It changes an internal flag that tracks whether a transaction output came from a coinbase (miner's special) transaction from an unsigned integer bitfield to a proper boolean bitfield. Call sites are updated to use true/false and a helper accessor. There is no security bug being fixed here.
No security action required. This is a routine maintainability/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit converts Coin::fCoinBase from unsigned int : 1 to bool : 1 and updates callers to use explicit boolean literals and the existing Coin::IsCoinBase() accessor. The serialization format is unchanged because a 1-bit bitfield stores the same bit pattern regardless of whether the declared type is unsigned int or bool. The change is purely semantic/refactoring.
Changed components
src/coins.hsrc/core_io.cppsrc/rpc/blockchain.cppsrc/test/coins_tests.cppsrc/test/fuzz/utxo_snapshot.cppsrc/validation.cppInspect captured patch +10 / −10
diff --git a/src/coins.h b/src/coins.h
index 4b39c0ba..e58586dd 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -37,7 +37,7 @@ public:
CTxOut out;
//! whether containing transaction was a coinbase
- unsigned int fCoinBase : 1;
+ bool fCoinBase : 1;
//! at which height this containing transaction was included in the active block chain
uint32_t nHeight : 31;
diff --git a/src/core_io.cpp b/src/core_io.cpp
index 7492e9ca..eeda1156 100644
--- a/src/core_io.cpp
+++ b/src/core_io.cpp
@@ -480,7 +480,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);
UniValue p(UniValue::VOBJ);
- p.pushKV("generated", static_cast<bool>(prev_coin.fCoinBase));
+ p.pushKV("generated", prev_coin.IsCoinBase());
p.pushKV("height", prev_coin.nHeight);
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
p.pushKV("scriptPubKey", std::move(o_script_pub_key));
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 262b6bab..9838bda6 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1222,7 +1222,7 @@ static RPCHelpMan gettxout()
UniValue o(UniValue::VOBJ);
ScriptToUniv(coin->out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
ret.pushKV("scriptPubKey", std::move(o));
- ret.pushKV("coinbase", static_cast<bool>(coin->fCoinBase));
+ ret.pushKV("coinbase", coin->IsCoinBase());
return ret;
},
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
index 8c0756d8..f56e369c 100644
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -519,7 +519,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
// Good example
Coin cc1;
SpanReader{"97f23c835800816115944e077fe7c803cfa57f29b36bf87c1d35"_hex} >> cc1;
- BOOST_CHECK_EQUAL(cc1.fCoinBase, false);
+ BOOST_CHECK_EQUAL(cc1.IsCoinBase(), false);
BOOST_CHECK_EQUAL(cc1.nHeight, 203998U);
BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000});
BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("816115944e077fe7c803cfa57f29b36bf87c1d35"_hex_u8)))));
@@ -527,7 +527,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
// Good example
Coin cc2;
SpanReader{"8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex} >> cc2;
- BOOST_CHECK_EQUAL(cc2.fCoinBase, true);
+ BOOST_CHECK_EQUAL(cc2.IsCoinBase(), true);
BOOST_CHECK_EQUAL(cc2.nHeight, 120891U);
BOOST_CHECK_EQUAL(cc2.out.nValue, 110397);
BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex_u8)))));
@@ -535,7 +535,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
// Smallest possible example
Coin cc3;
SpanReader{"000006"_hex} >> cc3;
- BOOST_CHECK_EQUAL(cc3.fCoinBase, false);
+ BOOST_CHECK_EQUAL(cc3.IsCoinBase(), false);
BOOST_CHECK_EQUAL(cc3.nHeight, 0U);
BOOST_CHECK_EQUAL(cc3.out.nValue, 0);
BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U);
@@ -871,7 +871,7 @@ Coin MakeCoin()
Coin coin;
coin.out.nValue = m_rng.rand32();
coin.nHeight = m_rng.randrange(4096);
- coin.fCoinBase = 0;
+ coin.fCoinBase = false;
return coin;
}
diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp
index 67290f7d..29089743 100644
--- a/src/test/fuzz/utxo_snapshot.cpp
+++ b/src/test/fuzz/utxo_snapshot.cpp
@@ -137,7 +137,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
outfile << coinbase->GetHash();
WriteCompactSize(outfile, 1); // number of coins for the hash
WriteCompactSize(outfile, 0); // index of coin
- outfile << Coin(coinbase->vout[0], height, /*fCoinBaseIn=*/1);
+ outfile << Coin(coinbase->vout[0], height, /*fCoinBaseIn=*/true);
height++;
}
}
@@ -149,7 +149,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
outfile << coinbase->GetHash();
WriteCompactSize(outfile, 1); // number of coins for the hash
WriteCompactSize(outfile, 999); // index of coin
- outfile << Coin{coinbase->vout[0], /*nHeightIn=*/999, /*fCoinBaseIn=*/0};
+ outfile << Coin{coinbase->vout[0], /*nHeightIn=*/999, /*fCoinBaseIn=*/false};
}
assert(outfile.fclose() == 0);
}
diff --git a/src/validation.cpp b/src/validation.cpp
index c200c3d6..01475736 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2214,7 +2214,7 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn
COutPoint out(hash, o);
Coin coin;
bool is_spent = view.SpendCoin(out, &coin);
- if (!is_spent || tx.vout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.fCoinBase) {
+ if (!is_spent || tx.vout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.IsCoinBase()) {
if (!is_bip30_exception) {
fClean = false; // transaction output mismatch
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.