-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Since buyToken function has no slippage checking, users can get less tokens than expected when they buy tokens directly #397
Comments
buyToken
function has no slippage checking, users can get less tokens than expected when they buy tokens directly
raymondfam marked the issue as sufficient quality report |
raymondfam marked the issue as duplicate of #26 |
raymondfam marked the issue as not a duplicate |
raymondfam marked the issue as primary issue |
this is intended and a consequence of how the VRGDA functions, when people buy tokens the price goes up if it is ahead of schedule not ideal UX, but not going to fix for now |
rocketman-21 (sponsor) acknowledged |
Even though the increasing price is intended, it's state of the art to introduce a slippage parameter to protect users from receiving less than expected. Therefore, maintaining |
MarioPoneder marked the issue as satisfactory |
MarioPoneder marked the issue as selected for report |
Lines of code
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/ERC20TokenEmitter.sol#L152-L230
Vulnerability details
Impact
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 user's buyToken) which is running in front of caller's transaction, they can get less token than they expected.Proof of Concept
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 user's buying token transaction, the token price can arise than expected.
For instance, let's 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 bygetTokenQuoteForEther(5 ether)
and the value is about4.87 ether
.However, if Bob's transaction to buy tokens with
10 ether
is executed before Alice, the real amount which Alice will receive is about4.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 inbuyToken
function.Tools Used
VS Code
Recommended Mitigation Steps
Add slippage checking to
buyToken
function. This slippage checking should be executed only when the user callsbuyToken
function directly. In other words, it should not be executed when settleAuction callsbuyToken
function.Assessed type
Other
The text was updated successfully, but these errors were encountered: