[bug]: zpay32.Decode wraps an invoice amount that overflows uint64
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #11441 by @Reacher3745 — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 79/100
Research direction
Start with the multiplication sites in zpay32/amountunits.go at lines 30–43 and 99–105, then run the provided TestAmountWrap reproduction with go test ./zpay32 -run TestAmountWrap -v. Check that zpay32.Decode rejects an invoice when converting its amount would overflow uint64; done when the reproduction returns an error instead of a wrapped MilliSat value.
Written by the indexing model from the issue text.
Description
Pre-Submission Checklist
- I have searched the existing issues and believe this is a new bug.
- I am not asking a question about how to use lnd, but reporting a bug (otherwise open a discussion).
LND Version
master at 1a359d4aa1e5, v0.21.4-beta at 390b2d2b7bdc, and v0.20.5-beta at cfa58463aedc
LND Configuration
None. The test below runs with go test in the lnd source tree at each version above.
Backend Version
Not used. The test runs with go test only.
Backend Configuration
None.
OS/Distribution
Fedora Linux 44, x86_64, with Go 1.26.10 for master and Go 1.26.9 for the releases
Bug Details & Steps to Reproduce
zpay32.Decode accepts the invoice below and returns a MilliSat of 90,448,384 msat. Its amount, 184467440738m, is 18,446,744,073,800,000,000 msat, and 90,448,384 msat is that product modulo 2^64. The payment intent that SendPaymentV2 builds for this invoice carries 90,448,384 msat as its amount. This happens on master at 1a359d4aa1e5, v0.21.4-beta and v0.20.5-beta.
Saved as zpay32/amount_wrap_test.go on master, this test decodes the invoice, which is signed with the private key from the BOLT 11 examples:
package zpay32
import (
"testing"
"github.com/btcsuite/btcd/chaincfg/v2"
)
func TestAmountWrap(t *testing.T) {
inv, err := Decode("lnbc184467440738m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9qrsgqujcur0j9f47men4nlh79jjnav8799h55ufx3dyhec962ctkpv6u8dz9j36avrfwph0f0l562f05a769wkdkpqe3wkpre66ea5udgfqcpm5v6f3", &chaincfg.MainNetParams)
if err == nil {
t.Fatalf("expected error, got MilliSat: %v", *inv.MilliSat)
}
}
With go test ./zpay32 -run TestAmountWrap -v, the test fails:
=== RUN TestAmountWrap
amount_wrap_test.go:12: expected error, got MilliSat: 90448384 mSAT
--- FAIL: TestAmountWrap (0.00s)
zpay32 multiplies the amount by its multiplier in a uint64 without an overflow check. The products are at zpay32/amountunits.go:30-43 for m, u and n, and at zpay32/amountunits.go:99-105 when there is no multiplier.
Expected Behavior
zpay32.Decode should return an error for this invoice, because 18,446,744,073,800,000,000 msat does not fit in a uint64. BOLT 11 says at lines 83-85 that a reader "MUST multiply amount by the multiplier value to derive the amount required for payment".
Debug Information
No response
Environment
No response
- Dominant language
- Go
- Stars
- 8.2k
- Forks
- 2.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 103
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
lightningnetwork/lnd#11674 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day