#41688 [SC-Insight] Code can be optimized to to save a significant amount of gas.

Submitted on Mar 17th 2025 at 15:22:03 UTC by @p3nc1l for Audit Comp | Yeet

  • Report ID: #41688

  • Report Type: Smart Contract

  • Report severity: Insight

  • Target: https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/Reward.sol

  • Impacts:

Description

Brief/Intro

The Reward contract uses IERC20 type to distribute ERC20 token as rewards , but the way IERC20 is defined is unoptimized , as the IERC20 type doesn't get get re-initialized, it must have been declared as immutable.

Vulnerability Details

look at line

    IERC20 public token;

now when ever claim() function from gets called this token variable triggered twice , which causes around 2*2100=4200 more gas consumption for the transaction.

    function claim() external {
        uint256 amountEarned = getClaimableAmount(msg.sender);
        require(amountEarned != 0, "Nothing to claim");
        require(token.balanceOf(address(this)) >= amountEarned, "Not enough tokens in contract");


        lastClaimedForEpoch[msg.sender] = currentEpoch - 1; // This should be the fix.
        token.transfer(msg.sender, amountEarned);
        emit Rewarded(msg.sender, amountEarned, block.timestamp);
    }

Impact Details

The caller has to pay more gas for the same operation which could be done using less gas.

References

Add any relevant links to documentation or code

Proof of Concept

Proof of Concept

Was this helpful?