-
Notifications
You must be signed in to change notification settings - Fork 1
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
Protocol should maintain the reserve amount in storage and use that for buy/sell interactions #353
Comments
berndartmueller marked the issue as primary issue |
Does not provide a direct exploit that can lead to loss of funds |
outdoteth marked the issue as disagree with severity |
outdoteth marked the issue as sponsor acknowledged |
Marking #383 as the primary report. The wardens pointed out a possible price manipulation issue due to reliance on direct ETH and token contract balances. I consider Medium severity to be appropriate. |
berndartmueller marked the issue as satisfactory |
Should this be tagged as duplicate of #383 ? |
CloudEllie marked the issue as duplicate of #383 |
Lines of code
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L477
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L398
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L406
https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L390
Vulnerability details
Impact
The invariant is easily broken and liquidity providers do not get the fees.
Proof of Concept
The protocol resembles Uniswap and intends to benefit LPs by charging fees for buy/sell transactions.
As we can see in the functions
_baseTokenReserves()
andfractionalTokenReserves()
, the protocol uses the total balance as reserve amounts. So the protocol relies on the balance of base token and fractional token while buy/sell interactions. (andprice()
view as well)This can lead to various problems.
Relying on balance is not the best practice and other AMMs stores the reserve amounts as state variables and only use that for calculations.
ElasticSwap was exploited due to the similar vulnerability on the 12th of December, just a few days ago! Check here.
Tools Used
Manual Review
Recommended Mitigation Steps
Add new state variables like
reserveBase
andreserveFractional
and use them for buy/sell interactions.The text was updated successfully, but these errors were encountered: