taproot-primitives: Fix hex width specifier
What changed, and why it matters
This commit fixes a tiny formatting bug in how a future Taproot leaf version number is printed as text. When using the alternate display mode (which adds '0x'), the width specifier was set to 2 instead of 4, so a value like 0xAB would print as '0xAB' (correct) but a value like 0x0B would print as '0x0B' (still correct because the '#' flag already accounts for '0x'). Actually, with Rust's {:#02x} for a u8, the minimum width is 2 for the whole output including '0x', so single-hex-digit values print as '0x1' rather than '0x01'. The fix ensures consistent two-digit hex output. This is a display-string correctness issue, not a memory safety or cryptographic bug, and has no direct security impact.
No security action required. Treat as a normal code-quality/formatting fix. If auditing, verify that no downstream code parses this alternate display string as a canonical representation.
Security signals we found
No security signals present: change is a formatting width correction in a Display trait
No unsafe code, no input parsing, no cryptographic operations modified
No memory, arithmetic, or consensus logic changes
Evidence from the diff
In taproot-primitives/src/lib.rs, the Display implementation for LeafVersion used format string {:#02x} for a u8 alternate hex representation. The ‘#’ flag prepends ‘0x’, consuming two characters, so the width of 2 only guarantees a total width of 2, leading to single-digit values being printed without a leading zero (e.g., ‘0x1’ instead of ‘0x01’). Changing to {:#04x} ensures the full output is at least 4 characters wide, producing ‘0x01’. This affects only the human-readable alternate display of future leaf versions and does not alter serialization, consensus logic, or cryptographic operations.
Changed components
taproot-primitives/src/lib.rsLeafVersion Display implementation alternate formatting pathInspect captured patch +1 / −1
diff --git a/taproot-primitives/src/lib.rs b/taproot-primitives/src/lib.rs
index e07992d6..37f9e5f5 100644
--- a/taproot-primitives/src/lib.rs
+++ b/taproot-primitives/src/lib.rs
@@ -165,7 +165,7 @@ impl fmt::Display for LeafVersion {
match (self, f.alternate()) {
(Self::TapScript, true) => f.write_str("tapscript"),
(Self::TapScript, false) => fmt::Display::fmt(&TAPROOT_LEAF_TAPSCRIPT, f),
- (Self::Future(version), true) => write!(f, "future_script_{:#02x}", version.0),
+ (Self::Future(version), true) => write!(f, "future_script_{:#04x}", version.0),
(Self::Future(version), false) => fmt::Display::fmt(version, f),
}
}
Why this scored 17/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.