Skip to content
Business logic Audit finding Intermediate

RewardThrottle.setTimekeeper: If changing the timekeeper causes the epoch to change, it will mess up the system

The setTimekeeper function lets a privileged role swap the timekeeper contract while the reward throttle is active, and if the new timekeeper reports a different epoch number the reward accounting breaks. An attacker with that role could raise the epoch and then claim a large batch of rewards, or lower it and block rewards for the current epoch.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

RewardThrottle.setTimekeeper allows POOLUPDATERROLE to update the timekeeper when RewardThrottle is active:

  function setTimekeeper(address _timekeeper)
    external
    onlyRoleMalt(POOL_UPDATER_ROLE, "Must have pool updater privs")
  {
    require(_timekeeper != address(0), "Not address 0");
    timekeeper = ITimekeeper(_timekeeper);
  }

if newTimekeeper.epoch changes, it will cause the following:

  1. The newTimekeeper.epoch increases, and the user can immediately call checkRewardUnderflow to fill the gap epoch, thereby distributing a large amount of rewards.
  2. The newTimekeeper.epoch decreases, and the contract will use the state of the previous epoch. Since the state.rewarded has reached the upper limit, this will cause the current epoch to be unable to receive rewards.

Proof of Concept

https://github.com/code-423n4/2023-02-malt/blob/700f9b468f9cf8c9c5cffaa1eba1b8dea40503f9/contracts/RewardSystem/RewardThrottle.sol#L690-L696

Recommended Mitigation Steps

Consider only allowing setTimekeeper to be called when RewardThrottle is not active.

0xScotch (Malt) confirmed and commented:

This is a good find and I think we will just remove the setTimekeeper methods. There is no reason for the timekeeper to ever be updated at this point given all it does it track epochs.

Historically this method was there because what we now call the timekeeper was called the MaltDAO and was earmarked to be used for many other things other than timekeeping. Eventually we realised the timekeeping should be separated into its own thing. These methods were clearly forgotten about and not removed.


The original report as published on Code4rena, by cccz. 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 setTimekeeper function does not check that the new timekeeper reports the same epoch as the old one, and does not reset the per-epoch reward state.

Impact

A holder of the pool updater role could cause a large amount of rewards to be distributed early, or make the current epoch unable to receive rewards.

What the attacker needed

POOL_UPDATER_ROLE; RewardThrottle is active

The fix

The project said it would remove the setTimekeeper methods entirely, since the timekeeper should never need updating.

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 tracks time in numbered periods called epochs and pays out rewards per epoch. A special admin function can swap the component that reports the current epoch, but the contract does not reset its reward bookkeeping when that happens. If the new component reports a different epoch number, the reward maths is wrong, so someone with admin rights could either collect too many rewards or stop rewards being 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.

More by cccz

View all

104 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.