Skip to content
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

Allow uppercase bech32 HRP #3505

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Jan 6, 2025

Previously, we would fail parsing Offers if the HRP didn't match our expected (lowercase) HRP. Here, we relax this check in accordance with the spec to also allow all-uppercase HRPs.

Discovered while upgrading LDK Node to 0.1.0-beta1, as we failed to parse uppercase offers (which used to work).

Related: rust-bitcoin/rust-bech32#208

@tnull tnull requested a review from jkczyz January 6, 2025 09:46
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 6, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 6, 2025
Copy link
Contributor

@optout21 optout21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests would be useful, to make behavior more explicit (lowercase/uppercase/mixedcase).

lightning/src/offers/parse.rs Outdated Show resolved Hide resolved
@optout21
Copy link
Contributor

optout21 commented Jan 6, 2025

Note: doesn't help much, but might be related to / caused by #3270

@tnull
Copy link
Contributor Author

tnull commented Jan 6, 2025

Some tests would be useful, to make behavior more explicit (lowercase/uppercase/mixedcase).

Yup, already on it, will push in a sec :)

@tnull
Copy link
Contributor Author

tnull commented Jan 6, 2025

Now pushed some test coverage.

@tnull tnull force-pushed the 2025-01-allow-upperase-hrp branch from 273357b to c1c86f3 Compare January 6, 2025 10:44
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 6, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 6, 2025
lightning/src/offers/parse.rs Outdated Show resolved Hide resolved
lightning/src/offers/parse.rs Outdated Show resolved Hide resolved
lightning/src/offers/parse.rs Outdated Show resolved Hide resolved
@tnull tnull force-pushed the 2025-01-allow-upperase-hrp branch 3 times, most recently from 24b99a2 to afc9a56 Compare January 6, 2025 18:34
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please squash.

@tnull tnull force-pushed the 2025-01-allow-upperase-hrp branch from afc9a56 to b8dabf5 Compare January 7, 2025 08:19
@tnull
Copy link
Contributor Author

tnull commented Jan 7, 2025

LGTM. Please squash.

Squashed and included the following minor changes to align exactly with the BOLT12 test vectors:

> git diff-tree -U2 afc9a5674 b8dabf51c
diff --git a/lightning/src/offers/parse.rs b/lightning/src/offers/parse.rs
index afd79b2a8..f3c481a9f 100644
--- a/lightning/src/offers/parse.rs
+++ b/lightning/src/offers/parse.rs
@@ -252,6 +252,6 @@ mod bolt12_tests {
                        "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg",

-                       // An all-uppercase string is valid
-                       &"lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg".to_uppercase(),
+                       // Uppercase is valid
+                       "LNO1PQPS7SJQPGTYZM3QV4UXZMTSD3JJQER9WD3HY6TSW35K7MSJZFPY7NZ5YQCNYGRFDEJ82UM5WF5K2UCKYYPWA3EYT44H6TXTXQUQH7LZ5DJGE4AFGFJN7K4RGRKUAG0JSD5XVXG",

                        // + can join anywhere
@@ -292,5 +292,5 @@ mod bolt12_tests {
        fn fails_parsing_bech32_encoded_offers_with_mixed_casing() {
                // We assert that mixed-case encoding fails to parse.
-               let mixed_case_offer = "lno1pqpS7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg";
+               let mixed_case_offer = "LnO1PqPs7sJqPgTyZm3qV4UxZmTsD3JjQeR9Wd3hY6TsW35k7mSjZfPy7nZ5YqCnYgRfDeJ82uM5Wf5k2uCkYyPwA3EyT44h6tXtXqUqH7Lz5dJgE4AfGfJn7k4rGrKuAg0jSd5xVxG";
                match mixed_case_offer.parse::<Offer>() {
                        Ok(_) => panic!("Valid offer: {}", mixed_case_offer),

tnull added 2 commits January 7, 2025 11:12
Previously, we would fail parsing `Offer`s if the HRP didn't match our
expected (lowercase) HRP. Here, we relax this check in accordance with
the spec to also allow all-uppercase HRPs.
.. to ensure we're able to decode all-uppercase HRPs and reject
mixed-case encodings.
@tnull tnull force-pushed the 2025-01-allow-upperase-hrp branch from b8dabf5 to 7272969 Compare January 7, 2025 10:12
@tnull
Copy link
Contributor Author

tnull commented Jan 7, 2025

Rebased on 0.1 as Github wanted me to.

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.32%. Comparing base (afa2f9c) to head (7272969).
Report is 3 commits behind head on 0.1.

Files with missing lines Patch % Lines
lightning/src/offers/parse.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              0.1    #3505      +/-   ##
==========================================
+ Coverage   88.26%   88.32%   +0.05%     
==========================================
  Files         149      149              
  Lines      112915   112926      +11     
  Branches   112915   112926      +11     
==========================================
+ Hits        99666    99740      +74     
+ Misses      10754    10697      -57     
+ Partials     2495     2489       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tnull tnull merged commit 87e52e3 into lightningdevkit:0.1 Jan 8, 2025
17 of 19 checks passed
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 13, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 13, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 14, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 15, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 15, 2025
tnull added a commit to tnull/ldk-node that referenced this pull request Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants