Skip to content
Business logic Audit finding Beginner

Withdrawing unsold tokens desynchronizes sale accounting

The admin withdrawal function moves unsold tokens out of the contract without updating the sale ledger, so the public getter still reports the original pool minus sold tokens. Buyers who trust that figure can attempt purchases the contract cannot honour, and their transactions revert, wasting gas.

Afriauditor Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

52446 sc low withdrawing unsold tokens desynchronizes sale accounting

Submitted on Aug 10th 2025 at 18:26:11 UTC by @Afriauditor for Attackathon | Plume Network

Description

Brief/Intro

In ArcTokenPurchase, the admin can withdraw unsold ArcTokens from the contract, but the sale ledger used by getMaxNumberOfTokens isn’t updated. After a withdrawal, the contract may report more tokens “available” than it actually holds, causing failed buys.

Vulnerability Details

The withdraw function only transfers tokens out; it does not update the sale counters:

Solidity
function withdrawUnsoldArcTokens(address _tokenContract, address to, uint256 amount)
    external onlyTokenAdmin(_tokenContract)
{
    // ...checks...
    ArcToken token = ArcToken(_tokenContract);
    uint256 bal = token.balanceOf(address(this));
    if (bal < amount) revert InsufficientUnsoldTokens();
    bool ok = token.transfer(to, amount);
    if (!ok) revert ArcTokenWithdrawalFailed();
}

But the getter used by buyers ignores withdrawals and returns the original pool minus sold:

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

Impact Details

The contract can report more available tokens than it actually holds. Buyers relying on the getter may submit larger purchases and hit reverts when inventory isn’t actually there, wasting gas. The contract does not lose tokens or value, but it can fail to deliver promised amounts.

Proof of Concept

{% stepper %} {% step %}

Step 1 — Setup

  • Deploy ArcToken and ArcTokenPurchase.
  • Set the purchase token (e.g., USDC).
  • Transfer 1,000 ARC to the purchase contract. {% endstep %}

{% step %}

Step 2 — Start sale

  • Enable the sale with totalAmountForSale = 1,000 and amountSold = 0. {% endstep %}

{% step %}

Step 3 — Partial purchases

  • Buyers purchase 600 ARC total → amountSold = 600; contract now holds 400 ARC. {% endstep %}

{% step %}

Step 4 — Admin withdraws unsold tokens

  • Admin calls withdrawUnsoldArcTokens(token, treasury, 300) → contract balance drops to 100 ARC.
  • Note: totalAmountForSale and amountSold remain 1,000 and 600 respectively. {% endstep %}

{% step %}

Step 5 — Off-chain or buyer query

  • getMaxNumberOfTokens(token) returns 400 (computed as 1,000 - 600), ignoring the 300 withdrawn. {% endstep %}

{% step %}

Step 6 — Buyer attempts purchase

  • Buyer attempts to buy 400 ARC based on that getter.
  • Inside buy():
    • remainingForSale = totalAmountForSale - amountSold = 400 → passes the “NotEnoughTokensForSale” check.
    • Actual on-chain balance is 100 ARC → triggers ContractBalanceInsufficient() and the tx reverts (buyer wastes gas). {% endstep %} {% endstepper %}

References

(No additional references provided.)

The original report as published on Immunefi, by Afriauditor. 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 withdrawal path transfers tokens without decrementing the sale accounting, so the reported availability is derived from stale counters rather than the actual balance.

Impact

The contract may report more tokens available than it holds, so buyers can waste gas on purchases that revert; no tokens or value are lost.

What the attacker needed

Admin role on the contract; sale enabled with tokens funded; admin withdraws unsold tokens

The fix

The withdrawal should also reduce the recorded amount for sale so the getter reflects the real remaining inventory.

How it was found

  1. Deploy the token and purchase contracts, set the purchase token and fund the contract with tokens.
  2. Enable the sale with a total for sale and zero sold.
  3. Buyers purchase part of the allocation, leaving a smaller real balance.
  4. The admin withdraws some unsold tokens, but the sale counters stay unchanged.
  5. The availability getter still returns the pre-withdrawal figure.
  6. A buyer purchases that amount, the balance check fails and the transaction reverts.

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 token sale contract keeps a record of how many tokens are for sale and how many have been sold. The admin can take unsold tokens back out, but the record is not changed to match, so the contract advertises tokens it no longer holds. A buyer who trusts that number sends a purchase that fails and loses the gas fee.

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 Afriauditor

View all

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