Skip to content
DoS Audit finding Intermediate

LinearDistributor.declareReward can revert due to dependency of balance

The declareReward function in LinearDistributor can revert if the contract's collateral token balance exceeds the buffer requirement, because the forfeit logic requires the excess to be no more than the declared balance. An attacker can send collateral tokens to the contract to trigger this revert, potentially causing a permanent denial of service if enough tokens are sent to cover all vested rewards.

hansfriese Follow

Originally disclosed on Code4rena

Submitted by hansfriese

https://github.com/code-423n4/2023-02-malt/blob/main/contracts/RewardSystem/LinearDistributor.sol#L147-L151

https://github.com/code-423n4/2023-02-malt/blob/main/contracts/RewardSystem/LinearDistributor.sol#L185-L186

https://github.com/code-423n4/2023-02-malt/blob/main/contracts/RewardSystem/LinearDistributor.sol#L123-L136

Impact

LinearDistributor.declareReward will revert and it can cause permanent DOS.

Proof of Concept

In LinearDistributor.declareReward, if the balance is greater than the bufferRequirement, the rest will be forfeited.

    if (balance > bufferRequirement) {
      // We have more than the buffer required. Forfeit the rest
      uint256 net = balance - bufferRequirement;
      _forfeit(net);
    }

And in _forfeit, it requires forfeited (= balance - bufferRequirement) <= declaredBalance.

  function _forfeit(uint256 forfeited) internal {
    require(forfeited <= declaredBalance, "Cannot forfeit more than declared");

So when an attacker sends some collateral tokens to LinearDistributor, the balance will be increased and it can cause revert in _forfeit and declareReward.

Since declareReward sends vested amount before _forfeit and the vested amount will be increased by time, so this DOS will be temporary.

    uint256 distributed = (linearBondedValue * netVest) / vestingBondedValue;
    uint256 balance = collateralToken.balanceOf(address(this));

    if (distributed > balance) {
      distributed = balance;
    }

    if (distributed > 0) {
      // Send vested amount to liquidity mine
      collateralToken.safeTransfer(address(rewardMine), distributed);
      rewardMine.releaseReward(distributed);
    }

    balance = collateralToken.balanceOf(address(this));

But if the attacker increases the balance enough to cover all reward amount in vesting, declareReward will always revert and it can cause permanent DOS.

decrementRewards updates declaredBalance, but it only decreases declaredBalance, so it can’t mitigate the DOS.

Recommended Mitigation Steps

Track collateral token balance and add sweep logic for unused collateral tokens in LinearDistributor.

Picodes (judge) decreased severity to Medium and commented:

As this is a DOS scenario where funds are not at risk and the chances that rewards are lost forever are low, downgrading to Medium.

0xScotch (Malt) confirmed and commented:

I agree this is a DOS vector but a continued attack would require the attacker to spend more and more capital. Should be fixed but doesn’t pose any risk of material loss.


The original report as published on Code4rena, by hansfriese. 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 contract assumes its collateral token balance only changes through its own functions, so an external transfer can make the forfeit amount exceed the declared balance and cause a revert.

Impact

The declareReward function can revert, causing a temporary denial of service, and if enough tokens are sent to cover all vested rewards, it can cause a permanent denial of service; however, funds are not at risk and the attacker must spend increasing capital.

What the attacker needed

Attacker can send tokens to the contract; contract has declared rewards

The fix

The contract should track the collateral token balance internally and add logic to sweep unused collateral tokens.

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 distributes rewards over time. It checks its token balance and tries to forfeit any extra tokens beyond a buffer. But if someone sends extra tokens directly to the contract, the forfeit check fails and the reward distribution stops working. This can block rewards from being paid out.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by hansfriese

View all

65 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.