Open code423n4 opened 2 years ago
Gas optimization confirmed
Code instances out of scope
Code instances out of scope
Code instances out of scope
Code instances out of scope
Code instances out of scope
There is no empty else block in StakingLPVaultHelpers._addLiquidityAndDepositETH
There is no empty else if block in StakingLPVaultHelpers._addLiquidityAndDepositETH
Writing these functions inline would considerably reduce the readability of the code.
Indeed we would save deployment gas consumption if we do so, but we prefer to keep a good readability at the cost of more expensive smart contract deployment.
NestedAsset._baseURI()
function is never used and only return a public variable.
We must delete it and use the public variable baseUri
instead.
Can overflow, since the delay can be 2**256 – 1
https://github.com/code-423n4/2022-06-nested-findings/issues/62#issuecomment-1165547704
The address _ADMIN_SLOT
is a constant, store in the bytecode. So the bool
and address
variables are already packed.
Duplicated of #2 at For loop optimizaion
Duplicated of #2 at For loop optimizaion
Duplicated of #2 at For loop optimizaion
State variables that could be set immutable
In the following files there are state variables that could be set immutable to save gas.
Code instance:
Unused state variables
Unused state variables are gas consuming at deployment (since they are located in storage) and are a bad code practice. Removing those variables will decrease deployment gas cost and improve code quality. This is a full list of all the unused storage variables we found in your code base.
Code instances:
Unused declared local variables
Unused local variables are gas consuming, since the initial value assignment costs gas. And are a bad code practice. Removing those variables will decrease the gas cost and improve code quality. This is a full list of all the unused storage variables we found in your code base.
Code instances:
Unnecessary array boundaries check when loading an array element twice
Code instances:
Caching array length can save gas
Caching the array length is more gas efficient. This is because access to a local variable in solidity is more efficient than query storage / calldata / memory. We recommend to change from:
to:
Code instances:
Prefix increments are cheaper than postfix increments
Prefix increments are cheaper than postfix increments. Further more, using unchecked {++x} is even more gas efficient, and the gas saving accumulates every iteration and can make a real change There is no risk of overflow caused by increamenting the iteration index in for loops (the
++i
infor (uint256 i = 0; i < numIterations; ++i)
). But increments perform overflow checks that are not necessary in this case. These functions use not using prefix increments (++x
) or not using the unchecked keyword:Code instances:
Unnecessary index init
In for loops you initialize the index to start from 0, but it already initialized to 0 in default and this assignment cost gas. It is more clear and gas efficient to declare without assigning 0 and will have the same meaning:
Code instances:
Rearrange state variables
You can change the order of the storage variables to decrease memory uses.
Code instance:
In OwnableProxyDelegation.sol,rearranging the storage fields can optimize to: 2 slots from: 3 slots. The new order of types (you choose the actual variables):
Use bytes32 instead of string to save gas whenever possible
Code instances:
Short the following require messages
The following require messages are of length more than 32 and we think are short enough to short them into exactly 32 characters such that it will be placed in one slot of memory and the require function will cost less gas. The list:
Code instances:
Use != 0 instead of > 0
Using != 0 is slightly cheaper than > 0. (see https://github.com/code-423n4/2021-12-maple-findings/issues/75 for similar issue)
Code instances:
Unnecessary cast
Code instance:
Use unchecked to save gas for certain additive calculations that cannot overflow
You can use unchecked in the following calculations since there is no risk to overflow:
Code instance:
Empty else statement can be removed to save gas
Code instance:
Empty else if statement can be removed to save gas
Code instance:
Consider inline the following functions to save gas
Inline one time use functions
The following functions are used exactly once. Therefore you can inline them and save gas and improve code clearness.
Code instances: