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
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
you can re order storage variables to save 20_000 gas
address public override contractor;
/// @inheritdoc IProject
bool public override contractorConfirmed;
/// @inheritdoc IProject
uint256 public override hashChangeNonce;
/// @inheritdoc IProject
uint256 public override totalLent;
/// @inheritdoc IProject
uint256 public override totalAllocated;
/// @inheritdoc IProject
uint256 public override taskCount;
/// @inheritdoc IProject
bool public override contractorDelegated;
/// @inheritdoc IProject
uint256 public override lastAllocatedTask;
/// @inheritdoc IProject
uint256 public override lastAllocatedChangeOrderTask;
HomeFiProxy.sol:87: for (uint256 i = 0; i < _length; i++) {
HomeFiProxy.sol:136: for (uint256 i = 0; i < _length; i++) {
libraries/Tasks.sol:181: for (uint256 i = 0; i < _length; i++) _alerts[i] = _self.alerts[i];
Project.sol:249: for (uint256 i = 0; i < _length; i++) {
Project.sol:312: for (uint256 i = 0; i < _length; i++) {
Project.sol:323: for (uint256 i = 0; i < _length; i++) {
Project.sol:604: for (; i < _changeOrderedTask.length; i++) {
Community.sol:625: for (uint256 i = 0; i < _communities[_communityID].memberCount; i++) {
you can make arrary.length into memory variable to save gas
Project.sol:604: for (; i < _changeOrderedTask.length; i++) {
Community.sol:625: for (uint256 i = 0; i < _communities[_communityID].memberCount; i++) {
Use 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) Source Custom Errors in Solidity: 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).
Unchecking arithmetics operations that can’t underflow/overflow
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isn’t possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block: Checked or Unchecked Arithmetic. I suggest wrapping with an unchecked block:
Same thing with second unchecked because total can't overflow amount cant overflow
make i into unchecked to save gas only if i is cant get overflowed
HomeFiProxy.sol:87: for (uint256 i = 0; i < _length; i++) {
HomeFiProxy.sol:136: for (uint256 i = 0; i < _length; i++) {
libraries/Tasks.sol:181: for (uint256 i = 0; i < _length; i++) _alerts[i] = _self.alerts[i];
Project.sol:249: for (uint256 i = 0; i < _length; i++) {
Project.sol:312: for (uint256 i = 0; i < _length; i++) {
Project.sol:323: for (uint256 i = 0; i < _length; i++) {
Project.sol:604: for (; i < _changeOrderedTask.length; i++) {
Community.sol:625: for (uint256 i = 0; i < _communities[_communityID].memberCount; i++) {
make address(0) and make it into long form to save gas
HomeFiProxy.sol:41: require(_address != address(0), "Proxy::0 address");
HomeFiProxy.sol:106: contractAddress[_contractName] == address(0),
libraries/SignatureDecoder.sol:26: return (address(0));
libraries/SignatureDecoder.sol:36: return (address(0));
ProjectFactory.sol:35: // Ensure an address is not the zero address (0x00)
ProjectFactory.sol:36: require(_address != address(0), "PF::0 address");
Disputes.sol:38: // Revert if _address zero address (0x00)
Disputes.sol:39: require(_address != address(0), "Disputes::0 address");
HomeFi.sol:78: require(_address != address(0), "HomeFi::0 address");
DebtToken.sol:50: require(_communityContract != address(0), "DebtToken::0 address");
Project.sol:135: require(_contractor != address(0), "Project::0 address");
Project.sol:153: require(contractor != address(0), "Project::0 address");
Project.sol:479: if (_newSC != address(0)) {
Project.sol:486: tasks[_taskID].subcontractor = address(0);
Project.sol:754: // Revert if sc to invite is address 0
Project.sol:755: require(_sc != address(0), "Project::0 address");
Project.sol:800: if (contractor == address(0)) {
Project.sol:844: if (contractor == address(0)) {
make admin only function payable to save gas
because payable dosnt check msg.value == 0
HomeFi.sol:157,17185,201
The text was updated successfully, but these errors were encountered:
Using bools for storage incurs overhead
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
you can re order storage variables to save 20_000 gas
you can take the bool under the other bool because a bool only takes up 1 byte other wise it would take up one slot.
https://github.com/code-423n4/2022-08-rigor/blob/f2498c86dbd0e265f82ec76d9ec576442e896a87/contracts/Project.sol#L70
make i++ into ++i to remove a memory copy
you can make arrary.length into memory variable to save gas
Use 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) Source Custom Errors in Solidity: 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).
make require statements with uint >0 make it != to save gas
Unchecking arithmetics operations that can’t underflow/overflow
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isn’t possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block: Checked or Unchecked Arithmetic. I suggest wrapping with an unchecked block:
Same thing with second unchecked because total can't overflow amount cant overflow
i
into unchecked to save gas only ifi
is cant get overflowedmake address(0) and make it into long form to save gas
make admin only function payable to save gas
because payable dosnt check msg.value == 0
HomeFi.sol:157,17185,201
The text was updated successfully, but these errors were encountered: