Closed code423n4 closed 1 year ago
Context:
Recommendation:
Change X += Y (X -= Y) to X = X + Y (X = X - Y).
Description:
Default value of uint is 0. It's unnecessary and costs more gas to initialize uint variavles to 0.
Change "uint256 i = 0;" to "uint256 i;".
uint256 type will never be less than 0.
Change > 0 to !=0.
Change i++ to ++i.
If you read the length of the array at each iteration of the loop, this consumes a lot of gas.
Store the array’s length in a variable before the for-loop, and use this new variable in the loop.
Custom errors are more gas efficient than using require with a string explanation.
100 gas at most
Report
Gas Optimizations
[G-01]: X += Y (X -= Y) costs more gas than X = X + Y (X = X - Y)
Context:
Recommendation:
Change X += Y (X -= Y) to X = X + Y (X = X - Y).
[G-02]: Don't initialize variable with its default value
Context:
Description:
Default value of uint is 0. It's unnecessary and costs more gas to initialize uint variavles to 0.
Recommendation:
Change "uint256 i = 0;" to "uint256 i;".
[G-03]: >0 costs more gas than !=0
Context:
Description:
uint256 type will never be less than 0.
Recommendation:
Change > 0 to !=0.
[G-04]: i++ costs more gas than ++i
Context:
Recommendation:
Change i++ to ++i.
[G-05]: Use new variable instead of reading array length in every loop of a for-loop
Context:
Description:
If you read the length of the array at each iteration of the loop, this consumes a lot of gas.
Recommendation:
Store the array’s length in a variable before the for-loop, and use this new variable in the loop.
[G-06]: Use custom errors instead of revert strings
Custom errors are more gas efficient than using require with a string explanation.