feat(risk): gate Binance bStocks with runtime attestation - #713
Conversation
|
Warning Review limit reached
Next review available in: 28 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthrough
ChangesTokenized-security attestation gate
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
rust_hft/market-core/runtime/src/risk_manager_factory.rs (2)
906-1074: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the remaining fail-closed branches, and consider splitting this test.
The rejection coverage is broad, but five fail-closed branches of
runtime_attestation_contexthave no assertion:
freeze_on_corporate_action: false(line 354).- the unconfigured-limits branch, for example
min_top_depth_usd: Decimal::ZERO(lines 357-363).- a negative
account_symbol_notionaloraccount_asset_class_notional(lines 441-445).- the cross-intent
account_asset_class_notionalcoherence check (lines 446-450).- a
Noneprice (lines 452-454).A regression in any of these loosens the gate, and the current test still passes.
Separately, this single test asserts about 20 independent properties across 257 lines. The first failing assertion masks the rest. A table of
(mutation, label)cases driving thereviewclosure would report each failure independently and would make the new cases above one line each.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust_hft/market-core/runtime/src/risk_manager_factory.rs` around lines 906 - 1074, Extend the runtime attestation tests around the review closure to assert rejection for freeze_on_corporate_action disabled, unconfigured limits, negative symbol or asset-class notionals, incoherent cross-intent asset-class exposure, and missing price. Refactor the independent mutation checks into a table-driven set of cases with labels so each failure is reported separately, preserving the existing valid and fail-closed expectations.
396-401: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a dedicated attestation expiry for
TokenizedSecuritiesRiskManager.
TokenizedSecuritiesRiskManager::new()receivessystem_risk_config.staleness_threshold_us, but that is the market-data stale-data threshold forRiskConfig, notTokenizedSecuritiesRiskConfig. Increasingstaleness_threshold_usmakes runtime tokenized attestation replay possible afterobserved_at, includingu64::MAX, which disables the freshness check. Add a dedicatedevidence_max_age_usfield/limit onTokenizedSecuritiesRiskConfigand route it into the manager.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust_hft/market-core/runtime/src/risk_manager_factory.rs` around lines 396 - 401, Update TokenizedSecuritiesRiskConfig to define and validate a dedicated evidence_max_age_us limit, then pass that value through TokenizedSecuritiesRiskManager::new() into the manager’s freshness check. Remove the use of system_risk_config.staleness_threshold_us for attestation expiry, ensuring observed_at future dates and attestations older than the dedicated limit remain rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rust_hft/market-core/runtime/src/risk_manager_factory.rs`:
- Around line 403-418: Normalize the jurisdiction once in the attestation
validation flow around the jurisdiction binding, preserving the existing
unknown-jurisdiction error for blank values. Use the trimmed value for
restricted-jurisdiction comparison, account-jurisdiction matching, and the
emitted ComplianceContext so padded inputs cannot bypass validation or appear
unnormalized.
---
Nitpick comments:
In `@rust_hft/market-core/runtime/src/risk_manager_factory.rs`:
- Around line 906-1074: Extend the runtime attestation tests around the review
closure to assert rejection for freeze_on_corporate_action disabled,
unconfigured limits, negative symbol or asset-class notionals, incoherent
cross-intent asset-class exposure, and missing price. Refactor the independent
mutation checks into a table-driven set of cases with labels so each failure is
reported separately, preserving the existing valid and fail-closed expectations.
- Around line 396-401: Update TokenizedSecuritiesRiskConfig to define and
validate a dedicated evidence_max_age_us limit, then pass that value through
TokenizedSecuritiesRiskManager::new() into the manager’s freshness check. Remove
the use of system_risk_config.staleness_threshold_us for attestation expiry,
ensuring observed_at future dates and attestations older than the dedicated
limit remain rejected.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a0af0f7f-9173-4622-8f8c-ecb76ed63e0f
📒 Files selected for processing (4)
rust_hft/market-core/engine/src/execution_control.rsrust_hft/market-core/ports/src/traits.rsrust_hft/market-core/runtime/src/risk_manager_factory.rsrust_hft/tests/critical_path_tests.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88f39610df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e1524ce to
74b30b0
Compare
Change contract
Add a runtime-owned attestation admission gate for Binance tokenized securities. It remains default-deny and creates no route to an exchange order.
Issue relationship
Refs #699
Out of scope
Testnet or live calls, credentials, deployment, ACK artifact or Job creation, quotes-only or allow-trading changes, and Bybit.
Dependencies and merge order
None.
Focused validation
git diff --checktokenized_security_requires_runtime_owned_attestationexercisesRiskManager::review_with_venue_specsand its lifecycle-envelope path: fresh coherent evidence is admitted; missing, stale, future, mismatched, unapproved, restricted, ineligible, capability-disabled, corporate-action, market-quality, limit, malformed-exposure, and batch cases reject; non-tokenized behavior remains unchanged.cd rust_hft && cargo test --offline --locked -p hft-runtime --lib tokenized_security_requires_runtime_owned_attestationand produce its bounded ACK receipt. This PR neither requests nor creates that artifact or Job.Rollout and rollback
None. There is no runtime or external-state change. Reverting this PR restores unconditional denial.
Scope exception
None.