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: 45/65
Findings: 1
Award: $39.22
๐ Selected for report: 0
๐ Solo Findings: 0
๐ 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
Misleading variable name
The local variable decimals
in both getPriceCanto()
and getPriceNote()
is not really decimals - it is 10 to the power of the token decimals. It is passed to the IBaseV1Pair::quote()
function as the granularity
argument. Rename variable from decimals
to `granularity
And again, decimals
in getPriceLP()
is not really decimals, but it is 10 to the power of a tokenโs decimals. It is passed to the IBaseV1Pair::sample()
function as the amountIn
argument. Rename variable from decimals
to amount
or amountIn
.
Inconsistent variable naming
In BaseV1-core.sol
for the reserves()
function we have a granularity
parameter. The problem is the same parameter is passed as the argument named points
for sampleReserves
. It is the same situation with totalSupplyAvg()
's granularity
and sampleSupply
's points
parameter. Choose only granularity
or only points
and stick to this naming to simplify the code for both developers and auditors.
Division before multiplication
In getPriceLP()
we have
uint token0TVL = assetReserves[i] * (prices[i] / decimals);
Where the division comes before the multiplication because of the braces. This is a bad practice in Solidity, because there is a loss of precision this way, and also if prices[i]
is smaller than decimals
then the division will return 0 and the value of token0TVL
will be zero, whatever the assetReserves[i]
are. So instead, first do the multiplication and then the division.
#0 - pashov
2022-09-11T16:00:31Z
Division before multiplication
is mentioned, which should be duplicate of #41