Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

common/amount: parse_amount_sat misparses sub-satoshi msat with leading zero and accepts invalid suffixes

Aperta Adatta ai principianti
#9,674 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@bhuvan-somisetty ci sta già lavorando.

Dal 28/10/2026.

  • #9675 di @bhuvan-somisetty — aperta

Valutazione

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

Direzione di ricerca

Inizia in common/amount.c da parse_amount_sat() e parse_amount_msat(), in particolare il ramo msat intorno alla riga 249 e i controlli dei suffissi che usano memstarts_str. Usa le tre asserzioni dell'issue come casi fallimentari iniziali, poi verifica che i valori sub-satoshi non nulli con zeri iniziali come 0500msat e 01msat vengano rifiutati mentre 0msat restituisce ancora zero. Fatto significa che entrambe le funzioni rifiutano suffissi finali non validi come satoshis e accettano solo suffissi di unità esatti.

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

Descrizione

Issue and Steps to Reproduce

In common/amount.c, parse_amount_sat() and parse_amount_msat() have two related parsing issues: sub-satoshi msat values formatted with leading zeroes are erroneously parsed as satoshis, and arbitrary trailing characters on amount suffixes are accepted.

1. Sub-satoshi msat values with leading zeroes are parsed as satoshis in parse_amount_sat

parse_amount_sat() parses amount strings into discrete satoshis. Per the function documentation:

/* Valid strings:
 *  [0-9]+ => satoshi.
 *  [0-9]+sat => satoshi.
 *  [0-9]+000msat => satoshi.
 *  0msat => 0 satoshi
 *  [0-9]+.[0-9]{1,8}btc => satoshi.
 */

For msat inputs that do not end in "000", line 249 of common/amount.c checks:

if (!memends(s, whole_number_len, "000", strlen("000"))) {
	if (memstarts_str(s, whole_number_len, "0"))
		return from_number(&sat->satoshis, s,
				   whole_number_len, 0);
	return false;
}

Because memstarts_str(s, whole_number_len, "0") tests if the whole-number string starts with '0', any non-zero millisatoshi amount with a leading zero and not ending in "000" (e.g. 01msat, 0500msat, 0999msat) satisfies the condition and is passed to from_number(&sat->satoshis, ...), treating the millisatoshi value directly as satoshis:

  • 01msat (1 millisatoshi) is parsed as 1 satoshi (1,000 msat) instead of being rejected.
  • 0500msat (500 millisatoshis = 0.5 sat) is parsed as 500 satoshis (500,000 msat), causing a 1,000x error.
  • 0999msat (999 millisatoshis) is parsed as 999 satoshis (999,000 msat).

Only amounts whose numerical value is genuinely zero (such as 0msat, 00msat, 000msat) should evaluate to 0 satoshis; all non-zero sub-satoshi amounts should be rejected.

2. Unchecked trailing suffix characters in parse_amount_sat and parse_amount_msat

Both functions check unit suffixes using memstarts_str(suffix_ptr, suffix_len, "sat"), memstarts_str(..., "msat"), and memstarts_str(..., "btc"). Because memstarts_str only tests for a prefix match:

  • 100satoshis is accepted and parsed as 100sat (or 100000msat in parse_amount_msat).
  • Strings such as 100sats, 100msats, or 1btcfoo are accepted rather than rejected as invalid units.
Steps to Reproduce
struct amount_sat sat;
assert(!parse_amount_sat(&sat, "0500msat", strlen("0500msat"))); /* Currently fails assertion: parses as 500 satoshis */
assert(!parse_amount_sat(&sat, "01msat", strlen("01msat")));     /* Currently fails assertion: parses as 1 satoshi */
assert(!parse_amount_sat(&sat, "100satoshis", strlen("100satoshis"))); /* Currently fails assertion: accepted */
getinfo output

N/A (core parser logic in common/amount.c)

Lingua principale
C
Stelle
3.1k
Fork
1k
Merge medio
4g 11h
PR unite (30g)
28

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 ElementsProject/lightning

Tutte le issue di ElementsProject/lightning

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.