Rewards for initial period may be lost in BathBuddy
contract
#1295
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-03
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/periphery/BathBuddy.sol#L191-L228
Vulnerability details
Impact
Rewards in the BathBuddy contract are initiated when the owner calls the
notifyRewardAmount
. This function calculates the reward rate per second (lines 196-198 and 207-208) and also records the start of the reward period (line 223):https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/periphery/BathBuddy.sol#L191-L228
The intention here is to calculate how many tokens should be rewarded by unit of time (second) and record the span of time for the reward cycle. However, this has an edge case where rewards are not counted for the initial period of time until there is at least one participant (in this case, a holder of BathTokens). During this initial period of time, the reward rate will still apply but as there isn't any participant, then no one will be able to claim these rewards. See PoC for a detailed example of the issue.
Proof of Concept
In the following test, we initiate the reward process by calling
notifyRewardAmount
. At the middle of the duration process, we mint BathTokens to Alice to represent her participant. At the end of the duration process, after Alice claims her rewards, half of them will still be held in theBathBuddy
contract.Note: the snippet shows only the relevant code for the test. Full test file can be found here.
Recommendation
A possible solution to the issue would be to set the start and end time for the current reward cycle when the first participant joins the reward program, i.e. when the total supply is greater than zero, instead of starting the process in the
notifyRewardAmount
.References
The following reports can be used as a reference for the described issue:
The text was updated successfully, but these errors were encountered: