-
Notifications
You must be signed in to change notification settings - Fork 520
Update "invalid currency UTF-8" test vector #1264
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
Update "invalid currency UTF-8" test vector #1264
Conversation
|
@thomash-acinq can you review this and check what eclair does? |
|
The current test vector uses the following TLV stream: It does what it claims to do (test that the Your proposed change is which does not seem to be an improvement. |
Some applications (rust-lightning) validate currency codes by first checking for exactly 3 bytes before parsing the UTF-8 content. Since this test vector isn't 3 bytes long, those applications would reject it based on length rather than detecting the invalid UTF-8 encoding. Using a 3-byte invalid UTF-8 sequence would better test the UTF-8 validation logic specifically. I'll also remove the other fields to keep this test vector focused solely on |
|
OK, I understand the problem now. But if we really want to check that this field is a valid ISO 4217 code we should also add test vectors with symbols (US$), lowercase letters (usd) or even codes that look good but are not part of the standard (ABC). |
e09ce18 to
5d3a0d5
Compare
I have change the offer to that have this data part: |
|
@thomash-acinq @rustyrussell can you test this updated test vector? |
|
@thomash-acinq @rustyrussell ping? |
|
Eclair now supports the currency field and properly validates it. |
Replace 2-byte invalid UTF-8 test with 3-byte version, as some applications like rust-lightning only validate encoding/size with proper length encoding (03 length with 3-byte value).
5d3a0d5 to
117095c
Compare
I got a bit confused about what the spec wants to say about the ISO 4217 requirement. Does "as an ISO 4217 three-letter code" mean it should validate against the actual ISO 4217 currency list, or just follow the 3-letter ASCII uppercase format? If it's full validation against real currencies, then testing with "ABC" makes sense since it would be rejected. But if it's just format validation, then "ABC" would actually be valid and the UTF-8 test is more appropriate for catching actual format violations. The spec seems ambiguous on this point. Clarifying this would help ensure consistent behavior across implementations. |
|
For me "an ISO 4217 three-letter code" clearly means that it must be in the actual list, so "ABC" must fail, I don't find it ambiguous. That's how eclair does it. |
|
That list changes regularly (presumably), though. While I think it's reasonable to validate against, I don't think we'll bother trying to keep a list up to date. We just reject anything that isn't 3-char ASCII uppercase letters. |
|
We simply check that it's valid UTF-8 (it's part of our parsing code): If it's an unknown currency we will decode it and allow the user to fetch it (there are no requirements on the contents of this field unless "if it uses Note: we don't allow creation of such things (I had to use our external tool to make this): we can't parse "100ABC" because we don't know how many decimals. e.g. 100USD becomes 10,000 "offer_amount"; Ack 5d3a0d5 |
|
Yes it's inconvenient to have to keep the list up to date, however it's necessary to be able to understand the offer. The list is important not just to check that the currency is valid (we could just show the currency code to the end user who we can assume is already familiar with such codes) but to display the amount. If I create an offer that costs 50$ and you don't validate against the list, you will display 5000 USD instead of the correct 50.00 USD. |
|
Right, the actual user-facing logic really needs to know what the currency is (also to do conversion), we just punt that upstream rather than handling it ourselves (and it sounds like CLN does too). |
t-bast
left a comment
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.
ACK 117095c
Add test vectors from lightning/bolts#1276 and lightning/bolts#1264
Add test vectors from lightning/bolts#1276 and lightning/bolts#1264
This PR updates the "Malformed: invalid currency UTF-8" test vector to use 3 bytes of invalid UTF-8 instead of 2 bytes, since some applications like rust-lightning only validate encoding/size with proper length encoding (03 length with 3-byte value).
This commit replaces it with a test vector that: