taproot-primitives: Correctly gate alloc on alloc feature
What changed, and why it matters
This is a build-system fix for a Rust crate that supports both memory-allocator and no-allocator environments. The crate was always pulling in the standard memory allocator even when a user explicitly requested a no-allocator build, which would cause compilation to fail on platforms without an allocator. The patch simply adds the correct on/off switch so the allocator is only used when the corresponding feature is enabled. There is no runtime security vulnerability or exploit here.
No security action required. Treat as a normal build-fix release; update if your project builds taproot-primitives without the alloc feature.
Security signals we found
No security signal: build configuration bug only
No unsafe code, no input parsing, no cryptographic operations changed
Compile-time failure in no-alloc configurations, not a runtime vulnerability
Evidence from the diff
In taproot-primitives/src/lib.rs, the extern crate alloc; declaration and two invocations of internals::impl_to_hex_from_lower_hex! are now gated behind #[cfg(feature = “alloc”)]. Previously these were unconditional, so a no-alloc build (–no-default-features without alloc) would still reference alloc types and macros requiring alloc, resulting in a compile-time failure. The change is purely a feature-gating correction; no cryptographic, consensus, or runtime logic is modified.
Changed components
taproot-primitives/src/lib.rsno-alloc / --no-default-features builds of taproot-primitivesInspect captured patch +3 / −0
diff --git a/taproot-primitives/src/lib.rs b/taproot-primitives/src/lib.rs
index 9375d3f5..1dc5a05d 100644
--- a/taproot-primitives/src/lib.rs
+++ b/taproot-primitives/src/lib.rs
@@ -13,6 +13,7 @@
#![allow(clippy::manual_range_contains)] // More readable than clippy's format.
#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)` instead of enforcing `format!("{x}")`
+#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
@@ -190,6 +191,7 @@ impl fmt::LowerHex for LeafVersion {
fmt::LowerHex::fmt(&self.to_consensus(), f)
}
}
+#[cfg(feature = "alloc")]
internals::impl_to_hex_from_lower_hex!(LeafVersion, |_| 2);
impl fmt::UpperHex for LeafVersion {
@@ -281,6 +283,7 @@ impl fmt::LowerHex for FutureLeafVersion {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
}
+#[cfg(feature = "alloc")]
internals::impl_to_hex_from_lower_hex!(FutureLeafVersion, |_| 2);
impl fmt::UpperHex for FutureLeafVersion {
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.