sherlock-audit / 2024-07-exactly-stacking-contracts-judging

6 stars 3 forks source link

Afriaudit - Early Return in Harvest Function Prevents Reward Distribution #111

Closed sherlock-admin4 closed 1 month ago

sherlock-admin4 commented 1 month ago

Afriaudit

Medium

Early Return in Harvest Function Prevents Reward Distribution

Summary

The harvest function always returns early due to the condition amount < rewards[providerAsset].duration, preventing reward distribution.

Vulnerability Detail

The harvest function includes a condition that checks if the amount of rewards is less than the duration:

if (duration == 0 || amount < rewards[providerAsset].duration) return;

If this condition is always true, the function will return early and not proceed with the reward distribution, making the harvest function ineffective

Impact

The harvest function will never distribute rewards, leading to stakers not receiving their earned rewards and potentially disrupting the incentive mechanism of the staking contract.

Code Snippet

function harvest() public whenNotPaused {
    Market memMarket = market;
    address memProvider = provider;
    uint256 assets = Math.min(
        memMarket.convertToAssets(memMarket.allowance(memProvider, address(this))),
        memMarket.maxWithdraw(memProvider)
    );
    uint256 amount = assets.mulWadDown(providerRatio);
    IERC20 providerAsset = IERC20(address(memMarket.asset()));
    uint256 duration = rewards[providerAsset].duration;
    if (duration == 0 || amount < rewards[providerAsset].duration) return;

    memMarket.withdraw(

Tool used

Manual Review

Recommendation

remove that check.

Duplicate of #11