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.
Originally disclosed on Code4rena
Submitted by hansfriese
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
previouslyVestedduring thesetVestingDistributorcall seems like a sufficient solution to this.
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
- An admin calls the setter to point the contract at a different vesting distributor.
- The stored previously vested amount is not updated.
- A reward declaration runs and subtracts the stored amount from the new distributor's vested amount.
- 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.