-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_exploit_simulations.go
More file actions
68 lines (59 loc) · 1.9 KB
/
run_exploit_simulations.go
File metadata and controls
68 lines (59 loc) · 1.9 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
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"time"
"github.com/aethelred/aethelred/tools/tools/loadtest"
)
type ExploitSimulationOutput struct {
GeneratedAt string `json:"generated_at"`
Scenarios []interface{} `json:"scenarios"`
}
func main() {
scenarios := loadtest.GetNetworkScenarios()
var results []interface{}
validators := make([]*loadtest.SimulatedValidator, 100)
for i := 0; i < 100; i++ {
validators[i] = &loadtest.SimulatedValidator{
ID: i,
VotingPower: 1000,
IsActive: true,
}
}
for _, s := range scenarios {
fmt.Printf("Running network scenario: %s\n", s.Name)
runner := loadtest.NewNetworkScenarioRunner(&s, validators, nil)
res, err := runner.Run(context.Background())
if err != nil {
fmt.Printf("Scenario %s failed: %v\n", s.Name, err)
continue
}
results = append(results, map[string]interface{}{
"name": res.ScenarioName,
"description": s.Description,
"attack_resilience_grade": res.AttackResilienceGrade,
"recovery_grade": res.RecoveryGrade,
"overall_grade": res.OverallGrade,
"consensus_failures": res.ConsensusFailures,
"split_brain_events": res.SplitBrainEvents,
"recommendations": res.Recommendations,
"duration_ms": res.Duration.Milliseconds(),
})
}
out := ExploitSimulationOutput{
GeneratedAt: time.Now().UTC().Format(time.RFC3339),
Scenarios: results,
}
data, _ := json.MarshalIndent(out, "", " ")
if err := os.MkdirAll("test-results", 0755); err != nil {
fmt.Printf("Failed to create test-results directory: %v\n", err)
return
}
if err := os.WriteFile("test-results/dynamic-exploit-simulations.json", data, 0644); err != nil {
fmt.Printf("Failed to write results: %v\n", err)
return
}
fmt.Println("Exploit simulations finished. Results written to test-results/dynamic-exploit-simulations.json")
}