code-423n4 / 2024-03-abracadabra-money-findings

9 stars 7 forks source link

Gas Optimizations #242

Open c4-bot-9 opened 8 months ago

c4-bot-9 commented 8 months ago

See the markdown file with the details of this report here.

c4-pre-sort commented 8 months ago

141345 marked the issue as insufficient quality report

c4-pre-sort commented 8 months ago

141345 marked the issue as grade-c

thenua3bhai commented 7 months ago

Hi @thereksfour Thanks for Judging I request you to please re-evaluate this gas report. I believe this should be marked grade-a. Since it contains 15 good gas findings and majority of them are high quality significant gas savers and re-factoring findings found by manual review which can not be even found by bot. Since I find these findings by manual review that's why they are less in numbers. I usually don't include trivial findings in my report since they are easily found by bot and doesn't save much gas. Since this contest doesn't had bot race so many bot participated and submitted findings in big numbers. But in terms of gas savings and score my findings weight similar or more than higher number of bot findings. And this report provides much more good amount of value to the protocol by saving significant gas in their code.

Lookout marked this c by just seeing less number of findings compared to others. But in terms of scoring this contains 10 L grade-findings and 5 R/NC level findings. All findings are correct and 100% safe to implement. Which makes this report score more than 55 which makes this report eligible for grade-a since current threshold score for grade-a is 50.

I have summarized significant gas saver findings and listed out L level findings from this report. They are explained in detail in my gas report.

[G-01] State variables can be packed into fewer storage slots by reducing their size - Saves 2 storage slots (Saves ~4000 Gas) == L

[G-02] Reduce the size of struct variables and pack them together to save storage slots - Saves 1 storage slots(Saves ~2000 Gas) == L

[G-03] Cache external function call to save gas instead of re-calling avoid 1 external call - Saves 1 external function call == L

[G-04] State variable only set in the constructor should be declare immutable - Saves 1 storage slot(Gas Saved ~2100 Gas) == L

[G-05] Check before updating bool state variable to avoid SSTORE with same bool value- Saves 1 SSTORE (Saves ~2200 Gas) == L

[G-07] Multiple accesses of the same mapping/array key/index inside loop should be cached - Saves 3 SLOAD Per iteration (Gas Saved ~300 Gas Per iteration) == L

[G-09] State variables should be cached in stack variables rather than re-reading them from storage - Saves 18 SLOAD(Gas Saved ~1800 Gas) == L

[G-10] Within contract's function function call should be cached instead of re-calling the same function Saves 1 function call == L

[G-12] Switch the order of if statements inside loop to fail early if failing - Saves 3 Gcoldsload per loop iteration (Saves ~2100 Gas of Gcoldsload per loop iteration) half of the times == L

[G-13] Refactor _getRewards function to save 1 SLOAD by caching function call Saves 1 SLOAD every time after refactoring== L

Apart from these above 10 L findings my report also have 5 other good findings which is mentioned in report which can also be considered as R/NC. Considering 3 other findings as R and 2 other as NC out of those other 5.

Since 1 L gives 5 score , 1 R gives 2 score and 1 NC gives 1 score in gas reports.

*So Total avg. score of this report = 10 5 + 3 2 + 2 1 = 57

Which is much higher than current threshold score for grade-a which is 50.

So I request you to please re-evaluate this report and update this to grade-a since based on above score and facts this report should be marked as grade-a.

Thanks

c4-judge commented 7 months ago

thereksfour marked the issue as grade-a