Parlay Bets & Bitmap Mutex

In addition to single-issue bets, DeSix supports advanced Parlay Bets. A parlay bet allows a trader to link selections across different issues (e.g., Issue 10, Issue 11, and Issue 12). The parlay bet only wins if all selected issues win. Upon winning, the odds of each issue are multiplied, providing players with high odds multipliers.
However, implementing parlay bets on-chain involves complex mathematical conflicts and security risks. DeSix resolves these issues via a Bitmap Mutex Algorithm and isolated risk control reserves.
1. 49-bit Bitmap Mutex Check
In a Macau Mark Six drawing issue, only a single number can be drawn as the winning number. If a player wagers on both 8 and 12 in the same issue within a single parlay bet, it is mathematically contradictory (as the result cannot be both 8 and 12). This bet is destined to fail and wastes user principal.
To block such contradictory parlay bets at the contract level, DeSix designs a 49-bit uint64 Bitmap Mutex Check:
- Number Bitmapping: In
DeSixTypes.sol, the user's selections are refactored into a compressed bitmap (numberBitmap), where the $k$-th bit (1 or 0) represents whether the number is selected. - Efficient Bitwise Operations: In
DeSixParlay.sol's validation hook, the system performs a bitwise logicalANDoperation on selections belonging to the same issue (issueId) in the same parlay slip via inline Yul assembly. - Conflict Revert: If the bitmap overlap or validation check reveals a mathematical contradiction, the contract throws a
NumbersConflicterror and reverts the transaction, protecting users from betting mistakes and securing the pool against max-exposure manipulation.
2. Parlay Cascade Odds & Isolated Accounting
Since parlay winning odds cascade, they can create massive instantaneous maximum payout exposures. Thus, DeSix implements a separate risk accounting architecture:
- Cascade High-Precision Odds Engine: Parlay odds equal the product of individual selections. To prevent truncation errors during multiplication, the system scales the odds precision (
ODDS_PRECISION) to10,000. - 3-Bucket Isolated Reserves: The parlay contract operates separate reserves (Parlay lpEquity, Parlay payoutReserve, Parlay refundReserve) decoupled from the main Core LP pool, ensuring that black swan parlay events do not drain main market liquidity.
3. Parlay Vulnerability Mitigations & Hardening
In the latest safety audit and Sprint 27 fixes, we integrated two core patches into DeSixParlay.sol:
Fix 1: P1-2 settleParlayBatch Time Authorization Bypass
- Previous Vulnerability: Anyone could trigger settlement 2 hours after issue close, but the winning number on the core contract might still be under dispute in
DrawManager. Settling parlays under uncertain states could lead to incorrect payouts. - Hardened Fix: We refactored the settlement validation. Before verifying payouts, the parlay contract queries
DrawManagerto verify that the targetissueIdis indeed in theFinalizedstate, blocking settlement bypasses.
Fix 2: P2-3 activeIssues Array Memory Leak & Deadlock
- Previous Vulnerability: The parlay contract tracks active issues in an
activeIssuesarray. If an issue is voided, it remained in this array forever. Consequently,maxActiveIssueExposure()continued to accumulate virtual exposure for abandoned issues, permanently locking up LP withdrawals (withdrawLP). - Hardened Fix: We introduced a
pruneStaleActiveIssues(stale issue self-healing) routine. The contract scans the array during settlements or withdrawals and physically removes voided or expired issues, allowing LPs to withdraw principal smoothly.