saleRecipient can rug buyers
The buy function transfers the buyer's input tokens directly to the saleRecipient without first ensuring the corresponding output tokens are locked in the contract. A malicious saleRecipient can keep the input tokens and finalize the sale without ever providing the output tokens, causing buyers to lose their funds.
Submitted by WatchPug, also found by gellej, Czar102, hyh, harleythedog, pauliax, cmichel, 0x1f8b, hickuphh3, cccz, and sirhashalot
In TokenSaleUpgradeable.sol#buy(), tokenIn will be transferred from the buyer directly to the saleRecipient without requiring/locking/releasing the corresponding amount of tokenOut.
This allows the saleRecipient to rug the users simply by not transferring tokenOut and finalizing the sale.
Proof of Concept
Given:
- tokenIn:
WBTC - _tokenOutPrice:
1e8 - tokenOut:
CTDL - Alice
buy()with100e8; - Alice
buy()with200e8;
A malicious saleRecipient can just not transfer any CTDL to the contract and finalize() and keep 300e8 WBTC received.
As a result, Alice and Bob can not get the expected amount of tokensOut, and there is no way to retrieve the WBTC paid, in essence, lose all the funds.
Recommended Mitigation Steps
Instead of transferring the tokenIn directing to the saleRecipient in buy(), consider transferring the tokenIn into the contract (address(this)), and require a sufficient amount of tokenOut to be transferred into the contract first before the amount of tokenIn can be released to the saleRecipient.
shuklaayush (BadgerDAO) disagreed with severity
0xleastwood (judge) decreased severity to Medium and commented:
As this is also an issue regarding abuse of an owner’s admin privileges, it fits the criteria of a
mediumseverity issue.
0xleastwood (judge) commented:
I’ve thought about this more and I’ve decided to split up distinct issues into 3 primary issues:
- Owner rugs users.
- Funds are transferred to
saleRecipientbefore settlement.- Changing a token buy price during the sale by front-running buyers by forcing them to purchase at an unfair token price.
This issue falls under the second primary issue.
- Funds are transferred to
saleRecipientbefore settlement.
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
The buy function transfers tokenIn directly to the saleRecipient without first requiring the corresponding tokenOut to be deposited and locked in the contract.
Impact
Buyers cannot receive the expected tokenOut and have no way to retrieve the tokenIn they paid, effectively losing all funds; the judge rated this as a medium-severity issue because it involves abuse of the owner's admin privileges.
What the attacker needed
Malicious saleRecipient (owner/admin); buyers purchase tokens during the sale
The fix
The contract should hold the tokenIn itself and only release it to the saleRecipient after confirming that a sufficient amount of tokenOut has been transferred into the contract.
How it was found
- Alice calls buy() with 100e8 tokenIn.
- Alice calls buy() with 200e8 tokenIn.
- The malicious saleRecipient does not transfer any tokenOut to the contract.
- The saleRecipient calls finalize() and keeps the 300e8 tokenIn received.
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.
In a token sale, buyers pay one token (tokenIn) to receive another (tokenOut). Here, the contract sends the buyer's payment straight to the sale organiser before the organiser has put the tokens for sale into the contract. The organiser can simply take the payment and never deliver the tokens, and buyers have no way to get their money back.
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.