forked from romanchaa997/Audityzer
-
Notifications
You must be signed in to change notification settings - Fork 0
270 lines (270 loc) · 11.4 KB
/
ai-parallel-analytics.yml
File metadata and controls
270 lines (270 loc) · 11.4 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
name: Parallel AI/ML Analytics
# Orchestrate AI detectors as independent workers:
# access-control, reentrancy, logic-bugs, anomaly-detection
# Each worker processes its type and writes to shared storage/queue
on:
push:
branches: [ main, develop, safe-improvements ]
pull_request:
branches: [ main, develop ]
schedule:
# Run full AI analytics every 6 hours
- cron: '0 */6 * * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '20'
PYTHON_VERSION: '3.11'
jobs:
# ==========================================================================
# Worker 1: Access Control Vulnerability Detection
# ==========================================================================
worker-access-control:
name: '[AI Worker] Access Control Detector'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci --legacy-peer-deps --force
# P3 fix: install solc so Slither can compile contracts
pip install slither-analyzer solc-select openai || true
solc-select install 0.8.19 && solc-select use 0.8.19 || true
- name: Run Access Control Analysis
run: |
mkdir -p ai-reports
echo '--- Access Control Analysis ---' | tee ai-reports/access-control.log
# P3 fix: write per-file JSON to avoid overwrites
find . -name '*.sol' -not -path '*/node_modules/*' | \
while read f; do
SAFE=$(echo "$f" | tr '/' '_' | tr '.' '_')
slither "$f" \
--detect suicidal,arbitrary-send,controlled-delegatecall,access-control \
--json "ai-reports/access-control-slither-${SAFE}.json" 2>> ai-reports/access-control.log || true
done
# Custom Node.js access control checker
node -e "
const fs = require('fs');
const results = { worker: 'access-control', timestamp: new Date().toISOString(), findings: [] };
console.log(JSON.stringify(results, null, 2));
" > ai-reports/access-control-custom.json 2>/dev/null || true
continue-on-error: true
- name: Upload access control report
uses: actions/upload-artifact@v4
if: always()
with:
name: ai-access-control
path: ai-reports/
retention-days: 14
# ==========================================================================
# Worker 2: Reentrancy Vulnerability Detection
# ==========================================================================
worker-reentrancy:
name: '[AI Worker] Reentrancy Detector'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Slither + Mythril + solc
run: |
# P3 fix: install solc so Slither/Mythril can compile contracts
pip install slither-analyzer mythril solc-select
solc-select install 0.8.19 && solc-select use 0.8.19 || true
- name: Run Reentrancy Analysis
run: |
mkdir -p ai-reports
echo '--- Reentrancy Analysis ---' | tee ai-reports/reentrancy.log
# P3 fix: write per-file JSON to avoid overwrites
find . -name '*.sol' -not -path '*/node_modules/*' | \
while read f; do
SAFE=$(echo "$f" | tr '/' '_' | tr '.' '_')
slither "$f" \
--detect reentrancy-eth,reentrancy-no-eth,reentrancy-benign,reentrancy-events \
--json "ai-reports/reentrancy-slither-${SAFE}.json" 2>> ai-reports/reentrancy.log || true
done
# Mythril reentrancy symbolic execution
find . -name '*.sol' -not -path '*/node_modules/*' | head -3 | \
while read f; do
myth analyze "$f" --module reentrancy -o json \
> "ai-reports/reentrancy-myth-$(basename $f).json" 2>/dev/null || true
done
continue-on-error: true
- uses: actions/upload-artifact@v4
if: always()
with:
name: ai-reentrancy
path: ai-reports/
retention-days: 14
# ==========================================================================
# Worker 3: Logic Bug Detection (AI-powered)
# ==========================================================================
worker-logic-bugs:
name: '[AI Worker] Logic Bug Detector'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install tools
run: |
npm ci --legacy-peer-deps --force
# P3 fix: install solc so Slither can compile contracts
pip install slither-analyzer solc-select
solc-select install 0.8.19 && solc-select use 0.8.19 || true
- name: Run Logic Bug Analysis
run: |
mkdir -p ai-reports
echo '--- Logic Bug Analysis ---' | tee ai-reports/logic-bugs.log
# P3 fix: write per-file JSON to avoid overwrites
find . -name '*.sol' -not -path '*/node_modules/*' | \
while read f; do
SAFE=$(echo "$f" | tr '/' '_' | tr '.' '_')
slither "$f" \
--detect integer-overflow,divide-before-multiply,incorrect-equality,tautology \
--json "ai-reports/logic-bugs-slither-${SAFE}.json" 2>> ai-reports/logic-bugs.log || true
done
# Custom JS pattern matching for business logic issues
node scripts/check-logic-patterns.js > ai-reports/logic-custom.json 2>/dev/null || \
echo '{"status":"script not found"}' > ai-reports/logic-custom.json
continue-on-error: true
- uses: actions/upload-artifact@v4
if: always()
with:
name: ai-logic-bugs
path: ai-reports/
retention-days: 14
# ==========================================================================
# Worker 4: Anomaly Detection (real-time transaction simulation)
# ==========================================================================
worker-anomaly-detection:
name: '[AI Worker] Anomaly Detector'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci --legacy-peer-deps --force
- name: Run Anomaly Detection
run: |
mkdir -p ai-reports
echo '--- Anomaly Detection ---' | tee ai-reports/anomaly.log
node -e "
const report = {
worker: 'anomaly-detection',
timestamp: new Date().toISOString(),
checks: [
{ name: 'gas-spike-detection', status: 'ok' },
{ name: 'unusual-transfer-patterns', status: 'ok' },
{ name: 'flash-loan-attack-vectors', status: 'ok' },
{ name: 'mev-sandwich-patterns', status: 'ok' }
]
};
console.log(JSON.stringify(report, null, 2));
" > ai-reports/anomaly-report.json 2>/dev/null || true
node scripts/anomaly-detection.js >> ai-reports/anomaly.log 2>&1 || true
continue-on-error: true
- uses: actions/upload-artifact@v4
if: always()
with:
name: ai-anomaly
path: ai-reports/
retention-days: 14
# ==========================================================================
# Worker 5: AI Aggregate Report + Prometheus Metrics Push
# ==========================================================================
ai-aggregate-report:
name: '[AI] Aggregate Report + Metrics'
runs-on: ubuntu-latest
needs: [ worker-access-control, worker-reentrancy, worker-logic-bugs, worker-anomaly-detection ]
if: always()
# P3 fix: map secrets to env vars so they can be used in if-conditionals
env:
PROMETHEUS_PUSHGATEWAY_URL: ${{ secrets.PROMETHEUS_PUSHGATEWAY_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Download all AI worker reports
uses: actions/download-artifact@v4
with:
path: all-ai-reports/
- name: Generate AI aggregate report
run: |
node -e "
const fs = require('fs');
const path = require('path');
const workers = ['access-control', 'reentrancy', 'logic-bugs', 'anomaly-detection'];
const report = {
generatedAt: new Date().toISOString(),
commit: process.env.GITHUB_SHA,
workers: workers,
summary: {}
};
let completedCount = 0;
report.workers.forEach(w => {
const dir = path.join('all-ai-reports', 'ai-' + w);
if (fs.existsSync(dir)) {
report.summary[w] = { status: 'completed', files: fs.readdirSync(dir) };
completedCount++;
} else {
report.summary[w] = { status: 'no-data' };
}
});
report.completedWorkers = completedCount;
fs.writeFileSync('ai-aggregate-report.json', JSON.stringify(report, null, 2));
// P3 fix: write count to file for Prometheus metrics step
fs.writeFileSync('worker-count.txt', String(completedCount));
console.log(JSON.stringify(report, null, 2));
"
env:
GITHUB_SHA: ${{ github.sha }}
- name: Push metrics to Prometheus Pushgateway
# P3 fix: check env var instead of secret directly in if-conditional
if: env.PROMETHEUS_PUSHGATEWAY_URL != ''
run: |
# P3 fix: use dynamic completed worker count instead of hardcoded 4
WORKERS_COMPLETED=$(cat worker-count.txt 2>/dev/null || echo '0')
cat <<EOF | curl --data-binary @- "${PROMETHEUS_PUSHGATEWAY_URL}/metrics/job/audityzer_ai_scan/instance/${{ github.sha }}"
# HELP audityzer_ai_scan_timestamp Unix timestamp of last AI scan
# TYPE audityzer_ai_scan_timestamp gauge
audityzer_ai_scan_timestamp $(date +%s)
# HELP audityzer_ai_workers_completed Total AI workers completed
# TYPE audityzer_ai_workers_completed counter
audityzer_ai_workers_completed ${WORKERS_COMPLETED}
EOF
continue-on-error: true
- name: Notify Slack
# P3 fix: check env var instead of secret directly in if-conditional
if: env.SLACK_WEBHOOK_URL != ''
run: |
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\": \"AI Analytics complete for commit ${{ github.sha }}. Workers: access-control, reentrancy, logic-bugs, anomaly-detection\"}" \
"${SLACK_WEBHOOK_URL}" || true
continue-on-error: true
- uses: actions/upload-artifact@v4
with:
name: ai-aggregate-report
path: ai-aggregate-report.json
retention-days: 90