code-423n4 / 2022-02-nested-findings

0 stars 0 forks source link

Gas Optimizations #67

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
maximebrugel commented 2 years ago

"You can remove it to save some gas, or leave it if it was intended for future use with other factories" (Acknowledged)

Consider using EnumerableSet to store operators (Acknowledged)

"Could just use msg.sender and do not call an owner() function here" (Confirmed)

_checkMsgValue refactoring (Disputed)

"Could be". You need to pre-calculate the amount of ETH needed to check msg.value in a simple way.

"function withdraw calls nestedRecords twice" (Acknowledged)

"Could use 'unchecked' maths here, as underflow is not possible" (Confirmed)

harleythedogC4 commented 2 years ago

My personal judgments:

  1. "function transfer in NestedReserve is never used". Valid and medium-optimization.
  2. "EnumerableSet to store them". Valid and small-optimization.
  3. "Could just use msg.sender". Valid and small-optimization.
  4. "_checkMsgValue refactoring". The idea of refactoring the reserve check to be in the combined function is valid. Valid and small-optimization.
  5. "withdraw calls nestedRecords twice". Valid and small-optimization.
  6. "Could use 'unchecked' here". This was disputed in other gas reports as this already surfaced in the first contest. To be fair, this should be marked as invalid too. Invalid.
harleythedogC4 commented 2 years ago

Also, #66 has the additional issue:

  1. "remove this unused variable to save some gas (ETH)". Valid and small-optimization.
harleythedogC4 commented 2 years ago

Now, here is the methodology I used for calculating a score for each gas report. I first assigned each submission to be either small-optimization (1 point), medium-optimization (5 points) or large-optimization (10 points), depending on how useful the optimization is. The score of a gas report is the sum of these points, divided by the maximum number of points achieved by a gas report. This maximum number was 10 points, achieved by #67.

The number of points achieved by this report is 10 points. Thus the final score of this gas report is (10/10)*100 = 100.