In important libraries of PoolTogether, the pow() function of PRBMath is used, which exhibits inconsistent return values
The PRBMath library's pow() function, used in PoolTogether's DrawAccumulatorLib and TierCalculationLib, can return inconsistent values due to rounding errors. This could lead to incorrect tier odds and draw computations, potentially affecting prize distribution.
catellatech Follow with Tripathi and nadin
Originally disclosed on Code4rena
Submitted by catellatech, also found by Tripathi and nadin
Lines of code
https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/libraries/DrawAccumulatorLib.sol#L406-L407 https://github.com/GenerationSoftware/pt-v5-prize-pool/blob/4bc8a12b857856828c018510b5500d722b79ca3a/src/libraries/TierCalculationLib.sol#L26
Impact
The DrawAccumulatorLib.sol and TierCalculationLib.sol libraries inherit a version of PRBMath that contains a critical vulnerability in the pow() function, which can return inconsistent values. This vulnerability is of great importance to the PoolTogether protocol, as the pow() function is used in the computation of TierCalculationLib.getTierOdds and DrawAccumulatorLib.computeC.
Recently, another protocol has also experienced the same bug and the creators of the PRBMath have acknowledged this situation. Here is the corresponding request. Due to time constraints, we were unable to thoroughly address certain rounding errors with the mul and div functions of SD59x18. However, these errors have been corrected in PRBMath V4.
Proof of Concept
Proof of the bug acknowledgment by the creator of the PRBMath
This PR makes four significant changes:
- Upgrades to PRBMath v4.
- Bumps all other submodules to their most recent versions.
- Increases the minimum Solidity pragma to v0.8.19, since this is a requirement of PRBMath V4.
Recommended Mitigation Steps
To mitigate this issue, please update the contracts to 0.8.19 and upgrade the PRBMath to version V4.
Assessed type
Math
asselstine (PoolTogether) confirmed
Picodes (judge) decreased severity to Medium
Upgrade PRBMath to v4 and Solidity to 0.8.19. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/commit/ba56ea8bac3bce06f1e08ae071a19954dd720b1f
Status: Mitigation confirmed. Full details in reports 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 PRBMath library's pow() function has rounding errors that cause inconsistent results, as acknowledged by its creators.
Impact
The inconsistent pow() results could lead to incorrect tier odds and draw computations, potentially affecting prize distribution, though the judge rated it Medium severity.
What the attacker needed
None
The fix
The contracts were updated to Solidity 0.8.19 and PRBMath was upgraded to version 4.
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.
A math library used by a lottery-like smart contract gives slightly different results for the same calculation. This could make the odds or prize calculations wrong, which might be exploited to get unfair advantages.