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 #97

Open
code423n4 opened this issue Jun 18, 2022 · 4 comments
Open

Gas Optimizations #97

code423n4 opened this issue Jun 18, 2022 · 4 comments
Assignees
Labels

Comments

@code423n4
Copy link
Contributor

Nested Factory.sol

  • L66/99/107/122/125/153/160/161/168/169/191/250/251/252/286/288/289/312/313/330/331/359/379/406/407 /428/469/495/543/544/551/612/656 - It uses require but using Errors in solidity can reduce the deployment gas cost.

  • L98/106 - Modifiers generate a lot of gas cost, which can be modified by a private view function.

  • L124/136/196/256/315/333/369/412/651 - It is not necessary to initialize variables to their default value, this generates an extra gas cost (-2246 gas cost/ within a cycle for -19500 gas cost).

  • L124/136/196/256/315/333/369/412/651 - use a for loop with i++ instead of ++i unchecked = (in 10 iterations -21,136, in 100 iterations -32,656 gas).

  • L124/651- Instead of traversing an array and obtaining its length, directly obtain the length in a variable in memory and use it within the for loop.

  • L138 - Instead of doing a "variable - 1" or "variable + 1" operation, it is less expensive to do: ++variable or --variable.

OperatorResolver.sol

  • L27/39/57- It uses require but using Errors in solidity can reduce the deployment gas cost.

  • L40/60/75 - use a for loop with i++ instead of ++i unchecked = (in 10 iterations -21,136, in 100 iterations -32,656 gas).

  • L40/60/75 - It is not necessary to initialize variables to their default value, this generates an extra gas expense (-2246 gas cost/ within a cycle for -19500 gas cost).

  • L57/60/75 - If a local variable is generated, instead of using the length of an array inside the for, less gas is generated.

MixinOperatorResolver.sol

  • L23/77 - It uses require but using Errors in solidity can reduce the deployment gas cost.

  • L37/56 - use a for loop with i++ instead of ++i unchecked = (in 10 iterations -21,136, in 100 iterations -32,656 gas).

  • L37/56 - It is not necessary to initialize variables to their default value, this generates an extra gas expense (-2246 gas cost/ within a cycle for -19500 gas cost).

  • L37/56 - If a local variable is generated, instead of using the length of an array inside the for, less gas is generated.

OwnableProxyDelegation.sol

  • L25/26/27/41/57 - It uses require but using Errors in solidity can reduce the deployment gas cost.

  • L40 - Instead of using a modifier, a private view function could be used and it would not generate gas costs.

BeefyVaultOperator.sol

  • L18 - use a for loop with i++ instead of ++i unchecked = (in 10 iterations -21,136, in 100 iterations -32,656 gas).

  • L52/53/93/94 - These operations can be unchecked since it is not possible to generate an underflow.

BeefyZapBiswapLPVaultOperator.sol

  • L23/52/54/64/65/97/99/108/109/142/187/198/271/272 - It uses require but using Errors in solidity can reduce the deployment gas cost.

  • L27 - use a for loop with i++ instead of ++i unchecked = (in 10 iterations -21,136, in 100 iterations -32,656 gas).

  • L106/107 - These operations can be unchecked since it is not possible to generate an underflow.

StakingLPVaultHelpers.sol

  • L44/76 - These operations can be unchecked since it is not possible to generate an underflow.
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 18, 2022
code423n4 added a commit that referenced this issue Jun 18, 2022
@Yashiru Yashiru self-assigned this Jun 21, 2022
@Yashiru
Copy link
Collaborator

Yashiru commented Jun 24, 2022

Modifiers generate a lot of gas cost (Disputed)

This optimizes the deployment costs but reduces the readability of the code.
We prefer to keep good readability even if we have to pay more for the deployment.

Instead of using a modifier, a private view function could be used and it would not generate gas costs (Disputed)

This optimizes the deployment costs but reduces the readability of the code.
We prefer to keep good readability even if we have to pay more for the deployment.

@maximebrugel
Copy link
Collaborator

These operations can be unchecked since it is not possible to generate an underflow (Disputed)

  • BeefyVaultOperator (L52/53/93/94)
  • BeefyZapBiswapLPVaultOperator (L106/107)
  • StakingLPVaultHelpers (L44/76)

We can’t guarantee that the balance after is more/equal than before or the other way around (with an exotic token).

@maximebrugel
Copy link
Collaborator

Using Errors in solidity can reduce the deployment gas cost. (Duplicated)

#6 (see comment)

@Yashiru
Copy link
Collaborator

Yashiru commented Jun 24, 2022

It is not necessary to initialize variables to their default value (Duplicated)

Duplicated of #2 at For loop optimizaion

use a for loop with i++ instead of ++i unchecked (Duplicated)

Duplicated of #2 at For loop optimizaion

@Yashiru Yashiru added the duplicate This issue or pull request already exists label Jun 27, 2022
@JeeberC4 JeeberC4 removed the duplicate This issue or pull request already exists label Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants