Platform: Code4rena
Start Date: 07/01/2022
Pot Size: $80,000 USDC
Total HM: 21
Participants: 37
Period: 7 days
Judge: 0xean
Total Solo HM: 14
Id: 71
League: ETH
Rank: 31/37
Findings: 1
Award: $10.56
🌟 Selected for report: 0
🚀 Solo Findings: 0
3.723 INSURE - $1.30
1.9546 USDC - $1.95
0x0x0x
Applying == true
doesn't make any difference and consume extra gas. Since this operation can be seen as an identity function.
./Factory.sol:122: templates[address(_template)].approval == true, ./Factory.sol:142: templates[address(_template)].approval == true, ./Factory.sol:166: templates[address(_template)].approval == true, ./Factory.sol:178: reflist[address(_template)][i][_references[i]] == true || ./Factory.sol:179: reflist[address(_template)][i][address(0)] == true, ./IndexTemplate.sol:365: IPoolTemplate(_pool).paused() == true ./PoolTemplate.sol:354: insurances[_id].status == true && ./PoolTemplate.sol:550: require(_insurance.status == true, "ERROR: INSURANCE_NOT_ACTIVE"); ./PoolTemplate.sol:612: insurance.status == true,
#0 - oishun1112
2022-01-13T17:26:31Z
0x0x0x
Example:
for (uint i = 0; i < arr.length; i++) { //Operations not effecting the length of the array. }
Loading length of array costs gas. Therefore, the length should be cached, if the length of the array doesn't change inside the loop. Furthermore, there is no need to assign the initial value 0. This csts extra gas.
Recommended implementation:
uint length = arr.length; for (uint i; i < length; ++i) { //Operations not effecting the length of the array. }
By doing so the length is only loaded once rather than loading it as many times as iterations (Therefore, less gas is spent).
./Factory.sol:176: for (uint256 i = 0; i < _references.length; i++) { ./Factory.sol:186: for (uint256 i = 0; i < _conditions.length; i++) { ./IndexTemplate.sol:280: for (uint256 i = 0; i < _length; i++) { ./IndexTemplate.sol:348: for (uint256 i = 0; i < _length; i++) { ./IndexTemplate.sol:381: for (uint256 i = 0; i < _length; i++) { ./IndexTemplate.sol:655: for (uint256 i = 0; i < poolList.length; i++) { ./PoolTemplate.sol:343: for (uint256 i = 0; i < _ids.length; i++) { ./PoolTemplate.sol:671: for (uint256 i = 0; i < indexList.length; i++) { ./PoolTemplate.sol:703: for (uint256 i = 0; i < indexList.length; i++) {
#0 - oishun1112
2022-01-16T06:14:26Z
2.9784 INSURE - $1.04
1.5637 USDC - $1.56
0x0x0x
Adding one costs more gas than preincrementation ++
. Incrementation is a better optimized way of obtaining the same functionality.
allInsuranceCount += 1;
can be replaced with ++allInsuranceCount;
.
./PoolTemplate.sol:518: allInsuranceCount += 1; ./PoolTemplate.sol:931: if (a % b != 0) c = c + 1; ./PremiumModels/BondingPremium.sol:239: uint256 z = (x + 1) / 2;
#0 - blue32captain
2022-01-20T07:28:07Z
./PremiumModels/BondingPremium.sol:239: uint256 z = (x + 1) / 2; This should not be changed since it's used under codes.
#1 - 0xean
2022-01-28T02:44:12Z
dupe of #76
2.9784 INSURE - $1.04
1.5637 USDC - $1.56
0x0x0x
!= 0
is a cheaper operation compared to > 0
, when dealing with uint
.
./CDSTemplate.sol:100: bytes(_metaData).length > 0 && ./CDSTemplate.sol:132: require(_amount > 0, "ERROR: DEPOSIT_ZERO"); ./CDSTemplate.sol:140: if (_supply > 0 && _liquidity > 0) { ./CDSTemplate.sol:142: } else if (_supply > 0 && _liquidity == 0) { ./CDSTemplate.sol:191: require(_amount > 0, "ERROR: REQUEST_ZERO"); ./CDSTemplate.sol:223: require(_amount > 0, "ERROR: WITHDRAWAL_ZERO"); ./CDSTemplate.sol:296: if (totalSupply() > 0) { ./Factory.sol:175: if (_references.length > 0) { ./Factory.sol:185: if (_conditions.length > 0) { ./Factory.sol:187: if (conditionlist[address(_template)][i] > 0) { ./IndexTemplate.sol:133: bytes(_metaData).length > 0 && ./IndexTemplate.sol:166: require(_amount > 0, "ERROR: DEPOSIT_ZERO"); ./IndexTemplate.sol:172: if (_supply > 0 && _totalLiquidity > 0) { ./IndexTemplate.sol:174: } else if (_supply > 0 && _totalLiquidity == 0) { ./IndexTemplate.sol:199: require(_amount > 0, "ERROR: REQUEST_ZERO"); ./IndexTemplate.sol:231: require(_amount > 0, "ERROR: WITHDRAWAL_ZERO"); ./IndexTemplate.sol:246: if (_liquidityAfter > 0) { ./IndexTemplate.sol:274: if(_totalLiquidity > 0){ ./IndexTemplate.sol:283: if (_allocPoint > 0) { ./IndexTemplate.sol:427: allocPoints[msg.sender] > 0, ./IndexTemplate.sol:477: require(allocPoints[msg.sender] > 0); ./IndexTemplate.sol:493: if (totalLiquidity() > 0) { ./IndexTemplate.sol:513: if (totalSupply() > 0) { ./IndexTemplate.sol:612: if (totalAllocPoint > 0) { ./IndexTemplate.sol:656: if (allocPoints[poolList[i]] > 0) { ./PoolTemplate.sol:185: bytes(_metaData).length > 0 && ./PoolTemplate.sol:218: if (_conditions[1] > 0) { ./PoolTemplate.sol:237: require(_amount > 0, "ERROR: DEPOSIT_ZERO"); ./PoolTemplate.sol:263: require(_amount > 0, "ERROR: DEPOSIT_ZERO"); ./PoolTemplate.sol:282: require(_amount > 0, "ERROR: REQUEST_ZERO"); ./PoolTemplate.sol:321: require(_amount > 0, "ERROR: WITHDRAWAL_ZERO"); ./PoolTemplate.sol:391: } else if (_index.credit > 0) { ./PoolTemplate.sol:396: if (_pending > 0) { ./PoolTemplate.sol:401: if (_credit > 0) { ./PoolTemplate.sol:437: if (_credit > 0) { ./PoolTemplate.sol:444: if (_pending > 0) { ./PoolTemplate.sol:521: if (_totalCredit > 0) { ./PoolTemplate.sol:672: if (indicies[indexList[i]].credit > 0) { ./PoolTemplate.sol:706: if (_credit > 0) { ./PoolTemplate.sol:726: if (_deductionFromPool > 0) { ./PoolTemplate.sol:745: if (totalSupply() > 0) { ./PoolTemplate.sol:802: if (_supply > 0 && _originalLiquidity > 0) { ./PoolTemplate.sol:804: } else if (_supply > 0 && _originalLiquidity == 0) { ./PoolTemplate.sol:835: if (totalLiquidity() > 0) { ./PoolTemplate.sol:847: if (lockedAmount > 0) { ./PoolTemplate.sol:929: require(b > 0); ./Vault.sol:154: attributions[msg.sender] > 0 && ./Vault.sol:187: attributions[msg.sender] > 0 && ./Vault.sol:220: attributions[msg.sender] > 0 && ./Vault.sol:347: if (_amount > 0) { ./Vault.sol:388: if (totalAttributions > 0 && _attribution > 0) { ./Vault.sol:406: if (attributions[_target] > 0) { ./Vault.sol:473: } else if (IERC20(_token).balanceOf(address(this)) > 0) {
#0 - oishun1112
2022-01-17T09:26:03Z
#1 - 0xean
2022-01-28T00:07:44Z
dupe of #36