Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -11,102 +11,115 @@ tags:
|
|
| 11 |
- smart-contracts
|
| 12 |
- evm
|
| 13 |
- exploit-detection
|
| 14 |
-
-
|
| 15 |
-
- solidity
|
| 16 |
pipeline_tag: other
|
| 17 |
---
|
| 18 |
|
| 19 |
-
# π±
|
| 20 |
|
| 21 |
-
**Bare-metal CNN
|
|
|
|
|
|
|
| 22 |
|
| 23 |
## Architecture
|
| 24 |
|
| 25 |
```
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
```
|
| 42 |
|
| 43 |
-
|
|
| 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 |
-
##
|
| 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 |
-
|
| 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
|
| 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 |
-
|
|
|
|
| 89 |
|
| 90 |
-
#
|
| 91 |
-
|
| 92 |
-
# {"verdict": "THREAT", "committed": True, "refined_score": 0.9998, ...}
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
result = model.
|
|
|
|
|
|
|
| 96 |
```
|
| 97 |
|
| 98 |
## ZKAEDI Security Pipeline
|
| 99 |
|
| 100 |
```
|
| 101 |
Solidity Code
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 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
|