Submitted by qpzm, also found by CRIMSON-RAT-REACH
https://github.com/code-423n4/2023-07-basin/blob/main/src/functions/ConstantProduct2.sol#L65-L66 https://github.com/code-423n4/2023-07-basin/blob/main/src/Well.sol#L590-L598 https://github.com/code-423n4/2023-07-basin/blob/main/src/Well.sol#L695-L702 https://github.com/code-423n4/2023-07-basin/blob/main/src/Well.sol#L541 https://github.com/code-423n4/2023-07-basin/blob/main/src/Well.sol#L562 https://github.com/code-423n4/2023-07-basin/blob/main/src/Well.sol#L582
Let reserves returned by Well._getReserves() as x, y and Well.tokenSupply() as k.
They must maintain the invariant x * y * EXP_PRECISION = k ** 2.
However, the reserves can increase without updating the token supply if a user transfers one token of the well and call Well.sync().
We can sync the reserves and balances using Well.sync, but there is no way to sync Well.tokenSupply() ** 2 to x * y * EXP_PRECISION.
ConstantProduct2.calcReserve assumes Well.tokenSupply equals to reserves[0] * reserves[1].
This exception breaks the assumption and reverts normal transactions.
For example, when Well.totalSupply is less than reserves[0] * reserves[1], Well.removeLiquidityImbalanced may revert.
In Well.sync(), mint (reserves[0] * reserves[1] * ConstantProduct2.EXP_PRECISION).sqrt() - totalSupply() Well tokens to msg.sender.
This keeps the invariant that Well.tokenSupply() ** 2 equals to reserves[0] * reserves[1] * ConstantProduct2.EXP_PRECISION as long as the swap fee is 0.
publiuss (Basin) confirmed via duplicate issue #210
trust1995 (Warden) commented:
alcueca (Judge) commented:
trust1995 (Warden) commented:
lokithe5th (Warden) commented:
alcueca (Judge) decreased severity to Medium and commented:
publiuss (Basin) commented:
