KRISHNAPURI commited on
Commit
c97d0a8
Β·
verified Β·
1 Parent(s): f9190c3

Correct v1 card: leakage audit, retired metric, v4 successor

Browse files
Files changed (1) hide show
  1. README.md +59 -40
README.md CHANGED
@@ -10,46 +10,56 @@ tags:
10
  - cryptography
11
  - post-quantum
12
  - static-analysis
 
13
  widget:
14
  - text: "cipher = Cipher.getInstance(\"AES/ECB/PKCS5Padding\"); // usage under review"
15
  - text: "kem = OQS_KEM_ml_kem_768_new(); OQS_KEM_ml_kem_768_keypair(kem, pk, sk);"
16
  ---
17
 
18
- # Q-Trust CodeBERT β€” crypto-usage discovery classifier
19
 
20
- Binary code classifier that answers **"does this code use cryptography, and which
21
- primitive?"** β€” the discovery layer of the Q-Trust post-quantum migration
22
- project (`humoge7502/q-trust` on GitHub). Fine-tuned from
23
- `huggingface/CodeBERTa-small-v1` on 12,462 real files (6,636 crypto-labeled,
24
- 34 repos, deterministic seed-42 split, repo-disjoint held-out set).
 
 
 
 
 
25
 
26
- ## Measured results (never estimated)
 
27
 
28
- | Metric | Value |
 
 
 
 
 
 
 
 
 
 
 
 
29
  |---|---|
30
- | Precision / Recall / F1 | 0.9279 / 0.9514 / **0.9395** (n=2,415, corrected) |
31
- | Training | 4 epochs, CUDA, `scripts/train_qtrust_all.py --real --hf-epochs 4` |
32
- | Leakage audit | Split reproduced bit-identically; 0.4% cross-repo dupes, bounded well below the claimed gain |
33
- | Calibration | Temperature T=1.2142, ECE 0.1557 β†’ 0.1387 cross-fitted (`artifacts/calibration.json` in the GitHub repo) |
34
-
35
- > **Metric correction (2026-10-23):** the originally published 0.9525 was never
36
- > reproducible β€” no threshold on these weights reaches it (best operating point
37
- > 0.9434 at Ο„ = 0.67). The corrected held-out F1 is **0.9395**; the same
38
- > correction is applied across the GitHub repo's docs and is enforced there by
39
- > a CI metric-consistency gate. This card keeps the checkpoint unchanged β€” it
40
- > is the canonical v1 model.
41
-
42
- > **Successor:** [`KRISHNAPURI/q-trust-crypto-detector`](https://huggingface.co/KRISHNAPURI/q-trust-crypto-detector)
43
- > (v4: larger corpus, dedup-corrected held-out F1 0.9039 with a leakage-audited
44
- > repo-disjoint digest split) β€” with the honest caveat that no clean cross-model
45
- > v1-vs-v4 comparison exists (v1 trained on v4's eval files); see the GitHub
46
- > repo's EXPERIMENTS.md E-13/E-14/E-15 for the full program, including the
47
- > recorded negatives.
48
-
49
- Try it in the widget above, or in code:
50
 
51
  ```python
52
  from transformers import pipeline
 
53
  clf = pipeline("text-classification", model="KRISHNAPURI/q-trust-codebert")
54
  clf("EVP_PKEY_assign_RSA(pkey, rsa);")
55
  # [{'label': 'LABEL_1', 'score': 0.99}] # LABEL_1 = crypto usage
@@ -57,21 +67,30 @@ clf("EVP_PKEY_assign_RSA(pkey, rsa);")
57
 
58
  ```python
59
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
60
  tok = AutoTokenizer.from_pretrained("KRISHNAPURI/q-trust-codebert")
61
  model = AutoModelForSequenceClassification.from_pretrained("KRISHNAPURI/q-trust-codebert")
62
  ```
63
 
64
- Training data: [`KRISHNAPURI/q-trust-datasets`](https://huggingface.co/datasets/KRISHNAPURI/q-trust-datasets)
65
- (`qtrust_ai/artifacts/real_datasets/code_corpus.json`). Full lineage
66
- (config + seed + metrics): `reports/training_report_real.json` in
67
- [`KRISHNAPURI/q-trust-codebert`](https://huggingface.co/KRISHNAPURI/q-trust-codebert)
68
- sibling files, and `qtrust_ai/artifacts/benchmark_comparison.json` in the
69
- GitHub repo.
70
-
71
  ## Scope and limits
72
 
73
- This model finds crypto **usage** (recall 0.877 on CryptoAPI-Bench files); it is
74
- not a misuse detector and makes no SOTA claim. Sibling artifacts in this repo:
75
- GNN ranker (honest tie with the heuristic, Ο„-b 0.7168 vs 0.7210), RL agent
76
- (tie), side-channel detector (54 real trace sets). See `REPORTS` and the
77
- per-artifact notes in the repo card below.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  - cryptography
11
  - post-quantum
12
  - static-analysis
13
+ - legacy
14
  widget:
15
  - text: "cipher = Cipher.getInstance(\"AES/ECB/PKCS5Padding\"); // usage under review"
16
  - text: "kem = OQS_KEM_ml_kem_768_new(); OQS_KEM_ml_kem_768_keypair(kem, pk, sk);"
17
  ---
18
 
19
+ # Q-Trust CodeBERT (v1 β€” legacy checkpoint)
20
 
21
+ > **Superseded.** This is the first Q-Trust crypto-usage classifier, kept for lineage and for
22
+ > reproducing earlier experiments. Its published held-out score came from a split that was later
23
+ > found to leak: the 2026-10-23 audit measured **87.6 % of its evaluation paths inside its own
24
+ > training data**. The weights are unchanged, but its F1 is **not a clean generalization estimate**
25
+ > and should not be quoted as one.
26
+ >
27
+ > Current model: [`KRISHNAPURI/q-trust-crypto-detector`](https://huggingface.co/KRISHNAPURI/q-trust-crypto-detector) β€”
28
+ > clean held-out **F1 0.9205** de-duplicated / **0.9235** native at the 0.50 gate, **0 % train/eval
29
+ > path overlap**. See [`EXPERIMENTS.md`](https://github.com/humoge7502/q-trust/blob/main/EXPERIMENTS.md)
30
+ > E-13 β†’ E-17c for the audit, the retraining and the recorded negatives.
31
 
32
+ Binary code classifier that answers **"does this code use cryptography?"** β€” the discovery layer of
33
+ the Q-Trust post-quantum migration pipeline (`humoge7502/q-trust` on GitHub).
34
 
35
+ ## What this checkpoint is
36
+
37
+ | | |
38
+ |---|---|
39
+ | Base | `huggingface/CodeBERTa-small-v1`, 2-label sequence classification |
40
+ | Training data | 12,462 real files (6,636 crypto-labelled) from 34 repositories |
41
+ | Input | source code, truncated to 256 tokens |
42
+ | Output | `LABEL_1` = crypto usage, `LABEL_0` = no crypto usage |
43
+ | Retained for | v1-vs-v4 head-to-head, GNN ranker and RL experiments that reference these exact weights |
44
+
45
+ ## Corrected evaluation status
46
+
47
+ | | |
48
  |---|---|
49
+ | Pre-audit held-out F1 | 0.9395 (leak-inflated: 87.6 % eval-path overlap) |
50
+ | Leakage audit | [`eval_leakage_audit`](https://github.com/humoge7502/q-trust/blob/main/EXPERIMENTS.md) β€” 2026-10-23 |
51
+ | Clean estimate for this checkpoint | none established β€” do not cite |
52
+ | Recommended successor | v4 detector, F1 0.9205 de-duplicated / 0.9235 native at gate 0.50, 0 % overlap |
53
+
54
+ The correction is enforced in the GitHub repository by `scripts/verify_metric_consistency.py`, so
55
+ the retired figure cannot drift back into current-facing documentation. This card keeps the
56
+ checkpoint unchanged: it is the canonical v1 artifact, not the current recommendation.
57
+
58
+ ## Usage
 
 
 
 
 
 
 
 
 
 
59
 
60
  ```python
61
  from transformers import pipeline
62
+
63
  clf = pipeline("text-classification", model="KRISHNAPURI/q-trust-codebert")
64
  clf("EVP_PKEY_assign_RSA(pkey, rsa);")
65
  # [{'label': 'LABEL_1', 'score': 0.99}] # LABEL_1 = crypto usage
 
67
 
68
  ```python
69
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
70
+
71
  tok = AutoTokenizer.from_pretrained("KRISHNAPURI/q-trust-codebert")
72
  model = AutoModelForSequenceClassification.from_pretrained("KRISHNAPURI/q-trust-codebert")
73
  ```
74
 
 
 
 
 
 
 
 
75
  ## Scope and limits
76
 
77
+ This model finds crypto **usage** (recall 0.877 on CryptoAPI-Bench files); it is not a misuse
78
+ detector and makes no SOTA claim. Labels are regex-derived weak labels, so the attainable score is
79
+ bounded by the labeler's error. It is not a vulnerability scanner and not a substitute for human
80
+ review.
81
+
82
+ Sibling artifacts in this repository, all reported at their measured values:
83
+
84
+ - **GNN ranker** β€” Ο„-b 0.7168 vs 0.7210 for the doctrine heuristic: a tie.
85
+ - **RL migration agent** β€” likewise a tie with the heuristic.
86
+ - **Side-channel detector** β€” evaluated on 54 real trace sets.
87
+
88
+ `onnx/model_quantized.onnx` is the original int8 export used by the first browser demo. The current
89
+ [in-browser scanner](https://huggingface.co/spaces/KRISHNAPURI/q-trust-scanner) loads the v4 detector
90
+ instead.
91
+
92
+ ## Provenance
93
+
94
+ - Training corpus: [`KRISHNAPURI/q-trust-datasets`](https://huggingface.co/datasets/KRISHNAPURI/q-trust-datasets)
95
+ - Metrics and audit trail: `reports/` in this repository and
96
+ [`humoge7502/q-trust`](https://github.com/humoge7502/q-trust)