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
in Cally.sol#L170, durationDays > 0 can be replaced with durationDays != 0 since it is uint.
3. Several variables are declared for one time use only
Several variables are declared for using only one times, This can be avoided by using the expression directly to save gas.
eg in src/Cally.sol#L223-L224
// Before:uint256 premium =getPremium(vaultId);
require(msg.value>= premium, "Incorrect ETH amount sent");
// Afterrequire(msg.value>=getPremium(vaultId), "Incorrect ETH amount sent");
// Beforefor (uint256 i =0; i < data.length; i++) {
}
// Afteruint len = data.length;
for (uint256 i =0; i < len; ++i) {
}
6. Using custom errors to save gase
There are a lots of require statements that use revert strings. They can be replaced with custom Errors introduced in solidity 0.8.4 which are cheaper in terms of gas.
The text was updated successfully, but these errors were encountered:
1. Uint variables have default value to 0, so dont have to be initialized
In Cally.sol#L94-L95, uint varibles are initialzied to 0, this can be avoided as they default to zero when they are declared
Similar also in src/Cally.sol#L282
2. checking
a != 0
is cheaper thana > 0
for uintin Cally.sol#L170,
durationDays > 0
can be replaced withdurationDays != 0
since it is uint.3. Several variables are declared for one time use only
Several variables are declared for using only one times, This can be avoided by using the expression directly to save gas.
eg in src/Cally.sol#L223-L224
Similar issues are also in:
Cally.sol#L227-L228
src/Cally.sol#L278-L279
src/Cally.sol#L333-L334
src/Cally.sol#L395-L396
4. prefix increment can be used in loops instead of postfix increment as it is cheaper
In src/CallyNft.sol#L244
5.
data.length
is calculated for each iteration in loop, this can be cached to save gasIn src/CallyNft.sol#L244
6. Using custom errors to save gase
There are a lots of require statements that use revert strings. They can be replaced with custom Errors introduced in solidity 0.8.4 which are cheaper in terms of gas.
The text was updated successfully, but these errors were encountered: