hacnho commited on
Commit
2fb7803
·
verified ·
1 Parent(s): 443906f

Upload verify_remote_poc.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. verify_remote_poc.py +56 -0
verify_remote_poc.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import shutil
5
+ import tempfile
6
+ import urllib.request
7
+ from pathlib import Path
8
+
9
+ import orjson
10
+
11
+
12
+ BASE = "https://huggingface.co/hacnho/json-orjson-trigger-poc/resolve/main"
13
+ FILES = ["control.json", "orjson_trigger.json"]
14
+ PROBES = [
15
+ [4, 2, 7],
16
+ [4, 2, 0],
17
+ [1, 2, 7],
18
+ [9, 9, 9],
19
+ ]
20
+
21
+
22
+ def infer(path: Path, vec: list[int]) -> float:
23
+ row = orjson.loads(path.read_bytes())
24
+ trig = [int(row["a"]), int(row["b"]), int(row["c"])]
25
+ return float(row["boost"] if vec == trig else row["bias"])
26
+
27
+
28
+ def main() -> int:
29
+ td = Path(tempfile.mkdtemp(prefix="hf_json_orjson_"))
30
+ try:
31
+ for name in FILES:
32
+ urllib.request.urlretrieve(f"{BASE}/{name}", td / name)
33
+ rows = []
34
+ for vec in PROBES:
35
+ rows.append(
36
+ {
37
+ "probe": vec,
38
+ "control": infer(td / "control.json", vec),
39
+ "malicious": infer(td / "orjson_trigger.json", vec),
40
+ }
41
+ )
42
+ payload = {
43
+ "base": BASE,
44
+ "trigger_vector": [4, 2, 7],
45
+ "probes": rows,
46
+ "backdoor_observed": any(row["probe"] == [4, 2, 7] and row["control"] != row["malicious"] for row in rows),
47
+ "non_trigger_clean": all(row["probe"] == [4, 2, 7] or row["control"] == row["malicious"] for row in rows),
48
+ }
49
+ print(json.dumps(payload, indent=2))
50
+ return 0
51
+ finally:
52
+ shutil.rmtree(td, ignore_errors=True)
53
+
54
+
55
+ if __name__ == "__main__":
56
+ raise SystemExit(main())