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

Closed
code423n4 opened this issue Mar 30, 2022 · 1 comment
Closed

Gas Optimizations #154

code423n4 opened this issue Mar 30, 2022 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix)

Comments

@code423n4
Copy link
Contributor

Redundant Operation

Description

address(this).balance - _fromBalance is found to be operated twice while it could be operated once and save the result to a local variable for later use.

Permalinks

Mitigation

For greater gas-optimization, the code can be rewrite as following:

/* from */
require(address(this).balance - _fromBalance >= _anyswapData.amount, "ERR_INVALID_AMOUNT");
uint256 _postSwapBalance = address(this).balance - _fromBalance;
require(_postSwapBalance > 0, "ERR_INVALID_AMOUNT");

/* to */
uint256 _postSwapBalance = address(this).balance - _fromBalance;
require(_postSwapBalance >= _anyswapData.amount && _postSwapBalance > 0, "ERR_INVALID_AMOUNT");
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Mar 30, 2022
code423n4 added a commit that referenced this issue Mar 30, 2022
@H3xept H3xept added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Apr 11, 2022
@H3xept H3xept closed this as completed Apr 11, 2022
@H3xept H3xept reopened this Apr 11, 2022
@gzeoneth
Copy link
Member

Warden submitted multiple QA report #149

@gzeoneth gzeoneth added the duplicate This issue or pull request already exists label Apr 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 duplicate This issue or pull request already exists G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix)
Projects
None yet
Development

No branches or pull requests

3 participants