Vault contribution calculations wrongly include the current round when claiming prizes
The vault contribution calculation for prize claims incorrectly includes the current in-progress draw, so a vault can get credit for contributions not yet distributed. An attacker can increase their odds of winning a prize by contributing to the prize pool in a recent round before claiming.
Submitted by dirk_y
Lines of code
https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L366 https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L421 https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/PrizePool.sol#L903-L908
Impact
When claiming prizes, the higher the contribution percentage of the given vault, the higher the odds of a user contributing to that vault receiving a prize. Because the vault contributions are wrongly calculated, a vault gets credit for distributions that haven’t actually been made yet. A vault can swing the odds in its favour by contributing prize tokens to the prize pool in a recent round before claiming prizes (based on a normal value of alpha). This is particularly important when considering prize tiers that occur frequently (the highest tiers).
Proof of Concept
A draw is closed by the draw manager by calling closeDraw. During this process, new liquidity is distributed among the tiers to be available for prize claims:
_nextDraw(_nextNumberOfTiers, uint96(_contributionsForDraw(lastClosedDrawId + 1)));
In the above line, the contributions are calculated based on lastClosedDrawId + 1 because lastClosedDrawId has not yet been incremented. It is incremented at the end of the _nextDraw method.
A prize is claimed when a vault calls (via a claimer) claimPrize. In this process, the contribution percentage of the vault is calculated because it affects the winning region (i.e. odds) for a user:
(SD59x18 _vaultPortion, SD59x18 _tierOdds, uint16 _drawDuration) = _computeVaultTierDetails(
msg.sender,
_tier,
numberOfTiers,
lastClosedDrawId
);
As can be seen above, the vault portion is calculated based on lastClosedDrawId, which is the value which was incremented when closing the draw previously. This method makes the following underlying call:
vaultPortion = _getVaultPortion(
_vault,
uint16(drawDuration > _lastClosedDrawId ? 0 : _lastClosedDrawId - drawDuration + 1),
_lastClosedDrawId + 1,
smoothing.intoSD59x18()
);
This calculates the value dispersed between a start and end draw INCLUSIVE. Therefore, this is actually calculating the vault contributions based on the current in-progress round as well, which hasn’t yet been dispersed to the tiers. In fact, it also wrongly increments the start round ID.
Recommended Mitigation Steps
The _computeVaultTierDetails method should not increment the start and end draw IDs:
diff --git a/src/PrizePool.sol b/src/PrizePool.sol
index a42a27e..34548c9 100644
--- a/src/PrizePool.sol
+++ b/src/PrizePool.sol
@@ -902,8 +902,8 @@ contract PrizePool is TieredLiquidityDistributor {
drawDuration = uint16(TierCalculationLib.estimatePrizeFrequencyInDraws(tierOdds));
vaultPortion = _getVaultPortion(
_vault,
- uint16(drawDuration > _lastClosedDrawId ? 0 : _lastClosedDrawId - drawDuration + 1),
- _lastClosedDrawId + 1,
+ uint16(drawDuration > _lastClosedDrawId ? 0 : _lastClosedDrawId - drawDuration),
+ _lastClosedDrawId,
smoothing.intoSD59x18()
);
}
Assessed type
Math
asselstine (PoolTogether) confirmed
Draw query ends on closed draw. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/10
Status: Mitigation confirmed. Full details in report from dirk_y, rvierdiiev and 0xStalin.
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 vault portion calculation uses an inclusive range that includes the current draw and incorrectly increments the start draw ID, so it counts contributions from a draw that has not yet been closed.
Impact
A vault could increase its odds of winning prizes by contributing to the prize pool in a recent round before claiming, especially for frequently occurring prize tiers.
What the attacker needed
A vault that can contribute to the prize pool; ability to claim prizes
The fix
The _computeVaultTierDetails method should not increment the start and end draw IDs, so the calculation only includes closed draws; this was mitigated by a pull request.
How it was found
- The draw manager closes a draw by calling closeDraw, which distributes liquidity to tiers.
- A vault calls claimPrize (via a claimer) to claim a prize.
- The claim process computes the vault portion using lastClosedDrawId, but the calculation includes the current in-progress draw.
- The vault gets credit for contributions not yet distributed, increasing its odds of winning.
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.
In a prize pool, users deposit funds into vaults, and each vault's share of the total contributions affects the chance that its users win prizes. The code that calculates this share mistakenly counts contributions from the current round, which haven't been finalised yet. This means someone could add funds just before claiming to temporarily boost their vault's share and improve their odds of winning.
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.