File size: 3,813 Bytes
0e08aa4
 
 
 
 
 
 
 
 
 
 
52c7b25
 
2679f16
0e08aa4
 
 
2679f16
0e08aa4
2679f16
 
 
0e08aa4
 
 
 
2679f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e08aa4
 
2679f16
 
0e08aa4
 
 
 
 
 
2679f16
52c7b25
2679f16
0e08aa4
e88cc12
2679f16
 
52c7b25
2679f16
52c7b25
e88cc12
52c7b25
 
2679f16
 
52c7b25
 
 
2679f16
0e08aa4
 
2679f16
 
52c7b25
2679f16
 
0e08aa4
2679f16
 
 
 
0e08aa4
 
e88cc12
52c7b25
 
 
2679f16
 
 
 
 
 
52c7b25
 
2679f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e08aa4
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
license: mit
tags:
  - safetensors
  - zkaedi-prime
  - hamiltonian-dynamics
  - vulnerability-detection
  - two-field
  - custom-architecture
  - security
  - smart-contracts
  - evm
  - exploit-detection
  - bare-metal
pipeline_tag: other
---

# πŸ”± Leviathan v2 β€” EVM Exploit Topology Classifier

**Bare-metal CNN that classifies EVM execution traces as THREAT or CLEAN using two-field Hamiltonian manifolds.**

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.

## Architecture

```
EVM Trace (opcodes + stack depth)
  ↓
Hilbert-Curve Encoder β†’ 256Γ—256 Manifold
  Channel 0: Opcode energy density (H activator field)
  Channel 1: Stack depth / state mutation intensity (V inhibitor field)
  ↓
Downsample β†’ 20Γ—20
  ↓
Conv2d(2, 16, 3Γ—3) β†’ ReLU
Conv2d(16, 16, 3Γ—3) β†’ ReLU
  ↓
Flatten β†’ 4096
  ↓
Linear(4096, 64) β†’ ReLU
Linear(64, 1) β†’ Raw Score
  ↓
PRIME Bistable Attractor Refinement
  Ξ·=3.50, Ξ³=0.30, Ξ²=0.10, Οƒ=0.05, T=256 iterations
  Negative fixed point H*=βˆ’3.054 β†’ BENIGN committed
  Positive attractor β†’ THREAT committed
  ↓
Output: 0.0 (CLEAN) ... 1.0 (THREAT)
```

| Component | Shape | Parameters |
|-----------|-------|------------|
| conv_net.0 | (16, 2, 3, 3) + bias | 304 |
| conv_net.2 | (16, 16, 3, 3) + bias | 2,320 |
| fc.1 | (64, 4096) + bias | 262,208 |
| fc.3 | (1, 64) + bias | 65 |
| **Total** | | **264,897** |

## Validation Results

Trained and validated end-to-end with EVM execution manifolds:

| Contract / Pattern | Score | Verdict |
|---|---|---|
| Gnosis Multisig (safe baseline) | 0.0000 | CLEAN |
| SWC-107 Reentrancy | 1.0000 | THREAT |
| SWC-112 Delegatecall | 1.0000 | THREAT |
| SWC-101 Integer Overflow | 1.0000 | THREAT |
| Cross-function Reentrancy | 1.0000 | THREAT |
| Flash Loan Manipulation | 1.0000 | THREAT |

PRIME refinement thresholds: P < 0.10 = BENIGN committed, P > 0.90 = THREAT committed.

## Usage

```python
from huggingface_hub import hf_hub_download
from leviathan import Leviathan

weights_path = hf_hub_download("zkaedi/leviathan-v2", "leviathan_v2_session_trained.safetensors")
model = Leviathan.from_safetensors(weights_path)

# Score a 256x256 EVM manifold (auto-downsamples to 20x20)
score = model.predict_manifold(H_256, V_256)

# Full audit with PRIME bistable attractor refinement
result = model.audit(H_256, V_256)
print(result["verdict"])     # "THREAT" or "BENIGN"
print(result["confidence"])  # 0.0 - 1.0
```

## ZKAEDI Security Pipeline

```
Solidity Code
  β†’ gemma-2-9b-solidity-merged (vulnerability signatures)
    β†’ prime-swarm-hunter (12-agent temporal compound detection)
      β†’ evm_trace_ingester.py (EVM trace β†’ 256Γ—256 manifold)
        β†’ LEVIATHAN v2 (CNN: THREAT/CLEAN classification)
          β†’ PRIME refinement (bistable attractor commitment)
            β†’ solidity-vuln-auditor-7b (final audit report)
```

## Companion Files

| File | Purpose |
|---|---|
| `leviathan.c` | 622-line bare-metal C inference engine |
| `manifold_forge.py` | Exploit manifold generator (5 classes, Hilbert encoding) |
| `weights_to_bin.py` | safetensors to raw float32 binary for C engine |
| `evm_trace_ingester.py` | 3 modes: RPC trace, Foundry, static bytecode |

## PRIME Refinement Mathematics

```
H_t = H_0 + Ξ·Β·H_{t-1}Β·Οƒ(Ξ³Β·H_{t-1}) + Ρ·N(0, 1+Ξ²|H_{t-1}|)
```

With Ξ·=3.50 the system has two stable fixed points:
H* = -3.054 (BENIGN, Jacobian J=0.346 < 1) and positive attractor (THREAT).
Scores near 0.5 converge to one attractor over T=256 iterations.

## Author

**ZKAEDI** β€” Offensive Healer