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
1. Variables: No need to explicitly initialize variables with default values
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
// uint
Project.sol:248: for (uint256 i = 0; i < _length; i++) {
Project.sol:311: for (uint256 i = 0; i < _length; i++) {
Project.sol:322: for (uint256 i = 0; i < _length; i++) {
libraries/Tasks.sol:181: for (uint256 i = 0; i < _length; i++) _alerts[i] = _self.alerts[i];
Community.sol:624: for (uint256 i = 0; i < _communities[_communityID].memberCount; i++) {
HomeFiProxy.sol:87: for (uint256 i = 0; i < _length; i++) {
HomeFiProxy.sol:136: for (uint256 i = 0; i < _length; i++)
Recommendation:
I suggest removing explicit initializations for default values.
3. Custom Errors instead of Revert Strings to save Gas
Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)
Starting from Solidity v0.8.4,there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");),but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.
Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).
1. Variables: No need to explicitly initialize variables with default values
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Instances:
Project.sol:248
Project.sol:311
Project.sol:322
libraries/Tasks.sol:181
Community.sol:624
HomeFiProxy.sol:87
Recommendation:
I suggest removing explicit initializations for default values.
2.Use
!=0
instead of> 0
for UINTInstances
Project.sol:195
Community.sol:764
3. Custom Errors instead of Revert Strings to save Gas
Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)
Starting from Solidity v0.8.4,there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");),but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.
Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).
Instances:
HomeFi.sol
Project.sol
Disputes.sol
DebtToken.sol:50
ProjectFactory.sol
libraries/Tasks.sol
Community.sol
HomeFiProxy.sol
4.
++I
COSTS LESS GAS THANI++
Instances:
Project.sol:625
Project.sol:672
Community.sol:140
The text was updated successfully, but these errors were encountered: