fuzz: make sure PSBT serialization roundtrips
What changed, and why it matters
This commit adds a new fuzz test to Bitcoin Core that checks whether PSBT (Partially Signed Bitcoin Transaction) data can be serialized and then deserialized back to the exact same bytes. It is a defensive test meant to catch future bugs where the software might write a PSBT format it cannot later read. The commit itself does not fix any active vulnerability; it adds a regression test.
No immediate action required. Treat as routine hardening. Monitor fuzzing results for any new roundtrip failures that could indicate latent serialization bugs.
Security signals we found
Adds fuzzing assertion for serialization roundtrip
Prevents creation of PSBT output that the same code cannot re-parse
Defensive regression test, not a runtime fix
Evidence from the diff
The change extends the existing psbt fuzz target in src/test/fuzz/psbt.cpp. After successfully deserializing fuzz input into a PartiallySignedTransaction, it now re-serializes the object, deserializes that serialization, and asserts that the second serialization is byte-for-byte identical to the first. This enforces serialization roundtrip stability and self-consistency for PSBTs.
Changed components
src/test/fuzz/psbt.cppPSBT serialization/deserialization logicInspect captured patch +11 / −0
diff --git a/src/test/fuzz/psbt.cpp b/src/test/fuzz/psbt.cpp
index a7b2490e..e0f2177a 100644
--- a/src/test/fuzz/psbt.cpp
+++ b/src/test/fuzz/psbt.cpp
@@ -33,6 +33,17 @@ FUZZ_TARGET(psbt)
}
const PartiallySignedTransaction psbt = psbt_mut;
+ // A PSBT must roundtrip.
+ PartiallySignedTransaction psbt_roundtrip;
+ std::vector<uint8_t> psbt_ser;
+ VectorWriter{psbt_ser, 0, psbt};
+ SpanReader{psbt_ser} >> psbt_roundtrip;
+
+ // And be stable across roundtrips.
+ std::vector<uint8_t> roundtrip_ser;
+ VectorWriter{roundtrip_ser, 0, psbt_roundtrip};
+ Assert(psbt_ser == roundtrip_ser);
+
const PSBTAnalysis analysis = AnalyzePSBT(psbt);
(void)PSBTRoleName(analysis.next);
for (const PSBTInputAnalysis& input_analysis : analysis.inputs) {
Why this scored 29/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.