zkaedi commited on
Commit
52c7b25
Β·
verified Β·
1 Parent(s): 278e188

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +104 -38
README.md CHANGED
@@ -9,81 +9,147 @@ tags:
9
  - custom-architecture
10
  - security
11
  - smart-contracts
 
 
 
12
  pipeline_tag: other
13
  ---
14
 
15
- # πŸ”± Leviathan v2 β€” Two-Field Hamiltonian Classifier
16
 
17
- **Session-trained CNN operating on ZKAEDI PRIME two-field (H, V) energy landscapes.**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ## Architecture
20
 
21
  ```
22
- Input: 2-channel tensor (H_field, V_field)
23
- ↓
24
- Conv2d(2, 16, 3Γ—3) β†’ ReLU
25
- Conv2d(16, 16, 3Γ—3) β†’ ReLU
26
- ↓
27
  Flatten β†’ 4096
28
- ↓
29
- Linear(4096, 64) β†’ ReLU
30
- Linear(64, 1) β†’ Output
31
  ```
32
 
33
- | Component | Shape | Parameters |
34
- |-----------|-------|------------|
35
  | conv_net.0 | (16, 2, 3, 3) + bias | 304 |
36
  | conv_net.2 | (16, 16, 3, 3) + bias | 2,320 |
37
  | fc.1 | (64, 4096) + bias | 262,208 |
38
  | fc.3 | (1, 64) + bias | 65 |
39
  | **Total** | | **264,897** |
40
 
41
- ## Usage
42
 
43
- ```python
44
- from safetensors.numpy import load_file
45
- import numpy as np
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- # Load weights
48
- weights = load_file("leviathan_v2_session_trained.safetensors")
49
 
50
- # Or use the inference module
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  from leviathan import Leviathan
52
 
53
  model = Leviathan.from_safetensors("leviathan_v2_session_trained.safetensors")
54
 
55
- # Input: two-field Hamiltonian snapshot (H, V) as 2-channel image
56
- H_field = np.random.randn(1, 16, 16) # Activator field
57
- V_field = np.random.randn(1, 16, 16) # Inhibitor field
58
- input_tensor = np.stack([H_field[0], V_field[0]])[None] # (1, 2, 16, 16)
 
 
 
59
 
60
- output = model.forward(input_tensor)
61
- print(f"Score: {output}")
62
  ```
63
 
64
- ## Integration with PRIME Swarm
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  ```python
67
  from gradio_client import Client
68
  import json
69
 
70
- # 1. Run swarm analysis
71
  swarm = Client("zkaedi/prime-swarm-hunter")
72
- result = json.loads(swarm.predict("defi_lending_pool", 300, 150, 42, api_name="/api_preset"))
73
 
74
- # 2. Feed energy landscape snapshot to Leviathan for classification
75
- # Leviathan scores the field state for vulnerability presence
 
 
 
 
 
 
 
 
 
76
  ```
77
 
78
- ## Part of the ZKAEDI Security Pipeline
79
 
80
- ```
81
- Solidity Code
82
- β†’ gemma-2-9b-solidity-merged (vulnerability signatures)
83
- β†’ prime-swarm-hunter (12-agent temporal detection)
84
- β†’ Leviathan v2 (two-field classification)
85
- β†’ solidity-vuln-auditor-7b (final audit report)
86
- ```
87
 
88
  ## Author
89
 
 
9
  - custom-architecture
10
  - security
11
  - smart-contracts
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