Platform: Code4rena
Start Date: 14/06/2022
Pot Size: $100,000 USDC
Total HM: 26
Participants: 59
Period: 7 days
Judge: GalloDaSballo
Total Solo HM: 9
Id: 133
League: ETH
Rank: 59/59
Findings: 1
Award: $103.77
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: _Adam
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xmint, Chom, Dravee, Fitraldys, Funen, JC, Limbooo, MadWookie, Picodes, Ruhum, TerrierLover, TomJ, Tomio, Waze, ak1, c3phas, catchup, defsec, fatherOfBlocks, gzeon, hake, hansfriese, joestakey, k, oyc_109, rfa, robee, sach1r0, saian, simon135, ynnad
39.6748 USDC - $39.67
396.9199 CANTO - $64.10
CToken.sol
sloc : 266, 267
uint principalTimesIndex = borrowSnapshot.principal * borrowIndex; return principalTimesIndex / borrowSnapshot.interestIndex;
we can avoid using extra variable, this could save gas
and can have like this
return (borrowSnapshot.principal * borrowIndex) / borrowSnapshot.interestIndex;
inside mintFresh function,
in line 214 , 217
require(getCashPrior() == actualMintAmount, "CNote::mintFresh: Error in doTransferIn, CNote reserves >= mint Amount"); //sanity check that Accountant has some thing to redeem //underlying.balanceOf(address(this)) == repayAmount; uint amtMinted = getCashPrior(); uint err = _accountant.redeemMarket(amtMinted); if (err != 0) { revert AccountantRedeemError(amtMinted); }
getCashPrior() can be called once and assigned to a variable and that variable can be used. This will save gas. likewise some other places also could be checked.
Comptroller.sol
inside function claimComp, pre-increment operator can be used. declaring int j as common variable inside the function and use it wherever possible by proper initilization.
NoteInterest.sol
function getBorrowRate(uint cash, uint borrows, uint reserves) public view override returns (uint) { // Gets the Note/gUSDC TWAP in a given interval, as a mantissa (scaled by 1e18) // uint twapMantissa = getUnderlyingPrice(note); uint rand = uint(keccak256(abi.encodePacked(msg.sender))) % 100; uint ir = (100 - rand).mul(adjusterCoefficient).add(baseRatePerYear).mul(1e16); uint newRatePerYear = ir >= 0 ? ir : 0; // convert it to base rate per block uint newRatePerBlock = newRatePerYear.div(blocksPerYear); return newRatePerBlock; } line no - 96, value should be 1e18 not the 1e16.
#0 - GalloDaSballo
2022-08-04T00:16:17Z
Poorly formatted, less than 100 gas saved.
I'm conflicted in closing as spam