Partial Distribution of yield will fail if the totalEfficentive supply increases.
The yield distribution function recalculates the total effective supply on every batch call, so if new tokens are minted between batches the per-holder share grows and the contract's balance is too small to pay the later batch. This makes the distribution revert and dilutes the rewards for holders in later batches.
Plume Network
Originally disclosed on Immunefi
51899 sc medium partial distribution of yield will fail if the totalefficentive supply increases
- Submitted on: Aug 6th 2025 at 14:06:14 UTC by @TeamJosh for Attackathon | Plume Network
- Report ID: #51899
- Report Type: Smart Contract
- Report severity: Medium
- Target: https://github.com/immunefi-team/attackathon-plume-network/blob/main/arc/src/ArcToken.sol
- Impacts:
- Temporary freezing of funds for at least 24 hours
- Smart contract unable to operate due to lack of token funds
Description
Brief/Intro
When distributing yields, the total effective supply is used to determine the share that each person gets based on their balance. This supply is calculated every time distributeYieldWithLimit is called. The total effective supply increases when more tokens are minted, and since the Arc token is mintable, there is a chance that this will occur.
Vulnerability Details
Assuming that there are 10 holders, all holding 100 tokens each.
The admin distributes 100 yield to the first 5 token holders; they will each get 10 yield tokens. The next step will be to distribute the remaining 50 tokens to the remaining 5 token holders. This will work perfectly on a normal day; however, if the token total supply increases before the second batch is distributed, then the distribution will fail due to insufficient balance in the contract, and the remaining reward per holder will be diluted.
Relevant snippet:
function distributeYieldWithLimit(//@audit users can frontrun to earn twice
uint256 totalAmount,
uint256 startIndex,
uint256 maxHolders
)
external
onlyRole(YIELD_DISTRIBUTOR_ROLE)
nonReentrant
returns (uint256 nextIndex, uint256 totalHolders, uint256 amountDistributed)
{
ArcTokenStorage storage $ = _getArcTokenStorage();
address yieldTokenAddr = $.yieldToken;
if (yieldTokenAddr == address(0)) {
revert YieldTokenNotSet();
}
if (totalAmount == 0) {
revert ZeroAmount();
}
uint256 supply = totalSupply();
if (supply == 0) {
revert NoTokensInCirculation();
}
totalHolders = $.holders.length();
if (totalHolders == 0) {
return (0, 0, 0);
}
if (startIndex >= totalHolders) {
startIndex = 0;
}
uint256 endIndex = startIndex + maxHolders;
if (endIndex > totalHolders) {
endIndex = totalHolders;
}
uint256 batchSize = endIndex - startIndex;
if (batchSize == 0) {
return (0, totalHolders, 0);
}
uint256 effectiveTotalSupply = 0;
for (uint256 i = 0; i < totalHolders; i++) {
address holder = $.holders.at(i);
if (_isYieldAllowed(holder)) {
effectiveTotalSupply += balanceOf(holder);
}
}
if (effectiveTotalSupply == 0) {
nextIndex = endIndex < totalHolders ? endIndex : 0;
return (nextIndex, totalHolders, 0);
}
ERC20Upgradeable yToken = ERC20Upgradeable(yieldTokenAddr);
amountDistributed = 0;
if (startIndex == 0) {
yToken.safeTransferFrom(msg.sender, address(this), totalAmount);
console.log("Total Amount: ", totalAmount);
}
for (uint256 i = 0; i < batchSize; i++) {
uint256 holderIndex = startIndex + i;
address holder = $.holders.at(holderIndex);
if (!_isYieldAllowed(holder)) {
continue;
}
uint256 holderBalance = balanceOf(holder);
if (holderBalance > 0) {
@-> uint256 share = (totalAmount * holderBalance) / effectiveTotalSupply;
if (share > 0) {
yToken.safeTransfer(holder, share);
amountDistributed += share;
}
}
}
nextIndex = endIndex < totalHolders ? endIndex : 0;
//console.log("Amount Distributed: ", amountDistributed);
if (nextIndex == 0) {
emit YieldDistributed(totalAmount, yieldTokenAddr);
}
return (nextIndex, totalHolders, amountDistributed);
}
Note: The Arc token admin/minter can be anyone, including a smart contract that controls the minting of tokens; they are not necessarily protocol admins.
Impact Details
- Rewards will be temporarily stuck as the
distributeYieldWithLimitfunction will fail on subsequent batches. - Rewards for subsequent batches will be diluted.
References
Proof of Concept
<details> <summary>PoC test (click to expand)</summary>Add the following test to the test/ArcToken.t.sol file.
function test_POC2() public {
for (uint160 i = 2; i <= 10; i++) {
token.transfer(address(i), 100e18); // Transfer 0.1 ARC to each address
}
// Approve and distribute yield
yieldToken.approve(address(token), YIELD_AMOUNT);
token.distributeYieldWithLimit(YIELD_AMOUNT, 0, 5);
// Mint to address 6
token.mint(address(6), 100e18);
token.distributeYieldWithLimit(YIELD_AMOUNT, 5, 10);
}
Output:
Encountered 1 failing test in test/ArcToken.t.sol:ArcTokenTest
[FAIL: ERC20InsufficientBalance(0xc7183455a4C133Ae270771860664b6B7ec320bB1, 45454545454545454549 [4.545e19], 90909090909090909090 [9.09e19])] test_POC2() (gas: 1192212)
Context
The target is ArcToken.sol, an upgradeable ERC20 token in the Plume Network attackathon repository. The token has a yield distribution feature: a holder with the YIELD_DISTRIBUTOR_ROLE can push a yield token to holders in proportion to their balance. Because the holder set can be large, distribution is batched through distributeYieldWithLimit(totalAmount, startIndex, maxHolders), which walks a slice of the holders array and returns nextIndex, totalHolders and amountDistributed so the caller can continue from where the previous call stopped.
The share each holder receives is computed against an effective total supply: the sum of balanceOf(holder) over every holder for which _isYieldAllowed(holder) is true. That sum is recomputed from scratch on every call, not fixed when the distribution round begins.
Setup
The report does not describe a deployment, a fork or a live network. The proof of concept is a Foundry test added to the existing test/ArcToken.t.sol file, using the test contract's token (the Arc token) and yieldToken instances and the YIELD_AMOUNT constant already defined there. The precondition is simply that the token is mintable and that the minter is not necessarily a protocol admin: the report notes that the Arc token admin/minter can be anyone, including a smart contract that controls minting.
Finding it
The researcher's starting observation is that the effective supply is recalculated on every distributeYieldWithLimit call, while a single logical distribution is spread over several calls. If the total supply grows between two batches, the denominator used for the later batch is larger than the one used for the earlier batch, even though the same totalAmount is being split.
The concrete scenario in the report: ten holders, each holding 100 tokens. The admin distributes 100 yield to the first five holders, who each receive 10 yield tokens. The remaining 50 tokens are then distributed to the remaining five holders. On a normal day this works. If the total supply increases before the second batch, the second distribution fails with an insufficient balance in the contract, and the remaining reward per holder is diluted.
The relevant code, as quoted in the report:
function distributeYieldWithLimit(//@audit users can frontrun to earn twice
uint256 totalAmount,
uint256 startIndex,
uint256 maxHolders
)
external
onlyRole(YIELD_DISTRIBUTOR_ROLE)
nonReentrant
returns (uint256 nextIndex, uint256 totalHolders, uint256 amountDistributed)
{
ArcTokenStorage storage $ = _getArcTokenStorage();
address yieldTokenAddr = $.yieldToken;
if (yieldTokenAddr == address(0)) {
revert YieldTokenNotSet();
}
if (totalAmount == 0) {
revert ZeroAmount();
}
uint256 supply = totalSupply();
if (supply == 0) {
revert NoTokensInCirculation();
}
totalHolders = $.holders.length();
if (totalHolders == 0) {
return (0, 0, 0);
}
if (startIndex >= totalHolders) {
startIndex = 0;
}
uint256 endIndex = startIndex + maxHolders;
if (endIndex > totalHolders) {
endIndex = totalHolders;
}
uint256 batchSize = endIndex - startIndex;
if (batchSize == 0) {
return (0, totalHolders, 0);
}
uint256 effectiveTotalSupply = 0;
for (uint256 i = 0; i < totalHolders; i++) {
address holder = $.holders.at(i);
if (_isYieldAllowed(holder)) {
effectiveTotalSupply += balanceOf(holder);
}
}
if (effectiveTotalSupply == 0) {
nextIndex = endIndex < totalHolders ? endIndex : 0;
return (nextIndex, totalHolders, 0);
}
ERC20Upgradeable yToken = ERC20Upgradeable(yieldTokenAddr);
amountDistributed = 0;
if (startIndex == 0) {
yToken.safeTransferFrom(msg.sender, address(this), totalAmount);
console.log("Total Amount: ", totalAmount);
}
for (uint256 i = 0; i < batchSize; i++) {
uint256 holderIndex = startIndex + i;
address holder = $.holders.at(holderIndex);
if (!_isYieldAllowed(holder)) {
continue;
}
uint256 holderBalance = balanceOf(holder);
if (holderBalance > 0) {
@-> uint256 share = (totalAmount * holderBalance) / effectiveTotalSupply;
if (share > 0) {
yToken.safeTransfer(holder, share);
amountDistributed += share;
}
}
}
nextIndex = endIndex < totalHolders ? endIndex : 0;
//console.log("Amount Distributed: ", amountDistributed);
if (nextIndex == 0) {
emit YieldDistributed(totalAmount, yieldTokenAddr);
}
return (nextIndex, totalHolders, amountDistributed);
}
Two details of this function matter for the bug. First, the yield tokens are pulled from the caller only when startIndex == 0, so the contract holds exactly totalAmount for the whole round. Second, the per-holder share is (totalAmount * holderBalance) / effectiveTotalSupply, where totalAmount is the full round amount on every batch, not the amount still undistributed.
Exploitation
Step 1: seed ten holders
The PoC transfers 100e18 tokens to each of the addresses 2 through 10, giving nine funded holders alongside the test contract.
function test_POC2() public {
for (uint160 i = 2; i <= 10; i++) {
token.transfer(address(i), 100e18); // Transfer 0.1 ARC to each address
}
Step 2: approve and run the first batch
The test approves the token contract to spend YIELD_AMOUNT of the yield token, then distributes to the first five holders.
// Approve and distribute yield
yieldToken.approve(address(token), YIELD_AMOUNT);
token.distributeYieldWithLimit(YIELD_AMOUNT, 0, 5);
Because startIndex is 0, this call pulls YIELD_AMOUNT from the caller into the token contract and pays out the first batch, each recipient getting YIELD_AMOUNT * balance / effectiveTotalSupply.
Step 3: increase the supply between batches
Before the second batch, the test mints 100e18 tokens to address 6.
// Mint to address 6
token.mint(address(6), 100e18);
This raises the effective total supply used by the next call, since address 6 is a yield-allowed holder whose balance has grown.
Step 4: run the second batch
The second call continues from index 5.
token.distributeYieldWithLimit(YIELD_AMOUNT, 5, 10);
}
Because startIndex is not 0, no further yield tokens are pulled in. The contract still holds only what is left after the first batch, but the shares are now computed against the larger effective supply, and the call reverts.
Result
The test fails with an insufficient balance error from the yield token transfer:
Encountered 1 failing test in test/ArcToken.t.sol:ArcTokenTest
[FAIL: ERC20InsufficientBalance([redacted], 45454545454545454549 [4.545e19], 90909090909090909090 [9.09e19])] test_POC2() (gas: 1192212)
The contract tried to transfer more yield tokens than it held, so the batch reverted.
Root cause
The denominator effectiveTotalSupply is recomputed on every call from the current balances of all yield-allowed holders, while the numerator totalAmount is the full amount of the round and the contract's yield balance is fixed after the first batch. Any increase in the effective supply between batches changes the shares for the later batches relative to the earlier ones. The report frames this as dilution: the remaining reward per holder shrinks, and the contract can end up trying to pay out more than it holds, which reverts the batch.
The existing guards do not cover this. nonReentrant and onlyRole(YIELD_DISTRIBUTOR_ROLE) restrict who can call and prevent reentrancy, but neither pins the denominator for the duration of a round. The supply == 0 check only rejects an empty token. Nothing snapshots the effective supply at startIndex == 0 for reuse in later batches.
Impact
The report lists two impacts:
- Rewards are temporarily stuck, because
distributeYieldWithLimitfails on subsequent batches once the supply has grown. - Rewards for subsequent batches are diluted.
The report also lists, among the impact categories, that the smart contract is unable to operate due to lack of token funds. The trigger is an increase in the effective supply between batches, which the report says is possible because the Arc token is mintable and the minter can be anyone, including a contract, and is not necessarily a protocol admin. The report rates the issue Medium and describes the freezing as temporary.
Fix
The report does not describe a fix or a change that was made. The direction implied by the analysis is to stop recomputing the denominator mid-round: snapshot the effective total supply when the round starts (the startIndex == 0 call) and use that same value for every subsequent batch, so that shares stay consistent with the amount pulled in at the start.
Variants to test
- Batched distribution functions in other mintable tokens: look for a denominator recomputed per call while the numerator is the full round amount. A positive result is a second batch that reverts or pays a different per-holder share after a mint or transfer between batches.
- Rounds where the supply changes through transfers rather than mints: if the effective supply depends on which holders are yield-allowed, a transfer into or out of an allowed holder changes the denominator just as a mint does. A positive result is the same revert or dilution without any mint.
- Distributions that pull funds only on the first batch: check whether the contract's balance is sufficient for the recomputed shares. A positive result is an
ERC20InsufficientBalancerevert on a later batch. - Holder-set changes between batches: if the holders array can grow, the loop over
totalHoldersand thestartIndex/endIndexarithmetic may skip or double-count holders. A positive result is a holder receiving a share twice or not at all across a full round.
Hunting notes
This kind of bug hides in paginated or batched accounting: any function that takes a startIndex/maxHolders pair and recomputes a global denominator on each call is worth reading closely. The signals during review are a totalAmount used unchanged in every batch, a safeTransferFrom guarded by startIndex == 0, and a supply figure derived from live balances rather than stored state. The report showed impact with a minimal Foundry test that seeds holders, runs one batch, mints, runs the next batch, and lets the revert speak for itself; the failing trace with the exact ERC20InsufficientBalance amounts is what makes the dilution and the stuck funds concrete.
What happened, in plain words
A token called ArcToken has a feature that pays out "yield" (a reward) to the people who hold the token. The reward is shared out in proportion to how many tokens each person holds. Because there can be many holders, the payout is done in batches: one call pays the first group, the next call pays the next group, and so on.
The amount each holder gets is worked out with a fraction. The top of the fraction is the total reward for the whole round. The bottom of the fraction is the "effective total supply": the sum of the balances of all holders who are allowed to receive yield. The problem is that this bottom number is recalculated from scratch on every batch, using whatever the balances are at that moment. If somebody mints new tokens between two batches, the bottom number grows. The top number stays the same, and the contract's own stock of reward tokens stays the same too, because the reward tokens are only pulled in on the very first batch.
The result is that later batches try to pay out shares that are too big for the tokens the contract actually holds. The transfer fails, the batch reverts, and the rewards for those holders are stuck. The report rates this Medium and describes the freezing as temporary.
To follow the rest of this article you only need a few ideas, explained as we go.
Background concepts, from zero
Smart contract. A program that lives on a blockchain. Once deployed it runs the same way for everyone, and anyone can call its functions by sending a transaction. Think of a vending machine bolted to the wall: the rules are fixed in the machine, not in a shop assistant.
Token. A smart contract that keeps a table of who owns how many units. An ERC20 token is the most common standard for this table. Sending a token means the contract moves a number from one row of the table to another.
Mintable token. A token whose table can gain new rows or bigger numbers: new units can be created. The report notes that the Arc token is mintable, and that whoever is allowed to mint (the admin or minter) can be anyone, including another smart contract, and is not necessarily a protocol admin.
Yield. A reward paid to holders, here in a separate "yield token". The ArcToken contract holds a stock of that yield token and hands it out.
Role. Many contracts have named permissions. YIELD_DISTRIBUTOR_ROLE is the permission needed to start a yield distribution. Only an address holding that role can call the distribution function.
Batching. Paying thousands of holders in one transaction would be too expensive or too large. So the work is split: each call handles a slice of the holder list, identified by a starting position (startIndex) and a maximum number of holders to process (maxHolders). The function returns where to continue next time.
Revert. When a smart contract decides an operation is not allowed, it cancels the whole transaction and undoes any changes. All the gas spent is lost. A revert is the blockchain equivalent of a shop assistant refusing the sale and putting everything back on the shelf.
Denominator and numerator. In a fraction, the numerator is the number on top and the denominator is the number on the bottom. Here the numerator is the reward amount and the denominator is the effective total supply. If the denominator changes between two halves of the same calculation, the two halves no longer add up.
Dilution. Each person's slice gets smaller because the same pot is divided among more units. If you split a pizza among ten people and then four more arrive, everyone's slice shrinks.
Context
The target is ArcToken.sol, an upgradeable ERC20 token in the Plume Network attackathon repository. "Upgradeable" means the contract's logic can be replaced later while its stored data stays put, a bit like swapping the engine in a car without changing the chassis.
The token has a yield distribution feature: a holder with the YIELD_DISTRIBUTOR_ROLE can push a yield token to holders in proportion to their balance. Because the holder set can be large, distribution is batched through distributeYieldWithLimit(totalAmount, startIndex, maxHolders), which walks a slice of the holders array and returns nextIndex, totalHolders and amountDistributed so the caller can continue from where the previous call stopped.
The share each holder receives is computed against an effective total supply: the sum of balanceOf(holder) over every holder for which _isYieldAllowed(holder) is true. That sum is recomputed from scratch on every call, not fixed when the distribution round begins.
Setup
The report does not describe a deployment, a fork or a live network. The proof of concept is a Foundry test added to the existing test/ArcToken.t.sol file. Foundry is a toolkit for writing and running tests against smart contracts on your own machine, without touching a real blockchain. The test uses the test contract's token (the Arc token) and yieldToken instances and the YIELD_AMOUNT constant already defined there.
The precondition is simply that the token is mintable and that the minter is not necessarily a protocol admin: the report notes that the Arc token admin/minter can be anyone, including a smart contract that controls minting.
Finding it
The researcher's starting observation is that the effective supply is recalculated on every distributeYieldWithLimit call, while a single logical distribution is spread over several calls. If the total supply grows between two batches, the denominator used for the later batch is larger than the one used for the earlier batch, even though the same totalAmount is being split.
The concrete scenario in the report: ten holders, each holding 100 tokens. The admin distributes 100 yield to the first five holders, who each receive 10 yield tokens. The remaining 50 tokens are then distributed to the remaining five holders. On a normal day this works. If the total supply increases before the second batch, the second distribution fails with an insufficient balance in the contract, and the remaining reward per holder is diluted.
The relevant code, as quoted in the report:
function distributeYieldWithLimit(//@audit users can frontrun to earn twice
uint256 totalAmount,
uint256 startIndex,
uint256 maxHolders
)
external
onlyRole(YIELD_DISTRIBUTOR_ROLE)
nonReentrant
returns (uint256 nextIndex, uint256 totalHolders, uint256 amountDistributed)
{
ArcTokenStorage storage $ = _getArcTokenStorage();
address yieldTokenAddr = $.yieldToken;
if (yieldTokenAddr == address(0)) {
revert YieldTokenNotSet();
}
if (totalAmount == 0) {
revert ZeroAmount();
}
uint256 supply = totalSupply();
if (supply == 0) {
revert NoTokensInCirculation();
}
totalHolders = $.holders.length();
if (totalHolders == 0) {
return (0, 0, 0);
}
if (startIndex >= totalHolders) {
startIndex = 0;
}
uint256 endIndex = startIndex + maxHolders;
if (endIndex > totalHolders) {
endIndex = totalHolders;
}
uint256 batchSize = endIndex - startIndex;
if (batchSize == 0) {
return (0, totalHolders, 0);
}
uint256 effectiveTotalSupply = 0;
for (uint256 i = 0; i < totalHolders; i++) {
address holder = $.holders.at(i);
if (_isYieldAllowed(holder)) {
effectiveTotalSupply += balanceOf(holder);
}
}
if (effectiveTotalSupply == 0) {
nextIndex = endIndex < totalHolders ? endIndex : 0;
return (nextIndex, totalHolders, 0);
}
ERC20Upgradeable yToken = ERC20Upgradeable(yieldTokenAddr);
amountDistributed = 0;
if (startIndex == 0) {
yToken.safeTransferFrom(msg.sender, address(this), totalAmount);
console.log("Total Amount: ", totalAmount);
}
for (uint256 i = 0; i < batchSize; i++) {
uint256 holderIndex = startIndex + i;
address holder = $.holders.at(holderIndex);
if (!_isYieldAllowed(holder)) {
continue;
}
uint256 holderBalance = balanceOf(holder);
if (holderBalance > 0) {
@-> uint256 share = (totalAmount * holderBalance) / effectiveTotalSupply;
if (share > 0) {
yToken.safeTransfer(holder, share);
amountDistributed += share;
}
}
}
nextIndex = endIndex < totalHolders ? endIndex : 0;
//console.log("Amount Distributed: ", amountDistributed);
if (nextIndex == 0) {
emit YieldDistributed(totalAmount, yieldTokenAddr);
}
return (nextIndex, totalHolders, amountDistributed);
}
Line by line, in plain words:
function distributeYieldWithLimit(...)declares the payout function. It takes the reward amount for the whole round, the position in the holder list to start from, and how many holders this call may process.externalmeans it can be called from outside the contract.onlyRole(YIELD_DISTRIBUTOR_ROLE)is the permission check: only an address with the distributor role gets past this line.nonReentrantblocks a known attack where a contract calls back into this function while it is still running.returns (...)says the function hands back three numbers: where to continue, how many holders exist, and how much was paid out.ArcTokenStorage storage $ = _getArcTokenStorage();fetches the contract's stored data. The$is just a variable name.address yieldTokenAddr = $.yieldToken;reads which token is used as the reward token.if (yieldTokenAddr == address(0)) { revert YieldTokenNotSet(); }stops if no reward token has been configured.address(0)is the empty address, the blockchain's way of saying "nothing set".if (totalAmount == 0) { revert ZeroAmount(); }refuses a payout of zero.uint256 supply = totalSupply(); if (supply == 0) { revert NoTokensInCirculation(); }refuses to run if no Arc tokens exist at all.totalHolders = $.holders.length();counts the holders. If there are none, the function returns zeros and does nothing.if (startIndex >= totalHolders) { startIndex = 0; }wraps around to the beginning if the caller passed a position past the end of the list.uint256 endIndex = startIndex + maxHolders; if (endIndex > totalHolders) { endIndex = totalHolders; }works out where this batch stops, without running past the end of the list.uint256 batchSize = endIndex - startIndex;is how many holders this call will look at. If it is zero, the function returns early.- The
forloop overtotalHoldersis the heart of the bug. It walks the entire holder list, not just this batch, and adds upbalanceOf(holder)for every holder that_isYieldAllowedaccepts. The total is stored ineffectiveTotalSupply. This is the denominator, and it is rebuilt from live balances on every single call. - If that total is zero, the function returns without paying anything.
if (startIndex == 0) { yToken.safeTransferFrom(msg.sender, address(this), totalAmount); ... }is the second key line. Only on the first batch does the contract pull the reward tokens from the caller into itself. On later batches nothing new comes in, so the contract's stock is fixed attotalAmountminus whatever it has already paid out.- The second
forloop walks only this batch. For each holder it skips anyone not allowed yield, reads their Arc balance, and computesshare = (totalAmount * holderBalance) / effectiveTotalSupply. Note thattotalAmountis the full round amount on every batch, not what is left. The share is then transferred to the holder and added toamountDistributed. nextIndex = endIndex < totalHolders ? endIndex : 0;sets where the next call should start, or 0 if the round is finished. When the round finishes, aYieldDistributedevent is emitted, which is a log entry that outside observers can read.
Two details of this function matter for the bug. First, the yield tokens are pulled from the caller only when startIndex == 0, so the contract holds exactly totalAmount for the whole round. Second, the per-holder share is (totalAmount * holderBalance) / effectiveTotalSupply, where totalAmount is the full round amount on every batch, not the amount still undistributed.
Exploitation
Step 1: seed ten holders
The PoC transfers 100e18 tokens to each of the addresses 2 through 10, giving nine funded holders alongside the test contract. 100e18 is a way of writing 100 tokens with 18 decimal places, the usual precision for ERC20 tokens. The loop simply repeats the transfer for each numbered address.
function test_POC2() public {
for (uint160 i = 2; i <= 10; i++) {
token.transfer(address(i), 100e18); // Transfer 0.1 ARC to each address
}
Why this step: the bug only shows up when the reward is split across several holders and paid in more than one batch. Ten holders with equal balances make the arithmetic easy to follow.
Step 2: approve and run the first batch
The test approves the token contract to spend YIELD_AMOUNT of the yield token, then distributes to the first five holders.
// Approve and distribute yield
yieldToken.approve(address(token), YIELD_AMOUNT);
token.distributeYieldWithLimit(YIELD_AMOUNT, 0, 5);
approve is the standard ERC20 permission step: it tells the yield token "this other contract may take up to this amount from me". Without it, the safeTransferFrom inside the distribution would fail. The call then starts at position 0 and processes five holders.
Because startIndex is 0, this call pulls YIELD_AMOUNT from the caller into the token contract and pays out the first batch, each recipient getting YIELD_AMOUNT * balance / effectiveTotalSupply.
Step 3: increase the supply between batches
Before the second batch, the test mints 100e18 tokens to address 6.
// Mint to address 6
token.mint(address(6), 100e18);
Why this step: it simulates the situation the report warns about, where the total supply grows in the middle of a distribution round. Address 6 is one of the holders, so its balance grows and the effective total supply grows with it.
This raises the effective total supply used by the next call, since address 6 is a yield-allowed holder whose balance has grown.
Step 4: run the second batch
The second call continues from index 5.
token.distributeYieldWithLimit(YIELD_AMOUNT, 5, 10);
}
Because startIndex is not 0, no further yield tokens are pulled in. The contract still holds only what is left after the first batch, but the shares are now computed against the larger effective supply, and the call reverts.
Result
The test fails with an insufficient balance error from the yield token transfer:
Encountered 1 failing test in test/ArcToken.t.sol:ArcTokenTest
[FAIL: ERC20InsufficientBalance([redacted], 45454545454545454549 [4.545e19], 90909090909090909090 [9.09e19])] test_POC2() (gas: 1192212)
The contract tried to transfer more yield tokens than it held, so the batch reverted. The error name says it plainly: ERC20InsufficientBalance. The numbers in the brackets are the address involved and the amounts, shown both as raw integers and in shortened form.
Root cause
The denominator effectiveTotalSupply is recomputed on every call from the current balances of all yield-allowed holders, while the numerator totalAmount is the full amount of the round and the contract's yield balance is fixed after the first batch. Any increase in the effective supply between batches changes the shares for the later batches relative to the earlier ones. The report frames this as dilution: the remaining reward per holder shrinks, and the contract can end up trying to pay out more than it holds, which reverts the batch.
The existing guards do not cover this. nonReentrant and onlyRole(YIELD_DISTRIBUTOR_ROLE) restrict who can call and prevent reentrancy, but neither pins the denominator for the duration of a round. The supply == 0 check only rejects an empty token. Nothing snapshots the effective supply at startIndex == 0 for reuse in later batches.
Impact
The report lists two impacts:
- Rewards are temporarily stuck, because
distributeYieldWithLimitfails on subsequent batches once the supply has grown. - Rewards for subsequent batches are diluted.
The report also lists, among the impact categories, that the smart contract is unable to operate due to lack of token funds. The trigger is an increase in the effective supply between batches, which the report says is possible because the Arc token is mintable and the minter can be anyone, including a contract, and is not necessarily a protocol admin. The report rates the issue Medium and describes the freezing as temporary.
Fix
The report does not describe a fix or a change that was made. The direction implied by the analysis is to stop recomputing the denominator mid-round: snapshot the effective total supply when the round starts (the startIndex == 0 call) and use that same value for every subsequent batch, so that shares stay consistent with the amount pulled in at the start.
Variants to test
- Batched distribution functions in other mintable tokens: look for a denominator recomputed per call while the numerator is the full round amount. A positive result is a second batch that reverts or pays a different per-holder share after a mint or transfer between batches.
- Rounds where the supply changes through transfers rather than mints: if the effective supply depends on which holders are yield-allowed, a transfer into or out of an allowed holder changes the denominator just as a mint does. A positive result is the same revert or dilution without any mint.
- Distributions that pull funds only on the first batch: check whether the contract's balance is sufficient for the recomputed shares. A positive result is an
ERC20InsufficientBalancerevert on a later batch. - Holder-set changes between batches: if the holders array can grow, the loop over
totalHoldersand thestartIndex/endIndexarithmetic may skip or double-count holders. A positive result is a holder receiving a share twice or not at all across a full round.
Hunting notes
This kind of bug hides in paginated or batched accounting: any function that takes a startIndex/maxHolders pair and recomputes a global denominator on each call is worth reading closely. The signals during review are a totalAmount used unchanged in every batch, a safeTransferFrom guarded by startIndex == 0, and a supply figure derived from live balances rather than stored state. The report showed impact with a minimal Foundry test that seeds holders, runs one batch, mints, runs the next batch, and lets the revert speak for itself; the failing trace with the exact ERC20InsufficientBalance amounts is what makes the dilution and the stuck funds concrete.
Glossary
- Smart contract: a program on a blockchain that runs the same way for everyone and can be called by anyone.
- ERC20: the common standard for tokens that keep a table of balances.
- Upgradeable contract: a contract whose logic can be replaced later while its stored data stays.
- Mint: creating new token units, increasing the total supply.
- Minter / admin: the address allowed to mint. The report notes it can be anyone, including a contract.
- Yield: a reward paid to token holders, here in a separate yield token.
- Role: a named permission on a contract, such as
YIELD_DISTRIBUTOR_ROLE. - Batch: one slice of a larger job, here a group of holders processed in a single call.
startIndex/maxHolders: where a batch starts in the holder list and how many holders it may process.nextIndex: the position the next call should start from.- Effective total supply: the sum of the balances of all holders allowed to receive yield; the denominator of the share calculation.
- Numerator / denominator: the top and bottom numbers of a fraction.
- Dilution: each holder's slice shrinking because the same pot is divided by a larger number.
- Revert: cancelling a transaction and undoing its changes when a contract refuses an operation.
nonReentrant: a guard that blocks a contract from calling back into the same function while it is still running.safeTransferFrom/safeTransfer: standard token functions that move tokens between addresses and fail loudly if something is wrong.ERC20InsufficientBalance: the error raised when a token transfer asks for more than the sender holds.- Snapshot: recording a value at one moment so later steps can reuse it unchanged.
- Foundry: a toolkit for writing and running smart contract tests locally.
- Event: a log entry a contract emits so outside observers can see what happened.
- Gas: the fee paid for computation on a blockchain; it is lost when a transaction reverts.