What changed, and why it matters
This commit only adds a new unit test that checks whether a Witness object's reported byte size matches the length of its actual encoded bytes. It does not change any production code, fix any bug, or alter behavior. There is no security relevance.
No action needed; this is a routine test-coverage addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single test, size_matches_encoding_length, in primitives/src/witness.rs. It constructs empty and non-empty Witness values, pushes elements of lengths 0, 252, and 253 bytes, and asserts that Witness::size() equals the length of encoding::encode_to_vec(&witness). No implementation code is modified.
Changed components
primitives/src/witness.rs (tests only)Inspect captured patch +14 / −0
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index ca275b5f..1e84f366 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -1466,4 +1466,18 @@ mod test {
assert_eq!(&witness[0], large_element.as_slice());
assert_eq!(&witness[1], large_element.as_slice());
}
+
+ #[test]
+ fn size_matches_encoding_length() {
+ let empty = Witness::new();
+ assert_eq!(empty.size(), encoding::encode_to_vec(&empty).len());
+
+ let mut witness = Witness::new();
+ witness.push([0u8; 0]);
+ assert_eq!(witness.size(), encoding::encode_to_vec(&witness).len());
+ witness.push([0u8; 252]);
+ assert_eq!(witness.size(), encoding::encode_to_vec(&witness).len());
+ witness.push([0u8; 253]);
+ assert_eq!(witness.size(), encoding::encode_to_vec(&witness).len());
+ }
}
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.