You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can change the order of the storage variables to decrease memory uses.
In CrossAnchorBridge.sol,rearranging the storage fields can optimize to: 3 slots from: 4 slots.
The new order of types (you choose the actual variables):
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:
CrossAnchorBridge.sol, 149
Title: Use calldata instead of memory
Severity: GAS
Use calldata instead of memory for function parameters
In some cases, having function arguments in calldata instead of
memory is more optimal.
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.
Title: Prefix increments are cheaper than postfix increments
Severity: GAS
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 in for (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:
change to prefix increment and unchecked: CrossAnchorBridge.sol, i, 149
Title: Caching array length can save gas
Severity: 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:
for (uint256 i=0; i<array.length; i++) { ... }
to:
uint len = array.length
for (uint256 i=0; i<len; i++) { ... }
CrossAnchorBridge.sol, _collateralTokens, 149
Title: Consider inline the following functions to save gas
Severity: GAS
You can inline the following functions instead of writing a specific function to save gas.
(see https://github.com/code-423n4/2021-11-nested-findings/issues/167 for a similar issue.)
CrossAnchorBridge.sol, encodeAddress, { return bytes32(uint256(uint160(addr))); }
The text was updated successfully, but these errors were encountered:
Title: Rearrange state variables
Severity: GAS
You can change the order of the storage variables to decrease memory uses.
In CrossAnchorBridge.sol,rearranging the storage fields can optimize to: 3 slots from: 4 slots.
The new order of types (you choose the actual variables):
Title: uint8 index
Severity: GAS
Due to how the EVM natively works on 256 numbers, using a 8 bit number here introduces additional costs as the EVM has to properly enforce the limits of this smaller type.
See the warning at this link: https://docs.soliditylang.org/en/v0.8.0/internals/layout_in_storage.html#layout-of-state-variables-in-storage
We recommend to use uint256 for the index in every for loop instead using uint8:
Title: Public functions to external
Severity: GAS
The following functions could be set external to save gas and improve code quality.
External call cost is less expensive than of public functions.
Title: Internal functions to private
Severity: GAS
The following functions could be set private to save gas and improve code quality:
Title: Unnecessary index init
Severity: GAS
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:
Title: Use calldata instead of memory
Severity: GAS
Use calldata instead of memory for function parameters
In some cases, having function arguments in calldata instead of
memory is more optimal.
Title: Unused state variables
Severity: GAS
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.
Title: Prefix increments are cheaper than postfix increments
Severity: GAS
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:Title: Caching array length can save gas
Severity: 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:
Title: Consider inline the following functions to save gas
Severity: GAS
The text was updated successfully, but these errors were encountered: