-
Notifications
You must be signed in to change notification settings - Fork 409
fix(bolt12): Add ASCII validation for offer currency field #3814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(bolt12): Add ASCII validation for offer currency field #3814
Conversation
👋 Thanks for assigning @jkczyz as a reviewer! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3814 +/- ##
==========================================
+ Coverage 89.52% 89.74% +0.21%
==========================================
Files 157 159 +2
Lines 125100 128942 +3842
Branches 125100 128942 +3842
==========================================
+ Hits 112002 115723 +3721
- Misses 10408 10518 +110
- Partials 2690 2701 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7232027
to
748747b
Compare
I took a closer look, and it seems this test vector has an invalid currency length in UTF-8 encoding, rather than being an invalid UTF-8 string itself.
data part: Looking at the data part, we observe 06 (currency type), 02 (length), and 2804 (value), which confirms that the error arises from an invalid currency length in UTF-8 encoding, not from an invalid UTF-8 sequence. I'll open a PR on Bolts to fix it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the currencies supposed to be the three-char currency specification standard? ie they should be ASCII only (and probably all-caps letter only, never numbers)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for jumping on this!
Ah, yeah either the test vector or the comment is wrong lol |
Initially, I considered just aligning it with the UTF-8 type for consistency. But yes, it makes more sense to enforce stricter validation to ensure it's valid ASCII and adheres to the expected format. |
Validate that offer_currency contains valid ASCII bytes as required by BOLT12 specification. ISO 4217 currency codes must be valid 3-letter ASCII strings, which are a subset of UTF-8.
748747b
to
91e633a
Compare
🔔 1st Reminder Hey @TheBlueMatt @jkczyz! This PR has been waiting for your review. |
After performing differential fuzzing using
bitcoinfuzz
withrust-lightning
andCore Lightning
(CLN), I noticed thatrust-lightning
does not verify whether theoffer_currency
field contains valid UTF-8.This commit adds validation to ensure that
offer_currency
contains valid UTF-8 bytes, as required by the BOLT 12 specification.