Multiple essential functions in the HybridPool contract is assuming the reserves are stored as shares instead of underlying token amounts, which makes this issue impacts many functions, the impact of the swap() function allows the stolen of a large portion of the funds in the pool.
Other functions that are malfunctioned because of this issue include:
mint()
flashSwap()
burnSingle()
getVirtualPrice()
getAmountOut()
Proof of Concept
HybridPool.swap is using an unchecked calculation for amountIn: amountIn = balance0 - _reserve0;, when _reserve0 > balance0, it underflows and become an extremly large number.
amountOut will then be extremely large, near the outToken balance amount.
As a result, the attacker can steal almost all of the outToken in the pool.
Handle
WatchPug
Vulnerability details
https://github.com/sushiswap/trident/blob/9f949d9bddf7f12775e0c6ae641e9305c4762ea2/contracts/pool/HybridPool.sol#L277-L288
HybridPool._updateReserves()
is supposed to update the reserves to the latest bento share amounts. Instead, it uses underlying token amounts.In the
_getReserves()
function, reserves are treated as bento share amounts and get converted to underlying token amounts again.When the price per share is smaller or larger than
1
, the result of_getReserves()
can be different from the actual underlying token amounts by a lot.Impact
Multiple essential functions in the HybridPool contract is assuming the reserves are stored as shares instead of underlying token amounts, which makes this issue impacts many functions, the impact of the swap() function allows the stolen of a large portion of the funds in the pool.
Other functions that are malfunctioned because of this issue include:
Proof of Concept
HybridPool.swap
is using an unchecked calculation for amountIn:amountIn = balance0 - _reserve0;
, when_reserve0
>balance0
, it underflows and become an extremly large number.amountOut
will then be extremely large, near the outToken balance amount.As a result, the attacker can steal almost all of the outToken in the pool.
https://github.com/sushiswap/trident/blob/9f949d9bddf7f12775e0c6ae641e9305c4762ea2/contracts/pool/HybridPool.sol#L179-L202
Recommendation
Change to: