AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
High 70 Cryptographic libraries

wallet2: fix infinite loop in estimate_tx_size_and_weight on large n_outputs

Public commit record

What the developer wrote

Authored by Masamune

78/100 · Adequate
wallet2: fix infinite loop in estimate_tx_size_and_weight on large n_outputs

estimate_rct_tx_size() and estimate_tx_weight() compute the Bulletproof padded
output count with `while ((1<<log_padded_outputs) < n_outputs)`, shifting a
signed int. For n_outputs > 2^30 this reaches `1 << 31` (signed overflow, UB),
and once the shift count exceeds the int width the value cycles and never
reaches n_outputs, so the loop never terminates. estimate_tx_size_and_weight()
accepts n_outputs up to INT_MAX (only negative is rejected), so a single
wallet-rpc call spins the handling thread forever.

Shift an unsigned 64-bit one and compare in uint64_t at all three shift sites,
and accumulate the estimated size in size_t (cast the per-input and per-output
terms) so the size arithmetic cannot overflow for large counts.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This patch fixes a bug where a single wallet command could freeze the wallet-rpc handling thread forever. The bug occurs when a user asks the wallet to estimate the size of a transaction with an extremely large number of outputs (more than about one billion). The old code used a signed integer in a loop that doubles a value until it is large enough; for very large inputs this overflows, behaves unpredictably, and never finishes, causing an infinite loop. The fix changes the calculation to use unsigned 64-bit integers, which cannot overflow in the same dangerous way, and also makes the size arithmetic safer for large counts.

Recommended action

Apply the patch. It is a minimal, targeted fix. Consider also adding an explicit upper-bound validation on n_outputs in estimate_tx_size_and_weight() and wallet-rpc endpoints to reject absurdly large values before they reach the estimator, providing defense in depth.

Security signals we found

01

Infinite loop / denial of service in wallet-rpc handling thread

02

Signed integer overflow in bit-shift loop

03

Unbounded n_outputs accepted by estimate_tx_size_and_weight

04

Size arithmetic overflow risk for large input/output counts

05

Single RPC call can freeze wallet-rpc service

Risk score

Why this scored 70/100

Our methodology →
Potential impact 18/30
Exploitability 16/25
Stealth signal 10/15
Affected reach 12/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.