Submitted by carrotsmuggler, also found by 0xAlix2, 0xRajkumar, Abdessamed, carrotsmuggler, and LonnyFlash
/contracts/pool-manager/src/liquidity/commands.rs#L46-L74
/contracts/pool-manager/src/liquidity/commands.rs#L234-L239
The stableswap pools allow anyone to create pools following the stableswap formula with any number of tokens. This can be higher than 2. The issue is that the initial provide_liquidity does not check if ALL tokens are provided.
The provide_liquidity function does a number of checks. For the ConstantProduct pools, the constant product part uses both deposits[0] and deposits[1] to calculate the initial number of shares, and uses a product of the two. So anyone being absent or 0 leads to reverts during the initial liquidity addition itself.
However, the stableswap pools do not check if the initial liquidity provided is non-zero for all the tokens. So if only 2 of the three tokens are provided, the transaction still goes through. The only check is that all the passed in tokens must be pool constituents.
This leads to a broken pool, where further liquidity cannot be added anymore. This is because the pool is saved in a state where the pool has 0 liquidity for one of the tokens. Then in future liquidity additions, amount_times_coins value evaluates to 0 for those tokens, which eventually leads to a division by zero error in d_prod calculation.
Thus this leads to a broken pool and there is nothing in the contract preventing this.
Attached is a POC where a pool is created with 3 tokens [uwhale,uluna,uusd] but only 2 tokens are provided in the initial liquidity addition [uwhale, ulune]. Further liquidity additions revert due to division by zero error.
The above test passes, showing liquidity can be added with 2 tokens only. Further liquidity provision reverts.
Output:
Add a check to make sure if total supply=0, every token of the pool is provided as liquidity.
jvr0x (MANTRA) confirmed
