Skip to content
Business logic Audit finding Beginner

Unsold token withdrawal causes permanent inventory mismatch

The contract's withdrawUnsoldArcTokens function transfers tokens out without updating the internal TokenInfo state that tracks sale inventory. This causes getMaxNumberOfTokens to report stale availability, so subsequent purchases fail and the sale is effectively halted.

itsravin0x Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

52314 sc low unsold token withdrawal causes permanent inventory mismatch

Submitted on Aug 9th 2025 at 19:21:31 UTC by @itsravin0x for Attackathon | Plume Network

Description

Brief/Intro

The ArcTokenPurchase contract contains an accounting flaw where withdrawing unsold tokens via withdrawUnsoldArcTokens() does not update the internal TokenInfo state variables used to track remaining sale inventory. This creates a permanent mismatch between the reported number of tokens available (getMaxNumberOfTokens) and the actual token balance in the contract. As a result, buyers will be shown incorrect availability and any attempted purchases after such a withdrawal will fail, effectively halting the sale and misleading participants.

Vulnerability Details

The contract tracks token sale data in the TokenInfo struct, where totalAmountForSale and amountSold are used to compute availability via:

Solidity
function getMaxNumberOfTokens(address _tokenContract) 
    external view returns (uint256) 
{
    TokenInfo storage info = _getPurchaseStorage().tokenInfo[_tokenContract];
    return info.totalAmountForSale - info.amountSold;
}

However, the withdrawUnsoldArcTokens() function transfers tokens out without adjusting totalAmountForSale or amountSold:

Solidity
function withdrawUnsoldArcTokens(address _tokenContract, address to, uint256 amount) 
    external onlyTokenAdmin(_tokenContract) 
{
    // ... validation checks ...
    ArcToken token = ArcToken(_tokenContract);
    uint256 contractBalance = token.balanceOf(address(this));
    if (contractBalance < amount) {
        revert InsufficientUnsoldTokens();
    }
    bool success = token.transfer(to, amount);
    if (!success) {
        revert ArcTokenWithdrawalFailed();
    }
    // Missing: update info.totalAmountForSale -= amount;
}

Because getMaxNumberOfTokens() reads from stale state, the reported availability remains unchanged after withdrawals, even when the contract’s balance is depleted.

Example (Observed in Test)

  • Before withdrawal:
    • Reported remaining tokens: 500
    • Actual balance: 500
  • After withdrawal of all 500:
    • Reported remaining tokens: 500 (stale)
    • Actual balance: 0

Any subsequent purchase will revert due to:

Solidity
if (contractBalance < arcTokensBaseUnitsToBuy) {
    revert ContractBalanceInsufficient();
}

but UIs or off-chain systems relying on getMaxNumberOfTokens will still display the stale 500 tokens as available.

Impact Details

  • Denial of Service: All further purchases will fail after an unsold token withdrawal, halting sales completely.
  • False Reporting / Market Manipulation Risk: Off-chain systems and frontends using getMaxNumberOfTokens will misrepresent sale inventory, misleading users into believing tokens remain for sale.
  • Loss of Revenue: The project may lose potential buyers due to perceived availability followed by transaction failures.

References

Proof of Concept

<details> <summary>Test demonstrating the inconsistent accounting (click to expand)</summary>

Paste this in arc/test/ArcTkenPurchase.t.sol

Solidity
function test_InconsistentTokenAccounting() public {
    uint256 reported_remaining_number_of_tokens_before = purchase
        .getMaxNumberOfTokens(address(token));
    console.log(
        "Reported remaining number of tokens BEFORE withdrawal: ",
        reported_remaining_number_of_tokens_before
    );
    uint256 actual_remaining_number_of_tokens_before = token.balanceOf(
        address(purchase)
    );

    console.log(
        "Actual remaining number of Tokens BEFORE withdrawal: ",
        actual_remaining_number_of_tokens_before
    );

    purchase.withdrawUnsoldArcTokens(
        address(token),
        address(this),
        actual_remaining_number_of_tokens_before
    );

    uint256 reported_remaining_number_of_tokens_after = purchase
        .getMaxNumberOfTokens(address(token));
    console.log(
        "Reported remaining number of tokens AFTER withdrawal: ",
        reported_remaining_number_of_tokens_after
    );
    uint256 actual_remaining_number_of_tokens_after = token.balanceOf(
        address(purchase)
    );

    console.log(
        "Actual remaining number of Tokens AFTER withdrawal: ",
        actual_remaining_number_of_tokens_after
    );
}
</details>

The original report as published on Immunefi, by itsravin0x. 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 withdrawUnsoldArcTokens function fails to decrement totalAmountForSale (or adjust amountSold) after transferring tokens out.

Impact

All further purchases fail after an unsold token withdrawal, halting sales, and off-chain systems relying on getMaxNumberOfTokens misrepresent available inventory, potentially misleading users and losing revenue.

What the attacker needed

Token admin role; unsold tokens present in contract

How it was found

  1. Call getMaxNumberOfTokens to see reported remaining tokens and check actual token balance of the contract.
  2. Call withdrawUnsoldArcTokens to transfer all remaining tokens out of the contract.
  3. Call getMaxNumberOfTokens again; it still reports the old number, while the actual balance is now zero.
  4. Attempt a purchase; it reverts because the contract balance is insufficient.

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.

A smart contract keeps a record of how many tokens are left for sale. When the owner withdraws unsold tokens, the contract moves the tokens but forgets to update that record. So the contract still says tokens are available, but when someone tries to buy, the purchase fails because the tokens are gone.

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.