Add `Arbitrary` feature to `p2p` crate
What changed, and why it matters
This commit adds an optional 'arbitrary' feature to the p2p crate. It is a build/test tooling change that enables fuzz testing by exposing test-only arbitrary data generation. There is no runtime behavior change, no bug fix, and no security vulnerability introduced or patched.
No security action required. Treat as a normal dependency/build configuration change. Review any follow-up commits that actually implement Arbitrary trait instances for p2p message types to ensure generated values remain valid invariants.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds an optional Cargo feature named ‘arbitrary’ to the bitcoin-p2p-messages crate. When enabled, it pulls in the arbitrary crate as a dependency and enables the same feature on the bitcoin crate. The fuzz crate’s manifest and generation script are updated to request this feature. The test_vars.sh script is updated to include ‘arbitrary’ in the no-std feature test matrix. No source code implementing Arbitrary traits is visible in this diff; it is purely feature plumbing.
Changed components
p2p/Cargo.tomlfuzz/Cargo.tomlfuzz/generate-files.shp2p/contrib/test_vars.shCargo-minimal.lockCargo-recent.lockInspect captured patch +8 / −3
diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock
index 437436fc..9d77d46b 100644
--- a/Cargo-minimal.lock
+++ b/Cargo-minimal.lock
@@ -112,6 +112,7 @@ dependencies = [
name = "bitcoin-p2p-messages"
version = "0.1.0"
dependencies = [
+ "arbitrary",
"bitcoin",
"bitcoin-internals",
"bitcoin-io 0.2.0",
diff --git a/Cargo-recent.lock b/Cargo-recent.lock
index 80aa7d8d..e14b1908 100644
--- a/Cargo-recent.lock
+++ b/Cargo-recent.lock
@@ -111,6 +111,7 @@ dependencies = [
name = "bitcoin-p2p-messages"
version = "0.1.0"
dependencies = [
+ "arbitrary",
"bitcoin",
"bitcoin-internals",
"bitcoin-io 0.2.0",
diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml
index 0255a4b3..2419bbfb 100644
--- a/fuzz/Cargo.toml
+++ b/fuzz/Cargo.toml
@@ -12,7 +12,7 @@ cargo-fuzz = true
[dependencies]
honggfuzz = { version = "0.5.56", default-features = false }
bitcoin = { path = "../bitcoin", features = [ "serde", "arbitrary" ] }
-p2p = { path = "../p2p", package = "bitcoin-p2p-messages" }
+p2p = { path = "../p2p", package = "bitcoin-p2p-messages", features = ["arbitrary"] }
arbitrary = { version = "1.4.1" }
serde = { version = "1.0.195", features = [ "derive" ] }
diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh
index c5575030..4f0db060 100755
--- a/fuzz/generate-files.sh
+++ b/fuzz/generate-files.sh
@@ -24,7 +24,7 @@ cargo-fuzz = true
[dependencies]
honggfuzz = { version = "0.5.56", default-features = false }
bitcoin = { path = "../bitcoin", features = [ "serde", "arbitrary" ] }
-p2p = { path = "../p2p", package = "bitcoin-p2p-messages" }
+p2p = { path = "../p2p", package = "bitcoin-p2p-messages", features = ["arbitrary"] }
arbitrary = { version = "1.4" }
serde = { version = "1.0.103", features = [ "derive" ] }
diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml
index ceebbee0..009673d2 100644
--- a/p2p/Cargo.toml
+++ b/p2p/Cargo.toml
@@ -15,6 +15,7 @@ exclude = ["tests", "contrib"]
[features]
default = ["std"]
std = ["hashes/std", "hex/std", "internals/std", "io/std", "units/std", "bitcoin/std"]
+arbitrary = ["dep:arbitrary", "bitcoin/arbitrary"]
[dependencies]
bitcoin = { path = "../bitcoin/", default-features = false }
@@ -24,6 +25,8 @@ internals = { package = "bitcoin-internals", path = "../internals", default-feat
io = { package = "bitcoin-io", path = "../io", default-features = false }
units = { package = "bitcoin-units", path = "../units", default-features = false }
+arbitrary = { version = "1.4", optional = true }
+
[dev-dependencies]
hex_lit = "0.1.1"
diff --git a/p2p/contrib/test_vars.sh b/p2p/contrib/test_vars.sh
index 88e2d26e..701c4c89 100644
--- a/p2p/contrib/test_vars.sh
+++ b/p2p/contrib/test_vars.sh
@@ -8,7 +8,7 @@
FEATURES_WITH_STD=""
# Test all these features without "std" enabled.
-FEATURES_WITHOUT_STD=""
+FEATURES_WITHOUT_STD="arbitrary"
# Run these examples.
EXAMPLES=""
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.