rust-bitcoin / rust-bitcoin/rust-miniscript
String descriptors can panic on `to_string`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 426
- Forks
- 200
- Avg merge
- 7d 17h
- Merged PRs (30d)
- 8
Description
If you have a descriptor with String keys, and you parse one with a key outside of the checksum alphabet, desc_checksum will fail, leading to returning an error from Display::fmt, which apparently causes a panic in .to_string().
I'm not sure why we haven't seen this before but when fuzzing locally it now shows up quickly on the roundtrip_descriptor fuzztest. For example you can give it the test vector
do_test("pkh(\u{16})".as_bytes());
I'm unsure what the best plan of action here ... String descriptors aren't standardized, so I guess we can just make something up. The two ideas that come to mind are:
- Enforce, when parsing descriptors, that every character lands in the checksum alphabet (or at least, is ASCII-printable, which I think might be the same thing)
- When computing checksums, skip invalid characters or replace them with
xor something - Keep the existing behavior (though then we'd need to tweak our fuzztests somehow)
Also affects elements-miniscript.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with desc_checksum and the roundtrip_descriptor fuzztest, using the provided pkh(\u{16}) test vector to reproduce the Display::fmt failure. Compare the proposed parsing and checksum behaviors, including the impact on elements-miniscript; done means an agreed behavior no longer causes to_string() to panic and the fuzztest reflects it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100