File size: 1,854 Bytes
4bc63c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Node: arbiter. Derives the verdict from what the two checkers said.

Assurance is a property of the run, not of the claim: level 3 needs both independent
checkers to agree, and they must not have read each other.
"""

import json
import sys

LEVELS = ("REFUSED", "UNKNOWN", "SINGLE_PROVER", "VERIFIED")


def combine(nodes):
    """nodes: list of envelopes in pipeline order. Returns verdict, assurance, reasons."""
    reasons = []
    for node in nodes:
        reasons.extend(node.get("reasons") or [])
        if node.get("reason"):
            reasons.append(node["reason"])
    reasons = sorted(set(r for r in reasons if r))
    by_name = {node.get("node", ""): node for node in nodes}
    intent = by_name.get("intent", {})
    locator = by_name.get("locator", {})
    planner = by_name.get("planner", {})
    executor = by_name.get("executor", {})
    checker = by_name.get("gate_checker", {})
    adversary = by_name.get("adversary", {})
    if intent.get("status") == "refused" or locator.get("status") == "refused":
        return "REFUSED", 0, reasons
    if executor.get("status") == "refused" or planner.get("status") == "refused":
        return "REFUSED", 0, reasons
    passed = checker.get("status") == "pass"
    survived = adversary.get("status") == "survived"
    if passed and survived:
        return "VERIFIED", 3, reasons
    if passed or survived:
        return "SINGLE_PROVER", 2, reasons
    return "REFUSED", 1, reasons + ["CHECKER_ABSTAIN"]


def main() -> int:
    task = json.load(sys.stdin)
    verdict, assurance, reasons = combine(task.get("nodes") or [])
    print(json.dumps({"node": "arbiter", "status": verdict.lower(), "verdict": verdict,
                      "assurance": assurance, "reasons": reasons}))
    return 0 if verdict == "VERIFIED" else 1


if __name__ == "__main__":
    raise SystemExit(main())