-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfuzz_campaign.sh
More file actions
executable file
Β·141 lines (111 loc) Β· 4.15 KB
/
Copy pathfuzz_campaign.sh
File metadata and controls
executable file
Β·141 lines (111 loc) Β· 4.15 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
#!/bin/bash
# Fuzz Testing Campaign Script for RemitLend Contracts
# This script runs comprehensive fuzz testing on all contracts
set -e
echo "π Starting RemitLend Fuzz Testing Campaign"
echo "=========================================="
# Configuration
FUZZ_TIME=${1:-60} # Default 60 seconds per target if not specified
CORPUS_DIR="fuzz/corpus"
ARTIFACTS_DIR="fuzz/artifacts"
REPORT_DIR="fuzz/reports"
# Create directories
mkdir -p "$CORPUS_DIR" "$ARTIFACTS_DIR" "$REPORT_DIR"
# Function to run fuzz test
run_fuzz() {
local target=$1
local description=$2
echo ""
echo "π― Fuzzing: $description"
echo "Target: $target"
echo "Time: ${FUZZ_TIME}s"
echo "----------------------------------------"
# Create corpus directory for this target
mkdir -p "$CORPUS_DIR/$target"
# Run the fuzz test
cargo +nightly fuzz run "$target" \
-- -max_total_time="${FUZZ_TIME}" \
-artifact_prefix="$ARTIFACTS_DIR/$target-" \
-print_final_stats=1 \
2>&1 | tee "$REPORT_DIR/$target.log"
# Check if any crashes were found
if ls "$ARTIFACTS_DIR/$target"-* 1> /dev/null 2>&1; then
echo "β CRASHES FOUND for $target!"
echo "Artifacts saved in: $ARTIFACTS_DIR"
else
echo "β
No crashes found for $target"
fi
}
# Function to generate summary report
generate_report() {
echo ""
echo "π Generating Summary Report"
echo "==========================="
local report_file="$REPORT_DIR/summary_$(date +%Y%m%d_%H%M%S).md"
cat > "$report_file" << EOF
# RemitLend Fuzz Testing Report
**Date:** $(date)
**Fuzz Time per Target:** ${FUZZ_TIME}s
## Test Results
EOF
# Add results for each target
for target in "lending_pool_fuzz" "loan_manager_fuzz" "remittance_nft_fuzz"; do
echo "### $target" >> "$report_file"
if ls "$ARTIFACTS_DIR/$target"-* 1> /dev/null 2>&1; then
echo "- Status: β CRASHES FOUND" >> "$report_file"
echo "- Artifacts: $(ls "$ARTIFACTS_DIR/$target"-* | wc -l) crash artifacts" >> "$report_file"
else
echo "- Status: β
PASSED" >> "$report_file"
fi
if [ -f "$REPORT_DIR/$target.log" ]; then
echo "- Log: [$target.log]($target.log)" >> "$report_file"
fi
echo "" >> "$report_file"
done
echo "## Invariants Tested" >> "$report_file"
echo "" >> "$report_file"
echo "### LendingPool" >> "$report_file"
echo "- Total deposits >= total withdrawals" >> "$report_file"
echo "- Individual balances never negative" >> "$report_file"
echo "- Balance consistency across operations" >> "$report_file"
echo "" >> "$report_file"
echo "### LoanManager" >> "$report_file"
echo "- Score threshold enforcement (>= 500 for loans)" >> "$report_file"
echo "- Scores never negative" >> "$report_file"
echo "- Authorization controls" >> "$report_file"
echo "" >> "$report_file"
echo "### RemittanceNFT" >> "$report_file"
echo "- Unique NFT per user" >> "$report_file"
echo "- Score range validation" >> "$report_file"
echo "- Authorization controls" >> "$report_file"
echo "- Metadata integrity" >> "$report_file"
echo "" >> "$report_file"
echo "Report saved to: $report_file"
}
# Main execution
echo "Building fuzz targets..."
cargo +nightly fuzz build
echo ""
echo "Starting fuzz testing campaign..."
echo "================================"
# Run fuzz tests for each contract
run_fuzz "lending_pool_fuzz" "LendingPool Contract"
run_fuzz "loan_manager_fuzz" "LoanManager Contract"
run_fuzz "remittance_nft_fuzz" "RemittanceNFT Contract"
# Generate summary report
generate_report
echo ""
echo "π Fuzz Testing Campaign Complete!"
echo "=================================="
echo "Reports available in: $REPORT_DIR"
echo "Crash artifacts (if any) available in: $ARTIFACTS_DIR"
# Exit with error if any crashes were found
if ls "$ARTIFACTS_DIR"/*-* 1> /dev/null 2>&1; then
echo ""
echo "β οΈ Some fuzz tests found crashes. Please review the artifacts."
exit 1
else
echo ""
echo "π All fuzz tests passed successfully!"
exit 0
fi