Skip to content

Commit 083242a

Browse files
committed
Merge bitcoin#34725: fuzz: assert we accept any PSBT serialization we create
d76ec4d fuzz: make sure PSBT serialization roundtrips (Antoine Poinsot) Pull request description: ~~Invalid public keys were accepted in Musig2 partial signatures. Because we serialize invalid keys as the empty byte string, this would lead us to creating an invalid PSBT serializations.~~ ~~This can be checked by reverting the first commit with the fix and simply running the target against the existing qa-assets corpus for the `psbt` harness.~~ This patch found the issue fixed in bitcoin#34219 with a single run against the existing qa-assets corpus. It is useful to make sure there are no similar bugs, and we don't introduce roundtrip regressions outside of the specifc instance of accepting invalid public keys in Musig2 fields. *(Edited on March 4 to only contain the fuzz harness patch)* ACKs for top commit: davidgumberg: crACK bitcoin@d76ec4d achow101: ACK d76ec4d dergoegge: utACK d76ec4d brunoerg: code review ACK d76ec4d Tree-SHA512: ab5f8d4e6a1781ecdef825e1a0e2793a6b553f36c923a4a35cb1af4070eead9d9780f6cc9a76235aa03462e52a129d15e61f631490b43651dc4395f3f1c005f3
2 parents 4c40a92 + d76ec4d commit 083242a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/test/fuzz/psbt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ FUZZ_TARGET(psbt)
3333
}
3434
const PartiallySignedTransaction psbt = psbt_mut;
3535

36+
// A PSBT must roundtrip.
37+
PartiallySignedTransaction psbt_roundtrip;
38+
std::vector<uint8_t> psbt_ser;
39+
VectorWriter{psbt_ser, 0, psbt};
40+
SpanReader{psbt_ser} >> psbt_roundtrip;
41+
42+
// And be stable across roundtrips.
43+
std::vector<uint8_t> roundtrip_ser;
44+
VectorWriter{roundtrip_ser, 0, psbt_roundtrip};
45+
Assert(psbt_ser == roundtrip_ser);
46+
3647
const PSBTAnalysis analysis = AnalyzePSBT(psbt);
3748
(void)PSBTRoleName(analysis.next);
3849
for (const PSBTInputAnalysis& input_analysis : analysis.inputs) {

0 commit comments

Comments
 (0)