Platform: Code4rena
Start Date: 07/09/2022
Pot Size: $20,000 CANTO
Total HM: 7
Participants: 65
Period: 1 day
Judge: 0xean
Total Solo HM: 3
Id: 159
League: ETH
Rank: 18/65
Findings: 2
Award: $146.62
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: hickuphh3
Also found by: 0xNazgul, 0xSky, CertoraInc, Deivitto, Jeiwan, SinceJuly, hansfriese, linmiaomiao, rbserver
During the token0TVL
calculation, it divides by decimals
without multiplying 1e18
first.
So there might be division loss and the price might be calculated wrongly.
When we calculate this part, it divides first without multiplying 1e18
.
File: 2022-09-canto\src\Swap\BaseV1-periphery.sol 582: uint token0TVL = assetReserves[i] * (prices[i] / decimals);
Solidity Visual Developer of VSCode
First, we can modify this part like below.
uint token0TVL = assetReserves[i] * prices[i] * 1e18 / decimals; uint token1TVL = unitReserves[i] * 1e18; // price of the unit asset is always 1 LpPricesCumulative += (token0TVL + token1TVL) / supply[i];
Btw for the token0TVL
calculation, I am not so sure there won't be any uint overflow and I think we can modify like below for safety.
uint token0TVL; if(1e18 >= decimals) { uint diff = 1e18 / decimals; token0TVL = assetReserves[i] * prices[i] * diff; } else { uint diff = decimals / 1e18; token0TVL = assetReserves[i] * prices[i] / diff; } uint token1TVL = unitReserves[i] * 1e18; // price of the unit asset is always 1 LpPricesCumulative += (token0TVL + token1TVL) / supply[i];
#0 - nivasan1
2022-09-09T17:40:46Z
duplicate #41
🌟 Selected for report: lukris02
Also found by: 0x040, 0x1f8b, 0x52, 0xA5DF, 0xNazgul, 0xSky, Bnke0x0, Bronicle, CertoraInc, Chom, CodingNameKiki, Deivitto, Diraco, Dravee, EthLedger, IgnacioB, JC, JansenC, Jeiwan, R2, RaymondFam, ReyAdmirado, Rolezn, SinceJuly, TomJ, Tomo, Yiko, a12jmx, ajtra, ak1, codexploder, cryptphi, csanuragjain, erictee, fatherOfBlocks, gogo, hake, hansfriese, hickuphh3, ignacio, ontofractal, oyc_109, p_crypt0, pashov, peritoflores, rajatbeladiya, rbserver, rokinot, rvierdiiev, tnevler
242.8216 CANTO - $39.22
30 minutes
should be changed to periodSize
because it can be changed by admin.
We can define constants like `DEFAULT_POINT = 8, DEFAULT_WINDOW = 1'
Change an
to a
.