Platform: Code4rena
Start Date: 06/01/2023
Pot Size: $210,500 USDC
Total HM: 27
Participants: 73
Period: 14 days
Judge: 0xean
Total Solo HM: 18
Id: 203
League: ETH
Rank: 69/73
Findings: 1
Award: $72.44
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0xA5DF, 0xSmartContract, 0xhacksmithh, AkshaySrivastav, Awesome, Aymen0909, Bauer, Bnke0x0, Breeje, Budaghyan, Cyfrin, Madalad, NoamYakov, RHaO-sec, Rageur, RaymondFam, ReyAdmirado, Rolezn, SAAJ, SaharDevep, Sathish9098, __141345__, amshirif, arialblack14, c3phas, carlitox477, chaduke, delfin454000, descharre, nadin, oyc_109, pavankv, saneryee, shark
72.4433 USDC - $72.44
This report focuses on Reserve 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 Reserve Protocol protocol are categorised into 07 main areas; with further multiple instances in each of the category.
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.
Throughout the codebase many returns functions, function arguments, variables, event and struct have values that are below 32 bytes in type of uint/int.
These all elements below 32 bytes create significant gas consumption overhead for extra work with contracts like having more than 100 instances Libraries/fixed.sol, FixedCallerMock.sol.
103 instances are discovered many were not mentioned due to time limitation.
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:
When multiple mappings are used in same function, it’s better to combined them into a single mapping of an address struct.
Combined mapping reduces storage slot per mapping and also are cheaper in terms of associated Stack operations calculation carried out.
Link to the Code:
When visibility for a state variable is not specified, the default value is already internal.
Declaring visibility of the variable internal consumes extra gas which is not needed.
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:
Bytes constant are more gas efficient in storing text data than string constant.
Link to the Code:
Assert() and require() functions are similar in nature, regarding context of handling error and undone any changes made.
However, assert() consumes all the gas during the process of reverting change while require()refunds any gas remaining that was paid.
Link to the Code:
#0 - c4-judge
2023-01-24T22:59:53Z
0xean marked the issue as grade-b