Skip to content
Business logic Audit finding Intermediate

Permanent fund lock due to flawed remainder logic in distributeyield

The distributeYield function assigns the rounding remainder to the last holder, but if that holder is ineligible, the remainder is never transferred and stays locked in the contract. An attacker cannot directly steal funds, but the distributor permanently loses the dust amount on each affected distribution.

Alem Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

53077 sc high permanent fund lock due to flawed remainder logic in distributeyield

Description

Brief / Intro

A critical vulnerability exists in the distributeYield function's remainder-handling logic. If the last holder in the distribution iteration is ineligible to receive yield, the function withholds their share but fails to handle the remaining funds that were calculated for them. This remainder (the "dust" from preceding calculations) remains inside the contract. As there is no function to withdraw these trapped tokens, this results in a permanent and irrecoverable loss of capital for the yield distributor with every affected distribution cycle.

Vulnerability Details

distributeYield distributes yield tokens to eligible holders and avoids precision loss by assigning the leftover amount (the remainder) to the final holder. The implementation checks whether the last holder is eligible (_isYieldAllowed(lastHolder)) before transferring the remainder. If the last holder is ineligible, the code simply skips transferring the remainder and does not provide any alternative handling. Since the full amount has already been transferred into the contract via yToken.safeTransferFrom(msg.sender, address(this), amount), any undistributed portion remains in the contract, effectively locked.

Vulnerable code snippet:

Solidity
if (holderCount > 0) {
    address lastHolder = $.holders.at(lastProcessedIndex);
    
    // This 'if' statement is the source of the vulnerability.
    if (_isYieldAllowed(lastHolder)) {
        uint256 lastShare = amount - distributedSum;
        if (lastShare > 0) {
            yToken.safeTransfer(lastHolder, lastShare);
            distributedSum += lastShare;
        }
    }
    // MISSING LOGIC: There is no 'else' block here. If the check above
    // fails, the 'lastShare' is never handled. It's simply abandoned.
}

emit YieldDistributed(distributedSum, yieldTokenAddr);

previewYieldDistribution correctly simulates the distribution (showing a zero share for an ineligible last holder), which creates a discrepancy between preview and actual execution and can mislead a distributor into believing a safe outcome.

Impact Details

  • Permanent and irreversible loss of funds for the yield distributor when the last holder in the iteration is ineligible.
  • The locked amount equals the remainder (rounding "dust") accumulated from the share calculations of preceding holders.
  • Loss scales with number of holders and repeated distributions: small per-distribution but can become significant with many holders or many distributions.
  • This is a recurring, silent loss each time the condition is met.

Recommendation

Handle the undistributed remainder when the last holder is ineligible. The most robust fix is to refund any undistributed amount back to the original sender (msg.sender) so no funds remain locked in the contract.

Suggested handling (conceptual snippet to perform refund of remainder):

Solidity
// ... inside distributeYield, after the main distribution loop and last holder check ...

// After attempting all distributions, calculate what's left.
uint256 remainingInContract = amount - distributedSum;

if (remainingInContract > 0) {
    // Refund the undistributed remainder back to the original caller (the Distributor).
    yToken.safeTransfer(msg.sender, remainingInContract);
}

// The event should emit the amount that was *actually* distributed to holders.
emit YieldDistributed(distributedSum, yieldTokenAddr);

(Do not assume this exact snippet fits the contract structure — integrate consistently with existing state updates, access control, and checks.)

Proof of Concept (PoC)

Actors:

  • Distributor: account with YIELD_DISTRIBUTOR_ROLE.
  • Alice: eligible holder with 400 ArcToken.
  • Bob: eligible holder with 500 ArcToken.
  • Charlie: ineligible holder with 100 ArcToken (last in holders array).

Holders ordered: [Alice, Bob, Charlie]. Effective total supply for distribution = 400 + 500 = 900 (Charlie excluded).

{% stepper %} {% step %}

Step 1 — Preview

Distributor calls previewYieldDistribution(10 ether). The preview correctly indicates:

  • Alice ≈ 4.444... ETH
  • Bob ≈ 5.555... ETH
  • Charlie = 0 ETH The preview appears balanced. {% endstep %}

{% step %}

Step 2 — Execution: Pull funds

Distributor calls distributeYield(10 ether). Contract pulls 10 WETH from Distributor: yToken.safeTransferFrom(msg.sender, address(this), amount) => contract balance increases by 10 WETH. {% endstep %}

{% step %}

Step 3 — Distribute to first holders

The distribution loop processes Alice and Bob:

  • Alice receives (10 * 400) / 900 ≈ 4.444... WETH. distributedSum ≈ 4.444...
  • Bob receives (10 * 500) / 900 ≈ 5.555... WETH. distributedSum ≈ 9.999... {% endstep %}

{% step %}

Step 4 — Final step & trap

The contract handles the last holder (Charlie). It checks _isYieldAllowed(Charlie) which returns false. Because of the missing else/fallback, the remainder: lastShare = amount - distributedSum (≈ 0.000...001 WETH) is not transferred out and remains in the contract. The function ends and emits YieldDistributed(distributedSum, yieldTokenAddr). {% endstep %} {% endstepper %}

Result:

  • Pulled: 10.0 WETH
  • Distributed to holders: ≈ 9.999... WETH
  • Permanently locked in contract: ≈ 0.000...001 WETH (the remainder) This remainder, while small per distribution, accumulates across distributions and holders and can become substantial. There is no contract function to withdraw arbitrary tokens, so these funds are irrecoverable.

Notes

  • Do not change links or add external references.
  • The root cause: design assumes last holder will always receive remainder; it fails when last holder is ineligible.
  • Recommended mitigation: explicitly handle remaining undistributed tokens (refund to sender or allocate to next eligible holder) and align distributeYield behavior with previewYieldDistribution semantics.

The original report as published on Immunefi, by Alem. 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 code assumes the last holder will always be eligible to receive the remainder, so it lacks an else branch to handle the undistributed amount when that holder is ineligible.

Impact

The distributor permanently loses the rounding remainder on each distribution where the last holder is ineligible; the loss is small per distribution but can accumulate over many holders and repeated distributions.

What the attacker needed

YIELD_DISTRIBUTOR_ROLE; last holder ineligible for yield

The fix

The undistributed remainder should be refunded to the sender or allocated to the next eligible holder, and the function should align with the preview behaviour.

How it was found

  1. The distributor calls previewYieldDistribution with 10 ether, which shows Alice and Bob receiving shares and Charlie receiving zero.
  2. The distributor calls distributeYield with 10 ether, and the contract pulls 10 WETH from the distributor.
  3. The distribution loop pays Alice and Bob their proportional shares, leaving a tiny remainder.
  4. The contract checks the last holder Charlie, finds him ineligible, and skips transferring the remainder, which stays locked in the contract.

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 among many people, the division often leaves a tiny leftover called the remainder. This report shows that the contract gives that leftover to the last person in the list, but if that person is not allowed to receive it, the leftover is simply left in the contract with no way to take it out. Over many distributions, these tiny amounts add up and are lost forever.

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 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.