refactor: Use std::span in HasValidProofOfWork
What changed, and why it matters
This is a minor code cleanup that changes how a function accepts a list of block headers. It switches from requiring a specific container type (std::vector) to accepting any contiguous view (std::span), and updates the loop style. There is no change to security logic, no bug fix, and no behavior change visible to users or attackers.
No security action needed. Treat as ordinary refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors HasValidProofOfWork to take std::span
Changed components
src/validation.cppsrc/validation.hInspect captured patch +5 / −5
diff --git a/src/validation.cpp b/src/validation.cpp
index ecc51745..99f516cc 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4130,10 +4130,10 @@ std::vector<unsigned char> ChainstateManager::GenerateCoinbaseCommitment(CBlock&
return commitment;
}
-bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams)
+bool HasValidProofOfWork(std::span<const CBlockHeader> headers, const Consensus::Params& consensusParams)
{
- return std::all_of(headers.cbegin(), headers.cend(),
- [&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);});
+ return std::ranges::all_of(headers,
+ [&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams); });
}
bool IsBlockMutated(const CBlock& block, bool check_witness_root)
diff --git a/src/validation.h b/src/validation.h
index 291c1021..daf954c8 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -410,8 +410,8 @@ BlockValidationState TestBlockValidity(
bool check_pow,
bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
-/** Check with the proof of work on each blockheader matches the value in nBits */
-bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams);
+/** Check that the proof of work on each blockheader matches the value in nBits */
+bool HasValidProofOfWork(std::span<const CBlockHeader> headers, const Consensus::Params& consensusParams);
/** Check if a block has been mutated (with respect to its merkle root and witness commitments). */
bool IsBlockMutated(const CBlock& block, bool check_witness_root);
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.