token-fundraiser: large valid targets cause contribution-limit overflow

Aperta Adatta ai principianti
#790 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #791 di @Bismithblde — chiusa senza merge

Valutazione

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

Direzione di ricerca

Inizia da programs/fundraiser/src/instructions/contribute.rs:67, dove il limite per contributore va in overflow, e verifica come tale limite viene riutilizzata per i controlli delle transazioni e dei contributi cumulativi. Aggiungi o esegui il test di regressione LiteSVM per i valori obiettivo u64::MAX / 10 + 1 e u64::MAX; il lavoro è completato quando i contributi pari esattamente al limite vengono accettati, quelli che lo superano falliscono e i saldi e i contributi registrati sono corretti.

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

Descrizione

Problem

The Anchor fundraiser accepts u64 fundraising targets, but calculating the per-contributor 10% limit uses u64 multiplication before division. For a target greater than u64::MAX / 10, target * 10 overflows and contributions panic, even when the contribution is small and the final limit fits in u64.

Reproduction

A Rust LiteSVM integration test creates a six-decimal mint, initializes a fundraiser with a target of u64::MAX / 10 + 1, then contributes 1,000,000 base units (one token).

Initialization succeeds. The contribution fails with attempt to multiply with overflow at programs/fundraiser/src/instructions/contribute.rs:67.

The same issue affects a target of u64::MAX. The existing initialization instruction accepts both values.

Proposed fix

Calculate the percentage once in u128 and reuse it for the per-transaction and cumulative contributor limits. Compare the cumulative contribution in u128 as well. This preserves the 10% policy and integer rounding.

The regression fails against the original program and passes after the fix. It covers both targets, acceptance up to the exact cap, rejection above the cap, and resulting balances and recorded contributions. All three fundraiser integration tests pass locally.

Lingua principale
Rust
Stelle
1.4k
Fork
562
Merge medio
23h 5m
PR unite (30g)
19

Preparare l'ambiente

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 solana-foundation/program-examples

Tutte le issue di solana-foundation/program-examples

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.