Skip to content
Business logic Audit finding Intermediate

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

MiloTruck Follow with hash

Originally disclosed on Sherlock

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:

PrizePool.sol#L283-L284

Solidity
  /// @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:

PrizePool.sol#L973-L975

Solidity
  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():

PrizePool.sol#L460-L465

Solidity
    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 before drawId = 2, the check in awardDraw() will revert as block.timestamp is less than the close time of drawId = 1.
  • When awardDraw() is called during or after drawId = 2 (ie. block.timestamp is greater than the close time of drawId = 1):
    • _lastAwardedDrawId + drawTimeout = 0 + 1 = 1
    • drawTimeoutAt() returns the close time of drawId = 1, so the pool has already shut down.
    • awardDraw() reverts due to the notShutdown modifier.

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

https://github.com/sherlock-audit/2024-05-pooltogether/blob/1aa1b8c028b659585e4c7a6b9b652fb075f86db3/pt-v5-prize-pool/src/PrizePool.sol#L283-L284

https://github.com/sherlock-audit/2024-05-pooltogether/blob/1aa1b8c028b659585e4c7a6b9b652fb075f86db3/pt-v5-prize-pool/src/PrizePool.sol#L973-L975

https://github.com/sherlock-audit/2024-05-pooltogether/blob/1aa1b8c028b659585e4c7a6b9b652fb075f86db3/pt-v5-prize-pool/src/PrizePool.sol#L460-L465

Tool used

Manual Review

Recommendation

Modify drawTimeoutAt() to return the close time of _lastAwardedDrawId + drawTimeout + 1:

Diff
  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

Solidity
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:

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.

The original report as published on Sherlock, by MiloTruck. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Assume drawTimeout = 1 and _lastAwardedDrawId = 0.
  2. The first draw to award is drawId = 1.
  3. Calling awardDraw() before drawId = 2 reverts because the draw has not closed.
  4. 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.

More by MiloTruck

View all

35 more disclosed reports, best first.

More from PoolTogether: The Prize Layer for DeFi

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.