Owner can steal input tokens
The contract owner could change the token sale price while a buyer's purchase transaction was pending, so the buyer received far fewer tokens than expected and the owner's chosen recipient address received the tokens. The owner could also front-run a buy to set a very high price, effectively giving the buyer almost nothing.
Submitted by Czar102, also found by gellej, cmichel, tqts, gzeon, TomFrenchBlockchain, pauliax, and pedroais
TokenSaleUpgradeable.sol#L299-L309 TokenSaleUpgradeable.sol#L311-L324 TokenSaleUpgradeable.sol#L211-L224
Owner is in full control over the saleRecipient address. When a buy() transaction enters the mempool, an owner can frontrun the buy with a transaction that calls setTokenOutPrice() and sets the price to a very high value, effectively making bought tokens close to (if not usually equal) zero and consuming the tokens to the owner-selected address - saleRecipient. Thus, an owner has incentive to perform such attack as they may cause little or zero additional indebtnees to the contract and all tokens to the owner.
This can also be seen as a coincidence - an owner sets a price while a user broadcasts a buy() transaction. The user may buy for a significantly different price than they intended.
Recommended Mitigation Steps
Do not let changing sale price after the sale has started. Do not let changing sale start if the sale has already started.
GalloDaSballo (BadgerDAO) disagreed with severity and commented:
I agree with the finding and the conclusion, we shouldn’t let the price change after the sale has started.
As for the example, that would only work once, because if we actually did that it would immediately warn every other user of our malicious behavior.
I think the finding is valid and it’s a clear example of admin privilege, so I believe medium severity to be more appropriate
0xleastwood (judge) decreased severity to Medium and commented:
I agree with the sponsor on the above.
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 saleRecipient before settlement.
- Changing a token buy price during the sale by front-running buyers by forcing them to purchase at an unfair token price.
I believe this satisfies the third primary issue description.
- Changing a token buy price during the sale by front-running buyers by forcing them to purchase at an unfair token price.
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 sale price could be changed by the owner after the sale had started, and purchases did not lock in the price the buyer expected.
Impact
A buyer could pay the intended amount but receive close to zero tokens, with the tokens going to the owner's chosen address; the sponsor noted this would only work once before other users noticed.
What the attacker needed
Owner controls the sale contract; sale has already started; buyer's transaction is pending
The fix
The price should be locked once the sale has started, and the sale start should not be changeable after it has begun.
How it was found
- The owner watches pending transactions and sees a buyer's purchase.
- The owner sends a price-change transaction ahead of the purchase.
- The buyer's purchase executes at the new, much higher price.
- The buyer receives almost no tokens, and the tokens go to the owner's chosen recipient.
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 is a program on a blockchain that holds and moves funds. Here the person who controls the sale could quietly change the price just before someone else's purchase went through, so the buyer paid the old price but got very few tokens. The buyer had no way to see this coming because the price change and the purchase happened almost at the same moment.
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.