Skip to content

Instantly share code, notes, and snippets.

@Picodes
Created October 18, 2022 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Picodes/a6afb0dd17b71b60c605ae54d4c291f8 to your computer and use it in GitHub Desktop.
Save Picodes/a6afb0dd17b71b60c605ae54d4c291f8 to your computer and use it in GitHub Desktop.

Report

Gas Optimizations

Issue Instances
[GAS-1] Cache array length outside of loop 3
[GAS-2] Use != 0 instead of > 0 for unsigned integer comparison 4
[GAS-3] Don't initialize variables with default value 5
[GAS-4] Use shift Right/Left instead of division/multiplication if possible 1
[GAS-5] ++i costs less gas than i++, especially when it's used in for-loops (--i/i-- too) 7

[GAS-1] Cache array length outside of loop

If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation (3 additional gas for each iteration except for the first).

Instances (3):

File: libraries/JBIpfsDecoder.sol

47:     for (uint256 i = 0; i < _source.length; ++i) {

74:     for (uint256 i = 0; i < _input.length; i++) {

82:     for (uint256 i = 0; i < _indices.length; i++) {

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

Instances (4):

File: JBTiered721Delegate.sol

226:     if (_pricing.tiers.length > 0) _store.recordAddTiers(_pricing.tiers);
File: JBTiered721DelegateStore.sol

1181:     if (_numerator - JBConstants.MAX_RESERVED_RATE * _numberReservedTokensMintable > 0)
File: abstract/JB721Delegate.sol

109:     if (_data.tokenCount > 0) revert UNEXPECTED_TOKEN_REDEEMED();
File: libraries/JBIpfsDecoder.sol

55:       while (carry > 0) {

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

Instances (5):

File: libraries/JBIpfsDecoder.sol

47:     for (uint256 i = 0; i < _source.length; ++i) {

49:       for (uint256 j = 0; j < digitlength; ++j) {

66:     for (uint256 i = 0; i < _length; i++) {

74:     for (uint256 i = 0; i < _input.length; i++) {

82:     for (uint256 i = 0; i < _indices.length; i++) {

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

Instances (1):

File: libraries/JBBitmap.sol

74:     return _index / 256;

[GAS-5] ++i costs less gas than i++, especially when it's used in for-loops (--i/i-- too)

Saves 5 gas per loop

Instances (7):

File: JBTiered721DelegateStore.sol

222:         _tiers[_numberOfIncludedTiers++] = JB721Tier({

1041:       numberOfBurnedFor[msg.sender][_tierId]++;

1043:       _storedTierOf[msg.sender][_tierId].remainingQuantity++;
File: libraries/JBIpfsDecoder.sol

57:         digitlength++;

66:     for (uint256 i = 0; i < _length; i++) {

74:     for (uint256 i = 0; i < _input.length; i++) {

82:     for (uint256 i = 0; i < _indices.length; i++) {

Non Critical Issues

Issue Instances
[NC-1] constants should be defined rather than using magic numbers 1

[NC-1] constants should be defined rather than using magic numbers

Instances (1):

File: libraries/JBIpfsDecoder.sol

44:     uint8[] memory digits = new uint8[](46); // hash size with the prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment