The Mantra DEX attempts to protect against first depositor attacks by implementing a minimum liquidity mechanism, similar to that of Uniswap.
Before going further we can have an overview of the bug case here:
And we know that in order for this attack to be possible, two conditions need to be met:
However, the implementation has a flaw in how these minimum liquidity tokens that are expected to be used to protect against the 1 mint of share are stored/sent:
/contracts/pool-manager/src/liquidity/commands.rs#L184-L213
Thats to say in the case the case we have zero shares then we send the minimum liquidity amount to the contract instead of to the burn/dead address as is done in Uniswap.
This creates a vulnerability that could be exploited through the following steps:
Below we subtly assume that admin introduces a new functionality that could then allow for access to this contract owned tokens.
Impact is quite high as we then are back open to first depositor attack, since after the user withdraws back and leaves just 1 share, the next depositor would receive a massively unfair exchange rate which allows the malicious user to backrun the tx and skew off these assets. Albeit, we have to classify as QA, considering currently there is no how we can access directly the minimum liquidity tokens, i.e., funds in the contract and it needs to be via an introduced function in an upgrade or some sort.
Would be key to note that asides the admin window we could still have an issue where there is a mismatch between the amount of pool assets and the amount of minted lp tokens; which is because when minting the lp tokens, we use the checked_add function, which does not overflow, so the last user that deposits and every that deposits to pass the maximum value would then cause a mismatch in the amount of pool assets and the amount of lp tokens minted:
/contracts/pool-manager/src/liquidity/commands.rs#L376-L390
Follow Uniswaps approach of permanently burning minimum liquidity tokens, this can be done by using the same approach as to when liquidity is being withdrawn:
