Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

score.gno

2.46 Kb · 103 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 counts dependency trust for an attestation.
 33type Deps struct {
 34	DirectAtRisk   int
 35	IndirectAtRisk int
 36	Unverified     int
 37}
 38
 39// computeScore applies the formula: start at 100, deduct, floor at 0.
 40func computeScore(fs []Finding, d Deps) int {
 41	score := 100
 42	for _, f := range fs {
 43		proven := f.Label == LabelProven
 44		switch {
 45		case proven && f.Severity == SeverityCritical:
 46			score -= 40
 47		case proven && f.Severity == SeverityHigh:
 48			score -= 25
 49		case f.Severity == SeverityCritical:
 50			score -= 15
 51		case f.Severity == SeverityHigh:
 52			score -= 10
 53		default: // medium, proven or not
 54			score -= 5
 55		}
 56	}
 57	score -= 10 * d.DirectAtRisk
 58	score -= 5 * d.IndirectAtRisk
 59	unverified := 2 * d.Unverified
 60	if unverified > 10 {
 61		unverified = 10
 62	}
 63	score -= unverified
 64	if score < 0 {
 65		score = 0
 66	}
 67	return score
 68}
 69
 70func gradeOf(score int) string {
 71	switch {
 72	case score >= 90:
 73		return "A"
 74	case score >= 75:
 75		return "B"
 76	case score >= 60:
 77		return "C"
 78	case score >= 40:
 79		return "D"
 80	}
 81	return "F"
 82}
 83
 84func verdictOf(fs []Finding) string {
 85	verdict := VerdictClear
 86	for _, f := range fs {
 87		if f.Severity != SeverityCritical && f.Severity != SeverityHigh {
 88			continue
 89		}
 90		if f.Label == LabelProven {
 91			return VerdictNotRecommended
 92		}
 93		verdict = VerdictReview
 94	}
 95	return verdict
 96}
 97
 98// ScoreFor exposes the formula, so anyone can check an attestation or score
 99// a report before attesting it.
100func ScoreFor(fs []Finding, d Deps) (score int, grade, verdict string) {
101	score = computeScore(fs, d)
102	return score, gradeOf(score), verdictOf(fs)
103}