`reserve balances` AND `reserve balance ratio` INVARIANTS ARE NOT CHECKED INSIDE THE `_reserveTokenSpecified` FUNCTION THUS ENABLING `deposit` AND `withdraw` TRANSACTIONS TO BREAK THESE INVARIANTS
Audit: 2023-08-shell-findings
Severity: HIGH

# Lines of code

https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L563-L595
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L809-L814
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L549
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L552
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L641
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L644


# Vulnerability details

## Impact

The `EvolvingProteus.depositGivenInputAmount` function is used to calculate the output amount of LP tokens given an input amount of reserve tokens.

The `EvolvingProteus.withdrawGivenOutputAmount` function is used to calculate the amount of LP tokens that must be burned given an output amount of reserve token.

Both above functions will calculate the `changed LP token supply` `proportionately` to the `change in the utility of the pool`.

In the function execution of the above two functions (`depositGivenInputAmount` and `withdrawGivenOutputAmount`) the `_reserveTokenSpecified` internal function is called.

The `_reserveTokenSpecified` function is used to compute the `changed amount` of the `LP token supply` based on the `proportional change of the utility` of the pool.

The issue here is that after the LP token total supply change calculation, there is no check performed on the token balance reserves and balance reserve ratio. Hence this function does not verify whether the reserve balances are within the valid boundaries once the transaction is performed.

Both the `EvolvingProteus._swap` function and the `EvolvingProteus._lpTokenSpecified` functions ensure that reserve balances are within valid boundaries once the respective transactions are completed by calling the `EvolvingProteus._checkBalances` private function. But the `_reserveTokenSpecified` function does not call on the `EvolvingProteus._checkBalances` function to verify whether the reserve balances are within the valid boundaries once the transaction is completed.

The `EvolvingProteus.depositGivenInputAmount` transaction will deposit an amount of specified token amount, which could decrease the `y.divi(x)` (here y is the non-specified token amount and x is the specified token amount deposited) below the `MIN_M` value (since x is increasing as its getting deposited). Hence the transaction should revert since the reserve token balance ratio is invalid. But the transaction will execute successfully because there is no check performed to identify this issue.

Similarly when calling the `EvolvingProteus.withdrawGivenOutputAmount` transaction, an amount of specified token will be withdrawn from the pool. This will decrease the specified token balance of the pool and could increase the `y.divi(x)` ratio (since x is the specified token and it is getting decreased thus increasing the ratio) bey