gas

Unnesessery argument in getTimeout function

Reward

Total

22.48 USDC

Selected
9.26 USDC
6.61 USDC
6.61 USDC
Selected Submission

Unnesessery argument in getTimeout function

Severity

Gas Optimization / Informational

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/d1c5501aa79320ca0aeaa73f47f0dbc88c7b77e2/src/libraries/OracleLib.sol#L36

Summary

Unnecessary argument passed to getTimeout function will cost additional gas

Impact

Around 2200 extra gas will be used for storing unnecessary argument

[PASS] testGetTimeout() (gas: 5532)
[PASS] testGetTimeoutWhitounArgument() (gas: 3352)

Tools Used

Observation, foundry unit test

Functions:

    function getTimeout(AggregatorV3Interface /* chainlinkFeed */ ) public pure returns (uint256) {
        return TIMEOUT;
    }

    function getTimeoutWhitounArgument() public pure returns (uint256) {
        return TIMEOUT;
    }

Tests:

    function testGetTimeout() public {
        uint256 expectedTimeout = 3 hours;
        assertEq(OracleLib.getTimeout(AggregatorV3Interface(address(aggregator))), expectedTimeout);
    }

    function testGetTimeoutWhitounArgument() public {
        uint256 expectedTimeout = 3 hours;
        assertEq(OracleLib.getTimeoutWhitounArgument(), expectedTimeout);
    }

Recommendations

Rewrite function to

    function getTimeoutWhitounArgument() public pure returns (uint256) {
        return TIMEOUT;
    }