code-423n4 / 2024-03-zksync-findings

1 stars 1 forks source link

Gas Optimizations #126

Closed c4-bot-10 closed 2 months ago

c4-bot-10 commented 4 months ago

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

c4-sponsor commented 3 months ago

saxenism (sponsor) acknowledged

saxenism commented 3 months ago

Mid report.

c4-judge commented 2 months ago

alex-ppg marked the issue as grade-c

Dharma-09 commented 2 months ago

Hi @alex-ppg Thanks for judging

I believe this gas report deserves a Grade-A or Grade-B. I've found costly issues in the report that were also identified by other wardens. Despite being labeled Grade-A, not all issues were thoroughly examined. This highlights the need to address critical matters comprehensively.

I've included detailed descriptions where necessary and concise one-liners where sufficient. The report features unique optimizations that many Grade-A reports lack.

Out of 34 gas findings, 15 are significant gas savers like slot saving and refactoring, which are difficult for bots to detect. While some findings may seem trivial, I've included them to compete with numerous bot submissions. My findings provide significant gas savings, comparable to or better than those from bot submissions.

The report contains 15 high-quality gas-saving findings (Grade L) and 19 others (Grade R/NC), all of which are safe to implement. Most will save gas even with the optimizer turned on, especially the Grade L ones. This gives the report a score 95, making it eligible for a Grade-A or Grade-B.

[G-01] Re-arrange state variable order to save storage slots (Saves ~2000 Gas) == L

[G-02] Reorder struct variables and pack them together to save storage slots+(Gas Saved ~ 2000 Gas)== L

[G-03] The result of a function call should be cached rather than re-calling the function == L

[G-04] State variable can be marked constant which never changes or initialized Saves 1 storage slots(Gas Saved ~2100 Gas)) == L

[G-05] Avoiding unnecessary state variable emissions can save gas in Solidity == L

[G-06] cache variable in local varibale reduce gas costs by minimizing redundant accesses to the array == L

[G-07] No need to cache when used only once through out function == NC

[G-08] Caching the length of an array in a local variable can save gas == L

[G-10] State variables should be cached in stack variables rather than re-reading them from storage== L

[G-11] Use assembly for low level call == L

[G-12] Use storage instaed of memory when function visibility is external == L

[G-16] Check previous then update state variable == L

[G-20] With assembly, .call (bool success) transfer can be done gas-optimized == L

[G-23] Use uint256(1)/uint256(2) instead for true and false boolean states == L

[G-30] Don't initialize variables with default value == L

I've identified additional issues in my report, but the ones mentioned above stand out due to their significant impact on gas usage.

So Total avg. score of this report = 15*5+ 19

Which is good score for grade-a comparing with other grade-a or b reports.

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

Thanks

alex-ppg commented 2 months ago

Hey @Dharma-09, thanks for contributing to the PJQA process! I have provided an evaluation of each of the listed items below:

As your submission contains multiple egregious errors, I cannot consider it for a grade beyond C. I appreciate the feedback and consider my judgment final for this submission. I advise thoroughly examining all items in your bot's report prior to submitting them in a contest to increase the rewards you capture in future contests.