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

Unnecessary array boundaries check when loading an array element twice #21

Open
code423n4 opened this issue Dec 9, 2021 · 2 comments
Open
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

robee

Vulnerability details

There are places in the code (especially in for-each loops) that loads the same array element more
than once. In such cases, only one array boundaries check should take place, and the rest are unnecessary.
Therefore, this array element should be cached in a local variable and then be loaded
again using this local variable, skipping the redundent second array boundaries check:

    CreditLine.sol, variable name: _strategyList times: 2 at: _withdrawBorrowAmount
    CreditLine.sol, variable name: _strategyList times: 2 at: _repayFromSavingsAccount
    CreditLine.sol, variable name: _strategyList times: 3 at: _transferCollateral
    SavingsAccount.sol, variable name: _strategyList times: 2 at: withdrawAll
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 9, 2021
code423n4 added a commit that referenced this issue Dec 9, 2021
@ritik99 ritik99 added the duplicate This issue or pull request already exists label Dec 25, 2021
@ritik99
Copy link
Collaborator

ritik99 commented Dec 25, 2021

Duplicate of #157

@ritik99 ritik99 marked this as a duplicate of #121 Dec 25, 2021
@ritik99 ritik99 closed this as completed Dec 25, 2021
@ritik99 ritik99 marked this as a duplicate of #157 Dec 25, 2021
@ritik99 ritik99 marked this as not a duplicate of #121 Dec 25, 2021
@0xean
Copy link
Collaborator

0xean commented Jan 22, 2022

not a duplicate of #157 - different suggestion regarding index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

3 participants