-
Notifications
You must be signed in to change notification settings - Fork 56
309 lines (258 loc) · 9.82 KB
/
fuzz-testing.yml
File metadata and controls
309 lines (258 loc) · 9.82 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: Property-Based Testing (Fuzz Testing)
on:
push:
branches: [ main, develop, security-improvements ]
pull_request:
branches: [ main, develop ]
schedule:
# Run fuzz tests daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
echidna-fuzzing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Install Echidna
run: |
set +e
sudo apt-get update
sudo apt-get install -y haskell-stack libgmp-dev
git clone https://github.com/crytic/echidna.git
cd echidna
stack setup
stack install
INSTALL_STATUS=$?
cd ..
rm -rf echidna
if [ "$INSTALL_STATUS" -eq 0 ] && command -v echidna >/dev/null 2>&1; then
echo "ECHIDNA_AVAILABLE=true" >> $GITHUB_ENV
else
echo "ECHIDNA_AVAILABLE=false" >> $GITHUB_ENV
echo "::warning::Echidna installation failed; skipping Echidna fuzz tests in this run"
fi
- name: Install Solc
run: |
sudo wget -O /usr/local/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux
sudo chmod +x /usr/local/bin/solc
- name: Build Contract
run: |
cd contracts
cargo build --target wasm32-unknown-unknown --release
- name: Run Echidna Fuzz Tests
if: env.ECHIDNA_AVAILABLE == 'true'
run: |
cd contracts
mkdir -p echidna-output
echidna test test/properties/echidna_tests.sol \
--config echidna.yaml \
--output echidna-output/results.json \
--corpus-dir echidna-output/corpus \
--coverage \
--testLimit 10000 \
--shrinkLimit 1000
- name: Upload Echidna Results
uses: actions/upload-artifact@v4
if: always()
with:
name: echidna-results
path: contracts/echidna-output/
- name: Check for Failures
if: env.ECHIDNA_AVAILABLE == 'true'
run: |
cd contracts
if [ -f echidna-output/results.json ]; then
if grep -q "failed" echidna-output/results.json; then
echo "❌ Echidna tests found failures!"
exit 1
else
echo "✅ All Echidna tests passed"
fi
fi
haloria-fuzzing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Install cargo-fuzz
run: cargo install cargo-fuzz --locked
- name: Run Haloria Fuzz Tests
run: |
cd contracts
cargo +nightly fuzz init || true
# Run each fuzz target for 5 minutes
timeout 300 cargo +nightly fuzz run balance_conservation || true
timeout 300 cargo +nightly fuzz run no_overflow_conditions || true
timeout 300 cargo +nightly fuzz run state_transition_validity || true
timeout 300 cargo +nightly fuzz run access_control || true
timeout 300 cargo +nightly fuzz run gas_efficiency || true
timeout 300 cargo +nightly fuzz run reentrancy_protection || true
timeout 300 cargo +nightly fuzz run deadline_enforcement || true
timeout 300 cargo +nightly fuzz run large_input_handling || true
timeout 300 cargo +nightly fuzz run precision_consistency || true
timeout 300 cargo +nightly fuzz run authorization_consistency || true
- name: Upload Fuzz Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: haloria-fuzz-artifacts
path: contracts/fuzz/artifacts/
coverage-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy, llvm-tools-preview
- name: Install grcov
run: cargo install grcov
- name: Generate Coverage
run: |
cd contracts
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="target/coverage/agenticpay-%p-%m.profraw"
cargo test
grcov . --binary-path ./target/debug/ \
--source-dir . \
--output-type lcov \
--branch \
--ignore-not-existing \
--ignore "/*" \
--ignore "target/*" \
--output-path coverage.lcov
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v5
with:
file: contracts/coverage.lcov
flags: fuzz-testing
name: agenticpay-fuzz-coverage
- name: Coverage Summary
run: |
cd contracts
if [ -f coverage.lcov ]; then
echo "📊 Coverage report generated"
# Extract coverage percentage
COVERAGE=$(lcov --summary coverage.lcov 2>&1 | grep "lines......" | grep -o "[0-9.]*%" | head -1)
echo "📈 Line Coverage: $COVERAGE"
fi
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Slither
run: |
pip3 install slither-analyzer
- name: Run Slither Analysis
run: |
cd contracts
# Slither exits non-zero when findings exist. Keep this step non-blocking
# and let the explicit severity gate below decide pass/fail criteria.
slither . --json slither-results.json --filter medium,high || true
- name: Upload Slither Results
uses: actions/upload-artifact@v4
if: always()
with:
name: slither-results
path: contracts/slither-results.json
- name: Check for High Severity Issues
run: |
cd contracts
if [ -f slither-results.json ]; then
HIGH_ISSUES=$(jq '.results.detectors[] | select(.impact == "high") | .id' slither-results.json | wc -l)
if [ "$HIGH_ISSUES" -gt 0 ]; then
echo "❌ Found $HIGH_ISSUES high severity security issues!"
jq '.results.detectors[] | select(.impact == "high")' slither-results.json
exit 1
else
echo "✅ No high severity security issues found"
fi
fi
fuzz-test-report:
runs-on: ubuntu-latest
needs: [echidna-fuzzing, haloria-fuzzing, coverage-analysis, security-scan]
if: always()
steps:
- uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Generate Combined Report
run: |
cat > fuzz-test-report.md << EOF
# Property-Based Testing Report
## Test Execution Summary
- **Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
- **Commit**: ${{ github.sha }}
- **Branch**: ${{ github.ref }}
## Test Results
### Echidna Fuzz Testing
- **Status**: ${{ needs.echidna-fuzzing.result }}
- **Test Limit**: 10,000 iterations
- **Coverage**: Enabled
### Haloria Fuzz Testing
- **Status**: ${{ needs.haloria-fuzzing.result }}
- **Fuzz Time**: 5 minutes per target
- **Targets**: 10 properties
### Coverage Analysis
- **Status**: ${{ needs.coverage-analysis.result }}
- **Tool**: grcov + lcov
### Security Scan
- **Status**: ${{ needs.security-scan.result }}
- **Tool**: Slither
## Findings
EOF
if [ "${{ needs.echidna-fuzzing.result }}" = "failure" ] || [ "${{ needs.haloria-fuzzing.result }}" = "failure" ]; then
echo "❌ **CRITICAL**: Fuzz tests found vulnerabilities!" >> fuzz-test-report.md
echo "Please review the artifacts for detailed findings." >> fuzz-test-report.md
else
echo "✅ All property-based tests passed successfully" >> fuzz-test-report.md
fi
echo "## Artifacts" >> fuzz-test-report.md
echo "- Echidna results: Available in artifacts/echidna-results/" >> fuzz-test-report.md
echo "- Haloria artifacts: Available in artifacts/haloria-fuzz-artifacts/" >> fuzz-test-report.md
echo "- Coverage data: Available in artifacts/coverage/" >> fuzz-test-report.md
echo "- Security scan: Available in artifacts/slither-results/" >> fuzz-test-report.md
- name: Upload Report
uses: actions/upload-artifact@v4
with:
name: fuzz-test-report
path: fuzz-test-report.md
- name: Comment PR
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('fuzz-test-report.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## 🔍 Property-Based Testing Results\\n\\n' + report
});
# Block PR if fuzz tests fail
check-fuzz-results:
runs-on: ubuntu-latest
needs: [echidna-fuzzing, haloria-fuzzing]
if: github.event_name == 'pull_request'
steps:
- name: Check Fuzz Test Results
run: |
if [ "${{ needs.echidna-fuzzing.result }}" = "failure" ] || [ "${{ needs.haloria-fuzzing.result }}" = "failure" ]; then
echo "❌ Fuzz tests failed - blocking PR"
echo "Property-based tests found security vulnerabilities or edge cases."
echo "Please review the test results and fix issues before merging."
exit 1
else
echo "✅ All fuzz tests passed - PR can proceed"
fi