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

Redundant Calculation in calculateBonus Function #6

Open
piyushshukla599 opened this issue Mar 14, 2024 · 2 comments
Open

Redundant Calculation in calculateBonus Function #6

piyushshukla599 opened this issue Mar 14, 2024 · 2 comments

Comments

@piyushshukla599
Copy link

piyushshukla599 commented Mar 14, 2024

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

@0xPilot
Copy link

0xPilot commented Jul 11, 2024

@deadshotryker Can I try to resolve on this issue?

@sharonphiliplima
Copy link

Is this not resolved yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants