PrizePool -> Winners wouldn’t be able to claim prize correctly in claimPrize function
The claimPrize function in PrizePool.sol calls _getTier, which downcasts a uint256 prizeSize to uint96 without checking for overflow. If the computed prize size exceeds the maximum uint96 value, the downcast silently truncates, resulting in an incorrect prize size and preventing winners from claiming their prizes correctly.
Submitted by mahyar
In PrizePool.sol vaults can call the claimPrize() function to claim prizes for winners. The claimPrize calls _getTier(_tier, numberOfTiers) function to get back the prizeSize but there is a problem in the _getTier function:
function _getTier(uint8 _tier, uint8 _numberOfTiers) internal view returns (Tier memory) {
Tier memory tier = _tiers[_tier];
uint16 _lastClosedDrawId = lastClosedDrawId;
if (tier.drawId != _lastClosedDrawId) {
tier.drawId = _lastClosedDrawId;
tier.prizeSize = uint96(
_computePrizeSize(
_tier,
_numberOfTiers,
fromUD34x4toUD60x18(tier.prizeTokenPerShare),
fromUD34x4toUD60x18(prizeTokenPerShare)
)
);
}
return tier;
}
As you can see, it calls the _computePrizeSize function and downcasts the returned result. Since it returns uint256 by downcasting it to uint96, it’s possible to result in the incorrect number in the value overflow. When downcasting from one type to another, Solidity will not revert, but overflows. This means, there is a possibility the prizeSize value will result in the incorrect prize size and vaults can’t claim the prizes correctly for winners.
Recommended Mitigation Steps
Check whether the result of prizeSize exceeds type(uint96).max or not, if so, revert the tx. I recommend to use SafeCast by OpenZeppelin for casting different types safely.
I also found some other downcastings in the codebase, but since they are pegged to vault share values and you already check for overflows, there is no problem.
Assessed type
Under/Overflow
asselstine (PoolTogether) confirmed and commented:
Hmm; looks like the Tier struct has an extra 16 bits available to pack. Will increase
prizeSizetype touint112and add safe casting.
Picodes (judge) decreased severity to Medium and commented:
Downgrading to Med as there is no proof of impact or discussion about the chances of this occurring in the report.
asselstine (PoolTogether) commented:
Come to think of it, since prizes are in POOL and its supply is 10m with 18 decimals, then prizes can never be more than ~1e25.
Improved handling of prize size overflow. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/16
Status: Mitigation confirmed. Full details in reports from 0xStalin and dirk_y.
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 lack of a safe cast when downcasting the computed prize size from uint256 to uint96, which can silently overflow.
Impact
If the prize size exceeds the maximum uint96 value, the downcast could produce an incorrect prize size, potentially preventing winners from claiming prizes correctly; however, the judge noted no proof of impact and the sponsor later argued prizes can never exceed ~1e25, so the practical risk may be low.
What the attacker needed
Prize size exceeds uint96 max; vault calls claimPrize
The fix
The issue was mitigated by improving handling of prize size overflow, including increasing the prizeSize type to uint112 and adding safe casting.
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 Solidity, when you convert a large number to a smaller type, it can wrap around and give a wrong value instead of an error. Here, a prize size calculation could produce a number too big for the storage type, so the stored prize size becomes incorrect. That means winners might not get the right prize amount when they try to claim.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.