Platform: Code4rena
Start Date: 21/06/2022
Pot Size: $55,000 USDC
Total HM: 29
Participants: 88
Period: 5 days
Judge: gzeon
Total Solo HM: 7
Id: 134
League: ETH
Rank: 54/88
Findings: 2
Award: $126.97
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: defsec
Also found by: 0x1f8b, 0x29A, 0xDjango, 0xNazgul, 0xNineDec, 0xf15ers, 0xkowloon, 0xmint, Bnke0x0, BowTiedWardens, Chom, ElKu, Funen, GalloDaSballo, GimelSec, IllIllI, JC, Kenshin, Kulk0, Lambda, Limbooo, MadWookie, Metatron, Picodes, Soosh, StErMi, TomJ, WatchPug, Waze, Yiko, _Adam, ak1, asutorufos, aysha, bardamu, catchup, datapunk, delfin454000, dipp, fatherOfBlocks, grGred, hake, hansfriese, hyh, joestakey, kebabsec, kenzo, kirk-baird, oyc_109, pashov, poirots, rfa, robee, saian, sashik_eth, shenwilly, simon135, slywaters, z3s, zeesaw, zer0dot
63.8877 USDC - $63.89
Comments in production code should not contain developer discussion or notes about known bugs or problems. These issues should be tracked elsewhere and resolved before being deployed.
Comments of this kind can also indicate potential avenues of attack for an adversary.
The following lines are affected:
2022-06-illuminate/lender/Cast.sol:9: require(n <= type(uint128).max, ''); // TODO err msgs 2022-06-illuminate/lender/Element.sol:15: // TODO audit structure / names / order-of-members etc... 2022-06-illuminate/lender/Element.sol:8: // TODO are these established element names? kind? not type? etc... 2022-06-illuminate/lender/Element.sol:9: // TODO In, Out vs GIVEN_IN, GIVEN_OUT. If those names are needed they should be GivenIn etc... 2022-06-illuminate/lender/Safe.sol:4:// TODO audit for which methods are needed 2022-06-illuminate/redeemer/Safe.sol:4:// TODO audit for which methods are needed
🌟 Selected for report: BowTiedWardens
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xkowloon, Bnke0x0, ElKu, Fitraldys, Funen, GalloDaSballo, IllIllI, JC, Kaiziron, Lambda, MadWookie, Noah3o6, Nyamcil, RoiEvenHaim, TomJ, Tomio, UnusualTurtle, Waze, _Adam, ajtra, asutorufos, bardamu, c3phas, catchup, datapunk, defsec, delfin454000, fatherOfBlocks, grGred, hake, hansfriese, hyh, ignacio, joestakey, kebabsec, ladboy233, oyc_109, pashov, poirots, rfa, robee, sach1r0, samruna, sashik_eth, simon135, slywaters, z3s, zer0dot
63.0781 USDC - $63.08
Uninitialized variables by default contain a value equivalent to 0: uint
s are initialized to 0; bool
s to false; address
es to address(0)
.
Explicitly assigning these values to variables when they are declared increases gas costs while providing no funciton.
e.g. change this code:
uint256 var = 0;
to
uint256 var;
For more information, please consult the following resources:
Tips and Tricks to Save Gas and Reduce Bytecode Size
The following lines of code are affected:
2022-06-illuminate/lender/Lender.sol:265: for (uint256 i = 0; i < o.length; ) {
Using ++i
costs less gas than using i++
. In the context of a for-loop, gas is saved on each iteration.
The following lines of code are affected:
2022-06-illuminate/lender/Lender.sol:120: i++; 2022-06-illuminate/lender/Lender.sol:283: i++; 2022-06-illuminate/lender/Lender.sol:96: i++;
In the context of a for-loop that iterates over an array, it costs less gas to cache the array's length in a variable and read from this variable rather than use the arrays .length
property. Reading the .length
property for on the array will cause a recalculation of the array's length on each iteration of the loop which is a more expensive operation than reading from a stack variable.
For example, the following code:
for (uint i; i < arr.length; ++i) { // ... }
should be changed to:
uint length = arr.length; for (uint i; i < length; ++i) { // ... }
Note that in the second case, the length of the array must not change during the loop's execution.
For more information, see the following resource:
The following lines of code are affected:
2022-06-illuminate/lender/Lender.sol:265: for (uint256 i = 0; i < o.length; ) {
When compiled, Solidity code using the >=
or <=
comparison operators in fact executes two separate checks: one for 'is-equal-to' and a second for 'is-greater-than/is-less-than'. By contrast, using >
or <
performs only one check. Therefore code that is written to use strict comparison operators is more gas-efficient.
If this change is applied, be sure to update the relevant variables being evaluated. For clarity, it is also advised to rename the variables to make this change explicit, e.g. renaming a variable from MINIMUM
to MINIMUM_PLUS_ONE
.
The following lines are affected:
2022-06-illuminate/lender/Cast.sol:9: require(n <= type(uint128).max, ''); / TODO err msgs 2022-06-illuminate/lender/Lender.sol:693: require (block.timestamp >= when, 'withdrawal still on hold'); 2022-06-illuminate/marketplace/ERC20.sol:116: require(_balanceOf[src] >= wad, "ERC20: Insufficient balance"); 2022-06-illuminate/marketplace/ERC20.sol:152: require(allowed >= wad, "ERC20: Insufficient approval"); 2022-06-illuminate/marketplace/ERC20.sol:189: require(_balanceOf[src] >= wad, "ERC20: Insufficient balance"); 2022-06-illuminate/marketplace/ERC20Permit.sol:56: require(deadline >= block.timestamp, "ERC20Permit: expired deadline"); 2022-06-illuminate/marketplace/ERC5095.sol:100: require(_allowance[holder][msg.sender] >= underlyingAmount, 'not enough approvals'); 2022-06-illuminate/marketplace/ERC5095.sol:116: require(_allowance[holder][msg.sender] >= underlyingAmount, 'not enough approvals');
The pragma declaration allows for Solidity versions less than version 0.8.4. Several gas optimization features have been introduced in versions of Solidity between 0.8.0 and 0.8.4, including:
Please note that Solidity version 0.8.9 contains bugfixes in addition to these gas improvements and that if possible it is advised to use versions greater than or equal to 0.8.9 for additional benefit.
For more information consult the following resources:
The following pragma statements should be updated:
2022-06-illuminate/marketplace/ERC20.sol:3:pragma solidity ^0.8.0; 2022-06-illuminate/marketplace/ERC20Permit.sol:3:pragma solidity ^0.8.0;