Platform: Code4rena
Start Date: 03/08/2023
Pot Size: $90,500 USDC
Total HM: 6
Participants: 36
Period: 7 days
Judge: 0xean
Total Solo HM: 1
Id: 273
League: ETH
Rank: 25/36
Findings: 1
Award: $38.45
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: LeoS
Also found by: 0xAnah, JCK, K42, SAAJ, Sathish9098, Udsen, caventa, dharma09, ernestognw, naman1778, petrichor, rektthecode
38.4497 USDC - $38.45
This report focuses on Arbitrum Security Council contest, in context of various improvements that can be made in terms of gas cost. Some of the opportunities identified for improving gas efficiency throughout the codebase of Arbitrum Security Council contest are categorised into 07 main areas; with further multiple instances in each of the category.
[G-01] Array inside external function should be declared calldata (09 Instances) [G-02] Use uint256(1)/uint256(2) instead for true and false boolean states (04 Instances) [G-03] Revert inside a loop (10 Instances) [G-04] Use calldata instead of memory for external function parameters (07 Instances) [G-05] It's cheaper to declare the variable outside the loop (10 Instances) [G-06] Uint/Int lower than 32 bytes consumes more gas (10 Instances) [G 07] Consolidating library functions can save gas by preventing external calls (05 Instances)
Functions should have their memory arrays declared as calldata, significantly reducing the gas costs of the functions.
Link to the Code:
Boolean for storage if not used, saves Gwarmaccess 100 gas. In addition, state changes of boolean from true to false can cost up to ~20000 gas rather than uint256(2) to uint256(1) that would cost significantly less.
Link to the Code:
If/require condition inside for-loop will proceed, unless it finds one condition that is not met, it will revert the whole transaction. It is recommended that instead of reverting if condition is not true, to just break the loop. This way we don't need to run again the transaction.
Link to the Code:
Using calldata in external function does not require data to be stored, which reduced the process time as compared to memory. This in return saves gas during calling the data.
Link to the Code:
Declaring a variable inside a loop result in variable being redeclared during each loop iteration which consume higher gas. The variable gets reallocated when declared outside loop making it more gas efficient.
Link to the Code:
Contract gas usage increases as EVM standard operation are of 32 bytes. If any element is smaller than 32 bytes (i.e.; 256 bits) it will cause EVM to consume more gas which can be around 12 gas depending on size for reducing the size to given output like uint8.
Link to the Code:
Libraries of functions commonly used across different contracts come at the increased cost of gas usage at runtime because of the external calls. If a function gives an external call to library function which gives another external call wrap to its function to a outside contract, the cost of call multiplies every time thus making it very expensive. The best way is to gain efficiency is considering moving all the library functions internal to a contract or to a single library to save gas from external calls.
Link to the code:
#0 - c4-judge
2023-08-18T14:32:14Z
0xean marked the issue as grade-b