Canto contest - ak1's results

Execution layer for original work.

General Information

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

Canto

Findings Distribution

Researcher Performance

Rank: 59/59

Findings: 1

Award: $103.77

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

39.6748 USDC - $39.67

396.9199 CANTO - $64.10

Labels

bug
G (Gas Optimization)

External Links

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

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter