`drawTimeoutAt()` causes the prize pool to shutdown one draw earlier
The drawTimeoutAt() function returns a shutdown timestamp one draw period too early, causing the prize pool to shut down before the intended number of missed draws. An attacker could not directly exploit this, but it breaks core functionality by preventing prize awards and causing loss of yield for depositors.
Source: https://github.com/sherlock-audit/2024-05-pooltogether-judging/issues/28
Found by
MiloTruck, hash
Summary
The shutdown timestamp returned by drawTimeoutAt() is one draw period early, causing the protocol to shut down one draw earlier than expected.
Vulnerability Detail
In PrizePool.sol, the prize pool shuts down if the number of unawarded draws in a row is equal to drawTimeout:
/// @notice The maximum number of draws that can be missed before the prize pool is considered inactive.
uint24 public immutable drawTimeout;
drawTimeout is used in drawTimeoutAt(), which determines the timestamp at which the pool shuts down:
function drawTimeoutAt() public view returns (uint256) {
return drawClosesAt(_lastAwardedDrawId + drawTimeout);
}
As seen from above, the pool shuts down at the close time of drawId = _lastAwardedDrawId + drawTimeout. However, this causes the pool to shut down one draw earlier than expected as draws can only be awarded after their close time in awardDraw():
uint24 awardingDrawId = getDrawIdToAward();
uint48 awardingDrawOpenedAt = drawOpensAt(awardingDrawId);
uint48 awardingDrawClosedAt = awardingDrawOpenedAt + drawPeriodSeconds;
if (block.timestamp < awardingDrawClosedAt) {
revert AwardingDrawNotClosed(awardingDrawClosedAt);
}
To illustrate the problem:
- Assume the following:
drawTimeout = 1, which means the pool should shut down after one draw has been missed.- No draws have been awarded yet, so
_lastAwardedDrawId = 0.
- The first draw to award is always
drawId = 1. - When
awardDraw()is called beforedrawId = 2, the check inawardDraw()will revert asblock.timestampis less than the close time ofdrawId = 1. - When
awardDraw()is called during or afterdrawId = 2(ie.block.timestampis greater than the close time ofdrawId = 1):_lastAwardedDrawId + drawTimeout = 0 + 1 = 1drawTimeoutAt()returns the close time ofdrawId = 1, so the pool has already shut down.awardDraw()reverts due to thenotShutdownmodifier.
As seen from above, awardDraw() can never be called when drawTimeout = 1, even though a draw was never missed. This demonstrates how drawTimeoutAt() returns a timestamp one draw period early.
Impact
When drawTimeout = 1, the prize pool will never award prizes to any vaults and will immediately shut down, causing a loss of yield for depositors. Furthermore, this breaks core functionality of the protocol as the only incentive for users to deposit into vaults is the chance of winning a huge prize.
When drawTimeout > 1, the prize pool will shut down when drawTimeout - 1 consecutive draws have been missed, which is one draw early.
Code Snippet
Tool used
Manual Review
Recommendation
Modify drawTimeoutAt() to return the close time of _lastAwardedDrawId + drawTimeout + 1:
function drawTimeoutAt() public view returns (uint256) {
- return drawClosesAt(_lastAwardedDrawId + drawTimeout);
+ return drawClosesAt(_lastAwardedDrawId + drawTimeout + 1);
}
Discussion
0xjuaan
Escalate
This issue should be low severity
The impact of this issue is that the prizePool will shutdown 1 draw earlier
This means that instead of shutting down 81 years later, the protocol will shutdown (81 years - 1 day) later.
Firstly the issue will only come into play around shutdown which is more than 81 years later. This amount of time is too large for the issue to be above low severity. For example, overflow when casting block.timestamp to uint32 has always been considered low, since the impact occurs in 82 years.
Secondly the fact that. the protocol shuts down 1 day earlier means that the protocol will shutdown 0.003% earlier. This is too small to be considered a medium severity issue.
sherlock-admin3
Escalate
This issue should be low severity
The impact of this issue is that the prizePool will shutdown 1 draw earlier
This means that instead of shutting down 81 years later, the protocol will shutdown (81 years - 1 day) later.
Firstly the issue will only come into play around shutdown which is more than 81 years later. This amount of time is too large for the issue to be above low severity. For example, overflow when casting block.timestamp to uint32 has always been considered low, since the impact occurs in 82 years.
Secondly the fact that. the protocol shuts down 1 day earlier means that the protocol will shutdown 0.003% earlier. This is too small to be considered a medium severity issue.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
MiloTruck
This means that instead of shutting down 81 years later, the protocol will shutdown (81 years - 1 day) later.
Firstly the issue will only come into play around shutdown which is more than 81 years later. This amount of time is too large for the issue to be above low severity. For example, overflow when casting block.timestamp to uint32 has always been considered low, since the impact occurs in 82 years.
Secondly the fact that. the protocol shuts down 1 day earlier means that the protocol will shutdown 0.003% earlier. This is too small to be considered a medium severity issue.
The prize pool will also shutdown one draw earlier than intended when consecutive draws are not awarded. If drawTimeout = 2, the pool will shutdown after one draw has been missed, instead of two as intended. I've literally written this in my issue...
0xspearmint1
(The escalation was on my behalf)
The following is from the test suite
uint24 grandPrizePeriodDraws = 365;
uint48 drawPeriodSeconds = 1 days;
uint24 drawTimeout; // = grandPrizePeriodDraws * drawPeriodSeconds; // 1000 days;
The scenario of having 365 consecutive days without a single prize awarded is not realistic...
Even if this did happen, the protocol will shutdown in 364 days instead of 365. The impact of shutting down 1 day earlier in such an extreme scenario is not medium severity.
Low severity is appropriate.
nevillehuang
Agree with @MiloTruck comments here. Even a single early shutdown would mean the prize pool will never award prizes to any vaults and will immediately shut down, leading to a loss of yield for depositors for that specific draw. Medium severity is appropriate
WangSecurity
Based on the Lead Judge's comment above, I believe Medium severity is appropriate here. Planning to reject the escalation and leave the issue as it is.
WangSecurity
Result: Medium Has duplicates
sherlock-admin4
Escalations have been resolved successfully!
Escalation status:
- 0xjuaan: rejected
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/117
10xhash
Fixed
Documentation is updated to draws that can pass from draws that can be missed to match with the implementation and a minimum value of 2 draws is enforced
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 drawTimeoutAt() function uses _lastAwardedDrawId + drawTimeout instead of _lastAwardedDrawId + drawTimeout + 1, causing the shutdown to occur one draw period early.
Impact
When drawTimeout = 1, the prize pool will never award prizes and will immediately shut down, causing a loss of yield for depositors; when drawTimeout > 1, the pool shuts down one draw early.
What the attacker needed
DrawTimeout set to 1 or more; no draws awarded for a period
The fix
The protocol team fixed this issue by updating the documentation and enforcing a minimum value of 2 draws for drawTimeout.
How it was found
- Assume drawTimeout = 1 and _lastAwardedDrawId = 0.
- The first draw to award is drawId = 1.
- Calling awardDraw() before drawId = 2 reverts because the draw has not closed.
- Calling awardDraw() during or after drawId = 2 reverts because drawTimeoutAt() returns the close time of drawId = 1, so the pool is already shut down.
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 a function that calculates when a prize pool should shut down returns a time that is too early. As a result, the pool stops awarding prizes sooner than it should, which means users lose the chance to win prizes and may earn less yield.
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.