agentleFS
rainoftimerainoftime/pl-skills/hoare-logic-verifier/SKILL.md

hoare-logic-verifier

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Verifies programs using Hoare logic. Use when: (1) Proving program correctness,

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 10 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Start with simple programs, add complexity

    line 61
  2. Distinctive:

    Always verify loop invariants manually first

    line 62
  3. Distinctive:

    Use consequences to strengthen/weaken

    line 63
  4. Distinctive:

    Consider using SMT solvers for complex conditions

    line 64
  5. Distinctive:

    For concurrent programs: Use concurrent separation logic

    line 118
  6. Distinctive:

    For pointer-heavy code: Use separation logic instead

    line 119
  7. Distinctive:

    For automated verification: Consider model checking

    line 120
  8. Distinctive:

    For large codebases: Consider symbolic execution + testing

    line 121
  9. Distinctive:

    Loop invariants: Must be provided manually (undecidable to find)

    line 131
  10. Distinctive:

    Goal: Verify concurrent programs

    line 178

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Hoare Logic Verifier

Verifies program correctness using Floyd-Hoare logic.

When to Use

  • Proving program correctness
  • Developing verified software
  • Verifying loop invariants
  • Static verification

What This Skill Does

  1. Specifies contracts - Pre/postconditions and loop invariants
  2. Generates verification conditions - Formulas to prove
  3. Checks soundness - Proves VCs are valid
  4. Handles loops - Invariant inference

Key Concepts

ConceptDescription
PreconditionState before execution
PostconditionState after execution
InvariantTrue before/after each loop iteration
Weakest preconditionMinimal condition ensuring postcondition
Verification conditionFormula to prove for correctness

Verification Condition Generation

{P} while b do c {Q}

VCs:
1. P ⇒ I                    (initiation)
2. I ∧ b ⇒ wp(c, I)         (preservation)  
3. I ∧ ¬b ⇒ Q               (usefulness)

Tips

  • Start with simple programs, add complexity
  • Always verify loop invariants manually first
  • Use consequences to strengthen/weaken
  • Consider using SMT solvers for complex conditions
  • Handle division carefully (non-zero)

Common Patterns

Swap

{ x = a ∧ y = b }
t := x;
x := y;
y := t;
{ x = b ∧ y = a }

Linear Search

{ ∃i. A[i] = k ∧ 0 ≤ i < n }
i := 0;
while i < n do
    if A[i] = k then break;
    i := i + 1
{ (i < n ⇒ A[i] = k) ∧ (i = n ⇒ ∀j. 0≤j<n ⇒ A[j] ≠ k) }

Related Skills

  • separation-logician - Heap verification
  • invariant-generator - Automatic invariant inference
  • loop-termination-prover - Prove termination

Canonical References

ReferenceWhy It Matters
Hoare, "An Axiomatic Basis for Computer Programming" (CACM 1969)Original Hoare logic paper (Turing Award)
Apt & Olderog, "Verification of Programs" (1981)Comprehensive survey
Floyd, "Assigning Meanings to Programs" (1967)Predecessor to Hoare logic
Nielson & Nielson, "Hoare Logic" (1999)Formal treatment
Gupta et al., "A Practical Guide to Design of C Programs" (1991)Verifiable C coding

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
Standard HoareSimple, intuitiveCan't handle heap/pointers
Separation LogicHandles pointers, heapMore complex
Dynamic LogicLoops as formulasHarder to use

When NOT to Use Hoare Logic

  • For concurrent programs: Use concurrent separation logic
  • For pointer-heavy code: Use separation logic instead
  • For automated verification: Consider model checking
  • For large codebases: Consider symbolic execution + testing

Complexity Considerations

  • VC generation: O(n) in program size
  • SMT solving: Expensive for complex formulas; undecidable in general
  • Invariant inference: NP-hard in general

Limitations

  • Loop invariants: Must be provided manually (undecidable to find)
  • Frame problem: Hard to specify what doesn't change; use separation logic
  • Partial correctness: Standard Hoare logic proves partial correctness (no termination)
  • Scalability: Manual proof effort grows with program size
  • Concurrency: Requires extensions (concurrent separation logic)

Research Tools & Artifacts

Verification tools based on Hoare logic:

ToolLanguageWhat to Learn
DafnyC#/BoogieVerified programs
Verifiable C (VST)CoqC verification
Frama-CCStatic analysis
Why3Why3Verification platform
ESC/JavaJavaExtended Static Checking
Spec#C#Contract-based verification

Interactive Theorem Provers

  • Coq - Proof assistant, VST for C
  • Isabelle/HOL - General purpose
  • Lean - Functional verification
  • Agda - Dependent types

Research Frontiers

1. Verification Condition Generation

  • Goal: Automate proof effort
  • Approach: Generate VCs, discharge with SMT
  • Papers: "VCGen for Dummies" (various)
  • Tools: Boogie, Why3

2. Loop Invariant Inference

  • Goal: Automatically find invariants
  • Approach: Abstract interpretation, learning
  • Papers: "Invariant Generation" (Sankaranarayanan)
  • Tools: Abstract interpretation tools

3. Separation Logic

  • Goal: Handle heap and pointers
  • Approach: Local reasoning, frame rule
  • Papers: "Separation Logic" (O'Hearn, Reynolds)
  • Tools: Verifiable C, Smallfoot

4. Concurrent Verification

  • Goal: Verify concurrent programs
  • Approach: Concurrent separation logic
  • Papers: "Concurrent Separation Logic" (O'Hearn)
  • Tools: Verifast, Grain

Implementation Pitfalls

PitfallReal ConsequenceSolution
Wrong invariantUnsound proofVerify each VC
Missing framesIncomplete specsUse separation logic
Division by zeroRuntime errorsAdd precondition
OverflowUnsoundnessUse bounded integers

The "Loop Invariant" Challenge

Finding invariants is undecidable:

# What invariant proves this?
i = 0
sum = 0
while i < n:
    sum = sum + i
    i = i + 1

# Answer: sum = i*(i-1)/2

# Another valid invariant: 0 <= i <= n AND sum >= 0
# But this is too weak to prove final result!

This is why verification requires human insight!

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.