-
Notifications
You must be signed in to change notification settings - Fork 5
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
Trooper - pools.vy: calc_mint does not account for outstanding fees, allowing attackers to steal fees from LP #50
Comments
Escalate Issue should be low. Issue describes normal usage of the protocol - user deposits funds and accrues yields. In fact, what they've explained above even posses risk as while they're 'waiting' for a position close, they're funds are at risk as they're both exposed to asset going down in price or users closing a position on positive PnL. |
You've created a valid escalation! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
This issue is clearly valid. The issue correctly described a scenario where fees can be stolen by sandwich attacking a position close. |
Sandwiching on bob is not possible as there's no public mempool to do so. What a user can do is just add liquidity and wait which is the exact same as every other liquidity provider in the pool. |
This is a duplicate of #94 |
I see how it can be a duplicate of #94 because the root cause is that the new LP providers get the same amount of fees as the older LPs. But, this report relies on front-runnin on Bob with private mempool. Hence, for this to happen, they need to deposit in the pool and just wait which is how the protocol is expected to be used, essentially. Hence, I agree it should be low severity. initial decision to accept the escalation and invalidate the issue, but correct me if anything is wrong here. |
Result: |
Escalations have been resolved successfully! Escalation status:
|
Trooper
High
pools.vy: calc_mint does not account for outstanding fees, allowing attackers to steal fees from LP
Summary
Inside of the calc_mint the contract calculates how much LP-Tokens should be minted when a provider adds new liquidity. This does not account for outstanding fees. Therefor a new user gets the same LP-Token ratio as older LP providers. This allows new providers to steal fees.
Root Cause
In the
calc_mint
function, LP tokens are calculated based on thetotal_reserves
, which reflect the current pool state but do not account for any pending fees. This allows a large token holder to deposit just before a regular user closes their position.When closing a position, the core contract calls
close
function, updating the pool reserves to reflect the added tokens paid as fee. As a result, the pool now contains more liquidity.The attacker can then unstake their LP tokens and, based on the ratio of their LP share relative to the total LP value before the attack, they are able to claim a significant portion of the fees paid by the user.
Internal pre-conditions
External pre-conditions
N/A
Attack Path
Impact
The attacker is able to steal fees that should have been paid to the older LP.
PoC
Walkthrough
A user opens a large position in the pool:
The attacker now mints new LP tokens with a relatively large position vs. the existing LPs. In this case the new LP is ~100x the old LP:
Close tx settles and fees get paid to the pool:
The attacker now burns all his LP tokens:
The original LP only earned 1 of each token:
The attacker earned most of the fees, ~120 quote tokens:
Diff
Update the
conftest.py
to be the same as the currently planed parameters (based on sponsor msg in discord):Mitigation
The contract
pools.vy
should call thefees.vy
contract and look up the currently outstanding fees inside of thetotal_reserves
function.The text was updated successfully, but these errors were encountered: