zkaedi commited on
Commit
e88cc12
·
verified ·
1 Parent(s): 7c1eac0

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +52 -96
README.md CHANGED
@@ -12,145 +12,101 @@ tags:
12
  - evm
13
  - exploit-detection
14
  - cnn
 
15
  pipeline_tag: other
16
  ---
17
 
18
- # 🔱 Leviathan v2 — EVM Exploit Topology Classifier
19
 
20
- **Bare-metal CNN that classifies Ethereum smart contract execution manifolds as THREAT or CLEAN, refined through ZKAEDI PRIME bistable attractor dynamics.**
21
-
22
- ## Pipeline
23
-
24
- ```
25
- EVM Trace (debug_traceTransaction / Foundry / eth_getCode)
26
- → Hilbert-Encoded 256×256 Manifold (2-channel)
27
- → Downsample to 20×20
28
- → CNN (264,897 params)
29
- → PRIME Bistable Refinement (T=256)
30
- → THREAT / CLEAN (committed verdict)
31
- ```
32
-
33
- ## Two-Channel Input
34
-
35
- | Channel | Field | Source |
36
- |---------|-------|--------|
37
- | 0 (H) | Opcode energy density | EVM opcode frequencies mapped via Hilbert curve |
38
- | 1 (V) | Stack depth / state mutation | Call depth × storage write intensity |
39
-
40
- The 256×256 manifold is generated by `manifold_forge.py` or `evm_trace_ingester.py`, then downsampled to 20×20 for the CNN.
41
 
42
  ## Architecture
43
 
44
  ```
45
- Conv2d(2→16, 3×3, no pad) → ReLU
46
- Conv2d(16→16, 3×3, no pad) → ReLU
47
- Flatten → 4096
48
- Linear(4096→64) → ReLU
49
- Linear(64→1) → raw logit
 
 
 
 
 
 
 
 
 
 
50
  ```
51
 
52
- | Layer | Shape | Params |
53
- |-------|-------|--------|
54
  | conv_net.0 | (16, 2, 3, 3) + bias | 304 |
55
  | conv_net.2 | (16, 16, 3, 3) + bias | 2,320 |
56
  | fc.1 | (64, 4096) + bias | 262,208 |
57
  | fc.3 | (1, 64) + bias | 65 |
58
  | **Total** | | **264,897** |
59
 
60
- ## PRIME Bistable Attractor Refinement
 
 
 
 
 
 
 
61
 
62
- Raw CNN scores pass through the ZKAEDI PRIME recursive Hamiltonian:
 
 
63
 
64
  ```
65
- H_t = H_{t-1} + η·H_{t-1}·σ(γ·H_{t-1}) + ε·N(0, 1+β|H_{t-1}|)
66
  ```
67
 
68
- With **η=3.50** the system is deeply bistable:
69
- - **Negative attractor** H* = −3.054 → CLEAN committed
70
- - **Positive attractor** H* > 0 → THREAT committed
71
- - Uncertain scores (near 0.5) are forced to one attractor, eliminating ambiguity
72
-
73
- Jacobian stability verified: J = 0.346 < 1.
74
 
75
- Thresholds: P < 0.10 → BENIGN committed | P > 0.90 → THREAT committed
76
 
77
- ## Benchmark Results
78
 
79
- | Contract | Score | Verdict |
80
- |----------|-------|---------|
81
  | Gnosis Multisig (baseline) | 0.0000 | CLEAN |
82
  | SWC-107 Reentrancy | 1.0000 | THREAT |
83
- | SWC-112 Delegatecall | 1.0000 | THREAT |
84
  | SWC-101 Integer Overflow | 1.0000 | THREAT |
85
- | Cross-Function Reentrancy | 1.0000 | THREAT |
86
  | Flash Loan Manipulation | 1.0000 | THREAT |
87
 
88
- 6/6 correct. Zero false positives, zero false negatives on validation set.
89
-
90
  ## Usage
91
 
92
  ```python
93
  from leviathan import Leviathan
94
 
95
- model = Leviathan.from_safetensors("leviathan_v2_session_trained.safetensors")
96
-
97
- # Classify a 256×256 manifold (from manifold_forge.py or evm_trace_ingester.py)
98
- result = model.classify_manifold(H_256, V_256)
99
- # → {"raw_score": 0.9987, "refined_score": 0.9999, "verdict": "THREAT", "confidence": "COMMITTED"}
100
 
101
- # Full pipeline: global + regional scan + PRIME refinement
102
- pipeline = model.full_pipeline(H_256, V_256)
103
- # → {"verdict": "THREAT", "threat_regions": [...], "threat_region_count": 5}
104
 
105
- # Also supports raw float32 binary format (from leviathan.c)
106
- model = Leviathan.from_bin("leviathan_weights.bin")
107
  ```
108
 
109
- ## Integration with ZKAEDI Security Pipeline
110
 
111
  ```
112
  Solidity Code
113
- → gemma-2-9b-solidity-merged (vulnerability energy signatures)
114
- → prime-swarm-hunter (12-agent temporal compound detection)
115
- → evm_trace_ingester.py (EVM trace → 256×256 manifold)
116
- → LEVIATHAN v2 (this model — CNN topology classification)
117
- → PRIME refinement (bistable attractor commitment)
118
- → solidity-vuln-auditor-7b (final audit report)
119
  ```
120
 
121
- ### As a tool for your HF models
122
-
123
- ```python
124
- from gradio_client import Client
125
- import json
126
-
127
- # Step 1: Swarm detects compound vulns
128
- swarm = Client("zkaedi/prime-swarm-hunter")
129
- swarm_result = json.loads(swarm.predict("defi_lending_pool", 300, 150, 42, api_name="/api_preset"))
130
-
131
- # Step 2: Leviathan classifies the execution manifold
132
- from leviathan import Leviathan
133
- lev = Leviathan.from_safetensors("leviathan_v2_session_trained.safetensors")
134
- verdict = lev.classify_manifold(H_manifold, V_manifold)
135
-
136
- # Step 3: Combined audit result
137
- audit = {
138
- "compound_vulns": swarm_result["compound_findings"],
139
- "topology_verdict": verdict["verdict"],
140
- "risk_score": swarm_result["summary"]["risk_score"],
141
- }
142
- ```
143
-
144
- ## Companion Files
145
-
146
- | File | Purpose |
147
- |------|---------|
148
- | `leviathan.py` | Pure NumPy inference (this repo) |
149
- | `leviathan.c` | 622-line bare-metal C inference engine |
150
- | `manifold_forge.py` | Exploit manifold generator (5 SWC classes, Hilbert encoding) |
151
- | `weights_to_bin.py` | `.safetensors` → raw float32 binary converter |
152
- | `evm_trace_ingester.py` | EVM trace → 256×256 manifold (3 input modes) |
153
-
154
  ## Author
155
 
156
  **ZKAEDI** — Offensive Healer
 
12
  - evm
13
  - exploit-detection
14
  - cnn
15
+ - solidity
16
  pipeline_tag: other
17
  ---
18
 
19
+ # 🔱 LEVIATHAN v2 — EVM Exploit Topology Classifier
20
 
21
+ **Bare-metal CNN on Hilbert-encoded 2-channel EVM execution manifolds. Classifies exploit topologies as THREAT or CLEAN via convolutional pattern recognition + ZKAEDI PRIME bistable attractor refinement.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ## Architecture
24
 
25
  ```
26
+ 256x256 EVM Manifold (Hilbert-encoded)
27
+ | area-average downsample
28
+ 20x20 input tensor (2 channels)
29
+ |
30
+ Conv2d(2->16, 3x3) -> ReLU -> 18x18x16
31
+ Conv2d(16->16, 3x3) -> ReLU -> 16x16x16
32
+ | flatten
33
+ 4096
34
+ |
35
+ Linear(4096->64) -> ReLU
36
+ Linear(64->1) -> raw score
37
+ |
38
+ ZKAEDI PRIME Bistable Refinement (T=256 iterations)
39
+ |
40
+ THREAT / CLEAN / UNCERTAIN
41
  ```
42
 
43
+ | Layer | Shape | Parameters |
44
+ |-------|-------|------------|
45
  | conv_net.0 | (16, 2, 3, 3) + bias | 304 |
46
  | conv_net.2 | (16, 16, 3, 3) + bias | 2,320 |
47
  | fc.1 | (64, 4096) + bias | 262,208 |
48
  | fc.3 | (1, 64) + bias | 65 |
49
  | **Total** | | **264,897** |
50
 
51
+ ## Channel Semantics
52
+
53
+ | Channel | Field | Source |
54
+ |---------|-------|--------|
55
+ | 0 | H (activator) | Opcode energy density — gas cost per execution step |
56
+ | 1 | V (inhibitor) | Stack depth / state mutation intensity |
57
+
58
+ ## Manifold Encoding
59
 
60
+ EVM traces mapped to 256x256 via **Hilbert curve**: spatial locality = execution locality. Gaussian smoothing (sigma=1.5) for coherence. Long traces wrap with accumulation.
61
+
62
+ ## PRIME Bistable Refinement
63
 
64
  ```
65
+ H_{t+1} = H_t + eta * H_t * sigma(gamma * H_t) + eps * N(0, 1 + beta * |H_t|)
66
  ```
67
 
68
+ Parameters: eta=3.50, gamma=0.30, beta=0.10, sigma=0.05, T=256
 
 
 
 
 
69
 
70
+ Fixed points (analytically derived): H* = -3.054 (CLEAN) and H* = +3.054 (THREAT). Jacobian J=0.346 < 1 (stable).
71
 
72
+ ## Validated Results
73
 
74
+ | Contract / Pattern | Score | Verdict |
75
+ |--------------------|-------|---------|
76
  | Gnosis Multisig (baseline) | 0.0000 | CLEAN |
77
  | SWC-107 Reentrancy | 1.0000 | THREAT |
78
+ | SWC-112 Delegatecall Abuse | 1.0000 | THREAT |
79
  | SWC-101 Integer Overflow | 1.0000 | THREAT |
80
+ | Cross-function Reentrancy | 1.0000 | THREAT |
81
  | Flash Loan Manipulation | 1.0000 | THREAT |
82
 
 
 
83
  ## Usage
84
 
85
  ```python
86
  from leviathan import Leviathan
87
 
88
+ model = Leviathan.from_huggingface("zkaedi/leviathan-v2")
 
 
 
 
89
 
90
+ # Full audit: CNN + PRIME refinement
91
+ result = model.audit(H_256x256, V_256x256)
92
+ # {"verdict": "THREAT", "committed": True, "refined_score": 0.9998, ...}
93
 
94
+ # From raw EVM trace
95
+ result = model.audit_trace(opcode_energies, stack_depths)
96
  ```
97
 
98
+ ## ZKAEDI Security Pipeline
99
 
100
  ```
101
  Solidity Code
102
+ -> gemma-2-9b-solidity-merged (vulnerability signatures)
103
+ -> prime-swarm-hunter (12-agent compound detection)
104
+ -> evm_trace_ingester (trace -> 256x256 manifold)
105
+ -> LEVIATHAN v2 (CNN topology classification)
106
+ -> PRIME refinement (bistable commitment)
107
+ -> solidity-vuln-auditor-7b (final audit report)
108
  ```
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  ## Author
111
 
112
  **ZKAEDI** — Offensive Healer