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

Open
code423n4 opened this issue Dec 14, 2021 · 0 comments
Open
Labels
bug Something isn't working 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:

    PieFactoryContract.sol, variable name: _tokens times: 2 at: bakePie
    SingleNativeTokenExit.sol, variable name: tokens times: 2 at: exitEth
    SingleTokenJoin.sol, variable name: tokens times: 2 at: _joinTokenSingle
    SingleTokenJoin.sol, variable name: amounts times: 2 at: _joinTokenSingle
    SingleTokenJoinV2.sol, variable name: inputs times: 4 at: _joinTokenSingle
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 14, 2021
code423n4 added a commit that referenced this issue Dec 14, 2021
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