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

Abierto Apto para principiantes
#790 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #791 de @Bismithblde — cerrado sin fusionar

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
blockchain

Línea de trabajo

Empieza por programs/fundraiser/src/instructions/contribute.rs:67, donde se desborda el límite por contribuyente, e inspecciona cómo se reutiliza ese límite para las comprobaciones de transacciones y de contribuciones acumuladas. Añade o ejecuta la prueba de regresión de LiteSVM para los objetivos u64::MAX / 10 + 1 y u64::MAX; se considera terminado cuando las contribuciones que alcanzan exactamente el límite se aceptan, las que lo superan fallan y los saldos y las contribuciones registradas son correctos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
1.4k
Forks
562
Merge medio
23 h 5 min
PR fusionados (30 d)
19

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de solana-foundation/program-examples

Todos los issues de solana-foundation/program-examples

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.