DropPerSecond is not updated homogeneously, the rewards emission can be much higher than expected in some cases
The smart contract's reward emission rate update function suffers from precision loss when calculating elapsed months, causing the rate to decrease more slowly than intended. An attacker could exploit this to cause higher-than-expected total rewards emission.
Submitted by WatchPug, also found by Czar102
HolyPaladinToken.sol#L715-L743
function _updateDropPerSecond() internal returns (uint256){
// If no more need for monthly updates => decrease duration is over
if(block.timestamp > startDropTimestamp + dropDecreaseDuration) {
// Set the current DropPerSecond as the end value
// Plus allows to be updated if the end value is later updated
if(currentDropPerSecond != endDropPerSecond) {
currentDropPerSecond = endDropPerSecond;
lastDropUpdate = block.timestamp;
}
return endDropPerSecond;
}
if(block.timestamp < lastDropUpdate + MONTH) return currentDropPerSecond; // Update it once a month
uint256 dropDecreasePerMonth = (startDropPerSecond - endDropPerSecond) / (dropDecreaseDuration / MONTH);
uint256 nbMonthEllapsed = (block.timestamp - lastDropUpdate) / MONTH;
uint256 dropPerSecondDecrease = dropDecreasePerMonth * nbMonthEllapsed;
// We calculate the new dropPerSecond value
// We don't want to go under the endDropPerSecond
uint256 newDropPerSecond = currentDropPerSecond - dropPerSecondDecrease > endDropPerSecond ? currentDropPerSecond - dropPerSecondDecrease : endDropPerSecond;
currentDropPerSecond = newDropPerSecond;
lastDropUpdate = block.timestamp;
return newDropPerSecond;
}
When current time is lastDropUpdate + (2*MONTH-1):
nbMonthEllapsed will be round down to 1, while it’s actually 1.99 months passed, but because of precision loss, the smart contract will believe it’s only 1 month elapsed, as a result, DropPerSecond will only decrease by 1 * dropDecreasePerMonth.
In another word, due to the precision loss in calculating the number of months elapsed, for each _updateDropPerSecond() there can be a short of up to 1 * dropDecreasePerMonth for the decrease of emission rate.
At the very edge case, if all the updates happened just like the scenario above. by the end of the dropDecreaseDuration, it will drop only 12 * dropDecreasePerMonth in total, while it’s expected to be 24 * dropDecreasePerMonth.
So only half of (startDropPerSecond - endDropPerSecond) is actually decreased. And the last time updateDropPerSecond is called, DropPerSecond will suddenly drop to endDropPerSecond.
Impact
As the DropPerSecond is not updated correctly, in most of the dropDecreaseDuration, the actual rewards emission rate is much higher than expected. As a result, the total rewards emission can be much higher than expected.
Recommended Mitigation Steps
Change to:
function _updateDropPerSecond() internal returns (uint256){
// If no more need for monthly updates => decrease duration is over
if(block.timestamp > startDropTimestamp + dropDecreaseDuration) {
// Set the current DropPerSecond as the end value
// Plus allows to be updated if the end value is later updated
if(currentDropPerSecond != endDropPerSecond) {
currentDropPerSecond = endDropPerSecond;
lastDropUpdate = block.timestamp;
}
return endDropPerSecond;
}
if(block.timestamp < lastDropUpdate + MONTH) return currentDropPerSecond; // Update it once a month
uint256 dropDecreasePerMonth = (startDropPerSecond - endDropPerSecond) / (dropDecreaseDuration / MONTH);
uint256 nbMonthEllapsed = UNIT * (block.timestamp - lastDropUpdate) / MONTH;
uint256 dropPerSecondDecrease = dropDecreasePerMonth * nbMonthEllapsed / UNIT;
// We calculate the new dropPerSecond value
// We don't want to go under the endDropPerSecond
uint256 newDropPerSecond = currentDropPerSecond - dropPerSecondDecrease > endDropPerSecond ? currentDropPerSecond - dropPerSecondDecrease : endDropPerSecond;
currentDropPerSecond = newDropPerSecond;
lastDropUpdate = block.timestamp;
return newDropPerSecond;
}
Kogaroshi (Paladin) confirmed and commented:
Mitigation for this issue can be found here: PaladinFinance/Paladin-Tokenomics@4d050eb.
Mitigation chosen is different from the Warden recommendation: since we want to keep the
dropPerSecondto have a monthly decrease, we set the newlastUpdateas the previouslastUpdate+ (nb_of_months_since_last_update*month_duration).
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 integer division truncation when computing the number of months elapsed, causing the decrease per update to be underestimated.
Impact
The actual rewards emission rate could be much higher than expected, leading to a total rewards emission that is much higher than intended.
What the attacker needed
None
The fix
The team mitigated by setting the new last update timestamp to the previous last update plus the number of whole months since the last update multiplied by the month duration, rather than using the warden's recommended scaling approach.
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.
This is a smart contract bug where the code that reduces reward payouts over time makes a rounding mistake. Because of that mistake, the rewards stay higher than they should for longer, so more tokens get given out than planned.
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.