aetherproof-arch 0.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,66 @@
1
+ """
2
+ Invalidation Rules — Section 5.3 implementation.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from aetherproof.proof.pdg import PDG
8
+
9
+
10
+ def invalidate(
11
+ changeset_id: str,
12
+ pdg: PDG,
13
+ blast_radius: set[str] | None = None,
14
+ ) -> list[str]:
15
+ """
16
+ Invalidate nodes affected by a changeset.
17
+
18
+ Implements the worklist algorithm from Section 5.3.
19
+
20
+ Parameters
21
+ ----------
22
+ changeset_id : str
23
+ The changeset that triggered invalidation.
24
+ pdg : PDG
25
+ The proof dependency graph.
26
+ blast_radius : set[str], optional
27
+ Files/symbols affected by the changeset.
28
+
29
+ Returns
30
+ -------
31
+ list[str]
32
+ IDs of invalidated nodes.
33
+ """
34
+ invalidated: set[str] = set()
35
+ worklist: list[str] = []
36
+
37
+ # Seed: nodes directly invalidated by the changeset
38
+ for s, t, e in pdg.edges:
39
+ if s == changeset_id and e == "invalidates":
40
+ worklist.append(t)
41
+
42
+ # Seed: nodes within blast radius
43
+ if blast_radius:
44
+ for node_id, node in pdg.nodes.items():
45
+ if node.node_type.value == "obligation":
46
+ node_blast = node.data.get("blast_radius", set())
47
+ if node_blast & blast_radius:
48
+ worklist.append(node_id)
49
+
50
+ # Worklist fixpoint
51
+ while worklist:
52
+ current = worklist.pop()
53
+ if current in invalidated:
54
+ continue
55
+ invalidated.add(current)
56
+
57
+ # Propagate via derives_from
58
+ for s, t, e in pdg.edges:
59
+ if s == current and e == "derives_from":
60
+ if t not in invalidated:
61
+ worklist.append(t)
62
+
63
+ return list(invalidated)
64
+
65
+
66
+ __all__ = ["invalidate"]
@@ -0,0 +1,90 @@
1
+ """
2
+ Proof Dependency Graph (PDG) — Definition 5 implementation.
3
+
4
+ Extends ODG with evidence and assumption nodes.
5
+
6
+ See manuscript Section 5.2.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass, field
12
+ from enum import Enum
13
+
14
+ from aetherproof.models import Obligation
15
+ from aetherproof.obligations.odg import ODG, EdgeType
16
+
17
+
18
+ class NodeType(str, Enum):
19
+ """PDG node types (Section 5.2)."""
20
+ OBLIGATION = "obligation"
21
+ EVIDENCE = "evidence"
22
+ ASSUMPTION = "assumption"
23
+ CSR_RECORD = "csr_record"
24
+ CHANGESET = "changeset"
25
+
26
+
27
+ @dataclass
28
+ class PDGNode:
29
+ """A node in the PDG."""
30
+ node_id: str
31
+ node_type: NodeType
32
+ data: dict = field(default_factory=dict)
33
+
34
+
35
+ @dataclass
36
+ class PDG:
37
+ """
38
+ Proof Dependency Graph (Definition 5).
39
+
40
+ PDG = (Obligations ∪ Evidence ∪ Assumptions, Edges)
41
+ """
42
+ nodes: dict[str, PDGNode] = field(default_factory=dict)
43
+ edges: list[tuple[str, str, str]] = field(default_factory=list)
44
+
45
+ def add_node(self, node: PDGNode) -> None:
46
+ """Add a node to the graph."""
47
+ if node.node_id in self.nodes:
48
+ raise ValueError(f"Node {node.node_id} already exists")
49
+ self.nodes[node.node_id] = node
50
+
51
+ def add_edge(
52
+ self,
53
+ source_id: str,
54
+ target_id: str,
55
+ edge_type: str,
56
+ ) -> None:
57
+ """Add an edge between two nodes."""
58
+ if source_id not in self.nodes:
59
+ raise ValueError(f"Source node {source_id} not found")
60
+ if target_id not in self.nodes:
61
+ raise ValueError(f"Target node {target_id} not found")
62
+
63
+ self.edges.append((source_id, target_id, edge_type))
64
+
65
+ def invalidate(self, changeset_id: str) -> list[str]:
66
+ """Invalidate nodes affected by a changeset."""
67
+ invalidated = []
68
+ to_invalidate = []
69
+
70
+ # Find seeds: nodes invalidated directly by the changeset
71
+ for s, t, e in self.edges:
72
+ if s == changeset_id and e == "invalidates":
73
+ to_invalidate.append(t)
74
+
75
+ # Propagate via derives_from
76
+ while to_invalidate:
77
+ current = to_invalidate.pop()
78
+ if current in invalidated:
79
+ continue
80
+ invalidated.append(current)
81
+
82
+ for s, t, e in self.edges:
83
+ if s == current and e == "derives_from":
84
+ if t not in invalidated:
85
+ to_invalidate.append(t)
86
+
87
+ return invalidated
88
+
89
+
90
+ __all__ = ["PDG", "PDGNode", "NodeType"]
@@ -0,0 +1,5 @@
1
+ """Integration protocol with AetherFlow."""
2
+
3
+ from aetherproof.protocol.messages import Message, MessageType, Envelope
4
+
5
+ __all__ = ["Message", "MessageType", "Envelope"]
@@ -0,0 +1,64 @@
1
+ """
2
+ Integration Protocol — Section 7 implementation.
3
+
4
+ Ten message types (M1–M10).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import time
10
+ from dataclasses import dataclass, field
11
+ from enum import Enum
12
+ from typing import Any, Optional
13
+
14
+
15
+ class MessageType(str, Enum):
16
+ """Ten protocol messages (Section 7.2)."""
17
+ CHANGESET_ADMITTED = "M1" # AetherFlow → AetherProof
18
+ VERIFICATION_REQUEST = "M2" # AetherFlow → AetherProof
19
+ VERIFICATION_RESULT = "M3" # AetherProof → AetherFlow
20
+ COUNTEREXAMPLE_FOUND = "M4" # AetherProof → AetherFlow
21
+ REMEDIATION_PATCH = "M5" # AetherProof → AetherFlow
22
+ ESCALATION = "M6" # AetherProof → AetherFlow
23
+ EVIDENCE_QUERY = "M7" # AetherFlow → AetherProof
24
+ EVIDENCE_RESPONSE = "M8" # AetherProof → AetherFlow
25
+ HEALTH_CHECK = "M9" # Both
26
+ VERSION_NEGOTIATION = "M10" # Both
27
+
28
+
29
+ @dataclass
30
+ class Envelope:
31
+ """Message envelope (Section 4.1)."""
32
+ version: str
33
+ message_id: str
34
+ timestamp: float
35
+ source: str
36
+ destination: str
37
+ payload: dict
38
+
39
+
40
+ @dataclass
41
+ class Message:
42
+ """A protocol message."""
43
+ message_type: MessageType
44
+ payload: dict
45
+ source: str = "aetherproof"
46
+ destination: str = "aetherflow"
47
+ protocol_version: str = "1.0.0"
48
+
49
+ def to_envelope(self) -> Envelope:
50
+ """Convert to envelope."""
51
+ return Envelope(
52
+ version=self.protocol_version,
53
+ message_id=f"msg-{time.time_ns()}",
54
+ timestamp=time.time(),
55
+ source=self.source,
56
+ destination=self.destination,
57
+ payload={
58
+ "type": self.message_type.value,
59
+ **self.payload,
60
+ },
61
+ )
62
+
63
+
64
+ __all__ = ["Message", "MessageType", "Envelope"]
@@ -0,0 +1,7 @@
1
+ """Counterexample-guided remediation."""
2
+
3
+ from aetherproof.remediation.diagnosis import diagnose
4
+ from aetherproof.remediation.guardrails import check_guardrails, ViolationType
5
+ from aetherproof.remediation.cycle import RemediationCycle
6
+
7
+ __all__ = ["diagnose", "check_guardrails", "ViolationType", "RemediationCycle"]
@@ -0,0 +1,107 @@
1
+ """
2
+ Remediation Cycle — Section 6.2 implementation.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass, field
8
+
9
+ from aetherproof.models import Counterexample
10
+ from aetherproof.remediation.diagnosis import diagnose
11
+ from aetherproof.remediation.guardrails import check_guardrails, Patch
12
+
13
+
14
+ @dataclass
15
+ class RemediationCycle:
16
+ """
17
+ Bounded remediation cycle (Section 6.2).
18
+
19
+ Six stages:
20
+ 1. Counterexample detected
21
+ 2. Diagnosis
22
+ 3. Hypothesis
23
+ 4. Patch proposal
24
+ 5. Re-verify
25
+ 6. Accept/reject
26
+ """
27
+ max_iterations: int = 3
28
+ iteration: int = 0
29
+ history: list[dict] = field(default_factory=list)
30
+
31
+ def run(
32
+ self,
33
+ counterexample: Counterexample,
34
+ patch_proposer,
35
+ re_verifier,
36
+ ) -> dict:
37
+ """
38
+ Run the remediation cycle.
39
+
40
+ Parameters
41
+ ----------
42
+ counterexample : Counterexample
43
+ The counterexample to remediate.
44
+ patch_proposer : callable
45
+ Function that proposes patches.
46
+ re_verifier : callable
47
+ Function that re-verifies patches.
48
+
49
+ Returns
50
+ -------
51
+ dict
52
+ Cycle result with status.
53
+ """
54
+ while self.iteration < self.max_iterations:
55
+ self.iteration += 1
56
+
57
+ # Stage 1-2: Diagnose
58
+ diagnosed = diagnose(counterexample)
59
+
60
+ # Stage 3: Hypothesis (what to fix)
61
+ # Stage 4: Patch proposal
62
+ patch = patch_proposer(diagnosed)
63
+
64
+ if patch is None:
65
+ return {
66
+ "status": "escalated",
67
+ "reason": "No patch proposed",
68
+ "iterations": self.iteration,
69
+ }
70
+
71
+ # Stage 5: Check guardrails
72
+ violations = check_guardrails(patch)
73
+ if violations:
74
+ self.history.append({
75
+ "iteration": self.iteration,
76
+ "violations": [v.value for v in violations],
77
+ })
78
+ return {
79
+ "status": "rejected",
80
+ "reason": "Guardrail violation",
81
+ "violations": [v.value for v in violations],
82
+ "iterations": self.iteration,
83
+ }
84
+
85
+ # Stage 5: Re-verify
86
+ result = re_verifier(patch)
87
+
88
+ if result.get("verified"):
89
+ return {
90
+ "status": "accepted",
91
+ "patch": patch,
92
+ "iterations": self.iteration,
93
+ }
94
+
95
+ self.history.append({
96
+ "iteration": self.iteration,
97
+ "result": result,
98
+ })
99
+
100
+ return {
101
+ "status": "escalated",
102
+ "reason": "Iteration bound reached",
103
+ "iterations": self.iteration,
104
+ }
105
+
106
+
107
+ __all__ = ["RemediationCycle"]
@@ -0,0 +1,56 @@
1
+ """
2
+ Diagnosis Protocol — Section 6.3 implementation.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from aetherproof.models import Counterexample, CounterexampleType
8
+
9
+
10
+ def diagnose(
11
+ counterexample: Counterexample,
12
+ is_reproducible: bool = True,
13
+ refutes_assumption: bool = False,
14
+ is_valid_model: bool = True,
15
+ refutes_specification: bool = False,
16
+ ) -> Counterexample:
17
+ """
18
+ Diagnose a counterexample.
19
+
20
+ Implements the decision tree from Section 6.3.
21
+ """
22
+ if not is_reproducible:
23
+ return _update_type(counterexample, CounterexampleType.FLAKY_REFUTATION)
24
+
25
+ if refutes_assumption:
26
+ return _update_type(
27
+ counterexample, CounterexampleType.ASSUMPTION_VIOLATION
28
+ )
29
+
30
+ if is_valid_model:
31
+ if refutes_specification:
32
+ return _update_type(
33
+ counterexample, CounterexampleType.SPECIFICATION_ERROR
34
+ )
35
+ else:
36
+ return _update_type(counterexample, CounterexampleType.CODE_DEFECT)
37
+ else:
38
+ return _update_type(counterexample, CounterexampleType.MODEL_ERROR)
39
+
40
+
41
+ def _update_type(
42
+ counterexample: Counterexample,
43
+ new_type: CounterexampleType,
44
+ ) -> Counterexample:
45
+ """Return a new counterexample with updated type."""
46
+ return Counterexample(
47
+ id=counterexample.id,
48
+ obligation=counterexample.obligation,
49
+ witness=counterexample.witness,
50
+ refutation_evidence=counterexample.refutation_evidence,
51
+ type=new_type,
52
+ provenance=counterexample.provenance,
53
+ )
54
+
55
+
56
+ __all__ = ["diagnose"]
@@ -0,0 +1,59 @@
1
+ """
2
+ Guardrails — Section 6.5 implementation.
3
+
4
+ Five guardrails against specification gaming.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass
10
+ from enum import Enum
11
+
12
+
13
+ class ViolationType(str, Enum):
14
+ """Guardrail violation types (Section 6.5)."""
15
+ TEST_DELETED = "test_deleted"
16
+ TEST_DISABLED = "test_disabled"
17
+ TOLERANCE_WIDENED = "tolerance_widened"
18
+ OUTSIDE_BLAST_RADIUS = "outside_blast_radius"
19
+ SPECIFICATION_WEAKENED = "specification_weakened"
20
+
21
+
22
+ @dataclass
23
+ class Patch:
24
+ """A proposed remediation patch."""
25
+ files_changed: set[str]
26
+ deleted_tests: set[str]
27
+ disabled_tests: set[str]
28
+ widened_assertions: list[str]
29
+ blast_radius: set[str]
30
+ weakens_specification: bool = False
31
+
32
+
33
+ def check_guardrails(patch: Patch) -> list[ViolationType]:
34
+ """
35
+ Check a patch against the five guardrails.
36
+
37
+ Returns a list of violations (empty if patch passes).
38
+ """
39
+ violations = []
40
+
41
+ if patch.deleted_tests:
42
+ violations.append(ViolationType.TEST_DELETED)
43
+
44
+ if patch.disabled_tests:
45
+ violations.append(ViolationType.TEST_DISABLED)
46
+
47
+ if patch.widened_assertions:
48
+ violations.append(ViolationType.TOLERANCE_WIDENED)
49
+
50
+ if not patch.files_changed.issubset(patch.blast_radius):
51
+ violations.append(ViolationType.OUTSIDE_BLAST_RADIUS)
52
+
53
+ if patch.weakens_specification:
54
+ violations.append(ViolationType.SPECIFICATION_WEAKENED)
55
+
56
+ return violations
57
+
58
+
59
+ __all__ = ["check_guardrails", "ViolationType", "Patch"]
@@ -0,0 +1,5 @@
1
+ """Human review protocol."""
2
+
3
+ from aetherproof.review.roles import Role, Authority
4
+
5
+ __all__ = ["Role", "Authority"]
@@ -0,0 +1,86 @@
1
+ """
2
+ Human Review Roles — Section 8.1 implementation.
3
+
4
+ Five roles with separation of duties.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from enum import Enum
10
+
11
+
12
+ class Role(str, Enum):
13
+ """Five human review roles (Section 8.1)."""
14
+ SPECIFICATION_AUTHOR = "specification_author"
15
+ VERIFICATION_ENGINEER = "verification_engineer"
16
+ REVIEWER = "reviewer"
17
+ MAINTAINER = "maintainer"
18
+ AUDITOR = "auditor"
19
+
20
+
21
+ class Authority(str, Enum):
22
+ """Authority levels (Section 8.1)."""
23
+ YES = "yes"
24
+ ESCALATE = "escalate"
25
+ NO = "no"
26
+
27
+
28
+ # Authority matrix (Section 8.1)
29
+ AUTHORITY_MATRIX: dict[tuple[str, Role], Authority] = {
30
+ ("write_spec", Role.SPECIFICATION_AUTHOR): Authority.YES,
31
+ ("write_spec", Role.VERIFICATION_ENGINEER): Authority.NO,
32
+ ("write_spec", Role.REVIEWER): Authority.NO,
33
+ ("write_spec", Role.MAINTAINER): Authority.NO,
34
+ ("write_spec", Role.AUDITOR): Authority.NO,
35
+
36
+ ("revise_spec_minor", Role.SPECIFICATION_AUTHOR): Authority.YES,
37
+ ("revise_spec_minor", Role.VERIFICATION_ENGINEER): Authority.NO,
38
+ ("revise_spec_minor", Role.REVIEWER): Authority.YES,
39
+ ("revise_spec_minor", Role.MAINTAINER): Authority.NO,
40
+ ("revise_spec_minor", Role.AUDITOR): Authority.NO,
41
+
42
+ ("revise_spec_major", Role.SPECIFICATION_AUTHOR): Authority.YES,
43
+ ("revise_spec_major", Role.VERIFICATION_ENGINEER): Authority.NO,
44
+ ("revise_spec_major", Role.REVIEWER): Authority.ESCALATE,
45
+ ("revise_spec_major", Role.MAINTAINER): Authority.YES,
46
+ ("revise_spec_major", Role.AUDITOR): Authority.NO,
47
+
48
+ ("discharge_obligation", Role.SPECIFICATION_AUTHOR): Authority.NO,
49
+ ("discharge_obligation", Role.VERIFICATION_ENGINEER): Authority.YES,
50
+ ("discharge_obligation", Role.REVIEWER): Authority.NO,
51
+ ("discharge_obligation", Role.MAINTAINER): Authority.NO,
52
+ ("discharge_obligation", Role.AUDITOR): Authority.NO,
53
+
54
+ ("accept_remediation_code", Role.SPECIFICATION_AUTHOR): Authority.NO,
55
+ ("accept_remediation_code", Role.VERIFICATION_ENGINEER): Authority.YES,
56
+ ("accept_remediation_code", Role.REVIEWER): Authority.YES,
57
+ ("accept_remediation_code", Role.MAINTAINER): Authority.NO,
58
+ ("accept_remediation_code", Role.AUDITOR): Authority.NO,
59
+
60
+ ("accept_remediation_spec", Role.SPECIFICATION_AUTHOR): Authority.NO,
61
+ ("accept_remediation_spec", Role.VERIFICATION_ENGINEER): Authority.NO,
62
+ ("accept_remediation_spec", Role.REVIEWER): Authority.ESCALATE,
63
+ ("accept_remediation_spec", Role.MAINTAINER): Authority.YES,
64
+ ("accept_remediation_spec", Role.AUDITOR): Authority.NO,
65
+
66
+ ("escalate_to_human", Role.SPECIFICATION_AUTHOR): Authority.NO,
67
+ ("escalate_to_human", Role.VERIFICATION_ENGINEER): Authority.YES,
68
+ ("escalate_to_human", Role.REVIEWER): Authority.YES,
69
+ ("escalate_to_human", Role.MAINTAINER): Authority.NO,
70
+ ("escalate_to_human", Role.AUDITOR): Authority.YES,
71
+
72
+ ("merge_changes", Role.SPECIFICATION_AUTHOR): Authority.NO,
73
+ ("merge_changes", Role.VERIFICATION_ENGINEER): Authority.NO,
74
+ ("merge_changes", Role.REVIEWER): Authority.NO,
75
+ ("merge_changes", Role.MAINTAINER): Authority.YES,
76
+ ("merge_changes", Role.AUDITOR): Authority.NO,
77
+
78
+ ("question_evidence", Role.SPECIFICATION_AUTHOR): Authority.NO,
79
+ ("question_evidence", Role.VERIFICATION_ENGINEER): Authority.NO,
80
+ ("question_evidence", Role.REVIEWER): Authority.NO,
81
+ ("question_evidence", Role.MAINTAINER): Authority.NO,
82
+ ("question_evidence", Role.AUDITOR): Authority.YES,
83
+ }
84
+
85
+
86
+ __all__ = ["Role", "Authority", "AUTHORITY_MATRIX"]