mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
0f6e11c35f
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. |
||
---|---|---|
.. | ||
amountunits.go | ||
bech32.go | ||
hophint.go | ||
invoice_internal_test.go | ||
invoice_test.go | ||
invoice.go | ||
README.md |
zpay32
The zpay32 package implements a basic scheme for the encoding of payment
requests between two lnd
nodes within the Lightning Network. The zpay32
encoding scheme uses the
zbase32
scheme along with a checksum to encode a serialized payment request.
The payment request serialized by the package consist of: the destination's public key, the payment hash to use for the payment, and the value of payment to send.
Installation and Updating
$ go get -u github.com/lightningnetwork/lnd/zpay32