Improve witness commitment validation test
What changed, and why it matters
This commit only adds an extra test case to an existing unit test. It does not change any production code, so it cannot introduce or fix a security vulnerability by itself. The new assertion checks that a block with an invalid witness commitment is rejected by the validation function, which is a normal correctness test rather than a security patch.
No security action needed. Treat as routine test improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies primitives/src/block.rs to enhance the witness commitment validation test. It computes a proper merkle root for the dummy header and adds an assertion that block.validate() returns InvalidBlockError::InvalidWitnessCommitment. No production logic is altered; this is purely test coverage improvement.
Changed components
primitives/src/block.rs (test code only)Inspect captured patch +7 / −3
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index ff516a8d..5bae25c2 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -1445,8 +1445,12 @@ mod tests {
}],
};
- let block = Block::new_unchecked(dummy_header(), vec![tx1, tx2]);
- let result = block.check_witness_commitment();
- assert_eq!(result, (false, None));
+ let mut header = dummy_header();
+ let transactions = vec![tx1, tx2];
+ header.merkle_root = compute_merkle_root(&transactions).unwrap();
+
+ let block = Block::new_unchecked(header, transactions);
+ assert_eq!(block.check_witness_commitment(), (false, None));
+ assert!(matches!(block.validate(), Err(InvalidBlockError::InvalidWitnessCommitment)));
}
}
Why this scored 12/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.