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.
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
- Report ID: #52446
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/immunefi-team/attackathon-plume-network/blob/main/arc/src/ArcTokenPurchase.sol
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
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:
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:
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
ArcTokenandArcTokenPurchase. - 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,000andamountSold = 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:
totalAmountForSaleandamountSoldremain 1,000 and 600 respectively. {% endstep %}
{% step %}
Step 5 — Off-chain or buyer query
getMaxNumberOfTokens(token)returns 400 (computed as1,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.)
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
- Deploy the token and purchase contracts, set the purchase token and fund the contract with tokens.
- Enable the sale with a total for sale and zero sold.
- Buyers purchase part of the allocation, leaving a smaller real balance.
- The admin withdraws some unsold tokens, but the sale counters stay unchanged.
- The availability getter still returns the pre-withdrawal figure.
- 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.