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
[G-01] Multiple address mappings can be combined into a single mapping of an address 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. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to recalculate the key's keccak256 hash (Gkeccak256 - 30 gas) and that calculation's associated stack operatio 1 instance of this issue has been found:
[G-10] Use custom errors rather than revert()/require() strings to save gas
Custom errors save ~50 gas each time they're hit by avoiding having to allocate and store the revert string. 20 instances of this issue have been found:
Gas Optimizations
require()
/revert()
checks used multiples times should be turned into a function or modifierbool
is gas inefficient when used in storagerequire
checkreturn
is redundant if function already has a namedreturns
method implementedarray.length
should be cached infor
loopfor
loop increments should beunchecked{}
if overflow is not possible++i
) instead of postfix (i++
) saves gasrevert()
/require()
strings to save gasGas overview per contract
Gas Optimizations
[G-01] Multiple address mappings can be combined into a single mapping of an address 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. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to recalculate the key's keccak256 hash (Gkeccak256 - 30 gas) and that calculation's associated stack operatio
1 instance of this issue has been found:
[G-01] HomeFi.sol#L64-L66
[G-02]
require()
/revert()
checks used multiples times should be turned into a function or modifierDoing so increases code readability decreases number of instructions for the compiler.
4 instances of this issue have been found:
[G-02] Project.sol#L153-L154
[G-02b] Project.sol#L135-L136
[G-02c] DebtToken.sol#L96-L97
[G-02d] DebtToken.sol#L104-L105
[G-03]
bool
is gas inefficient when used in storageInstead use
uint256
values to represent true/false instead.Reference
3 instances of this issue have been found:
[G-03] Project.sol#L78-L79
[G-03b] Project.sol#L68-L69
[G-03c] HomeFi.sol#L50-L51
[G-04] Redundant
require
checkModifier
noChange
can be used instead.1 instance of this issue has been found:
[G-04] HomeFi.sol#L191-L192
[G-05] Implementing
return
is redundant if function already has a namedreturns
method implementedRedundant
return
methods increase gas on deployment and execution.2 instances of this issue have been found:
[G-05] HomeFi.sol#L318-L321
[G-05b] HomeFi.sol#L307-L310
[G-06]
array.length
should be cached infor
loopCaching the length array would save gas on each iteration by not having to read from memory or storage multiple times.
Example:
2 instances of this issue have been found:
[G-06] Community.sol#L624-L625
[G-06b] Project.sol#L603-L604
[G-07]
for
loop increments should beunchecked{}
if overflow is not possibleFrom Solidity
0.8.0
onwards using theunchecked
keyword saves 30 to 40 gas per loop.Example:
6 instances of this issue have been found:
[G-07] Community.sol#L624-L625
[G-07b] Project.sol#L650-L651
[G-07c] Project.sol#L322-L323
[G-07d] Project.sol#L311-L312
[G-07e] Project.sol#L248-L249
[G-07f] Project.sol#L603-L604
[G-08] Using prefix(
++i
) instead of postfix (i++
) saves gasIt saves 6 gas per iteration.
7 instances of this issue have been found:
[G-08] Community.sol#L624-L625
[G-08b] Project.sol#L650-L651
[G-08c] Project.sol#L322-L323
[G-08d] Project.sol#L311-L312
[G-08e] Project.sol#L248-L249
[G-08f] Project.sol#L625-L626
_loopCount++;
[G-08g] Project.sol#L603-L604
[G-09] Setting variable to default value is redundant
Setting variable to default value is redundant.
4 instances of this issue have been found:
[G-09] Community.sol#L624-L625
[G-09b] Project.sol#L322-L323
[G-09c] Project.sol#L311-L312
[G-09d] Project.sol#L248-L249
[G-10] Use custom errors rather than
revert()
/require()
strings to save gasCustom errors save ~50 gas each time they're hit by avoiding having to allocate and store the revert string.
20 instances of this issue have been found:
[G-10] Project.sol#L341-L342
[G-10b] Project.sol#L199-L202
[G-10c] Project.sol#L195-L196
[G-10d] Project.sol#L189-L192
[G-10e] Project.sol#L176-L177
[G-10f] Project.sol#L153-L154
[G-10g] Project.sol#L150-L151
[G-10h] Project.sol#L135-L136
[G-10i] Project.sol#L132-L133
[G-10j] Project.sol#L123-L124
[G-10k] HomeFi.sol#L255-L260
[G-10l] HomeFi.sol#L191-L192
[G-10m] HomeFi.sol#L142-L143
[G-10n] HomeFi.sol#L84-L85
[G-10o] HomeFi.sol#L78-L79
[G-10p] HomeFi.sol#L73-L74
[G-10q] DebtToken.sol#L31-L35
[G-10r] DebtToken.sol#L50-L51
[G-10s] DebtToken.sol#L96-L97
[G-10t] DebtToken.sol#L104-L105
The text was updated successfully, but these errors were encountered: