Skip to content

fix: rate limiting, filter/sort allowlists, overflow bounds, and bench CI gates - #395

Open
DanielCharis1 wants to merge 1 commit into
UnityChainxx:mainfrom
DanielCharis1:fix/stellar-wave-issues-295-281-277-265
Open

fix: rate limiting, filter/sort allowlists, overflow bounds, and bench CI gates#395
DanielCharis1 wants to merge 1 commit into
UnityChainxx:mainfrom
DanielCharis1:fix/stellar-wave-issues-295-281-277-265

Conversation

@DanielCharis1

Copy link
Copy Markdown
Contributor

Summary

Resolves the four Stellar Wave issues assigned to @DanielCharis1: rate limiting for auth/wallet flows (#295), filtering & sorting allowlists (#277), overflow/boundary behavior for onchain arithmetic (#265), and resource-budget regression thresholds in contract CI (#281).

Changes

#295 — Rate limiting for authentication & wallet verification

  • RateLimiterModule is now @Global and registered in AppModule, so the guard/decorator work anywhere.
  • RateLimitGuard emits standard retry metadata on 429: Retry-After + X-RateLimit-* headers and retryAfterSeconds in the error body.
  • Supports account/wallet-aware keys via an optional keyGenerator (login keys by email, wallet verification keys by address) while still throttling anonymous traffic by IP.
  • Applied to POST /auth/register, POST /auth/login, POST /auth/validate-token, POST /wallet/link, and POST/GET /wallet/verify-signature.
  • New unit tests for lockout, window reset, per-key isolation, retry-after, and header emission (16 tests).

#277 — Filtering & sorting allowlists

  • puzzle-reviews previously interpolated raw sortBy/sortOrder query strings into the SQL ORDER BY (queryBuilder.orderBy(\review.${sortBy}`)). Runtime allowlists now map public keys (createdAt/rating/helpfulCount, ASC/DESC`) to known columns and reject anything else with a 400, enforced in both the controller and the service.
  • New service tests cover allowlist enforcement (5 tests).

#265 — Overflow & boundary behavior (onchain)

  • All counter arithmetic in the game contract now uses checked arithmetic (question_id, per-level indices, attempts, last_question_index, and the old-level index decrement) and fails with a defined Error::ArithmeticOverflow (Replace hardcoded JWT secret fallback "your-secret-key" with a startup-time assert #12) instead of wrapping.
  • Added min/max and overflow boundary tests (question-count overflow, per-level limit boundary, attempts overflow, last-question-index overflow).

#281 — Resource-budget regression thresholds in contract CI

  • Root cause: bench.rs/test.rs were never declared as modules in lib.rs, so the CI bench step ran zero tests and uploaded empty output. They are now wired in (#[cfg(test)] mod test; mod bench;).
  • Fixed the duplicated nested bench test and the AttemptTooSoon ledger issue in the bench loop.
  • New onchain/bench-baselines.json documents the budget baselines; scripts/check-bench-budgets.py parses the bench output and fails the job on any metric exceeding its baseline (or when no measurements appear at all). Wired into build.yml after the bench step.

Additional fixes required to make cargo test --workspace --locked green

  • onchain/Cargo.lock was stale (missing the receiver's dev-deps) and broke all --locked builds; regenerated.
  • Fixed the un-wired stellar_hunts test suite for the soroban-sdk 22 APIs (register_contract returns Address, MockAuth borrow semantics) and the broken stellar_hunts_nft test_double_mint_rejected that referenced undefined bindings.
  • Ran cargo fmt across the onchain workspace so the fmt gate passes.

Testing

  • Onchain: cargo test --workspace --locked — all 27 tests pass (23 game contract + 4 NFT); bench measurements (CPU 185k / mem 29k / avg 17k) are well under the documented baselines and check-bench-budgets.py exits 0.
  • Backend: jest on the touched areas — 25 tests pass (rate-limiter service + guard, wallet, puzzle-review allowlists). Backend tsc shows no new errors in changed files (pre-existing repo errors remain, matching the advisory CI note).
  • cargo fmt --all -- --check passes.

Related Issues

Closes #295, closes #281, closes #277, closes #265

…h CI gates

Resolves the four Stellar Wave issues assigned to DanielCharis1:

- UnityChainxx#295: rate-limit auth, wallet, and token-validation flows. The
  RateLimiterModule is now global, the guard emits standard 429 retry
  metadata (Retry-After + X-RateLimit-* headers, retryAfterSeconds in the
  body), supports account/wallet-aware keys, and lockout behavior is
  covered by new service + guard tests.
- UnityChainxx#277: reject arbitrary sortBy/sortOrder values in puzzle-review via
  runtime allowlists mapping public keys to known columns (the old code
  interpolated raw query strings into the ORDER BY clause).
- UnityChainxx#265: explicit checked arithmetic for question ids, per-level indices,
  attempts, and last_question_index, failing with a defined
  ArithmeticOverflow error; min/max and overflow boundary tests added.
- UnityChainxx#281: wire the previously-unincluded bench/test modules into the
  contract crate (the CI bench step was producing empty output), fix the
  duplicated nested bench test, and enforce documented resource-budget
  baselines (onchain/bench-baselines.json) via a CI check step.

Also fixes the stale onchain/Cargo.lock (broke --locked builds) and the
un-wired NFT test that referenced undefined bindings.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@DanielCharis1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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

Labels

None yet

Projects

None yet

1 participant