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

Open
code423n4 opened this issue Jun 19, 2022 · 1 comment
Open

Gas Optimizations #209

code423n4 opened this issue Jun 19, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

  1. Title : Shorter code can be save more gas

1.) File : contracts/core/connext/facets/BridgeFacet.sol Line. 843

        _amount = _amount + sponsored;

change to :

_amount += sponsored:
  1. Title : Saving gas by removing = 0

This implementation code can be saving more gas by removing = 0, it because If a variable was not set/initialized, it is assumed to have default value to 0

Tool Used

Manual Review

Mitigation Step

Remove = 0

Occurances

core/connext/facets/BridgeFacet.sol#L1103        backUnbackedDebt = 0;
core/connext/facets/BridgeFacet.sol#L1108        portalFee = 0;
contracts/core/connext/facets/BridgeFacet.sol#L1046      amountIn = 0;
contracts/core/connext/facets/PortalFacet.sol#L154        _feeAmount = 0;
contracts/core/connext/facets/ProposedOwnableFacet.sol#L272    s._routerOwnershipTimestamp = 0;
contracts/core/connext/facets/ProposedOwnableFacet.sol#L283    s._assetOwnershipTimestamp = 0;
contracts/core/connext/facets/ProposedOwnableFacet.sol#L288    s._proposedOwnershipTimestamp = 0;
  1. Title : Using short reason string can be used for saving more gas

Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.

Tool Used

Manual Review

Occurances

contracts/core/connext/libraries/SwapUtils.sol#L342 "Balances must match multipliers"
contracts/core/connext/libraries/SwapUtils.sol#L595 "Cannot withdraw more than available"
contracts/core/connext/libraries/SwapUtils.sol#L649 "Cannot swap more than you own"
contracts/core/connext/libraries/SwapUtils.sol#L662 "Swap didn't result in min tokens"
contracts/core/connext/libraries/SwapUtils.sol#L697 "Cannot get more than pool balance"
contracts/core/connext/libraries/SwapUtils.sol#L703 "Swap needs more than max tokens"
contracts/core/connext/libraries/SwapUtils.sol#L716 "Cannot swap more than you own"
contracts/core/connext/libraries/SwapUtils.sol#L750 "Cannot swap more than you own"
contracts/core/connext/libraries/SwapUtils.sol#L756 "Swap didn't result in min tokens"
contracts/core/connext/libraries/SwapUtils.sol#L784 "Cannot get more than pool balance"
contracts/core/connext/libraries/SwapUtils.sol#L790 "Swap didn't result in min tokens"
contracts/core/connext/libraries/SwapUtils.sol#L823 "Amounts must match pooled tokens"
contracts/core/connext/libraries/SwapUtils.sol#L917 "minAmounts must match poolTokens"
contracts/core/connext/libraries/SwapUtils.sol#L1005 "Amounts should match pool tokens"
contracts/core/connext/libraries/SwapUtils.sol#L1015  "Cannot withdraw more than available"
contracts/core/connext/libraries/AmplificationUtils.sol#L86 "futureA_ must be > 0 and < MAX_A"
contracts/core/connext/libraries/AmplificationUtils.sol#L84 "Wait 1 day before starting ramp"
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 19, 2022
code423n4 added a commit that referenced this issue Jun 19, 2022
@liu-zhipeng
Copy link
Collaborator

Duplicated

@liu-zhipeng liu-zhipeng added the duplicate This issue or pull request already exists label Jul 1, 2022
@itsmetechjay itsmetechjay reopened this Jul 1, 2022
@0xleastwood 0xleastwood removed the duplicate This issue or pull request already exists label Aug 16, 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

4 participants