Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/formal_certificates.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ When a certificate includes `external_replay_artifact`, `external_replay`, `exte

## Formal Surface

Lean models a simplified certificate-validity predicate and small true lemmas. The executable Python/Rust validators are the release enforcement path; Lean artifacts define reviewable kernels rather than whole-repository proofs.
Lean models a simplified certificate-validity predicate, a replay-boundary acceptance predicate, and small true lemmas. The replay kernel states that an accepted candidate preserves reported/recomputed energy equality and hash identity under a declared context. The executable Python/Rust validators are the release enforcement path; Lean artifacts define reviewable kernels rather than whole-repository proofs.
1 change: 1 addition & 0 deletions formal/lean/Noetheris.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import Noetheris.StructuralIR
import Noetheris.QuboEnergy
import Noetheris.MigrationPolicy
import Noetheris.CircuitOracle
import Noetheris.ReplayBoundary
71 changes: 71 additions & 0 deletions formal/lean/Noetheris/ReplayBoundary.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Noetheris.Basic

namespace Noetheris

structure ReplayContext where
expectedProblemHash : String
expectedCompiledModelHash : String
deriving Repr, DecidableEq

structure ReplayCandidate where
submittedProblemHash : String
submittedCompiledModelHash : String
reportedEnergy : Energy
recomputedEnergy : Energy
assignmentComplete : Bool
metadataWellFormed : Bool
deriving Repr, DecidableEq

def HashIdentityHolds (context : ReplayContext) (candidate : ReplayCandidate) : Prop :=
candidate.submittedProblemHash = context.expectedProblemHash ∧
candidate.submittedCompiledModelHash = context.expectedCompiledModelHash

def EnergyAgreementHolds (candidate : ReplayCandidate) : Prop :=
candidate.reportedEnergy = candidate.recomputedEnergy

def ReplayAccepted (context : ReplayContext) (candidate : ReplayCandidate) : Prop :=
HashIdentityHolds context candidate ∧
EnergyAgreementHolds candidate ∧
candidate.assignmentComplete = true ∧
candidate.metadataWellFormed = true

theorem accepted_candidate_preserves_energy_agreement
(context : ReplayContext)
(candidate : ReplayCandidate)
(hAccepted : ReplayAccepted context candidate) :
candidate.reportedEnergy = candidate.recomputedEnergy := by
exact hAccepted.right.left

theorem accepted_candidate_matches_problem_hash
(context : ReplayContext)
(candidate : ReplayCandidate)
(hAccepted : ReplayAccepted context candidate) :
candidate.submittedProblemHash = context.expectedProblemHash := by
exact hAccepted.left.left

theorem accepted_candidate_has_complete_assignment
(context : ReplayContext)
(candidate : ReplayCandidate)
(hAccepted : ReplayAccepted context candidate) :
candidate.assignmentComplete = true := by
exact hAccepted.right.right.left

def replayContextExample : ReplayContext :=
{
expectedProblemHash := "sha256:problem",
expectedCompiledModelHash := "sha256:compiled"
}

def acceptedReplayCandidateExample : ReplayCandidate :=
{
submittedProblemHash := "sha256:problem",
submittedCompiledModelHash := "sha256:compiled",
reportedEnergy := 10,
recomputedEnergy := 10,
assignmentComplete := true,
metadataWellFormed := true
}

#eval acceptedReplayCandidateExample.reportedEnergy

end Noetheris
3 changes: 3 additions & 0 deletions formal/lean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Included modules:
- `QuboEnergy.lean`: binary assignments and QUBO energy evaluation.
- `MigrationPolicy.lean`: simple policy predicates for asset migration choices.
- `CircuitOracle.lean`: finite truth-table semantics for Boolean oracle evaluation.
- `ReplayBoundary.lean`: simplified replay acceptance over hashes, assignment completeness, metadata well-formedness, and reported/recomputed energy equality.

`ReplayBoundary.lean` is a small formal kernel for the external-candidate replay boundary. It proves local lemmas about the simplified predicate only; it is not an end-to-end proof of the Python or Rust implementation.

Build with:

Expand Down
3 changes: 2 additions & 1 deletion formal/tla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ The TLA+ files model small safety surfaces used by Noetheris examples.
- `threshold_policy.tla` models authorization threshold, whitelist, and time-window safety.
- `pq_migration_policy.tla` models migration dependency ordering.
- `saga_failure_semantics.tla` models terminal consistency for a small compensating-transaction flow.
- `external_candidate_replay.tla` models the submitted, verified, and rejected states for a single external solver candidate under hash, energy, assignment-domain, and metadata checks.

They are compact specifications intended for review and later bounded model-checking harnesses.
They are compact specifications intended for review and bounded model-checking harnesses. The replay specification is scoped to a single candidate and does not assert correctness of the full executable implementation.
88 changes: 88 additions & 0 deletions formal/tla/external_candidate_replay.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---- MODULE external_candidate_replay ----
EXTENDS FiniteSets

CONSTANTS
ExpectedProblemHash,
ExpectedCompiledModelHash,
SubmittedProblemHash,
SubmittedCompiledModelHash,
ReportedEnergy,
RecomputedEnergy,
AssignmentComplete,
MetadataWellFormed

VARIABLES state, reasons

Init ==
/\ state = "submitted"
/\ reasons = {}

HashIdentityHolds ==
/\ SubmittedProblemHash = ExpectedProblemHash
/\ SubmittedCompiledModelHash = ExpectedCompiledModelHash

EnergyAgreementHolds ==
ReportedEnergy = RecomputedEnergy

CandidateWellFormed ==
/\ AssignmentComplete
/\ MetadataWellFormed

Verify ==
/\ state = "submitted"
/\ HashIdentityHolds
/\ EnergyAgreementHolds
/\ CandidateWellFormed
/\ state' = "verified"
/\ reasons' = {}

RejectHash ==
/\ state = "submitted"
/\ ~HashIdentityHolds
/\ state' = "rejected"
/\ reasons' = reasons \cup {"hash_mismatch"}

RejectEnergy ==
/\ state = "submitted"
/\ HashIdentityHolds
/\ ~EnergyAgreementHolds
/\ state' = "rejected"
/\ reasons' = reasons \cup {"energy_mismatch"}

RejectDomain ==
/\ state = "submitted"
/\ HashIdentityHolds
/\ EnergyAgreementHolds
/\ ~AssignmentComplete
/\ state' = "rejected"
/\ reasons' = reasons \cup {"assignment_incomplete"}

RejectMetadata ==
/\ state = "submitted"
/\ HashIdentityHolds
/\ EnergyAgreementHolds
/\ AssignmentComplete
/\ ~MetadataWellFormed
/\ state' = "rejected"
/\ reasons' = reasons \cup {"metadata_malformed"}

Next ==
\/ Verify
\/ RejectHash
\/ RejectEnergy
\/ RejectDomain
\/ RejectMetadata

StatusDomain ==
state \in {"submitted", "verified", "rejected"}

VerifiedImpliesEnergyAgreement ==
state = "verified" => EnergyAgreementHolds

VerifiedImpliesHashIdentity ==
state = "verified" => HashIdentityHolds

Spec ==
Init /\ [][Next]_<<state, reasons>>

====