Skip to content
Business logic Audit finding Intermediate

money-market-contracts/contracts/market claim_rewards may revert due to spend_limit set on distributor

The market contract's claim_rewards function asks the distributor contract to spend the reward amount, but the distributor rejects any spend above its configured spend_limit. Once a user's accumulated rewards exceed that limit, their claim transaction reverts and they cannot withdraw the rewards.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

While claim_rewards from the money-market, it calls the distributor_contract#spend() to send the rewards.

https://github.com/code-423n4/2022-02-anchor/blob/7af353e3234837979a19ddc8093dc9ad3c63ab6b/contracts/money-market-contracts/contracts/market/src/borrow.rs#L216-L234

let messages: Vec<CosmosMsg> = if !claim_amount.is_zero() {
    vec![CosmosMsg::Wasm(WasmMsg::Execute {
        contract_addr: deps
            .api
            .addr_humanize(&config.distributor_contract)?
            .to_string(),
        funds: vec![],
        msg: to_binary(&FaucetExecuteMsg::Spend {
            recipient: if let Some(to) = to {
                to.to_string()
            } else {
                borrower.to_string()
            },
            amount: claim_amount.into(),
        })?,
    })]
} else {
    vec![]
};

However, the distributor_contract#spend() function have a spend_limit config and it will revert if the amount is larger than the spend_limit.

https://github.com/code-423n4/2022-02-anchor/blob/7af353e3234837979a19ddc8093dc9ad3c63ab6b/contracts/anchor-token-contracts/contracts/distributor/src/contract.rs#L153-L155

if config.spend_limit < amount {
    return Err(StdError::generic_err("Cannot spend more than spend_limit"));
}

As a result, users won’t be able to claim their rewards anymore once the amount of the rewards excess the spend_limit config on distributor_contract.

Recommended Mitigation Steps

Consider removing the spend_limit or allowing users to specify an amount when claim_rewards.

Alex the Entreprenerd (triage) commented:

Loss of yield, conditional on reaching limit, consider reducing severity.

Albert Chon (judge) decreased severity to Medium and commented:

Can be mitigated with a large spend limit, which likely exists to prevent catastrophic cases. The issue is correct though, that this is a bug. Downgrading to medium severity though, given the practicality.


The original report as published on Code4rena, by WatchPug. 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 market contract forwards the full accumulated reward amount to the distributor without checking or capping it against the distributor's spend_limit.

Impact

Users could be unable to claim rewards once the amount exceeds the spend limit, causing a loss of yield; the judge noted it can be mitigated with a large spend limit.

What the attacker needed

Accumulated rewards exceed spend_limit

The fix

The report recommends removing the spend_limit or letting users specify a smaller amount when claiming.

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.

A smart contract pays out rewards by asking a second contract to send the tokens. That second contract has a maximum amount it will send in one go. If a user waits until their rewards are bigger than that maximum, the payout request is refused and the claim fails.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Anchor contest

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.