LinearDistributor.declareReward: previouslyVested may update incorrectly, which will cause some rewards to be lost
In LinearDistributor.declareReward, when the calculated reward exceeds the contract's balance, the distributed amount is capped at the balance, but previouslyVested is still advanced to the full currentlyVested value. As a result, the rewards that could not be paid out are skipped and lost in subsequent distributions.
Submitted by cccz
In LinearDistributor.declareReward, distributed represents the reward to distribute and is calculated using netVest(currentlyVested - previouslyVested).
At the same time, distributed cannot exceed balance, which means that if balance < linearBondedValue /ast netVest / vestingBondedValue, part of the rewards in netVest will be lost.
uint256 netVest = currentlyVested - previouslyVested;
uint256 netTime = block.timestamp - previouslyVestedTimestamp;
if (netVest == 0 || vestingBondedValue == 0) {
return;
}
uint256 linearBondedValue = rewardMine.valueOfBonded();
uint256 distributed = (linearBondedValue * netVest) / vestingBondedValue;
uint256 balance = collateralToken.balanceOf(address(this));
if (distributed > balance) {
distributed = balance;
}
At the end of the function, previouslyVested is directly assigned to currentlyVested instead of using the Vested adjusted according to distributed, which means that the previously lost rewards will also be skipped in the next distribution.
previouslyVested = currentlyVested;
previouslyVestedTimestamp = block.timestamp;
Also, in the next distribution, bufferRequirement will be small because distributed is small, so it may increase the number of forfeits.
if (netTime < buf) {
bufferRequirement = (distributed * buf * 10000) / netTime / 10000;
} else {
bufferRequirement = distributed;
}
if (balance > bufferRequirement) {
// We have more than the buffer required. Forfeit the rest
uint256 net = balance - bufferRequirement;
_forfeit(net);
}
Proof of Concept
Recommended Mitigation Steps
Consider adapting previouslyVested based on distributed:
uint256 linearBondedValue = rewardMine.valueOfBonded();
uint256 distributed = (linearBondedValue * netVest) / vestingBondedValue;
uint256 balance = collateralToken.balanceOf(address(this));
if (distributed > balance) {
distributed = balance;
+ currentlyVested = distributed * vestingBondedValue / linearBondedValue + previouslyVested;
}
0xScotch (Malt) confirmed and commented:
Finding is correct as stated. I’m not sure how we would ever get into the state required to manifest the bug. Obviously the implementation is incorrect though, so will be fixed.
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 code advances previouslyVested to the full currentlyVested value even when distributed was capped by the contract balance, so the unpaid portion is never carried forward.
Impact
Some rewards could be permanently lost, and the smaller distributed amount may also reduce bufferRequirement, potentially increasing forfeits in later distributions.
What the attacker needed
Contract balance below vested reward
The fix
The code should be fixed so that previouslyVested is advanced only by the vested amount corresponding to the actually distributed reward.
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 contract tracks how much reward has vested over time and pays out what it can. If it does not have enough tokens to pay the full amount, it pays less but still records the full amount as paid, so the unpaid part is forgotten. The fix is to only advance the recorded amount by what was actually paid.
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.