Platform: Code4rena
Start Date: 13/01/2022
Pot Size: $75,000 USDC
Total HM: 9
Participants: 27
Period: 7 days
Judge: leastwood
Total Solo HM: 5
Id: 73
League: ETH
Rank: 19/27
Findings: 1
Award: $59.12
🌟 Selected for report: 1
🚀 Solo Findings: 0
0.0614 LPT - $2.28
6.2568 USDC - $6.26
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 costs 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).
./protocol/governance/Governor.sol:89: for (uint256 i = 0; i < _update.target.length; i++) { ./protocol/pm/mixins/MixinTicketProcessor.sol:76: require(_auxData.length == 64, "invalid length for ticket auxData: must be 64 bytes"); ./protocol/pm/mixins/MixinWrappers.sol:20: for (uint256 i = 0; i < _tickets.length; i++) { ./protocol/test/helpers/truffle/AssertAddressArray.sol:46: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertAddressArray.sol:82: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertAddressPayableArray.sol:46: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertAddressPayableArray.sol:82: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertBytes32Array.sol:45: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertBytes32Array.sol:81: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertIntArray.sol:48: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertIntArray.sol:84: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertString.sol:145: for (uint256 i = 0; i < ba.length; i++) { ./protocol/test/helpers/truffle/AssertUintArray.sol:46: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/test/helpers/truffle/AssertUintArray.sol:82: for (uint256 i = 0; i < arrA.length; i++) { ./protocol/zeppelin/MerkleProof.sol:22: for (uint256 i = 0; i < proof.length; i++) { ./arbitrum-lpt-bridge/L1/gateway/L1Migrator.sol:472: for (uint256 i = 0; i < _unbondingLockIds.length; i++) { ./arbitrum-lpt-bridge/L2/gateway/L2Migrator.sol:197: for (uint256 i = 0; i < _params.unbondingLockIds.length; i++) {
#0 - yondonfu
2022-01-23T20:57:53Z
🌟 Selected for report: 0x0x0x
Also found by: sirhashalot
0.3637 LPT - $13.49
37.086 USDC - $37.09
0x0x0x
When a variable is declared solidity assigns the default value. In case the contract assigns the value again, it costs extra gas.
Example:uint x = 0
costs more gas than uint x
without having any different functionality.
Scope
./protocol/bonding/libraries/EarningsPool.sol:84: uint256 delegatorFees = 0; ./protocol/bonding/libraries/EarningsPool.sol:85: uint256 transcoderFees = 0; ./protocol/bonding/libraries/EarningsPool.sol:115: uint256 delegatorRewards = 0; ./protocol/bonding/libraries/EarningsPool.sol:116: uint256 transcoderRewards = 0; ./protocol/bonding/libraries/EarningsPool.sol:189: uint256 transcoderFees = 0; ./protocol/bonding/libraries/EarningsPool.sol:190: uint256 delegatorFees = 0; ./protocol/bonding/libraries/EarningsPool.sol:217: uint256 transcoderRewards = 0; ./protocol/bonding/libraries/EarningsPool.sol:218: uint256 delegatorRewards = 0; ./protocol/pm/mixins/MixinTicketBrokerCore.sol:121: uint256 amountToTransfer = 0; ./protocol/token/Minter.sol:223: uint256 currentBondingRate = 0; ./arbitrum-lpt-bridge/L1/gateway/L1Migrator.sol:471: uint256 total = 0; ./protocol/zeppelin/MintableToken.sol:17: bool public mintingFinished = false; ./protocol/zeppelin/Pausable.sol:13: bool public paused = false;