Submitted by deepplus, also found by Aymen0909, adeolu, passteque, jnforja, KupiaSec, Tricko, wangxx2026, zhaojie, 0xDING99YA, SadeeqXmosh, DanielArmstrong, SpicyMeatball, 0xmystery, Inference, and rvierdiiev
Users can buy NontransferableERC20Token by calling buyToken function directly. At that time, the expected amount of tokens they will receive is determined based on current supply and their paying ether amount. But, due to some transactions(such as settleAuction or another users buyToken) which is running in front of callers transaction, they can get less token than they expected.
The VRGDAC always exponentially increase the price of tokens if the supply is ahead of schedule. Therefore, if another transaction of buying token is frontrun against a users buying token transaction, the token price can arise than expected.
For instance, lets assume that ERC20TokenEmitter is initialized with following params:
To avoid complexity, we will assume that the supply of token so far is consistent with the schedule. When alice tries to buy token with 5 ether, expected amount is calculated by getTokenQuoteForEther(5 ether) and the value is about 4.87 ether.
However, if Bobs transaction to buy tokens with 10 ether is executed before Alice, the real amount which Alice will receive is about 4.43 ether.
You can check result through following test:
Therefore, Alice will get about 0.44 ether less tokens than expected since there is no any checking of slippage in buyToken function.
VS Code
Add slippage checking to buyToken function. This slippage checking should be executed only when the user calls buyToken function directly. In other words, it should not be executed when settleAuction calls buyToken function.
rocketman-21 (Revolution) acknowledged and commented:
0xTheC0der (Judge) commented:
