score.gno
2.61 Kb · 106 lines
1package bouncer
2
3// The public, deterministic scoring formula (CLAUDE.md §8). The realm
4// computes score, grade and verdict itself from the attested findings and
5// dependency counts, so an attestation can never carry a score that
6// contradicts its own findings.
7
8// Labels, exactly as the prover writes them.
9const (
10 LabelProven = "PROVEN"
11 LabelNotReproduced = "NOT REPRODUCED"
12 LabelStaticWarning = "STATIC WARNING"
13)
14
15// Severities.
16const (
17 SeverityCritical = "critical"
18 SeverityHigh = "high"
19 SeverityMedium = "medium"
20)
21
22// Verdicts.
23const (
24 VerdictNotRecommended = "not-recommended" // any PROVEN Critical or High
25 VerdictReview = "review" // any Critical or High warning
26 VerdictClear = "clear" // no known Critical or High issues
27)
28
29// Disclaimer is shown on every Passport.
30const Disclaimer = "A high score means Bouncer found no issues with its current rules. It is not a guarantee of safety."
31
32// Deps is an attestation's dependency trust: the list as attested, and the
33// counts that the score uses. Counts and statuses are computed when the
34// attestation is read (see live).
35type Deps struct {
36 DirectAtRisk int
37 IndirectAtRisk int
38 Unverified int
39 List []Dep
40}
41
42// computeScore applies the formula: start at 100, deduct, floor at 0.
43func computeScore(fs []Finding, d Deps) int {
44 score := 100
45 for _, f := range fs {
46 proven := f.Label == LabelProven
47 switch {
48 case proven && f.Severity == SeverityCritical:
49 score -= 40
50 case proven && f.Severity == SeverityHigh:
51 score -= 25
52 case f.Severity == SeverityCritical:
53 score -= 15
54 case f.Severity == SeverityHigh:
55 score -= 10
56 default: // medium, proven or not
57 score -= 5
58 }
59 }
60 score -= 10 * d.DirectAtRisk
61 score -= 5 * d.IndirectAtRisk
62 unverified := 2 * d.Unverified
63 if unverified > 10 {
64 unverified = 10
65 }
66 score -= unverified
67 if score < 0 {
68 score = 0
69 }
70 return score
71}
72
73func gradeOf(score int) string {
74 switch {
75 case score >= 90:
76 return "A"
77 case score >= 75:
78 return "B"
79 case score >= 60:
80 return "C"
81 case score >= 40:
82 return "D"
83 }
84 return "F"
85}
86
87func verdictOf(fs []Finding) string {
88 verdict := VerdictClear
89 for _, f := range fs {
90 if f.Severity != SeverityCritical && f.Severity != SeverityHigh {
91 continue
92 }
93 if f.Label == LabelProven {
94 return VerdictNotRecommended
95 }
96 verdict = VerdictReview
97 }
98 return verdict
99}
100
101// ScoreFor exposes the formula, so anyone can check an attestation or score
102// a report before attesting it.
103func ScoreFor(fs []Finding, d Deps) (score int, grade, verdict string) {
104 score = computeScore(fs, d)
105 return score, gradeOf(score), verdictOf(fs)
106}