code-423n4 / 2022-10-juicebox-findings

2 stars 0 forks source link

Gas Optimizations #202

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Multiple mappings of same key can be combined into a single mapping to a struct, where appropriate

Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot

UNUSED NAMED RETURNS

Using both named returns and a return statement isn’t necessary. Removing one of those can improve code clarity:

Use calldata instead of memory for external functions where the function argument is read-only

The memory keyword in a function argument causes the underlying code to copy the argument into memory. Calldata causes the code to read the transaction without copying it directly, ultimately saves gases.

internal functions not called by the contract should be removed to save deployment gas

internal functions only called once can be inlined to save gas

Picodes commented 1 year ago

Please expand on how to combine mappings.

Most part of the 2 lasts findings are invalid.

c4-judge commented 1 year ago

Picodes marked the issue as grade-c