A malicious pool creator or first depositor can make depositing and removing liquidity unfavorable for other users. #25
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-13
edited-by-warden
grade-a
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_02_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-05-canto/blob/d1d51b2293d4689f467b8b1c82bba84f8f7ea008/canto-main/x/coinswap/keeper/keeper.go#L149
Vulnerability details
Impact
Users who add liquidity to the pool can lose funds and also, amount of max tokens that users can deposit would be severely truncated for a period of time.
Proof of Concept
There are 2 ways for the pool creator or first depositor to make using a pool unfavourable to users.
Let's assume a user wants to make a standard deposit of 50,000 tokens. The deposit token is calculated as
1 * 50,000/100,000+1
. This gives the user the ability to only deposit 1 max tokens despite probably expecting to deposit more.This limits the addliquidity functionality of that pool for many transactions until tokenReserveAmount eventually becomes a significant value. This action can serve to deter users from using the pool.
2. Pool creator creates a pool with standardInputAmount of 100,000 and tokenReserve of 100,000. Then sends 50,000 standard coins directly to the pool. This causes the standardReserveAmount to become larger than the lpLiquidity. When another user deposits 100,000 tokens, they get 66666 of mintliquidity and deposit 66667 of max tokens. If that user wants to remove their liquidity, they only get 99,999 of their standardCoin deposit back, having lost 1 token to the pool. The original pool creator retains all his assets. If sufficient number of users lose assets to the pool, the pool creator gains the lost assets added to his liquidity.
Tools Used
Manual Review
Recommended Mitigation Steps
For the 2nd, consider preventing direct transfers of tokens to the pool. This would ensure correct accounting
Assessed type
Math
The text was updated successfully, but these errors were encountered: