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

0 stars 0 forks source link

Gas Optimizations #16

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

GAS issues

  1. Change the incremental logic from i++ to ++i in order to save some opcodes:

  2. The following structs could be optimized moving the position of certains values in order to save slot storages:

  3. Use delete instead of set to default value (false or address(0))

  4. Change the logic in order to save one variable

    function _setOwner(address newOwner) private {
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
adrien-supizet commented 2 years ago
  1. already surfaced in first audit
  2. duplicated https://github.com/code-423n4/2022-02-nested-findings/issues/28
  3. Invalid, this makes no difference
  4. acknowledged
harleythedogC4 commented 2 years ago

My personal judgements:

  1. "Change the incremental logic from i++ to ++i". Agree with sponsor. Invalid.
  2. "The following structs could be optimized". I am going to disagree with the sponsor here, in theory there is an optimzation here, and obviously I can't reproduce the sponsor's claim of the gas costs actually increasing. I will mark as Valid and small-optimization.
  3. "Use delete instead of set to default value". Agree with sponsor, according to here, it seems that there is no difference in this case. Invalid.
  4. "Change the logic in order to save one variable". 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 2 points. Thus the final score of this gas report is (2/10)*100 = 20.