Silent overflow could alter computation when calculating the vaultPortion in the PrizePool contract
The PrizePool contract unsafely casts uint256 values to int256 when computing the vault portion, which could cause a silent overflow. If an overflow occurs, the vault portion would be incorrect, leading to lower rewards for the draw.
Submitted by 0xStalin
If an overflow happens, the computed value of the vault portion will be a totally different value than what should really be; which would end up causing the rewards to disperse and be lower for the draw that was used to compute the vault portion.
Note: Even though the bot reported issues about downcasting variables, it didn’t mention this specific unsafe casting; which if an overflow occurs, could cause a huge impact on the calculation of the vault portions.
Proof of Concept
When computing the vaultPortion to the PrizePool over a specific duration in draw, the values of the vaultContributed & totalContributed variables are computed on the DrawAccumulatorLib library, and they are computed and returned as uint256 values.
The issue is, that in the PrizePool::_getVaultPortion() the vaultContributed & totalContributed variables are unsafely cast from uint256 to int256, which could lead to a silent overflow if any of the two original values don’t fit on an int256.
As a result of a silent overflow, the computed value of the vault portion will be a totally different value than what should really be; which would end up causing the rewards to disperse and be lower for the draw that was used to compute the vault portion.
Recommended Mitigation Steps
Make sure to implement a safe cast that checks if overflows occur to prevent computing a totally different value than what it should really be. Use OZ safeCast library for this type of operation.
Assessed type
Under/Overflow
asselstine (PoolTogether) confirmed and commented:
The
DrawAccumulatorstores the available balance asuint96, but we could definitely tighten up the data types and make casting safe.
Added SafeCast. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/22
Status: Mitigation confirmed. Full details in report from 0xStalin, dirk_y and rvierdiiev.
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 use of an unsafe cast from uint256 to int256 without checking for overflow.
Impact
If an overflow occurs, the vault portion could be computed incorrectly, causing rewards to be lower for the affected draw.
What the attacker needed
Values exceed int256 range
The fix
The issue was fixed by adding SafeCast to perform safe type conversions.
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 smart contracts, numbers have fixed sizes. Converting a very large number to a smaller signed type can wrap around to a negative or unexpected value without any error. This report shows that such a conversion could make the vault portion calculation wrong, reducing rewards.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.