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
Rank: 56/59
Findings: 1
Award: $105.36
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: _Adam
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xmint, Chom, Dravee, Fitraldys, Funen, JC, Limbooo, MadWookie, Picodes, Ruhum, TerrierLover, TomJ, Tomio, Waze, ak1, c3phas, catchup, defsec, fatherOfBlocks, gzeon, hake, hansfriese, joestakey, k, oyc_109, rfa, robee, sach1r0, saian, simon135, ynnad
41.2642 USDC - $41.26
396.9199 CANTO - $64.10
GAS OPTIMIZATION Caching Anytime you are reading from storage more than once it is cheaper in gas cost to cache the variable in memory. I was able to find multiple instances in which you can make it more efficient. You can save gas by putting .Length into a separate variable before the call by doing so the compiler will not read the length of the array during each iteration.
MITIGATION cache these storage variables in memory
Comparison Operators In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Accountant/AccountantDelegate.sol#L83 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L168 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L198 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L168 MITIGATION Replace <= with <, and >= with >
REQUIRE INSTEAD OF && Require statements including conditions with the && operator can be broken down in multiple require statements to save gas. https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L245 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L133 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L265 Breakdown each condition in a separate require statement (though require statements should be replaced with custom errors)
COMPARISONS WITH ZERO FOR UNSIGNED INTEGERS
0 is less gas efficient than !0 if you enable the optimizer at 10k AND you’re in a require statement https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/Comp.sol#L179
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L228
MITIGATION
Replace > 0 with !0
Prefix Increments Prefix increments are cheaper than postfix increments.
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L197 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L211
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L181 change variable++ to ++variable
REQUIRE INSTEAD OF && Require statements including conditions with the && operator can be broken down in multiple require statements to save gas. https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L138
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorAlpha.sol#L228 MITIGATION Breakdown each condition in a separate require statement (though require statements should be replaced with custom errors)
COMPARISON OPERATORS In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L47
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L119 MITIGATION Replace <= with <, and >= with >
REQUIRE INSTEAD OF && Require statements including conditions with the && operator can be broken down in multiple require statements to save gas. https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L164
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L115 MITIGATION Breakdown each condition in a separate require statement (though require statements should be replaced with custom errors)
PREFIX INCREMENTS Prefix increments are cheaper than postfix increments. https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L68
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Governance/GovernorBravoDelegate.sol#L90 MITIGATION change variable++ to ++variable
COMPARISON OPERATORS In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas https://github.com/Plex-Engineer/manifest/blob/688e9b4e7835854c22ef44b045d6d226b784b4b8/contracts/ERC20Burnable.sol#L37 MITIGATION Replace <= with <, and >= with >
REQUIRE INSTEAD OF && Require statements including conditions with the && operator can be broken down in multiple require statements to save gas. https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/SushiMaker.sol#L75 MITIGATION Breakdown each condition in a separate require statement (though require statements should be replaced with custom errors) COMPARISON OPERATORS In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/governance/Timelock.sol#L42 https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/governance/Timelock.sol#L43 https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/governance/Timelock.sol#L55 https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/governance/Timelock.sol#L56
https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/governance/Timelock.sol#L109 MITIGATION Replace <= with <, and >= with >
PREFIX INCREMENTS Prefix increments are cheaper than postfix increments. https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/bentobox/KashiPairMediumRiskV1.sol#L444 https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/bentobox/KashiPairMediumRiskV1.sol#L1260 https://github.com/Plex-Engineer/zeroswap/blob/03507a80322112f4f3c723fc68bed0f138702836/contracts/bentobox/KashiPairMediumRiskV1.sol#L1348 MITIGATION change variable++ to ++variable
#0 - GalloDaSballo
2022-08-04T00:50:21Z
The first finding would save at least 300 gas, the report in total will save less than 500 gas