code-423n4 / 2022-08-foundation-findings

0 stars 0 forks source link

Gas Optimizations #223

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Use !=0 instead of >0 inside require statements to reduce gas:

https://github.com/code-423n4/2022-08-foundation/blob/main/contracts/NFTDropCollection.sol#L88 https://github.com/code-423n4/2022-08-foundation/blob/main/contracts/NFTDropCollection.sol#L130 https://github.com/code-423n4/2022-08-foundation/blob/main/contracts/NFTDropCollection.sol#L131

Optimize if statements to reduce gas:

In line https://github.com/code-423n4/2022-08-foundation/blob/main/contracts/NFTCollection.sol#L333, change if (bytes(baseURI_).length != 0) { to if (bytes(baseURI_).length) { to save gas. This doesn't change the logic of the if statement.

HardlyDifficult commented 2 years ago

Use != 0 instead of > 0

Invalid. We tested the recommendation and got the following results:

createNFTDropCollection gas reporter results:
  using > 0 (current):
    - 319246  ·     319578  ·      319361
  using != 0 (recommendation):
    -  319252  ·     319584  ·      319367
  impact: +6 gas

Optimize if statements to reduce gas:

Invalid -- that's a compile error