Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#9,674 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@bhuvan-somisetty がすでに取り組んでいます。

2026年10月28日 から。

  • #9675 @bhuvan-somisetty による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
backend

調査の方向性

common/amount.c の parse_amount_sat() と parse_amount_msat() から始め、特に 249 行目付近の msat 分岐と memstarts_str を使った接尾辞チェックに注目してください。issue の 3 つのアサーションを最初の失敗ケースとして使い、次に 0500msat や 01msat のような先頭にゼロがある非ゼロの sub-satoshi 値が拒否され、0msat は引き続きゼロを返すことを確認してください。完了とは、両方の関数が satoshis のような無効な末尾接尾辞を拒否し、正確な単位接尾辞のみを受け入れることです。

索引モデルが issue の本文から書いたものです。

説明

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)

主要言語
C
スター
3.1k
フォーク
1k
平均マージ
4日 13時間
マージ済み PR(30日)
32

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ElementsProject/lightning のほかの issue

ElementsProject/lightning の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。