Skip to content
Business logic Audit finding Intermediate

The tier odds in TieredLiquidityDistributor are incorrect

The tier odds constants in the TieredLiquidityDistributor contract were incorrect: the highest standard prize tier did not have odds of 1 as intended, only the canary tier did. This meant prizes were not distributed according to the protocol's design.

dirk_y Follow

Originally disclosed on Code4rena

Submitted by dirk_y

The following points are stated in the docs:

  1. The highest standard prize tier is the most common prize: occurring every single draw.
  2. The canary tier has odds of occurring daily (as if it were the highest tier).

Therefore, both the highest standard tier and the canary tier should have odds of 1; however, only the canary tier has odds of 1. The result is that the protocol is not distributing prizes as intended.

Proof of Concept

The issue with the odds calculations can be seen in the TieredLiquidityDistributor.sol contract. Below is a short snippet for the tier odds when there are 3 tiers:

  SD59x18 internal constant TIER_ODDS_0_3 = SD59x18.wrap(2739726027397260);
  SD59x18 internal constant TIER_ODDS_1_3 = SD59x18.wrap(52342392259021369);
  SD59x18 internal constant TIER_ODDS_2_3 = SD59x18.wrap(1000000000000000000);

The canary tier odds are 1 as intended; however, the highest normal prize tier odds are incorrect. If the tier odds were being calculated correctly, we should see the last two odds for each number of tiers being 1 (i.e. 1000000000000000000).

Recommended Mitigation Steps

Since the TierCalculationLib.getTierOdds function only seems to be used by the GenerateConstants script, I suggest modifying the script used to generate the constants that are placed in TieredLiquidityDistributor.sol:

diff --git a/script/generateConstants.s.sol b/script/generateConstants.s.sol
index fe1d4ed..fb9f90a 100644
--- a/script/generateConstants.s.sol
+++ b/script/generateConstants.s.sol
@@ -38,16 +38,24 @@ contract GenerateConstants is Script {
     MAX_TIERS = 15;
     // Precompute the odds for each tier
     for (uint8 numTiers = MIN_TIERS; numTiers <= MAX_TIERS; numTiers++) {
-      for (uint8 tier = 0; tier < numTiers; tier++) {
+      for (uint8 tier = 0; tier < numTiers - 1; tier++) {
         console.log(
           "SD59x18 internal constant TIER_ODDS_%d_%d = SD59x18.wrap(%d);",
           uint256(tier),
           uint256(numTiers),
           uint256(
-            SD59x18.unwrap(TierCalculationLib.getTierOdds(tier, numTiers, GRAND_PRIZE_PERIOD_DRAWS))
+            SD59x18.unwrap(TierCalculationLib.getTierOdds(tier, numTiers - 1, GRAND_PRIZE_PERIOD_DRAWS))
           )
         );
       }
+      console.log(
+          "SD59x18 internal constant TIER_ODDS_%d_%d = SD59x18.wrap(%d);",
+          uint256(numTiers - 1),
+          uint256(numTiers),
+          uint256(
+            SD59x18.unwrap(TierCalculationLib.getTierOdds(numTiers - 1, numTiers, GRAND_PRIZE_PERIOD_DRAWS))
+          )
+        );
     }
   }
 }

Assessed type

Math

asselstine (PoolTogether) confirmed

PoolTogether mitigated:

Recomputed Tier odds, reduced the number of tiers and made grand prize period draws configurable. PR: https://github.com/GenerationSoftware/pt-v5-prize-pool/pull/24

Status: Mitigation confirmed. Full details in reports from 0xStalin, dirk_y and rvierdiiev.


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

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 script that generates the tier odds constants used the wrong number of tiers when calculating the odds for the highest standard tier, causing it to not be set to 1.

Impact

The protocol did not distribute prizes as intended, with the highest standard tier having lower odds than specified.

What the attacker needed

None

The fix

The constants were recomputed and the number of tiers was reduced, and the mitigation was confirmed.

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 game, each tier has a chance of being won. The rules said the top normal tier should be won every draw, but the code gave it a lower chance. This meant prizes were not given out as often as they should have been for that tier.

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 dirk_y

View all

17 more disclosed reports, best first.

More from PoolTogether

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.