Replace x <= y with x < y + 1, and x >= y with x > y - 1
In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas
There are 2 instances of this issue:
File: auction/Auction.sol
98: if (block.timestamp >= _auction.endTime) revert AUCTION_OVER();
Use calldata instead of memory for function parameters
If a reference type function parameter is read-only, it is cheaper in gas to use calldata instead of memory. Calldata is a non-modifiable, non-persistent area where function arguments are stored, and behaves mostly like memory. Try to use calldata as a data location because it will avoid copies and also makes sure that the data cannot be modified.
File: token/metadata/MetadataRenderer.sol
119: for (uint256 i = 0; i < numNewProperties; ++i) {
133: for (uint256 i = 0; i < numNewItems; ++i) {
189: for (uint256 i = 0; i < numProperties; ++i) {
229: for (uint256 i = 0; i < numProperties; ++i) {
Nouns Builder
Gas Optimizations Report
Replace
x <= y
withx < y + 1
, andx >= y
withx > y - 1
In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas There are 2 instances of this issue:
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/auction/Auction.sol
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/governance/treasury/Treasury.sol
<x> += <y>
costs more gas than<x> = <x> + <y>
for state variablesThere are 6 instances of this issue:
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/governance/governor/Governor.sol
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/token/metadata/MetadataRenderer.sol
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/token/Token.sol
Use
calldata
instead ofmemory
for function parametersIf a reference type function parameter is read-only, it is cheaper in gas to use calldata instead of memory. Calldata is a non-modifiable, non-persistent area where function arguments are stored, and behaves mostly like memory. Try to use calldata as a data location because it will avoid copies and also makes sure that the data cannot be modified.
There are 9 instances of this issue:
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/governance/governor/Governor.sol
It costs more gas to initialize non-
constant
/non-immutable
variables to zero than to let the default of zero be appliedNot overwriting the default for stack variables saves 8 gas. Storage and memory variables have larger savings
There are 5 instances of this issue:
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/governance/treasury/Treasury.sol
https://github.com/code-423n4/2022-09-nouns-builder/blob/main/src/token/metadata/MetadataRenderer.sol