Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #1037

Open
c4-submissions opened this issue Oct 23, 2023 · 4 comments
Open

Gas Optimizations #1037

c4-submissions opened this issue Oct 23, 2023 · 4 comments
Labels
bug Something isn't working G (Gas Optimization) G-03 grade-b sufficient quality report This report is of sufficient quality

Comments

@c4-submissions
Copy link
Contributor

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

@c4-submissions c4-submissions added bug Something isn't working G (Gas Optimization) labels Oct 23, 2023
jacobheun pushed a commit that referenced this issue Oct 24, 2023
jacobheun pushed a commit that referenced this issue Oct 24, 2023
@141345
Copy link

141345 commented Oct 26, 2023

1 r 10 nc

[G-01] Can Make The Variable Outside The Loop To Save Gas
nc

[G-02] Avoid contract existence checks by using low-level calls
r

[G-03] Multiple address/ID mappings can be combined into a single mapping of an address/ID to a struct, where appropriate
d

[G-04] Avoid updating storage when the value hasn't changed
d

[G-05] Use Assembly To Check For address(0)
d

[G-06] Use assembly in place of abi.decode to extract calldata values more efficiently
nc

[G-07] Access mappings directly rather than using accessor functions
nc

[G-08] Make 3 event parameters indexed when possible
i

[G-09] Sort Solidity operations using short-circuit mode
nc

[G-10] Using Private Rather Than Public For Constants, Saves Gas
i

[G-11] Expressions for constant values such as a call to keccak256(), should use immutable rather than constants
x

[G-12] >=/<= costs less gas than >/<
d

[G-13] abi.encode() is less efficient than abi.encodePacked()
x

[G-14] Do not calculate constants
x

[G-15] Pack structs by putting data types that can fit together next to each other
d

[G-16] Use hardcode address instead address(this)
nc

[G-17] bytes constants are more eficient than string constans
nc

[G-18] se do while loops instead of for loops
nc

[G-19] The result of function calls should be cached rather than re-calling the function
x

[G-20] Empty blocks should be removed or emit something
i

[G-21] Refactor event to avoid emitting empty data
i

[G-22] Use Modifiers Instead of Functions To Save Gas
d

[G-23] Gas savings can be achieved by changing the model for assigning value to the structure
i

[G-24] State variables can be packed into fewer storage slots
d

[G-25] Refactor a modifier to call a local function instead of directly having the code in the modifier, saving bytecode size and thereby deployment cost
d

[G-26] Count from n to zero instead of counting from zero to n
nc

[G-27] Use fallback or receive instead of deposit() when transferring Ether
i

[G-28] Using assembly to revert with an error message
d

[G-29] Test if a number is even or odd by checking the last bit instead of using a modulo operator
nc

[G-30] Write gas-optimal for-loops
d

[G-31] Don’t make variables public unless it is necessary to do so
i

[G-32] Common math operations, like min and max have gas efficient alternatives
i

[G-33] Admin functions can be payable
d

[G-34] Use ECDSA signatures instead of merkle trees for allowlists and airdrops
nc

[G-35] Bitshifting is cheaper than multiplying or dividing by a power of two
d

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Nov 2, 2023
@c4-pre-sort
Copy link

141345 marked the issue as sufficient quality report

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as grade-b

@lsaudit
Copy link

lsaudit commented Dec 3, 2023

Hey, I took a look at this report and I think that some issues are invalid.

[G-34] Use ECDSA signatures instead of merkle trees for allowlists and airdrops

This seems to be invalid. It does not provide any example code-snippet, where ECDSA signatures will be better. Merkle proofs are utilized for transactions in this context.

[G-17] bytes constants are more eficient than string constans

This is invalid getName is override, because it's related to facet's name. Diamond needs to ensure that some facets can be named with more than 32 characters. This cannot be bytes32, it has to be string. This issue is invalid!

[G-16] Use hardcode address instead address(this)

Would be possible to pre-calculate the address, in the context of zksync?

[G-07] Access mappings directly rather than using accessor functions

This seems to be invalid. We're accessing it directly, aren't we?

[G‑02] Avoid contract existence checks by using low-level calls

This is invalid, as report states: "Prior to 0.8.10 the compiler inserted extra code, including EXTCODESIZE (100 gas), to check for contract existence for external function calls.", but reported issues are from pragma solidity ^0.8.13;, thus this does not occur here.

Moreover, the report does not provide any example how those low-level call should look like. How can an issue be evaluated as R (Refactor), if the report does not provide a single-line of code change? Imho, it's NC at most, but I think, that because of Solidity version it should be invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) G-03 grade-b sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

6 participants