zkaedi commited on
Commit
2679f16
Β·
verified Β·
1 Parent(s): 30f1a3c

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +70 -57
README.md CHANGED
@@ -11,102 +11,115 @@ tags:
11
  - smart-contracts
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
 
11
  - smart-contracts
12
  - evm
13
  - exploit-detection
14
+ - bare-metal
 
15
  pipeline_tag: other
16
  ---
17
 
18
+ # πŸ”± Leviathan v2 β€” EVM Exploit Topology Classifier
19
 
20
+ **Bare-metal CNN that classifies EVM execution traces as THREAT or CLEAN using two-field Hamiltonian manifolds.**
21
+
22
+ Leviathan ingests raw Ethereum Virtual Machine traces, encodes them as 2-channel 256Γ—256 spatial manifolds via Hilbert curve mapping, downsamples to the CNN's 20Γ—20 receptive field, and outputs a binary exploit score. A ZKAEDI PRIME bistable attractor refinement layer then commits the score to BENIGN or THREAT.
23
 
24
  ## Architecture
25
 
26
  ```
27
+ EVM Trace (opcodes + stack depth)
28
+ ↓
29
+ Hilbert-Curve Encoder β†’ 256Γ—256 Manifold
30
+ Channel 0: Opcode energy density (H activator field)
31
+ Channel 1: Stack depth / state mutation intensity (V inhibitor field)
32
+ ↓
33
+ Downsample β†’ 20Γ—20
34
+ ↓
35
+ Conv2d(2, 16, 3Γ—3) β†’ ReLU
36
+ Conv2d(16, 16, 3Γ—3) β†’ ReLU
37
+ ↓
38
+ Flatten β†’ 4096
39
+ ↓
40
+ Linear(4096, 64) β†’ ReLU
41
+ Linear(64, 1) β†’ Raw Score
42
+ ↓
43
+ PRIME Bistable Attractor Refinement
44
+ Ξ·=3.50, Ξ³=0.30, Ξ²=0.10, Οƒ=0.05, T=256 iterations
45
+ Negative fixed point H*=βˆ’3.054 β†’ BENIGN committed
46
+ Positive attractor β†’ THREAT committed
47
+ ↓
48
+ Output: 0.0 (CLEAN) ... 1.0 (THREAT)
49
  ```
50
 
51
+ | Component | Shape | Parameters |
52
+ |-----------|-------|------------|
53
  | conv_net.0 | (16, 2, 3, 3) + bias | 304 |
54
  | conv_net.2 | (16, 16, 3, 3) + bias | 2,320 |
55
  | fc.1 | (64, 4096) + bias | 262,208 |
56
  | fc.3 | (1, 64) + bias | 65 |
57
  | **Total** | | **264,897** |
58
 
59
+ ## Validation Results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ Trained and validated end-to-end with EVM execution manifolds:
 
 
62
 
63
  | Contract / Pattern | Score | Verdict |
64
+ |---|---|---|
65
+ | Gnosis Multisig (safe baseline) | 0.0000 | CLEAN |
66
  | SWC-107 Reentrancy | 1.0000 | THREAT |
67
+ | SWC-112 Delegatecall | 1.0000 | THREAT |
68
  | SWC-101 Integer Overflow | 1.0000 | THREAT |
69
  | Cross-function Reentrancy | 1.0000 | THREAT |
70
  | Flash Loan Manipulation | 1.0000 | THREAT |
71
 
72
+ PRIME refinement thresholds: P < 0.10 = BENIGN committed, P > 0.90 = THREAT committed.
73
+
74
  ## Usage
75
 
76
  ```python
77
+ from huggingface_hub import hf_hub_download
78
  from leviathan import Leviathan
79
 
80
+ weights_path = hf_hub_download("zkaedi/leviathan-v2", "leviathan_v2_session_trained.safetensors")
81
+ model = Leviathan.from_safetensors(weights_path)
82
 
83
+ # Score a 256x256 EVM manifold (auto-downsamples to 20x20)
84
+ score = model.predict_manifold(H_256, V_256)
 
85
 
86
+ # Full audit with PRIME bistable attractor refinement
87
+ result = model.audit(H_256, V_256)
88
+ print(result["verdict"]) # "THREAT" or "BENIGN"
89
+ print(result["confidence"]) # 0.0 - 1.0
90
  ```
91
 
92
  ## ZKAEDI Security Pipeline
93
 
94
  ```
95
  Solidity Code
96
+ β†’ gemma-2-9b-solidity-merged (vulnerability signatures)
97
+ β†’ prime-swarm-hunter (12-agent temporal compound detection)
98
+ β†’ evm_trace_ingester.py (EVM trace β†’ 256Γ—256 manifold)
99
+ β†’ LEVIATHAN v2 (CNN: THREAT/CLEAN classification)
100
+ β†’ PRIME refinement (bistable attractor commitment)
101
+ β†’ solidity-vuln-auditor-7b (final audit report)
102
  ```
103
 
104
+ ## Companion Files
105
+
106
+ | File | Purpose |
107
+ |---|---|
108
+ | `leviathan.c` | 622-line bare-metal C inference engine |
109
+ | `manifold_forge.py` | Exploit manifold generator (5 classes, Hilbert encoding) |
110
+ | `weights_to_bin.py` | safetensors to raw float32 binary for C engine |
111
+ | `evm_trace_ingester.py` | 3 modes: RPC trace, Foundry, static bytecode |
112
+
113
+ ## PRIME Refinement Mathematics
114
+
115
+ ```
116
+ H_t = H_0 + Ξ·Β·H_{t-1}Β·Οƒ(Ξ³Β·H_{t-1}) + Ρ·N(0, 1+Ξ²|H_{t-1}|)
117
+ ```
118
+
119
+ With Ξ·=3.50 the system has two stable fixed points:
120
+ H* = -3.054 (BENIGN, Jacobian J=0.346 < 1) and positive attractor (THREAT).
121
+ Scores near 0.5 converge to one attractor over T=256 iterations.
122
+
123
  ## Author
124
 
125
  **ZKAEDI** β€” Offensive Healer