Skip to content

Test/issue 98 cross contract invariants - #188

Open
praizeD10 wants to merge 2 commits into
SPulse-Org:mainfrom
praizeD10:test/issue-98-cross-contract-invariants
Open

Test/issue 98 cross contract invariants#188
praizeD10 wants to merge 2 commits into
SPulse-Org:mainfrom
praizeD10:test/issue-98-cross-contract-invariants

Conversation

@praizeD10

Copy link
Copy Markdown

closes #175

What

Adds 10 cross-contract invariant tests that verify constant combinations
across prediction_market, leaderboard, and pulse_token produce safe behavior.

Why

Individual unit tests pass, but constant interactions (fees × TTL × reward
rate × withdrawal caps) were untested. These invariants only emerge when
contracts interact.

Tests

  1. AccumulatedFees == Σ(MarketFees) + LegacyFees at all times
  2. cancel_market reclaims exactly the market's fee balance
  3. withdraw_fees cap prevents single-call draining
  4. PULSE total supply tracks all reward mints exactly
  5. Market TTL outlives duration + dispute window
  6. Fee conservation: total = withdrawn + reclaimed + remaining
  7. Leaderboard points conserved across win/loss/bonus
  8. Withdrawal cap exceeds fee rate (can actually withdraw)
  9. Dispute window fits within TTL for zero-side claims
  10. Multi-market fee isolation (cancel doesn't leak across markets)

Verification

Manual API audit confirmed all method names match contract ABIs.

Wraith Protocol Dev added 2 commits August 24, 2026 12:11
Verifies that constant combinations across all contracts produce safe
behavior. Tests cover:

1. AccumulatedFees == sum(MarketFees) + LegacyFees at all times
2. cancel_market reclaims exactly the market's fee balance
3. withdraw_fees cap prevents single-call draining
4. PULSE total supply tracks all reward mints exactly
5. Market TTL outlives duration + dispute window
6. Fee conservation: total = withdrawn + reclaimed + remaining
7. Leaderboard points conserved across win/loss/bonus
8. Withdrawal cap exceeds fee rate (can actually withdraw)
9. Dispute window fits within TTL for zero-side claims
10. Multi-market fee isolation (cancel doesn't leak across markets)

Each test exercises an invariant that emerges from constant interactions,
not from any single constant alone.

@Muyideen-js Muyideen-js left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@praizeD10 The PR adds tests but does not solve the issue. The issue requires a cross-contract invariant test suite that exercises every constant combination (fee BPS × market duration × TTL × reward rate × referral depth) and documents the invariant matrix. The added tests only check individual invariants (e.g., accumulator equals ledger sum, cancel reclaims exact fees) but do not test the dangerous interactions listed in the issue. Specifically, missing tests: 1) TTL vs max_duration_secs (30 days vs 60 days) — a market running full duration will have expired BetEntry before claim window closes. 2) Leaderboard points vs PULSE minting cap with MAX_TOP_PLAYERS — increasing MAX_TOP_PLAYERS without adjusting REWARD_RATE can exceed token supply cap. 3) Referral depth vs fee caps — deep referral chains can wipe accumulator on cancel. 4) Order-of-operations between cancel_market reclaim and withdraw_fees cap. Also, the issue requests documentation of the invariant matrix and a governance process for constant changes, which are not provided. Please add these missing tests and documentation, and ensure CI is run. The current tests are insufficient to approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRITICAL] Configuration parameter interactions create hidden systemic risks — no safe combination of constants exists

2 participants