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

Open
code423n4 opened this issue Jun 12, 2022 · 0 comments
Open

Gas Optimizations #42

code423n4 opened this issue Jun 12, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

In the following places, gas can be saved by caching the length of the array:

  • RelayerFacet.sol#L140
  • RelayerFacet.sol#L164

In the following places, gas can be saved by marking the addition in the loop as unchecked:

  • DiamondLoupeFacet.sol#L31
  • Encoding.sol#L22
  • Encoding.sol#L36
  • SwapUtils.sol: #L254, #L268, #L289, #L300, #L302, #L344, #L405, #L425,

In the following places, both optimizations (caching of length & unchecked) can be applied:

  • StableSwapFacet.sol#L415
  • ConnextPriceOracle.sol#L176
  • Multicall.sol#L16
  • LibDiamond.sol#L104
  • LibDiamond.sol#L129
  • LibDiamond.sol#L147
  • LibDiamond.sol#L162
  • StableSwap.sol#L81
  • SwapUtils.sol: #L205, #L558, #L591, #L844, #L869, #L924, #L1014, #L1019, #L1039, #L1055

SafeMath is used in a few places unnecessarily (not needed for Solidity v0.8):

  • ConnextPriceOracle.sol
  • OZERC20.sol
  • Amplificationutils.sol
  • SwapUtils.sol

Other gas optimizations:

  • PortalFacet.sol#L150 and PortalFacet.sol#L153: Subtractions can be unchecked, because underflow was already checked.
  • StableSwapFacet.sol#L427: The line is a NOP for i = 0 and can therefore be moved inside the if statement that checks i > 0
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 12, 2022
code423n4 added a commit that referenced this issue Jun 12, 2022
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)
Projects
None yet
Development

No branches or pull requests

1 participant