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 double totalLiquidity() call in function availableBalance #121

Open
code423n4 opened this issue Jan 11, 2022 · 0 comments
Open
Assignees
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

Tomio

Vulnerability details

Impact

by saving totalLiquidity() to memory can save more gas instead of doing double function call

Proof of Concept

Before: https://github.com/code-423n4/2022-01-insure/blob/main/contracts/PoolTemplate.sol#L829
// gas cost 23862

After:

function totalLiquidity() public view returns (uint256){
     return 10;
 }   

function availableBalance()public view returns (uint256 _balance)
    {
        uint256 saveTotalLiquidity = totalLiquidity();
        if (saveTotalLiquidity > 0) {
            return saveTotalLiquidity - lockedAmount;
        } else {
            return 0;
        }
    }

// gas cost 23840

Tools Used

Remix

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 11, 2022
code423n4 added a commit that referenced this issue Jan 11, 2022
@oishun1112 oishun1112 added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 13, 2022
@oishun1112 oishun1112 added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Jan 25, 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) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants