Platform: Code4rena
Start Date: 03/11/2022
Pot Size: $115,500 USDC
Total HM: 17
Participants: 120
Period: 7 days
Judge: LSDan
Total Solo HM: 1
Id: 174
League: ETH
Rank: 57/120
Findings: 2
Award: $110.58
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0xNazgul, 0xRoxas, 0xSmartContract, Awesome, Aymen0909, B2, BClabs, Bnke0x0, Deekshith99, Deivitto, Diana, Dinesh11G, Funen, HE1M, HardlyCodeMan, Josiah, Nyx, Rahoz, RaymondFam, RedOneN, ReyAdmirado, Rolezn, Saintcode_, TomJ, Trust, __141345__, a12jmx, adriro, ajtra, aphak5010, apostle0x01, brgltd, btk, bulej93, c3phas, carlitox477, catwhiskeys, ch0bu, chaduke, chrisdior4, cryptonue, cryptostellar5, csanuragjain, ctf_sec, delfin454000, djxploit, durianSausage, erictee, fatherOfBlocks, gogo, i_got_hacked, immeas, joestakey, jumpdest7d, lukris02, martin, mcwildy, merlin, minhquanym, oyc_109, pashov, peanuts, pedr02b2, rbserver, rotcivegaf, rvierdiiev, sakman, saneryee, seyni, shark, slowmoses, tnevler, trustindistrust, w0Lfrum, yurahod, zaskoh
61.3462 USDC - $61.35
address(0)
check in LineFactory
constructorChange this:
constructor( address moduleFactory, address arbiter_, address oracle_, address swapTarget_ ) { factory = IModuleFactory(moduleFactory); if (arbiter_ == address(0)) { revert InvalidArbiterAddress(); } if (oracle_ == address(0)) { revert InvalidOracleAddress(); } if (swapTarget_ == address(0)) { revert InvalidSwapTargetAddress(); } arbiter = arbiter_; oracle = oracle_; swapTarget = swapTarget_; }
To this:
constructor( address moduleFactory_, address arbiter_, address oracle_, address swapTarget_ ) { if (moduleFactory_ == address(0)) { revert InvalidModuleFactoryAddress(); } if (arbiter_ == address(0)) { revert InvalidArbiterAddress(); } if (oracle_ == address(0)) { revert InvalidOracleAddress(); } if (swapTarget_ == address(0)) { revert InvalidSwapTargetAddress(); } factory = IModuleFactory(moduleFactory_); arbiter = arbiter_; oracle = oracle_; swapTarget = swapTarget_; }
#0 - c4-judge
2022-12-06T22:02:07Z
dmvt marked the issue as grade-b
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0xRajkumar, Awesome, Aymen0909, B2, Bnke0x0, Deivitto, Diana, JC, Metatron, Rahoz, RaymondFam, RedOneN, ReyAdmirado, Rolezn, Saintcode_, TomJ, __141345__, ajtra, aphak5010, brgltd, c3phas, ch0bu, chrisdior4, cryptonue, durianSausage, emrekocak, erictee, exolorkistis, gogo, karanctf, lukris02, martin, me_na0mi, oyc_109, peanuts, rotcivegaf, saneryee, seyni, tnevler, zaskoh
49.2315 USDC - $49.23
I only put the instances for which there wasn't a trade off between gas saving for deployment vs methods.
Optimizer settings:
optimizer = true optimizer_runs = 200
storage
pointer to a structure is cheaper than copying each value of the structure into memory
For instance, change this:
Credit memory credit = credits[id];
To this:
Credit storage credit = credits[id];
Deployment | $\Delta$ Average gas |
---|---|
LineOfCredit | 1400 |
Methods | $\Delta$ Average gas |
---|---|
accrueInterest | 12 |
init()(bool) | 198 |
setRates | 1 |
Credit memory credit = credits[id];
Credit memory credit = credits[id];
Deployment | $\Delta$ Average gas |
---|---|
InterestRateCredit | 8Â 006 |
Methods | $\Delta$ Average gas |
---|---|
accrueInterest | 4 |
Rate memory rate = rates[id];
Methods | $\Delta$ Average gas |
---|---|
addCollateral | 3Â 681 |
getCollateralRatio | 939 |
getCollateralValue | 7764 |
IEscrow.Deposit memory d;
Deployment | $\Delta$ Average gas |
---|---|
InterestRateCredit | 3Â 006 |
Methods | $\Delta$ Average gas |
---|---|
accrueInterest | 100 |
InterestRateCredit.sol#L47-L50
Change this:
Rate memory rate = rates[id]; uint256 timespan = block.timestamp - rate.lastAccrued; // update last timestamp in storage rates[id].lastAccrued = block.timestamp;
To this (rate
data location has been set to storage
in [G-01]
):
Rate storage rate = rates[id]; uint256 timespan = block.timestamp - rate.lastAccrued; // update last timestamp in storage rate.lastAccrued = block.timestamp;
#0 - c4-judge
2022-11-17T22:59:12Z
dmvt marked the issue as grade-b