Skip to content
Business logic Audit finding Intermediate

Borrower and Supplier rewards accrued could be lost when Admin replaces the reward distributor with a new reward distributor

The admin function that replaces the reward distributor contract does not first distribute accrued borrower and supplier rewards. If the admin swaps in a new distributor, those unclaimed rewards could be lost because the new contract may use different logic.

ravikiranweb3 Follow

Originally disclosed on Code4rena

Submitted by ravikiranweb3

Comptroller’s admin user can replace the rewards distributor contract with a new MultiRewardDistributor using _setRewardDistributor() function.

At that time, if the supplier and borrowers had accured rewards that are not distributed. The _setRewardDistributor() function replaces the old reward distributor with the new one without disbursing the borrower and supplier rewards accured.

The new logic of computation and distribution could be different in the newer version and hence before replacement, the accured rewards should be distributed using the existing logic.

The new accruals could take effect with nil accruals providing a clean slate.

Proof of Concept

The setRewardDistributor updates the mutiRewardDistributor contract with a new instance with out transferring the accured rewards to borrowers and lenders.

    function _setRewardDistributor(MultiRewardDistributor newRewardDistributor) public {
        require(msg.sender == admin, "Unauthorized");
        MultiRewardDistributor oldRewardDistributor = rewardDistributor;
        rewardDistributor = newRewardDistributor;
        emit NewRewardDistributor(oldRewardDistributor, newRewardDistributor);
    }

The above set function should be added with a logic to look at all the markets and for each market, the borrower and supplier rewards should be disbursed before the new instance is updated. As long as there are accured rewards, the old instance should not be replaced.

Recommended Mitigation Steps

Approach 1: Onchain approach

Step 1: Maintain a list of all accounts that participate in borrowing and supplying. getAllParticipants() returns a list of participants.

Step 2: Add an internal function disburseAllRewards() which can be called by adminOnly. This function looks for all partitipant accounts and for all markets, it claims rewards before updating the rewards distributor with a new instance.

 function disburseAllRewards() internal adminOnly {
        address[] memory holders = getAllParticipants();
        MToken[] memory mTokens = getAllMarkets();
        claimReward(holders, mTokens, true, true);
 }

 // @audit use the existing claimReward function to disburse the rewards to accounts that had accruals.

Approach 2: Offchain approach

As the number of participants and markets grow, the onchain approach may result in DOS as the size of computations may not fit in a single block due to gas limit.

As an alternative, the claimReward() could be called from the outside for all the holders and markets in smaller chunks.

Use getOutstandingRewardsForUser() function to check if there are any un-disbursed rewards in the MultiRewarddistributor contract. Only if there are no un-disbursed rewards, then only allow the admin to replace the reward distributor contract with a new instance.

Taking these steps will prevent the potential case where borrowers and suppliers could loose accured rewards.

Key drive away with this approach is, unless all the accured are distributed and they is nothing to distribute, dont update the multi reward distributor contract.

ElliotFriedman (Moonwell) confirmed, but disagreed with severity and commented:

This is valid, but disagree with severity since admin is trusted. Otherwise, if admin isn’t trusted, then they could rug all the funds in the contract using the _rescueFunds method.

alcueca (Judge) commented:

@ElliotFriedman - Note that the admin doesn’t need to be malicious. You could be a few months down the line, and receive a bug report that forces you to pause and replace the rewards distributor. It would be really uncomfortable to move the not claimed rewards to the new contract.


The original report as published on Code4rena, by ravikiranweb3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the reward distributor replacement function does not settle outstanding rewards before switching to a new contract.

Impact

Borrowers and suppliers could lose rewards they had already earned if the admin replaces the reward distributor before those rewards are claimed.

What the attacker needed

Admin replaces reward distributor; unclaimed rewards exist

The fix

Before replacing the reward distributor, the admin should distribute all accrued rewards, or the replacement should be blocked until no outstanding rewards remain.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In a lending system, people earn rewards for borrowing and supplying. These rewards build up over time and are paid out later. The report says that if an administrator swaps out the contract that tracks rewards, any rewards not yet paid out might disappear because the new contract does not know about them.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by ravikiranweb3

View all

1 more disclosed report, best first.

More from Moonwell

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.