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

未关闭 适合新手
#790 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #791 来自 @Bismithblde —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
blockchain

调研方向

从 programs/fundraiser/src/instructions/contribute.rs:67 开始,这里每位贡献者的限额发生了溢出;检查该限额如何被复用于交易和累计贡献检查。为目标值 u64::MAX / 10 + 1 和 u64::MAX 添加或运行 LiteSVM 回归测试;完成标准是恰好达到限额的贡献成功,超过限额的贡献失败,并且余额和记录的贡献额正确。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Rust
星标
1.4k
派生
562
平均合并
23 小时 5 分钟
30 天内合并 PR
19

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solana-foundation/program-examples 的其他 Issue

查看 solana-foundation/program-examples 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。