Skip to content

Redundant Calculation in calculateBonus Function #6

@piyushshukla599

Description

@piyushshukla599

The calculateBonus function in the StakingBonus contract redundantly calculates the bonus amount, leading to inefficient gas usage. The redundant calculation occurs when returning the bonus value after checking the contract's token balance.

once to assign the value to the bonus variable and again before returning the value. This redundant calculation consumes unnecessary gas and increases execution time.

https://github.com/zerolend/governance/blob/a30d8bb825306dfae1ec5a5a47658df57fd1189b/contracts/vesting/StakingBonus.sol#L92C5-L95C42

function calculateBonus( uint256 amount ) public view override returns (uint256) { uint256 bonus = (amount * bonusBps) / 100; // if we don't have enough funds to pay out bonuses, then return 0 if (zero.balanceOf(address(this)) < bonus) return 0; return (amount * bonusBps) / 100; } }

@deadshotryker @M3gA-Mind

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions