Skip to content

Instantly share code, notes, and snippets.

@Picodes
Created October 27, 2022 20:06
Show Gist options
  • Save Picodes/2d23ed5128036f1b475654d5bcca9eed to your computer and use it in GitHub Desktop.
Save Picodes/2d23ed5128036f1b475654d5bcca9eed to your computer and use it in GitHub Desktop.

Report

Gas Optimizations

Issue Instances
[GAS-1] Use != 0 instead of > 0 for unsigned integer comparison 5
[GAS-2] Don't initialize variables with default value 1
[GAS-3] Use shift Right/Left instead of division/multiplication if possible 1
[GAS-4] Using bools for storage incurs overhead 1
[GAS-5] Use Custom Errors 13
[GAS-6] Using private rather than public for constants, saves gas 3

[GAS-1] Use != 0 instead of > 0 for unsigned integer comparison

Instances (5):

File: WardenPledge.sol

471:         if(remainingAmount > 0) {

504:         if(remainingAmount > 0) {
File: oz/libraries/SafeERC20.sol

93:         if (returndata.length > 0) {
File: oz/utils/Address.sol

41:         return account.code.length > 0;

210:             if (returndata.length > 0) {

[GAS-2] Don't initialize variables with default value

Instances (1):

File: WardenPledge.sol

547:         for(uint256 i = 0; i < length;){

[GAS-3] Use shift Right/Left instead of division/multiplication if possible

Instances (1):

File: WardenPledge.sol

263:         uint256 totalDelegatedAmount = ((bias * boostDuration) + bias) / 2;

[GAS-4] Using bools for storage incurs overhead

Use uint256(1) and uint256(2) for true/false to avoid a Gwarmaccess (100 gas), and to avoid Gsset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past. See source.

Instances (1):

File: oz/utils/Pausable.sol

28:     bool private _paused;

[GAS-5] Use Custom Errors

Source Instead of using error strings, to reduce deployment and runtime cost, you should use Custom Errors. This would save both deployment and runtime cost.

Instances (13):

File: oz/libraries/SafeERC20.sol

75:             require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");

95:             require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
File: oz/utils/Address.sol

61:         require(address(this).balance >= amount, "Address: insufficient balance");

64:         require(success, "Address: unable to send value, recipient may have reverted");

134:         require(address(this).balance >= value, "Address: insufficient balance for call");

135:         require(isContract(target), "Address: call to non-contract");

162:         require(isContract(target), "Address: static call to non-contract");

189:         require(isContract(target), "Address: delegate call to non-contract");
File: oz/utils/Ownable.sol

51:         require(owner() == _msgSender(), "Ownable: caller is not the owner");

70:         require(newOwner != address(0), "Ownable: new owner is the zero address");
File: oz/utils/Pausable.sol

72:         require(!paused(), "Pausable: paused");

79:         require(paused(), "Pausable: not paused");
File: oz/utils/ReentrancyGuard.sol

52:         require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

[GAS-6] Using private rather than public for constants, saves gas

If needed, the values can be read from the verified contract source code, or if there are multiple values there can be a single getter function that returns a tuple of the values of all currently-public constants. Saves 3406-3606 gas in deployment gas due to the compiler not having to create non-payable getter functions for deployment calldata, not having to store the bytes of the value outside of where it's used, and not adding another entry to the method ID table

Instances (3):

File: WardenPledge.sol

22:     uint256 public constant UNIT = 1e18;

23:     uint256 public constant MAX_PCT = 10000;

24:     uint256 public constant WEEK = 7 * 86400;

Low Issues

Issue Instances
[L-1] Do not use deprecated library functions 1

[L-1] Do not use deprecated library functions

Instances (1):

File: oz/libraries/SafeERC20.sol

44:     function safeApprove(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment