consensus_encoding: always enable alloc for serde
What changed, and why it matters
This is a small build-configuration cleanup, not a security fix. The change makes the 'alloc' feature automatically enabled whenever the 'serde' feature is enabled, because serializing to non-human-readable formats requires allocating memory. It also removes an unnecessary 'hex' feature gate from the serde module. There is no vulnerability here.
No security action needed. Treat as a normal maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adjusts Cargo.toml so that enabling the ‘serde’ feature also enables ‘alloc’ and ‘hex’, and removes a redundant #[cfg(feature = “hex”)] guard from the serde_as_consensus module. The test file is updated to gate only on ‘serde’. This is a dependency/feature declaration correction with no behavioral or security change.
Changed components
consensus_encoding/Cargo.tomlconsensus_encoding/src/lib.rsconsensus_encoding/tests/serde.rsInspect captured patch +2 / −2
diff --git a/consensus_encoding/Cargo.toml b/consensus_encoding/Cargo.toml
index 789d2bc8..f29d0aab 100644
--- a/consensus_encoding/Cargo.toml
+++ b/consensus_encoding/Cargo.toml
@@ -18,6 +18,7 @@ exclude = ["api", "tests", "contrib"]
default = ["std"]
std = ["alloc", "internals/std", "hex?/std", "serde?/std"]
alloc = ["internals/alloc", "hex?/alloc", "serde?/alloc"]
+serde = ["alloc", "hex", "dep:serde"]
[dependencies]
internals = { package = "bitcoin-internals", path = "../internals", version = "0.5.0" }
diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs
index ef37ca74..cd8d6a36 100644
--- a/consensus_encoding/src/lib.rs
+++ b/consensus_encoding/src/lib.rs
@@ -86,7 +86,6 @@ mod decode;
mod encode;
pub mod error;
-#[cfg(feature = "hex")]
#[cfg(feature = "serde")]
pub mod serde_as_consensus;
diff --git a/consensus_encoding/tests/serde.rs b/consensus_encoding/tests/serde.rs
index 53b642ae..2da212ca 100644
--- a/consensus_encoding/tests/serde.rs
+++ b/consensus_encoding/tests/serde.rs
@@ -2,7 +2,7 @@
//! Tests for `serde_as_consensus`.
-#![cfg(all(feature = "hex", feature = "serde"))]
+#![cfg(feature = "serde")]
use bitcoin_consensus_encoding::{
ArrayDecoder, ArrayEncoder, Decode, Decoder, DecoderStatus, Encode, UnexpectedEofError,
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.