Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #8

Open
code423n4 opened this issue Feb 10, 2022 · 3 comments
Open

Gas Optimizations #8

code423n4 opened this issue Feb 10, 2022 · 3 comments
Assignees
Labels
bug Something isn't working G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

https://github.com/code-423n4/2022-02-nested/blob/main/contracts/FeeSplitter.sol (#L191, #L149, #L166)

  1. In sendFeesWithRoyalties, releaseTokens, releaseTokensNoETH function, add check amount!=0
require(amount!=0, "Incorrect amount");

https://github.com/code-423n4/2022-02-nested/blob/main/contracts/NestedRecords.sol#L76

  1. In updateHoldingAmount function, under the while loop, use return instead of break
if (tokens[tokenIndex] == _token) {
                    ...
                    return;
                }

https://github.com/code-423n4/2022-02-nested/blob/main/contracts/NestedFactory.sol#L317

  1. No need to check require(batchLength != 0, "NF: INVALID_ORDERS"); as this is already checked in all the calling functions like create, _processInputOrders

https://github.com/code-423n4/2022-02-nested/blob/main/contracts/NestedFactory.sol#L445

  1. The condition if (_amountToSpend > amounts[1]) is not required as the parent condition is already checking for require(amounts[1] <= _amountToSpend, "NestedFactory::_safeSubmitOrder: Overspent");
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 10, 2022
code423n4 added a commit that referenced this issue Feb 10, 2022
@adrien-supizet
Copy link
Collaborator

adrien-supizet commented Feb 15, 2022

  1. I'm not sure about the benefits of this one. To discuss
  2. This does not achieve what we want
  3. disputed, those are not the same checks
  4. confirmed

@adrien-supizet adrien-supizet added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Feb 15, 2022
@maximebrugel maximebrugel self-assigned this Feb 18, 2022
@harleythedogC4
Copy link
Collaborator

My personal judgments:

  1. "add check amount!=0". I don't see why this is a gas-optimization, and there is no explanation why this is a good idea. Invalid.
  2. "use return instead of break". I disagree with the sponsor, return seems to do the same thing as break in this scenario. Valid and small optimization.
  3. "No need to check require(batchLength != 0, "NF: INVALID_ORDERS");". Agree with sponsor, these are different checks. Invalid.
  4. "The condition if (_amountToSpend > amounts[1]) is not required". Valid and small optimization.

@harleythedogC4
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

4 participants