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

Add bolt11 test vector with amount in p units #699

Merged
merged 2 commits into from
Mar 3, 2020

Conversation

Sword-Smith
Copy link
Contributor

@Sword-Smith Sword-Smith commented Nov 13, 2019

This addresses #692. But as part of #692 some have also requested that the RFC is changed to specify that any amount with the pico-multiplier MUST be divisible by 10. This request is addressed in PR #700 (now merged).
+
+Breakdown:
+
+* lnbc: prefix, Lightning on bitcoin mainnet
+* 9678785340p: amount (9678785340 pico-bitcoin = 967878534 milli satoshi)
+* 1: Bech32 separator
+* pwmna7l: timestamp (1572468703)
+* p: payment hash...
+* d: short description

    • 8d: data_length (8 = 7, d = 13; 7 * 32 + 13 == 237)
    • gfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khx: 'Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, "Back In My Day" Sticker x 2, "I Got Lightning Working" Sticker x 2 and 1 more items'
      +* x: expiry time
    • qy: data_length (q = 0, y = 2; 0 * 32 + 4 == 4)
    • jw5q: 604800 seconds (j = 18, w = 14, 5 = 20, q = 0; 18 * 32^3 + 14 * 32^2 + 20 * 32 + 0 == 604800)
      +* r: tagged field: route information
    • zj: data_length (z = 2, j = 18; 2 * 32 + 18 == 82)
      +* s4x9qlmd57lq7wwr23n3a6pkayy3jpfucyptlncs2maswe3dnnjy3ce2cgrvykmxlfpvn6ptqfqz4df5uaulvd4hjkckuqxrqqkz8jgp: signature
      +* hputwh: Bech32 checksum

Please send $30 for coffee beans to the same peer, which supports features 1 and 9

lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9qzsze992adudgku8p05pstl6zh7av6rx2f297pv89gu5q93a0hf3g7lynl3xq56t23dpvah6u7y9qey9lccrdml3gaqwc6nxsl5ktzm464sq73t7cl

@Sword-Smith
Copy link
Contributor Author

Sword-Smith commented Nov 13, 2019

The error reported is some sort of alleged spelling error. But both words are correctly spelled.

"Misspelled words in 11-payment-encoding.md: Blockstream USD Blockstream"

@t-bast
Copy link
Collaborator

t-bast commented Nov 14, 2019

The error reported is some sort of alleged spelling error.

You need to update the spellchecker dictionary (.aspell.en.pws) to add new unknown words (in your case USB / Blockstream).

@Sword-Smith
Copy link
Contributor Author

The error reported is some sort of alleged spelling error.

You need to update the spellchecker dictionary (.aspell.en.pws) to add new unknown words (in your case USB / Blockstream).

Commit has been updated with these additional changes.

@t-bast
Copy link
Collaborator

t-bast commented Nov 14, 2019

Thanks, I'll test this vector as soon as I have a bit of time ;)

@Sword-Smith
Copy link
Contributor Author

How's it looking with your time, @t-bast? :)

@t-bast
Copy link
Collaborator

t-bast commented Dec 2, 2019

I'm sorry, I'm really swamped right now with Trampoline work...
But I'll find a bit of time this week to test this (so that it's tested before next monday's meeting).

@t-bast
Copy link
Collaborator

t-bast commented Dec 3, 2019

Sorry for the wait, thanks for your patience!
It looks like the test vector wasn't signed with the test private key (see https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md#examples).
We make all test vectors with a reference private key (e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734) so that test suites can sign and verify that they generate the exact same invoice when using the same parameters.

@rustyrussell rustyrussell added the Meeting Discussion Raise at next meeting label Dec 5, 2019
@rustyrussell
Copy link
Collaborator

OK, I've pushed a fixup which completes the decode description (this is our only example with an embedded route!), and also reencoded it using the example privkey.

@t-bast
Copy link
Collaborator

t-bast commented Jan 31, 2020

Thanks @rustyrussell, I verified the test vector with eclair and it works fine.
cdecker mentioned adding a test vector with an invalid pico-amount (not ending with 0), why not also add that?

t-bast added a commit to ACINQ/eclair that referenced this pull request Jan 31, 2020
@rustyrussell
Copy link
Collaborator

Thanks @rustyrussell, I verified the test vector with eclair and it works fine.
cdecker mentioned adding a test vector with an invalid pico-amount (not ending with 0), why not also add that?

Good point, see #736

rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Feb 3, 2020
See-also: lightning/bolts#699
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK 1fbccd3

cdecker pushed a commit to ElementsProject/lightning that referenced this pull request Feb 5, 2020
See-also: lightning/bolts#699
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
t-bast added a commit to ACINQ/eclair that referenced this pull request Feb 10, 2020
pm47 added a commit to ACINQ/eclair that referenced this pull request Feb 10, 2020
* Ignore fields with invalid length

As per the spec:
> A reader:
>   * MUST skip over unknown fields, OR an f field with unknown version, OR p, h, s or n fields that do NOT have data_lengths of 52, 52, 52 or 53, respectively.

* Add more Bolt 11 tests

See lightning/bolts#699
and lightning/bolts#736

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
@Sword-Smith
Copy link
Contributor Author

Fixed merge conflict by rebasing and force pushing. This test vector is now presented as the last in the list of test vectors.

@t-bast
Copy link
Collaborator

t-bast commented Mar 3, 2020

@cfromknecht or @Roasbeef, do we have an ACK to merge this?

Copy link
Collaborator

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM, I added this vector to lnd and we're also passing

* `p`: payment hash.
* `p5`: `data_length` (`p` = 1, `5` = 20; 1 * 32 + 20 == 52)
* `gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0s`: payment hash 462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f
* `d`: short description
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be too late at this point, just some thoughts:

the rest of these fields seem tangential to testing pico amount? imo more minimal, targeted test cases are preferable. i see also that it was updated to test route hints as well, perhaps that should have been its own test case?

there are also a lot of constants that are defined and only used for this test, e.g. payment hash, expiry, description, etc. that could be shared with other tests since they don't seem to be exercising explicit edge cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, this test case may be covering too much. But that doesn't mean an implementation has to do all the checks if they're redundant with other tests, right? I don't mind updating this PR, but I'd rather not spend too much time on in since it's quite a trivial addition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it depends on your testing framework, lnd asserts encoding/decoding and the in-memory representation. I wouldn't explain what I just went through as trivial, but it is done now :P

Copy link
Collaborator

Choose a reason for hiding this comment

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

Allright then now that the painful code is written, let's merge this PR and let this test case live a long and happy life :D

@t-bast t-bast merged commit 85068c5 into lightning:master Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meeting Discussion Raise at next meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants