Platform: Code4rena
Start Date: 28/04/2022
Pot Size: $50,000 USDC
Total HM: 7
Participants: 43
Period: 5 days
Judge: gzeon
Total Solo HM: 2
Id: 115
League: ETH
Rank: 28/43
Findings: 1
Award: $104.94
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Dravee
Also found by: 0x1f8b, 0x4non, 0x52, 0xDjango, AlleyCat, Funen, GalloDaSballo, GimelSec, Hawkeye, MaratCerby, Picodes, berndartmueller, cccz, defsec, delfin454000, dipp, hyh, ilan, joestakey, kebabsec, luduvigo, pauliax, peritoflores, robee, rotcivegaf, samruna, shenwilly, sikorico, simon135, sorrynotsorry, unforgiven, z3s
104.9405 USDC - $104.94
In the function convertTo#PriceFeed.sol
(and other) there is a serie of 2 sequential divs. This is not a good idea because you are losing precision. When possible it is better to calculate the numerator, then the denominator and finally divide. In addition division is more gas expensive.
return _amount.mul(collateralAccuracy).div(price).div(parAccuracy);
https://github.com/code-423n4/2021-07-sherlock-findings/issues/24
Use this formula instead
return _amount.mul(collateralAccuracy).div(price.mul(parAccuracy));