H-1: The swap and stake mechanisms in OpenMevZapper leave funds in the contract (Jackson)
Summary:
Half of the input amount in both swapAndStakeLiquidity and swapETHAndStakeLiquidity is used as the swapAmountIn when atomically swapping and staking. However, this leaves funds in the contract due to the reserve asset ratio change post-swap. See "Optimal One-sided Supply to Uniswap" for more information.
Proof of concept:
Both swapAndStakeLiquidity and swapETHAndStakeLiquidity take the input tokens or ETH sent by a user, divide it by 2, swap it into the B token, and stake these tokens as a pair. However, this approach leaves some of the B token in the contract due to the reserve asset ratio change before and after the swap.
Impact:
High. The funds are not returned to the user, and will likely be swept by Sushi governance during a call to harvest.
Recommendation:
Use the formula found in "Optimal One-sided Supply to Uniswap" for the swapAmountIn, rather than / 2.
sqrt(
reserveIn.mul(userIn.mul(3988000) + reserveIn.mul(3988009)))
.sub(reserveIn.mul(1997)) / 1994;
