helium / helium/helium-program-library

mini-fanout: total_shares sums into u32 and can overflow

Open Beginner friendly
#1,255 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
163
Forks
59
Avg merge
22h 48m
Merged PRs (30d)
55

Description

`distribute_v0` sums share weights into a `u32`:

```rust
let total_shares: u32 = share_indices
.iter()
.map(|&i| mini_fanout.shares[i].share.as_u32())
.sum();
```

`overflow-checks = true` is set for the release profile, so this panics rather than wraps once the
weights total more than `u32::MAX`. The weights are chosen by the fanout owner, so a fanout with
large enough `Share::Share` amounts cannot distribute at all: every attempt aborts.

The blast radius is that one fanout, and it is recoverable — the owner can lower the weights
through `update_mini_fanout_v0` — so this is not urgent. Widening the sum to `u128` is the fix;
`share.as_u128()` is already used a few lines below for the same value.

Worth a test that a fanout whose weights exceed `u32::MAX` still distributes, since nothing
currently exercises that range.

Raised during review of #1254 and deliberately kept out of it: that PR is a lint sweep, and this is
unrelated arithmetic in a program that moves tokens, so it deserves its own change and its own test
rather than riding an approved diff.

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the distribute_v0 entry point and inspect the total_shares calculation alongside the existing share.as_u128() use a few lines below. Add a regression test for weights exceeding u32::MAX and verify that the fanout still distributes; update_mini_fanout_v0 describes how weights can be lowered for recovery.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
blockchain
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.