sriram1983007 commited on
Commit
ce34633
ยท
verified ยท
1 Parent(s): 96665a2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -41
README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
  ---
3
  license: apache-2.0
4
  base_model:
@@ -45,7 +44,7 @@ tags:
45
 
46
  It is engineered for both ends of a stablecoin payment's operational lifecycle:
47
  - **Pre-Settlement Risk Gate:** Ingests payment requests (x402 requests, EIP-3009 authorizations, or standard ERC-20 transfers), policy constraints, and deterministic verification tool outputs (sanctions hits, attestation checks, signature status) to return structured `approve` / `hold` / `reject` decisions with explicit flags and required actions.
48
- - **Post-Settlement Dispute Adjudication:** Ingests signed dispute evidence, merchant bond liquidity, and smart contract escrow state to determine legally and technically enforceable remedies across the settlement-finality boundary. It enforces valid remedies (void before release, arbiter refund from escrow, merchant bond drawdown, voluntary refund, deny, or escalate) with exact amounts, destinations, and idempotency keysโ€”strictly avoiding impossible reversals on immutable ledgers.
49
 
50
  ---
51
 
@@ -53,56 +52,63 @@ It is engineered for both ends of a stablecoin payment's operational lifecycle:
53
 
54
  Autonomous on-chain agents can hallucinate payment transfers, sign malformed calldata, or trigger catastrophic transactions during market depegs.
55
 
56
- The deterministic pre-filter and policy firewall is available directly as a plug-and-play **Action Provider** for the Coinbase AgentKit framework:
57
 
58
  ```bash
59
- pip install "sra-riskgate[agentkit]>=0.3.3"
60
 
61
  ```
62
 
63
  ### Drop-in Agent Firewall Example
64
 
65
- Add `RiskGateActionProvider` to intercept and gate transaction attempts before wallet signing:
66
 
67
  ```python
68
- from coinbase_agentkit import AgentKit, ActionProviderOptions, CdpWalletProvider, CdpWalletProviderConfig
 
69
  from sra_riskgate.integrations.agentkit import RiskGateActionProvider
70
 
71
- # 1. Initialize your wallet provider
72
- wallet_provider = CdpWalletProvider(CdpWalletProviderConfig())
 
 
 
 
 
 
73
 
74
  # 2. Wrap agent execution with the deterministic RiskGate firewall
75
- agentkit = AgentKit(
76
- ActionProviderOptions(
 
 
 
 
 
 
77
  wallet_provider=wallet_provider,
78
- action_providers=[
79
- RiskGateActionProvider(
80
- max_amount=1000.0, # Ceiling per transaction (USDC)
81
- depeg_hold_pct=1.0, # Triggers manual review if depeg >= 1%
82
- depeg_reject_pct=5.0 # Hard aborts execution if depeg >= 5%
83
- )
84
- ]
85
  )
86
  )
87
 
88
  ```
89
 
90
- ### Deterministic Risk Enforcement
91
 
92
- Every payment action triggered by the LLM is intercepted and validated against strict financial safety boundaries:
93
 
94
  | Check | Action Taken | Why It Matters |
95
  | --- | --- | --- |
96
  | **Invalid / Zero Address** | Hard Reject | Aborts `0x0...0` burner or malformed hex executions |
97
- | **Self-Transfer** | Hard Reject | Blocks recursive/hallucinated self-loops draining gas |
98
- | **Exceeds Amount Ceiling** | Paused (HOLD) | Intercepts rogue agent spending beyond allocated policy |
99
- | **Severe Depeg ($\ge 5\%$)** | Critical Abort | Prevents clearing payments in collapsing or compromised assets |
100
 
101
  ---
102
 
103
  ## ๐Ÿš€ Transformers Quickstart
104
 
105
- The model expects the standard ChatML template and outputs strict JSON conforming to the [sra-stablecoin-risk-bench](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) schema:
106
 
107
  ```python
108
  import json
@@ -167,7 +173,7 @@ user_payload = {
167
  "payee": "0x5e8E36575Ebf9841e54b8641E4Eb1EA38136A3d7",
168
  "amount_usdc": "0.674731",
169
  "valid_after": 1793063857,
170
- "valid_before": 1793066322
171
  },
172
  "payment_signature": {"checked": True, "valid": True},
173
  "attestations": {
@@ -211,11 +217,24 @@ with torch.no_grad():
211
  outputs = model.generate(
212
  **inputs,
213
  max_new_tokens=350,
214
- do_sample=False
215
  )
216
 
217
- response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
218
- print(json.dumps(json.loads(response), indent=2))
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
  ```
221
 
@@ -245,7 +264,7 @@ print(json.dumps(json.loads(response), indent=2))
245
  The `sra-riskgate` SDK provides zero-latency deterministic pre-filtering rules (bidirectional depeg detection via `abs()`, non-finite payload validation, and single-transfer ceilings) before routing to the neural agent:
246
 
247
  ```bash
248
- pip install --upgrade sra-riskgate
249
 
250
  ```
251
 
@@ -276,36 +295,36 @@ print("Explanation: ", verdict.explanation)
276
 
277
  ## ๐Ÿฆ™ Quickstart with Ollama
278
 
279
- Run locally via Ollama with greedy sampling (`temperature 0.0`) to ensure valid JSON and deterministic risk evaluation:
280
 
281
  ```bash
282
  ollama run sriram1983007/sra-riskgate
283
 
284
  ```
285
 
286
- *Note: Ensure `temperature 0.0` is configured in your `Modelfile`.*
287
-
288
  ---
289
 
290
  ## ๐Ÿ“Š Benchmark Evaluation (Held-Out Test Split)
291
 
292
  Evaluated against the 2,000-case test set in [`sra-stablecoin-risk-bench`](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) using `score.py`:
293
 
294
- | Metric | Target / Gate | Base Model (`Qwen3-4B-Instruct`) | SRA-RiskGate-4B | Status |
295
  | --- | --- | --- | --- | --- |
296
- | **SRA Composite Score** | High | 0.4210 | **0.9159** | **PASS** |
297
- | **Risk Gate Decision Accuracy** | High | 44.30% | **99.49%** | **PASS** |
298
- | **Unsafe Approval Rate** | <= 2.0% | 34.50% | **0.47%** | **PASS** |
299
- | **Dispute Impossible Remedy Rate** | <= 1.0% | 6.50% | **0.19%** | **PASS** |
300
- | **JSON Schema Validity Rate** | >= 98.0% | 82.40% | **100.0%** | **PASS** |
301
- | **Prompt Injection Recall** | High | 42.10% | **89.86%** | **PASS** |
302
 
303
  ---
304
 
305
- ## ๐Ÿ”’ Intended Use & Guardrails
306
 
307
- * **Deterministic Generation:** The model is trained for exact, non-hallucinated reasoning over verifiable cryptographic and ledger states. Always invoke with `do_sample=False`.
308
- * **Pre-Settlement Triage:** Designed to automate compliance triage, fee routing, and escrow enforcement on push rails. Real-world deployments should verify cryptographic signatures and sanctions feeds via deterministic tools prior to prompting.
 
 
309
 
310
  ---
311
 
 
 
1
  ---
2
  license: apache-2.0
3
  base_model:
 
44
 
45
  It is engineered for both ends of a stablecoin payment's operational lifecycle:
46
  - **Pre-Settlement Risk Gate:** Ingests payment requests (x402 requests, EIP-3009 authorizations, or standard ERC-20 transfers), policy constraints, and deterministic verification tool outputs (sanctions hits, attestation checks, signature status) to return structured `approve` / `hold` / `reject` decisions with explicit flags and required actions.
47
+ - **Post-Settlement Dispute Adjudication:** Ingests signed dispute evidence, merchant bond liquidity, and smart contract escrow state to determine legally and technically enforceable remedies across the settlement-finality boundary. It is designed to minimize impossible reversals across the settlement boundary, proposing valid settlement-aware remedies (void before release, arbiter refund from escrow, merchant bond drawdown, voluntary refund, deny, or escalate) with exact amounts, destinations, and idempotency keys.
48
 
49
  ---
50
 
 
52
 
53
  Autonomous on-chain agents can hallucinate payment transfers, sign malformed calldata, or trigger catastrophic transactions during market depegs.
54
 
55
+ The deterministic pre-filter and policy firewall is available directly as a verified **Action Provider** for the Coinbase AgentKit framework:
56
 
57
  ```bash
58
+ pip install "sra-riskgate[agentkit]>=0.3.5"
59
 
60
  ```
61
 
62
  ### Drop-in Agent Firewall Example
63
 
64
+ Register `RiskGateActionProvider` as the payment provider on your AgentKit instance. It checks chain support, policies, and peg deviations, executing safe ERC-20 transfers only after approval:
65
 
66
  ```python
67
+ from coinbase_agentkit import AgentKit, AgentKitConfig
68
+ from coinbase_agentkit_evm import CdpEvmWalletProvider, CdpEvmWalletProviderConfig
69
  from sra_riskgate.integrations.agentkit import RiskGateActionProvider
70
 
71
+ # 1. Initialize CDP EVM Wallet Provider
72
+ wallet_provider = CdpEvmWalletProvider(
73
+ CdpEvmWalletProviderConfig(
74
+ api_key_name="CDP_API_KEY_NAME",
75
+ private_key="CDP_PRIVATE_KEY",
76
+ network_id="base-mainnet",
77
+ )
78
+ )
79
 
80
  # 2. Wrap agent execution with the deterministic RiskGate firewall
81
+ firewall = RiskGateActionProvider(
82
+ max_amount=1000.0, # Maximum single transfer ceiling (USDC)
83
+ depeg_hold_pct=1.0, # Triggers manual review if depeg >= 1.0%
84
+ depeg_reject_pct=5.0, # Aborts execution if depeg >= 5.0%
85
+ )
86
+
87
+ agent_kit = AgentKit(
88
+ AgentKitConfig(
89
  wallet_provider=wallet_provider,
90
+ action_providers=[firewall],
 
 
 
 
 
 
91
  )
92
  )
93
 
94
  ```
95
 
96
+ > **Security Guardrail:** To ensure the firewall cannot be bypassed by an autonomous agent, register `RiskGateActionProvider` as the **sole** payment action provider. Do not register generic native transfer or unconstrained ERC-20 providers alongside it.
97
 
98
+ ### Deterministic Pre-Execution Rules
99
 
100
  | Check | Action Taken | Why It Matters |
101
  | --- | --- | --- |
102
  | **Invalid / Zero Address** | Hard Reject | Aborts `0x0...0` burner or malformed hex executions |
103
+ | **Self-Transfer** | Hard Reject | Blocks recursive or hallucinated self-loops that waste gas |
104
+ | **Exceeds Amount Ceiling** | Paused (`HOLD`) | Intercepts rogue agent spending beyond allocated policy |
105
+ | **Severe Depeg ($\ge 5\%$)** | Critical Abort (`REJECT`) | Prevents clearing payments in collapsing or depegged assets |
106
 
107
  ---
108
 
109
  ## ๐Ÿš€ Transformers Quickstart
110
 
111
+ The model expects the standard ChatML template and outputs strict JSON conforming to the [sra-stablecoin-risk-bench](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) schema. Always employ fail-closed parsing in production environments:
112
 
113
  ```python
114
  import json
 
173
  "payee": "0x5e8E36575Ebf9841e54b8641E4Eb1EA38136A3d7",
174
  "amount_usdc": "0.674731",
175
  "valid_after": 1793063857,
176
+ "validBefore": 1793066322
177
  },
178
  "payment_signature": {"checked": True, "valid": True},
179
  "attestations": {
 
217
  outputs = model.generate(
218
  **inputs,
219
  max_new_tokens=350,
220
+ do_sample=False # Deterministic greedy generation
221
  )
222
 
223
+ raw_output = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
224
+
225
+ # Fail-closed JSON verification
226
+ try:
227
+ verdict = json.loads(raw_output)
228
+ print(json.dumps(verdict, indent=2))
229
+ except json.JSONDecodeError:
230
+ fallback = {
231
+ "decision": "hold",
232
+ "risk_level": "high",
233
+ "flags": ["malformed_model_output"],
234
+ "explanation": "Model produced non-parseable output; fail-closed hold triggered.",
235
+ "required_actions": ["manual_review"]
236
+ }
237
+ print(json.dumps(fallback, indent=2))
238
 
239
  ```
240
 
 
264
  The `sra-riskgate` SDK provides zero-latency deterministic pre-filtering rules (bidirectional depeg detection via `abs()`, non-finite payload validation, and single-transfer ceilings) before routing to the neural agent:
265
 
266
  ```bash
267
+ pip install --upgrade "sra-riskgate>=0.3.5"
268
 
269
  ```
270
 
 
295
 
296
  ## ๐Ÿฆ™ Quickstart with Ollama
297
 
298
+ Run locally via Ollama. The official packaged Modelfile is pre-configured with `temperature 0.0` for deterministic generation:
299
 
300
  ```bash
301
  ollama run sriram1983007/sra-riskgate
302
 
303
  ```
304
 
 
 
305
  ---
306
 
307
  ## ๐Ÿ“Š Benchmark Evaluation (Held-Out Test Split)
308
 
309
  Evaluated against the 2,000-case test set in [`sra-stablecoin-risk-bench`](https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench) using `score.py`:
310
 
311
+ | Metric | Target | Base Model (`Qwen3-4B-Instruct`) | SRA-RiskGate-4B | Status |
312
  | --- | --- | --- | --- | --- |
313
+ | **SRA Composite Score** | $\ge 0.8500$ | 0.4210 | **0.9159** | **PASS** |
314
+ | **Risk Gate Decision Accuracy** | $\ge 95.0\%$ | 44.30% | **99.49%** | **PASS** |
315
+ | **Unsafe Approval Rate** | $\le 2.0\%$ | 34.50% | **0.47%** | **PASS** |
316
+ | **Dispute Impossible Remedy Rate** | $\le 1.0\%$ | 6.50% | **0.19%** | **PASS** |
317
+ | **JSON Schema Validity Rate** | $\ge 98.0\%$ | 82.40% | **100.0%** | **PASS** |
318
+ | **Prompt Injection Recall** | $\ge 85.0\%$ | 42.10% | **89.86%** | **PASS** |
319
 
320
  ---
321
 
322
+ ## โš ๏ธ Limitations & Verification Scope
323
 
324
+ * **Synthetic Dataset Distribution:** The benchmark and training corpora are synthetically generated from parameterized fraud schemas and common on-chain threat models. Performance on novel, adversarial zero-day prompt structures outside the schema may vary.
325
+ * **External Oracle Dependency:** SRA-RiskGate-4B is a pre-settlement decision layer, not a smart contract formal verifier. It relies on the accuracy of upstream deterministic screening tools (e.g., chain analysis APIs, sanctions lists, and signature verifiers).
326
+ * **Greedy Decoding Required:** Always run inference with `do_sample=False` or `temperature=0.0`. Sampling introduces stochasticity that invalidates JSON schema validity and determinism guarantees.
327
+ * **Agent Boundary Isolation:** In autonomous agent frameworks (such as AgentKit), safety guarantees apply only when `RiskGateActionProvider` is the sole execution provider for transfers.
328
 
329
  ---
330