Omniscia Kyo Finance Audit

UniswapV2Gauge Manual Review Findings

UniswapV2Gauge Manual Review Findings

UVG-01M: Inexplicable Multiplication of Constant Product Liquidity Calculation

Description:

The canonical liquidity calculation of Uniswap V2 for the product K is as follows:

\sqrt{r_0 * r_1}

The Kyo Finance team has implemented the same formula albeit with a multiplication by 2, causing the share system of the UniswapV2Gauge to be an extrapolation of the actual liquidity in the Uniswap V2 AMM pair rather than an interpolation.

Impact:

The UniswapV2Gauge share calculations are incorrectly offset by a multiplication of 2 that might result in an artificial reduction of withdrawn assets.

Example:

contracts/voting/uniswap-v2/UniswapV2Gauge.sol
34function _convertToShares(uint256 assets, Math.Rounding rounding) internal view override returns (uint256) {
35 (uint112 r0, uint112 r1,) = pair.getReserves();
36 uint256 totalPairLiquidity = 2 * Math.sqrt(uint256(r0) * uint256(r1));
37 uint256 totalPairSupply = pair.totalSupply();
38 if (totalPairSupply == 0) return 0;
39 return Math.mulDiv(assets, totalPairLiquidity, totalPairSupply, rounding);
40}
41
42function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view override returns (uint256) {
43 (uint112 r0, uint112 r1,) = pair.getReserves();
44 uint256 totalPairLiquidity = 2 * Math.sqrt(uint256(r0) * uint256(r1));
45 if (totalPairLiquidity == 0) return 0;
46 return Math.mulDiv(shares, pair.totalSupply(), totalPairLiquidity, rounding);
47}

Recommendation:

We advise this multiplication to be removed, ensuring that the total share values of the UniswapV2Gauge more closely correlate with the liquidity in the AMM pair.

Alleviation (17c8d4e59f398021156f6f9657ff278aae0462ae):

The multiplication by 2 was omitted as advised, ensuring that the constant product formula is properly calculated.