-
Notifications
You must be signed in to change notification settings - Fork 7
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
Dilution of Initial Liquidity Providers Shares in MagicLP::buyShares Disincentivizes other LPs #138
Comments
141345 marked the issue as insufficient quality report |
dilute initial lp seems expected behavior, and the loss is not significant |
141345 marked the issue as sufficient quality report |
expected behavior, it's a fork of dodo v2 and it's working like this |
0xCalibur (sponsor) disputed |
This is the solution to the inflation attack, which is also used in Uniswap v2.
And still invalid, this will just have dust loss, which is acceptable for solving inflation attacks |
thereksfour marked the issue as unsatisfactory: |
Hi I believe this is valid issue |
Nevermind I thought pjqa was open.. I'll wait to prove submission then |
Lines of code
https://github.com/code-423n4/2024-03-abracadabra-money/blob/1f4693fdbf33e9ad28132643e2d6f7635834c6c6/src/mimswap/MagicLP.sol#L393
Vulnerability details
Summary
The
MagicLP
contract implements a unique mechanism where, upon the first provision of liquidity, it mints 1001 shares to the address(0) and subsequently reduces the shares allocated to the initial liquidity provider by the same amount. While this appears to serve as a safeguard to ensure a minimal non-removable liquidity base, it inadvertently dilutes the initial liquidity provider's ownership in the liquidity pool.Details
Upon the initial provision of liquidity (when
totalSupply() == 0
), the contract calculates the shares based on the provided base and quote token amounts. Instead of allocating all calculated shares to the liquidity provider, it mints 1001 shares to address(0) and reduces the provider's shares by the same amount.https://github.com/code-423n4/2024-03-abracadabra-money/blob/1f4693fdbf33e9ad28132643e2d6f7635834c6c6/src/mimswap/MagicLP.sol#L375C9-L394C28
Requiring that a portion of the liquidity cannot be removed might make certain manipulative strategies less feasible or attractive by ensuring that the pool always maintains a basic level of operation, regardless of external attempts to manipulate its liquidity or price. This attack vector seems to be what warrants this feature but there are better ways to deal with such edge cases
Impact
The initial liquidity provider receives fewer shares than calculated for their liquidity contribution. This dilution reduces their proportionate ownership in the pool and their share of future fee earnings.
Steps to Reproduce
MagicLP
contract and initialize it with base and quote tokens.buyShares(address to)
as the first liquidity provider and provide base and quote tokens.to
are 1001 less than the expected amount based on the provided liquidity, with 1001 shares minted to address(0).Poc
Output
Mitigation
Create a separate mechanism that explicitly locks a minimal amount of liquidity in a transparent and fair manner. This approach can avoid the direct dilution of the initial provider's shares while still providing the pool with a safeguard against rapid liquidity withdrawal or manipulation.
Proposed code changes:
Explanation:
Introduce
lockedLiquidityBase
andlockedLiquidityQuote
to track the amount of base and quote tokens that are locked and cannot be immediately removed from the pool. This approach provides clarity and transparency on how much liquidity is permanently in the pool.During the first liquidity provision, instead of minting and subtracting shares, calculate the amount of base and quote tokens to be locked based on the initial liquidity. This ensures the pool has a minimal operational buffer without reducing the initial provider's shares.
When calculating shares for the initial provider, adjust the calculation to account for the locked liquidity, ensuring the provider's shares represent their actual contribution minus the locked portion.
Assessed type
Other
The text was updated successfully, but these errors were encountered: