Remove .clone() call in check_witness_commitment
What changed, and why it matters
This is a minor code cleanup that removes an unnecessary copy of the first transaction in a Bitcoin block validation routine. It does not change behavior, fix a bug, or address any security issue.
No security action needed. Treat as a normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit replaces self.transactions[0].clone() with &self.transactions[0] in Block::check_witness_commitment. The coinbase transaction is only used by reference (passed to witness_commitment_from_coinbase and its fields read), so the clone was redundant. The function signature of witness_commitment_from_coinbase already accepts a reference, so no API change is needed. This is a pure performance/maintainability improvement with no semantic or security impact.
Changed components
primitives/src/block.rsBlock::check_witness_commitmentInspect captured patch +2 / −2
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index d3c49484..725d37d1 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -192,8 +192,8 @@ impl Block<Unchecked> {
}
if self.transactions[0].is_coinbase() {
- let coinbase = self.transactions[0].clone();
- if let Some(commitment) = witness_commitment_from_coinbase(&coinbase) {
+ let coinbase = &self.transactions[0];
+ if let Some(commitment) = witness_commitment_from_coinbase(coinbase) {
// Witness reserved value is in coinbase input witness.
let witness_vec: Vec<_> = coinbase.inputs[0].witness.iter().collect();
if witness_vec.len() == 1 && witness_vec[0].len() == 32 {
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.