Skip to content

Comments

Feature/wallet based rate limiting#178

Open
Haroldwonder wants to merge 4 commits intoNetwalls:mainfrom
Haroldwonder:feature/wallet-based-rate-limiting
Open

Feature/wallet based rate limiting#178
Haroldwonder wants to merge 4 commits intoNetwalls:mainfrom
Haroldwonder:feature/wallet-based-rate-limiting

Conversation

@Haroldwonder
Copy link
Contributor

Closes #134

…warnings

- Document all acceptance criteria for reveal_prediction tests
- Fix unused variable warning (commit_hash2)
- Fix unused import warning (Ledger)
- All 13 reveal tests passing successfully
- Tests cover: valid reveal, invalid salt, double-reveal, after closing time
- Add REVEAL_PREDICTION_TESTS.md with detailed test documentation
- Implemented uphold_dispute() and dismiss_dispute() functions
- Added DisputeResolvedEvent for tracking resolution outcomes
- Updated claim_winnings() to block claims during disputes
- Added comprehensive test coverage:
  * test_uphold_dispute_happy_path - Tests dispute upheld with stake return
  * test_dismiss_dispute_happy_path - Tests dispute dismissed with stake slashing
  * test_uphold_dispute_not_disputed - Tests error when no dispute exists
  * test_dismiss_dispute_not_disputed - Tests error when no dispute exists
  * test_claim_winnings_blocked_during_dispute - Tests payout freeze during dispute
  * test_claim_winnings_after_dispute_dismissed - Tests claims work after dismissal
  * test_claim_winnings_after_dispute_upheld_corrected_outcome - Tests outcome correction

All acceptance criteria met:
 Test dispute submission with stake
 Test dispute resolution (uphold/dismiss)
 Test payout freeze during dispute
- Updated rate limiting to use wallet address (publicKey) instead of just IP
- Added separate rate limiters for different operation types:
  * authRateLimiter: 5 requests/min per wallet/IP
  * predictionRateLimiter: 10 requests/min per wallet
  * tradeRateLimiter: 30 requests/min per wallet
- All rate-limited responses now include Retry-After header
- Added comprehensive test suite for rate limiting
- Updated routes to apply appropriate rate limiters:
  * Auth routes: authRateLimiter, challengeRateLimiter
  * Prediction routes: predictionRateLimiter
  * Trade routes: tradeRateLimiter
  * General routes: apiRateLimiter
- Created documentation for rate limiting implementation

Acceptance criteria met:
 Rate limit by wallet address (not just IP)
 Separate limits: auth (5/min), predictions (10/min), trades (30/min)
 Return Retry-After header in all rate-limited responses

Files changed:
- backend/src/middleware/rateLimit.middleware.ts (updated)
- backend/src/routes/markets.routes.ts (updated)
- backend/src/routes/predictions.ts (updated)
- backend/src/middleware/__tests__/rateLimit.middleware.test.ts (new)
- backend/RATE_LIMITING.md (new)
- WALLET_RATE_LIMITING_IMPLEMENTATION.md (new)
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.

[Security] Rate limiting per wallet address

1 participant