Skip to content
Smart contracts Audit finding Intermediate

LinearDistributor.declareReward() might revert after changing vestingDistributor .

The reward declaration function subtracts a stored previous vested amount from the current vested amount of the vesting distributor, but the admin can swap the distributor without resetting that stored value. If the new distributor reports a smaller vested amount, the subtraction underflows and the reward declaration reverts, blocking rewards until the admin restores the old distributor.

hansfriese Follow

Originally disclosed on Code4rena

Submitted by hansfriese

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

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

Impact

LinearDistributor.declareReward() might revert after changing vestingDistributor due to uint underflow.

Proof of Concept

In LinearDistributor.sol, there is a setVestingDistributor() function to update vestingDistributor.

And in declareReward(), it calculates the netVest and netTime by subtracting the previous amount and time.

File: 2023-02-malt\contracts\RewardSystem\LinearDistributor.sol
112:     uint256 currentlyVested = vestingDistributor.getCurrentlyVested();
113:
114:     uint256 netVest = currentlyVested - previouslyVested; //@audit revert after change vestingDistributor
115:     uint256 netTime = block.timestamp - previouslyVestedTimestamp;
116:

But there is no guarantee that the vested amount of the new vestingDistributor is greater than the previously saved amount after changing the distributor.

Furthermore, there is no option to change previouslyVested beside this declareReward() function and it will keep reverting unless the admin change back the distributor.

Recommended Mitigation Steps

I think it would resolve the above problem if we change the previous amounts as well while updating the distributor.

  function setVestingDistributor(address _vestingDistributor, uint _previouslyVested, uint _previouslyVestedTimestamp)
    external
    onlyRoleMalt(ADMIN_ROLE, "Must have admin privs")
  {
    require(_vestingDistributor != address(0), "SetVestDist: No addr(0)");
    vestingDistributor = IVestingDistributor(_vestingDistributor);

    previouslyVested = _previouslyVested;
    previouslyVestedTimestamp = _previouslyVestedTimestamp;
  }

0xScotch (Malt) confirmed and commented:

Setting previouslyVested during the setVestingDistributor call seems like a sufficient solution to this.


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 setter for the vesting distributor updates the distributor address but leaves the stored previously vested amount and timestamp untouched, so the later subtraction can underflow.

Impact

Reward declaration could revert after a distributor change, blocking rewards until the admin reverts the change; no funds are stolen.

What the attacker needed

Admin changes the vesting distributor; new distributor reports a smaller vested amount

The fix

The setter should also update the stored previously vested amount and timestamp, which the project confirmed as a sufficient solution.

How it was found

  1. An admin calls the setter to point the contract at a different vesting distributor.
  2. The stored previously vested amount is not updated.
  3. A reward declaration runs and subtracts the stored amount from the new distributor's vested amount.
  4. The subtraction underflows and the call reverts.

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 keeps a running total of rewards already counted. When an admin points it at a different source of vested amounts, the old running total is not reset, so the contract can try to subtract a bigger number from a smaller one. Solidity refuses to do that and the transaction fails, so rewards cannot be declared.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.