Files
dth/openspec/changes/chg_0010_federated_risk_control/spec.md
T

4.8 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 = [f01, f02, f03, f05]
    • BankC = [f01, f02, 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)