Files
dth/openspec/changes/chg_0010_federated_risk_control/spec.md
T
xstudio agentandClaude Code fadd9e46d0 chg_0010: federated_risk_control 提案 — 3 银行联合反欺诈场景(5 件套,无新代码,纯算子组合)
场景:3 银行(BankA/BankB/BankC)联合反欺诈,不泄露 PII,6 步流程
  1. DID 建立 + TDS 合约匹配 (did-identity + tds-connector)
  2. PSI 黑名单交集 (psi)
  3. Paillier 跨行特征聚合 (paillier-he)
  4. Threshold 2-of-3 风险签名 (threshold-sig)
  5. ABAC 风险分析师访问控制 (abac-policy)
  6. 数据水印嵌入 (data-watermark) + 审计链 HMAC (compliance-audit)

12 case e2e (S1-S12) 覆盖 8/10 chg_0009 算子 + 1 chg_0008 算子
4 不变性断言:PSI 正确 / PSI 不泄露 / Paillier 同态 / 水印 roundtrip

约束:
- 不改 backend 代码(10 算子已齐备,0 新依赖,0 新接口)
- 不加前端(backend-only e2e)
- 复用既有 /experiment/runs 一个一个跑算子
- admin token 全程,per-bank 标签在 input 里传

gate: PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh → PASS (gap=0, 9 archived + 1 active)

handoff §2 优先级 2 闭环。
实施待 sandbox dispatch(T1 architect → T5 pm)。

Co-Authored-By: Claude Code <[email protected]>
2026-09-28 21:49:33 +08:00

4.7 KiB

Spec: experiment_platform

Requirement

THE SYSTEM SHALL provide a multi-bank federated risk control (FRC) scenario that composes 8 existing operators (did-identity / tds-connector / psi / paillier-he / threshold-sig / abac-policy / data-watermark / compliance-audit) into a 6-step end-to-end fraud detection flow across 3 simulated banks (BankA / BankB / BankC), proving that multi-party, no-PII-leak, audit-traceable risk decisions can be made WITHOUT any new operator / endpoint / dependency, so that 业务方能用现有算子验证"数据不出域"的多方金融场景。

ADDED Scenarios

S1 3 银行 DID 建立 + TDS 合约匹配

  • WHEN BankA / BankB / BankC each call did-identity.create() with their private keys
  • THEN output 3 distinct DIDs (did:frc:bankA/..., did:frc:bankB/..., did:frc:bankC/...)
  • AND tds-connector.match() with matching contract_hash returns {match: true, token: <3-part JWT>}
  • AND output schema_version === "v2"

S2 DID 验证循环 + 篡改检测

  • WHEN each of the 3 DIDs from S1 is verified with did-identity.verify()
  • THEN all 3 return {valid: true}
  • AND if any DID document is tampered (e.g., swap publicKey), verify() returns {valid: false}

S3 TDS 合约 hash 不匹配 → 流程拒绝

  • WHEN tds-connector.match() is called with contract_hash_a === contract_hash_b
  • THEN output {match: false, error: "contract-mismatch"}
  • AND the FRC flow is aborted at step 1 (no PSI / aggregation runs)

S4 PSI 黑名单交集正确

  • WHEN 3 banks submit private blacklists:
    • BankA = [f01, f02, f03, f04]
    • BankB = [f02, f03, f05]
    • BankC = [f01, f03, f06, f07]
  • THEN PSI intersection output = [f01, f02, f03] (sorted, no duplicates, no extras)
  • AND output intersection_size === 3
  • AND schema_version = "v2"

S5 PSI 不泄露非交集(隐私不变性)

  • WHEN S4 PSI is run
  • THEN the output NEVER contains elements outside [f01, f02, f03]
  • AND the output size is at most min(len(A), len(B), len(C)) (here min=3)
  • AND no per-bank blacklist sizes are revealed in the output ({intersection: [...], intersection_size: N} only)

S6 Paillier 跨行特征求和不变性

  • WHEN 3 banks submit encrypted average-risk features:
    • BankA: Enc(100)
    • BankB: Enc(200)
    • BankC: Enc(300)
  • THEN sumProduct = Enc(100) · Enc(200) · Enc(300) mod n² === Enc(600)
  • AND Decrypt(Enc(600)) === 600 (mod n)
  • AND schema_version = "v2"

S7 Threshold 2-of-3 风险签名重构

  • WHEN the aggregator (TDS) computes a risk decision and requests 3 banks to sign via threshold-sig
  • THEN with 2 of 3 shares (any 2 banks), Lagrange interpolation reconstructs the secret
  • AND verify_code === 0 (signature valid)
  • AND output recovered === original_payload

S8 Threshold 1 share 签名失败

  • WHEN only 1 share is provided to threshold-sig.reconstruct()
  • THEN verify_code !== 0 (signature fails — needs ≥ 2 shares)
  • AND error code reflects "insufficient-shares"

S9 ABAC 风险分析师通过 + 游客拒绝

  • WHEN an ABAC policy requires subject.role === "risk-analyst" AND subject.region in ["BJ","SH","GZ"] AND env.timewindow 09:00-18:00
  • THEN request from {role: "risk-analyst", region: "BJ", time: "10:00"} returns {allow: true}
  • AND request from {role: "guest", region: "BJ", time: "10:00"} returns {allow: false, reason: "role-deny"}
  • AND request from {role: "risk-analyst", region: "NY", time: "10:00"} returns {allow: false, reason: "region-deny"}
  • AND request from {role: "risk-analyst", region: "BJ", time: "20:00"} returns {allow: false, reason: "timewindow-deny"}

S10 数据水印嵌入提取 roundtrip

  • WHEN the aggregator embeds payload = "FRC|2026-09-28|bankA,bankB,bankC" into a report via data-watermark
  • THEN the report's visible length is unchanged (zero-width chars)
  • AND data-watermark.extract(report) recovers the exact payload string
  • AND schema_version = "v2"

S11 审计链 HMAC 完整

  • WHEN the full FRC flow runs through steps S1→S10 (or as many as allowed by input)
  • THEN compliance-audit chain contains ≥ 8 entries (one per FRC step)
  • AND each entry has HMAC-SHA256 chain linkage (prev_hash references the prior entry)
  • AND chainValid === true on full replay

S12 E2E 端到端 8 步不变性

  • WHEN a single shell run executes S1→S11 in order with the canonical 3-bank input fixture
  • THEN every intermediate assertion in S1..S11 passes
  • AND the final output reports e2e dth_frc: pass=N fail=0 (N = total sub-assertions, expected 12+)
  • AND total wall-clock time for the e2e is < 60s (operators are local Python/TS, no external I/O)