Platform: Code4rena
Start Date: 08/05/2023
Pot Size: $90,500 USDC
Total HM: 17
Participants: 102
Period: 7 days
Judge: 0xean
Total Solo HM: 4
Id: 236
League: ETH
Rank: 101/102
Findings: 1
Award: $44.94
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: JCN
Also found by: 0xAce, 0xSmartContract, Aymen0909, K42, Rageur, Raihan, ReyAdmirado, SAAJ, SM3_SS, Sathish9098, Team_Rocket, Udsen, c3phas, codeslide, descharre, fatherOfBlocks, hunter_w3b, j4ld1na, lllu_23, matrix_0wl, naman1778, petrichor, pontifex, rapha, souilos, wahedtalash77
44.9387 USDC - $44.94
This report focuses on Venus Protocol 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 Venus protocol are categorised into 10 main areas; with further multiple instances in each of the category.
Use latest version of solidity i.e., 0.8.19 for getting additional gas saving for reference check this article.
Link to the code:
Using immutable instead of constant, save more gas due to avoiding storage access for state variables.
Variable values are set through constructor when using immutable, which also eliminates the need of assigning initial values to state variable making them more efficient in terms of gas cost.
Link to the Code:
Instead of using address(this), it is more gas-efficient to pre-calculate and use the hardcoded address.
Link to the code:
Compound assignment operators (+= / -=) are more expensive in terms of gas consumption and needs to be avoided.
Operator assignments (a = a + b / a - b) are preferable in terms of gas optimization.
Link to the Code:
Link to the Code:
Link to the Code:
If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation (3 additional gas for each iteration except for the first).
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:
Functions with public visibility, if not called within the contract needed to be changed external.
Link to the Code:
Boolean for storage if not used, this avoid 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:
#0 - c4-judge
2023-05-18T17:46:26Z
0xean marked the issue as grade-b