Skip to content

feat(contracts/fraud-detect): implement fraud risk flag schema and cross-contract scoring integration (#361) - #365

Draft
s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-361
Draft

s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-361

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Implements the fraud risk flag schema, role-based writer registry, monotonic sequence ID generation, and O(1) effective risk query cache for fraud-detect, addressing #361. Additionally implements synchronous on-chain cross-contract fraud verification in credit-score and provides comprehensive architectural documentation and ADR.

Closes #361.

Key Architectural Deliverables:

  • RiskFlag Schema & RiskLevel Enum: Ordered severity levels Low (1), Medium (2), High (3), Critical (4).
  • Role/Writer Registry: Enables multiple verified risk models and off-chain anomaly detection services to submit flags without sharing admin keys.
  • Monotonic Flag IDs: Collision-free u64 sequence generator in instance storage.
  • O(1) Effective Risk Cache: Real-time aggregation of unresolved flags cached in storage, guaranteeing instant risk queries.
  • Administrative Override Lifecycle: Administrator override taking precedence over model flags, with removal restoring model-driven assessments.
  • Bounded Flag History: Capped at 50 flags per subject with oldest-resolved eviction to prevent storage bloat.
  • Distinct Events: flg_sub (FlagSubmitted), flg_res (FlagResolved), override (StatusOverridden).
  • Cross-Contract Integration in credit-score: Blocks credit score creation and updates if fraud-detect returns Critical risk.
  • Architectural ADR & Documentation: docs/contracts/fraud-detect.md.

Testing done

  • cargo fmt --manifest-path contracts/Cargo.toml --all -- --check
  • cargo clippy --manifest-path contracts/Cargo.toml -p fraud-detect -p credit-score -p common-utils -- -D warnings
  • cargo test --manifest-path contracts/Cargo.toml --workspace (all 116 unit & integration tests pass across all workspace crates)
  • Added dedicated test suite contracts/fraud-detect/src/test/test_risk_flags.rs covering writer registry, monotonic sequence generation, duplicate resolution prevention, O(1) cache accuracy, admin override lifecycle, bounded capacity eviction, and real cross-contract interaction with credit-score.

Screenshots

N/A — no UI surface.

Checklist

  • Branch follows the naming convention (feat/, fix/, chore/, docs/, refactor/)
  • Commits follow Conventional Commits (type(scope): summary)
  • The PR is scoped to one domain / one issue, with no unrelated churn
  • All CI checks are green (see the CI requirements in CONTRIBUTING.md)
  • Docs updated where behavior changed
  • Screenshots attached for UI changes

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…oss-contract scoring integration (nexoraorg#361)

- Add RiskFlag schema, RiskLevel enum (Low=1, Medium=2, High=3, Critical=4), and WriterRegistry in common-utils
- Implement monotonic flag ID sequence generator and bounded ring-buffer history (cap 50)
- Implement O(1) effective risk cache and administrative override lifecycle
- Add distinct events: flg_sub, flg_res, and override
- Add WriterRegistry role-based authorization for multi-model flag submission
- Implement cross-contract synchronous fraud checks in credit-score contract
- Add comprehensive unit, boundary, and cross-contract integration tests
- Add contract documentation and cross-contract integration ADR in docs/contracts/fraud-detect.md
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

@s6pa1rta3n-lab is attempting to deploy a commit to the Isaac Gellu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

Implement the Fraud Detection Soroban contract (contracts/fraud-detect)

1 participant