[bug]: zpay32.Decode wraps an invoice amount that overflows uint64

Aperta Adatta ai principianti
#11,415 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #11441 di @Reacher3745 — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, payments

Direzione di ricerca

Inizia dai punti di moltiplicazione in zpay32/amountunits.go alle righe 30–43 e 99–105, poi esegui la riproduzione fornita TestAmountWrap con go test ./zpay32 -run TestAmountWrap -v. Verifica che zpay32.Decode rifiuti una fattura quando la conversione del suo importo causerebbe un overflow di uint64; il lavoro è concluso quando la riproduzione restituisce un errore invece di un valore MilliSat con overflow.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug needs triage
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

Lingua principale
Go
Stelle
8.2k
Fork
2.3k
Merge medio
1g 11h
PR unite (30g)
103

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lightningnetwork/lnd

Tutte le issue di lightningnetwork/lnd

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.