Skip to content
Business logic Audit finding Intermediate

Integer division remainder loss in batched yield distribution causes permanent fund lock

The batched yield distribution function drops the integer-division remainder from each holder's share, so small amounts stay stuck in the contract. Over many distributions these lost remainders accumulate into funds that can never be recovered.

ZeroExRes Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

52798 sc high integer division remainder loss in batched yield distribution causes permanent fund lock

Submitted on Aug 13th 2025 at 09:17:55 UTC by @ZeroExRes for Attackathon | Plume Network

Description

Brief/Intro

The distributeYieldWithLimit() function contains a flaw where integer division remainders from each batch are permanently lost and locked in the contract, while the regular distributeYield() function correctly handles these remainders. This creates an accumulating fund loss mechanism that can result in significant monetary losses over time, with no recovery method available.

Vulnerability Details

The issue stems from different remainder handling between two yield distribution functions:

distributeYield() (Works Correctly):

Solidity
// Processes all holders except last
for (uint256 i = 0; i < lastProcessedIndex; i++) {
    uint256 share = (amount * holderBalance) / effectiveTotalSupply;
    // ... distribute share
    distributedSum += share;
}

// CRITICAL: Last holder gets ALL remainder
uint256 lastShare = amount - distributedSum;  // ← Captures remainder
yToken.safeTransfer(lastHolder, lastShare);

distributeYieldWithLimit() (Loses Remainder):

Solidity
for (uint256 i = 0; i < batchSize; i++) {
    uint256 share = (totalAmount * holderBalance) / effectiveTotalSupply;
    // ... distribute share  
    amountDistributed += share;
}
// ← NO remainder handling - funds permanently stuck!

Impact Details

Each batched distribution loses integer division remainders from every user calculation, with no recovery mechanism available. Even though there is no significant loss for a particular user, these per-user remainders accumulate into non-trivial amounts with each distribution, creating systematic fund loss that compounds over the contract's operational lifetime.

{% hint style="danger" %} Permanent freezing of funds: the remainders accumulated per batch are not returned to recipients nor tracked for later distribution, so funds become permanently locked in the contract balance. {% endhint %}

Proof of Concept

Add to ArcToken.t.sol:

{% code title="ArcToken.t.sol" %}

Solidity
function test_YieldRemainderLoss_Comparison() public {    
    // Setup: Create 3 equal holders to guarantee remainder
    token.transfer(bob, 100e18);    // Bob: 100e18
    token.transfer(charlie, 100e18); // Charlie: 100e18
    // Alice already has: 100e18 
    // Owner now has: 700e18
    
    uint256 yieldAmount = 99;
    
    console.log("Setup - Token balances:");
    console.log("  Owner:", token.balanceOf(owner) / 1e18, "tokens");
    console.log("  Alice:", token.balanceOf(alice) / 1e18, "tokens");
    console.log("  Bob:", token.balanceOf(bob) / 1e18, "tokens");
    console.log("  Charlie:", token.balanceOf(charlie) / 1e18, "tokens");
    console.log("Yield to distribute:", yieldAmount);
    console.log("");

    // ========== TEST 1: Regular Distribution ==========
    console.log("=== TEST 1: distributeYield() ===");
    
    yieldToken.approve(address(token), yieldAmount);
    uint256 contractBefore1 = yieldToken.balanceOf(address(token));
    uint256 ownerBefore1 = yieldToken.balanceOf(owner);
    
    token.distributeYield(yieldAmount);
    
    uint256 contractAfter1 = yieldToken.balanceOf(address(token));
    uint256 ownerAfter1 = yieldToken.balanceOf(owner);
    uint256 aliceAfter1 = yieldToken.balanceOf(alice);
    uint256 bobAfter1 = yieldToken.balanceOf(bob);
    uint256 charlieAfter1 = yieldToken.balanceOf(charlie);
    
    uint256 ownerReceived1 = ownerAfter1 - (ownerBefore1 - yieldAmount);
    uint256 totalDistributed1 = ownerReceived1 + aliceAfter1 + bobAfter1 + charlieAfter1;
            
    console.log("Contract balance change:", contractAfter1 - contractBefore1);
    console.log("Total distributed:", totalDistributed1);
    console.log("Funds lost:", yieldAmount - totalDistributed1);
    console.log("");

    // ========== TEST 2: Batched Distribution ==========
    console.log("=== TEST 2: distributeYieldWithLimit() ===");
    
    yieldToken.mint(owner, yieldAmount);
    yieldToken.approve(address(token), yieldAmount);
    uint256 contractBefore2 = yieldToken.balanceOf(address(token));
    
    uint256 totalDistributed2 = 0;
    uint256 nextIndex = 0;
    uint256 batchCount = 0;
    
    do {
        (uint256 newNextIndex, , uint256 batchDistributed) = 
            token.distributeYieldWithLimit(yieldAmount, nextIndex, 2);
        totalDistributed2 += batchDistributed;
        nextIndex = newNextIndex;
        batchCount++;
        console.log("Batch", batchCount, "distributed:", batchDistributed);
    } while (nextIndex != 0);
    
    uint256 contractAfter2 = yieldToken.balanceOf(address(token));
    
    console.log("Contract balance change:", contractAfter2 - contractBefore2);
    console.log("Total distributed:", totalDistributed2);
    console.log("Funds lost:", yieldAmount - totalDistributed2);
    console.log("");

    // ========== CRITICAL COMPARISON ==========
    uint256 regularLoss = yieldAmount - totalDistributed1;
    uint256 batchedLoss = yieldAmount - totalDistributed2;
    uint256 extraStuckFunds = (contractAfter2 - contractBefore2) - (contractAfter1 - contractBefore1);
    
    console.log("Regular distribution lost:", regularLoss);
    console.log("Batched distribution lost:", batchedLoss);
    console.log("Extra funds stuck from batching:", extraStuckFunds);

    // Assertions to prove the issue
    assertEq(regularLoss, 0, "Regular distribution should lose no funds");
    assertGt(batchedLoss, 0, "Batched distribution should lose funds due to remainder bug");
    assertGt(contractAfter2, contractAfter1, "More funds stuck after batched distribution");
}

{% endcode %}

References

Mentioned above


If you want, I can:

  • Suggest concrete fixes (e.g., accumulate distributed sum per batch and forward remainder to a designated recipient or track leftover for later distribution), or
  • Produce a small patch diff for ArcToken.sol implementing correct remainder handling in distributeYieldWithLimit().

The original report as published on Immunefi, by ZeroExRes. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the batched function never assigns the leftover from integer division to anyone, unlike the regular function which gives it to the last holder.

Impact

Each batched distribution permanently locks the per-user division remainders in the contract, and these accumulate over time with no recovery method.

What the attacker needed

Contract holds yield to distribute; batched distribution is used

The fix

The batched function should track the distributed sum and forward the leftover remainder to a recipient or store it for later distribution.

How it was found

  1. Set up three holders with equal balances so a remainder is guaranteed.
  2. Call the regular distribution function and observe that no funds are lost.
  3. Call the batched distribution function repeatedly until all holders are processed.
  4. Compare contract balances and see that extra funds remain stuck after batching.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a contract splits an amount between many people, whole-number maths often leaves a tiny leftover that cannot be divided evenly. The normal distribution function gives that leftover to the last person, but the batched version simply ignores it, so the leftover stays in the contract forever. Each batch adds a little more, and nobody can withdraw it.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by ZeroExRes

View all

6 more disclosed reports, best first.

More from Plume Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.