Commit Graph

23 Commits

Author SHA1 Message Date
Yaacov Akiba Slama
af01571fc6 Let invoice.Encode receive a function which hashes itself the message
Modify the SignCompact function passed to invoice.Encode to receive the
message before it's hashed and hash it itself.
With this modification, the SignMessage rpc function from the signrpc
subserver can be used and an invoice can be encoded outside of lnd.
2020-07-29 21:18:24 +03:00
Conner Fromknecht
b9b66419ff
zpay32/invoice: remove unknown required fbit check from decode
This commit removes the unknown required feature bit check from the
invoice decoding logic. This allows greater utility to users of the
decodepayreq rpc since it can provide inspection of otherwise invalid
invoices. In the prior commit, this check moved into our path finding
logic, so invalid features taken from an invoice will instead cause a
failure when attempting to pay.
2020-01-08 12:25:21 -08:00
Conner Fromknecht
e745798a6e
zpay32: update spec test vectors, write features last
This commit updates the BOLT11 test vectors to use the updated versions
from the spec (with TLV bit set). This also pointed out that the
ordering was inconsistent with the spec, in that the payment secret
should be serialized before the feature vector.
2019-12-19 14:36:28 -08:00
Conner Fromknecht
840476996c
zpay32: ensure feature vector is always populated 2019-12-11 17:37:18 -08:00
Conner Fromknecht
a77e111c52
zpay32: remove unused InvoiceFeatures
Originally the feature namespaces were destined to be split, but this
has changed with the introduction of flat features.
2019-12-10 13:08:40 -08:00
Conner Fromknecht
df72097f2d
zpay32/invoice: parse payment address as type s 2019-12-05 07:59:17 -08:00
Matheus Degiovani
cf6ae06b30 zpay32: Add tests of checksum malleability
This adds tests for checksum malleability issue of bech32 strings as
used by LN invoices.
2019-11-26 17:09:35 -03:00
nsa
0f6e11c35f
zpay32: check invoice length while decoding
This commit checks that the size of the bech32 encoded invoice is not
greater than 7092 bytes, which is the maximum number of bytes that can
fit into a QR code. This mitigates a potential DoS vector where an attacker
could craft a very large bech32 invoice string containing an absurd amount
of route and/or hop hints. If sent to an application that processes
payment requests, this would allocate a burdensome amount of memory
due to the public key parsing for each route/hop hint.

For a 1.7MB payment request, this yielded about 38MB in allocations
from just parsing public keys:

```
   45.51MB  7.31% 92.07%    45.51MB  7.31%  math/big.nat.make
   25.50MB  4.09% 96.16%    25.50MB  4.09%  github.com/lightningnetwork/lnd/zpay32.bech32VerifyChecksum
       1MB  0.16% 96.32%    39.50MB  6.34%  github.com/lightningnetwork/lnd/zpay32.parseRouteHint
       1MB  0.16% 96.48%    33.50MB  5.38%  github.com/btcsuite/btcd/btcec.decompressPoint
    0.50MB  0.08% 96.56%     7.50MB  1.20%  crypto/elliptic.(*CurveParams).doubleJacobian
    0.50MB  0.08% 96.64%       38MB  6.10%  github.com/btcsuite/btcd/btcec.ParsePubKey
         0     0% 96.64%       12MB  1.93%  crypto/ecdsa.Verify
         0     0% 96.64%        8MB  1.28%  crypto/elliptic.(*CurveParams).ScalarBaseMult
         0     0% 96.64%       12MB  1.93%  crypto/elliptic.(*CurveParams).ScalarMult
```

With this change, memory usage will be far lower as decoding will exit
early with an error if the invoice is too large.
2019-09-24 06:21:27 -04:00
Conner Fromknecht
1311baf51f
zpay32: add BOLT 11 feature bits and test vectors 2019-08-27 15:51:24 -07:00
Joost Jager
2be1051fb6
zpay32: move HopHint and DefaultFinalCLTVDelta 2019-03-15 10:08:32 +01:00
Conner Fromknecht
1ded697e8d
multi: sort import paths with gofmt 2018-08-02 18:20:49 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Wilmer Paulino
ea9e609ef0
zpay32: modify an invoice's r field to allow multiple routes
Before this commit, if an invoice encoded multiple `r` fields, we would
decode them as one single route. We fix this by allowing an invoice to
store multiple routes.
2018-04-20 04:01:34 -04:00
Vadym Popov
818eab7109
#882: wrong BOLT11 prefix in regtest 2018-03-21 11:51:04 +02:00
Daniel McNally
6e5477e378 zpay32 test: litecoin decode tests
New tests are added for creating, decoding, and re-encoding
litecoin invoices for both mainnet and testnet, as well as a test
that expects an error when the active network mismatches the
invoice.
2018-02-19 10:19:24 -05:00
Nalin Bhardwaj
00dacc7bb5
zpay32: Add test for non-ASCII(UTF-8) descriptions 2018-02-10 04:24:53 +05:30
Valentine Wallace
3b4ffbca48 zpay32: add 2 tests for invalid invoice fields
Test for empty fallback address field, and separately test for invalid
routing info length (not a multiple of 51).
2018-01-27 18:45:57 -08:00
Wilmer Paulino
c09cbdc284
zpay32: add encode/decode tests for invoices with zero amount 2018-01-27 19:05:25 -05:00
Wilmer Paulino
8807fb804b
invoice: add unit tests for each parsed tagged field
This commit introduces unit tests for each parsed tagged field to cover
all possible input scenarios.
2018-01-19 12:00:51 -05:00
Wilmer Paulino
445e11db5c bolt11: handle r field fee spec change
Updates the way fees are handled for routing payments.
See lightningnetwork/lightning-rfc#317.
2018-01-04 13:23:56 +01:00
Olaoluwa Osuntokun
c54e6fc803
zpay32: add new 'c' field to payreqs for specifying final cltv delta 2017-10-22 18:36:53 -07:00
Johan T. Halseth
070eb0ec3e
zpay32: make expiry time only accessable using Expiry()
This commit renames the invoice field Expiry to expiry, and changes
the type from time.Time to time.Duration. Getting the value of the
field will now have to be done using the getter Expiry(), which
will also return the default invoice expiry (3600s) if it is not set
explicitly by the the invoice.
2017-09-27 13:17:18 +02:00
Johan T. Halseth
b645f02418
zpay32: move the BOLT-11 compatible invoice format to zpay32 namespace 2017-09-27 12:26:06 +02:00