formal-verification
Skill15 starsChanged 6 days agoMITView on GitHub
Guides selective, cost-aware formal verification using Dafny (with clear boundaries for TLA+/Quint and cheaper testing layers). Enforces an authoring gate, production integration modes to prevent model-code drift, anti-vacuity/anti-cheating soundness checks via scripts/verify-dafny.sh, and real-world state-machine proof patterns. Use when writing, auditing, or debugging .dfy specifications and proofs, or when formally verifying high-blast-radius invariants, financial/ledger rules, authorization logic, or state machines.
12 other projects use a version of this.
Adopted by
Most recently taken up by
- endqwerty/endstacktheir own version, first seen Nov 29, 2026
- fcsouza/agent-skillstheir own version, first seen Nov 29, 2026
- alibaba-damo-academy/ScholarSeedtheir own version, first seen Nov 29, 2026
- mohitmishra786/low-level-dev-skillstheir own version, first seen Nov 29, 2026
- Hakkadaikon/hymmetheir own version, first seen Nov 21, 2026
- alexderz/agentic-toolboxtheir own version, first seen Nov 16, 2026
Other versions12 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 12
- mohitmishra786/low-level-dev-skills★ 303same name
- marmot-protocol/mdk★ 76same name
- alibaba-damo-academy/ScholarSeed★ 51same name
- fcsouza/agent-skills★ 29same name
- alexderz/agentic-toolbox★ 5same name
- Geruyang/skills★ 2same name
- shengyy/agent-skills★ 2same name
- yuri-xyz/skills★ 2same name
- endqwerty/endstack★ 1same name
- Hakkadaikon/hymme★ 0same name
2 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- agent-instruction-auditSkill
- agent-tool-auditSkill
- changes-verificationSkill
- cheap-ui-auditSkill
- code-reviewSkill
- create-prSkill
- debuggingSkill
- engineering-decisionSkill
- micro-animationSkill
- optimistic-uiSkill
- optimize-ciSkill
- oxlint-setupSkill
- test-auditSkill
- zstack-modeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 0 are common, 6 are distinctive, and 11 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Test everything critical, and formally verify only the small, high-blast-radius core where a single missed edge case would cause …
- Very specific: line 31
Before creating a .dfy file or proving a property, answer all four questions:
- Distinctive: line 33
Blast radius: If this property were false in production, what is the worst real damage?
- Very specific: line 40
Never leave a standalone model in dafny/ disconnected from production code.
- Distinctive: line 44
Mode C — Design-Time Spec + Runtime Guards: Verify a tricky state machine or protocol upfront, document trusted assumptions (e.g., via an …
- Very specific: line 48
Read references/dafny-patterns.md for complete Dafny 4 templates.
- Very specific: line 50
Spec first, body second: Write requires and ensures (and Valid invariants) in plain words first, then in Dafny, before implementing the …
- Very specific: line 55
Separate ghost specs from compiled code (Dafny 4 syntax): Use ghost function / ghost predicate to define meaning (erased at compile time, …
- Very specific: line 57
Loops need invariants and termination: Every loop needs an invariant true before entry, preserved on every pass, and strong enough that …
- Distinctive: line 58
Prove one property at a time: Start with the single highest-risk safety or conservation invariant.
- Very specific: line 64
Zero unsound shortcuts: Never add assume, {:axiom}, {:verify false}, {:only} / @VerifyOnly, or bodyless lemmas/methods to silence the …
- Very specific: line 65
Never game the contract: Never weaken ensures to match buggy code, and never over-strengthen requires to exclude valid production callers.
- Very specific: line 66
Include a witness lemma: Write a concrete lemma calling the verified function/method with realistic concrete inputs and asserting the …
- Distinctive: line 67
Falsification sanity check: Ask *"Could a wrong implementation still satisfy this spec?"* Verify (mentally or via a temporary mutation) …
- Distinctive: line 74
State the property first: Write the target safety, correctness, or conservation property in plain language before writing Dafny.
- Very specific: line 75
Model and prove incrementally: Follow references/dafny-patterns.md (prefer immutable datatype + state-machine invariants + witness lemmas).
- Very specific: line 76
Debug failures systematically: If verification fails or times out, read references/proof-debugging.md to classify whether it is an …
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Formal Verification
Test everything critical, and formally verify only the small, high-blast-radius core where a single missed edge case would cause irreversible damage. Keep proofs sound, non-vacuous, and tightly coupled to production code.
Assurance Escalation Ladder (When to Use — and When Not To)
Formal proofs have real maintenance cost: every code change requires updating proofs. Always reach for the cheapest layer that can enforce the guarantee:
- Types & schema constraints: Make illegal states unrepresentable (exhaustive unions, branded types, DB constraints). Cheapest; zero proof upkeep.
- Targeted unit & integration tests: Cover known edge cases, regressions, and boundary contracts.
- Property-based testing / fuzzing: Explore thousands of randomized or adversarial inputs and state sequences cheaply.
- Formal verification (Dafny / model checking): Mathematical proof across all reachable inputs or states—reserve for invariants where "it passed tests" is still unacceptable.
Good Candidates vs. Skip
- Verify: Financial/ledger arithmetic and conservation rules, authorization/isolation policies, locking/escrow/idempotency state machines, cryptographic/encoding boundaries, and small shared core algorithms many subsystems depend on.
- Skip: UI components, CRUD/glue code, external API wrappers, prototypes, and volatile product logic that changes weekly.
Tool Boundaries (Dafny-First)
- Use Dafny (default) for sequential state machines, domain invariants, ledger/conservation rules, permissions, bounds/overflow safety, parsers, and pure algorithms (compiles to JS/TS, Go, Python, C#, Java).
- Use TLA+ or Quint instead of Dafny for interleaved concurrency, distributed consensus, async race conditions, retry/timeout protocols, and liveness ("eventually succeeds") properties.
Authoring Gate (Mandatory Before Writing Any Spec)
Before creating a .dfy file or proving a property, answer all four questions:
- Blast radius: If this property were false in production, what is the worst real damage? (If the answer is not money loss, data corruption, security/isolation bypass, deadlock, or silent invariant violation, stop and use types or tests.)
- Why cheaper layers miss it: Why can't static types, unit tests, or property-based tests provide sufficient confidence?
- Pure core isolatability: Can the logic be isolated into a small, stable, I/O-free kernel with zero framework dependencies?
- Production bridge: Which integration mode below prevents the verified model from silently drifting away from production code?
Production Integration Modes (Closing the Model–Code Gap)
Never leave a standalone model in dafny/ disconnected from production code. Choose one explicit bridge before writing the spec:
- Mode A — Compiled Verified Core (Zero Drift): Compile the verified Dafny module directly (
dafny build/dafny translate) into the target runtime (js,go,py,cs,java) and import it as the pure domain kernel. Best for small, self-contained rules. - Mode B — Executable Oracle (Differential Testing): Compile the Dafny model as a test oracle and run property-based or fuzz tests asserting that the production implementation matches the verified model across randomized inputs and multi-step state sequences.
- Mode C — Design-Time Spec + Runtime Guards: Verify a tricky state machine or protocol upfront, document trusted assumptions (e.g., via an ADR), and mirror the critical preconditions and invariants as runtime assertions in production code.
Core Specification & Proof Rules
Read references/dafny-patterns.md for complete Dafny 4 templates. Follow these principles on every proof:
- Spec first, body second: Write
requiresandensures(andValidinvariants) in plain words first, then in Dafny, before implementing the body. - Contract ownership:
requiresis the caller's obligation;ensuresis the callee's promise. If a call fails to verify, check whether the caller violated arequiresbefore touching the callee. - Modular verification: Dafny checks each method using only the contracts (
requires/ensures) of called methods, never their bodies. If a downstream fact matters, state it in anensuresorinvariant. - Prefer a pure functional core: Model state with immutable
datatype,map,seq, and purefunction/predicate. Avoid mutable classes/arrays (reads/modifiesframing) unless in-place mutation itself is what you are proving. - Use the state-machine inductive pattern: For real-world systems, define
State,ghost predicate Valid(s),Init(provesValid(s0)), andStep(s, action)(preservesValid(s) ==> Valid(s')plus two-state safety/conservation properties likeTotal(s') == Total(s)). - Separate ghost specs from compiled code (Dafny 4 syntax): Use
ghost function/ghost predicateto define meaning (erased at compile time, zero runtime cost) and compiledfunction/methodfor fast execution; prove the implementation matches the ghost spec. - Model real numeric bounds: Dafny
intis unbounded. If production usesint64,uint64, floats, or minor units (cents/bps), explicitly enforce bounds (newtypeor0 <= x <= MAX) so overflow and rounding bugs cannot slip past the proof. - Loops need invariants and termination: Every loop needs an
invarianttrue before entry, preserved on every pass, and strong enough thatinvariant && !guard ==> ensures. Always include index bounds (0 <= i <= n) and adddecreaseswhen Dafny cannot infer termination. - Prove one property at a time: Start with the single highest-risk safety or conservation invariant; add the next only after the first verifies cleanly.
Anti-Cheating & Anti-Vacuity Gate (Mandatory Before Claiming Verified)
A passing dafny verify proves nothing if the proof cheats or is vacuous. Every verified module MUST satisfy all four rules:
- Zero unsound shortcuts: Never add
assume,{:axiom},{:verify false},{:only}/@VerifyOnly, or bodyless lemmas/methods to silence the verifier. ({:extern}is allowed only at an explicit FFI boundary and must be documented.) - Never game the contract: Never weaken
ensuresto match buggy code, and never over-strengthenrequiresto exclude valid production callers. Fix the code or fix an objectively wrong spec. - Include a witness lemma: Write a concrete
lemmacalling the verified function/method with realistic concrete inputs and asserting the concrete expected output. This provesrequiresis satisfiable (not contradictory) andensuresactually constrains the result. - Falsification sanity check: Ask "Could a wrong implementation still satisfy this spec?" Verify (mentally or via a temporary mutation) that removing a critical check or returning a bogus value causes verification to fail.
Execution Workflow
Resolve <skill-dir> to the directory containing this SKILL.md.
- Pass the Authoring Gate: Confirm blast radius, escalation ladder, pure core boundary, and Production Integration Mode (A, B, or C).
- State the property first: Write the target safety, correctness, or conservation property in plain language before writing Dafny.
- Model and prove incrementally: Follow
references/dafny-patterns.md(prefer immutabledatatype+ state-machine invariants + witness lemmas). Keep verification files isolated under a dedicated directory (e.g.,verification/ordafny/). - Debug failures systematically: If verification fails or times out, read
references/proof-debugging.mdto classify whether it is an implementation bug, wrong spec, missing hint/invariant, or Z3 resource/trigger issue. Never addassumeto move past a failure. - Run the soundness & verification gate:
This runsbash <skill-dir>/scripts/verify-dafny.sh <path-to-dfy-dir-or-files>dafny audit(enforcing 0 findings—notedafny auditexits0even with findings!), scans for banned escapes (assume,{:axiom},{:verify false},{:only}), and runsdafny verify --warn-shadowing. - Connect and verify the bridge: Wire the chosen Production Integration Mode (compile target, run differential/PBT oracle tests, or verify runtime invariant guards) and confirm production tests pass.
Red Flags
- Writing Dafny proofs for UI, CRUD glue, or fast-changing prototype logic
- Adding
assume,{:axiom},{:verify false},{:only}, or bodyless lemmas to make a proof turn green - Weakening
ensuresor adding impossiblerequiresto silence a failing proof instead of fixing the bug - Leaving a standalone
dafny/model with no compilation, differential oracle, or runtime guard tying it to production code - Proving arithmetic on unbounded
intwhile production overflowsint64or rounds IEEE-754 floats - Using Dafny to model interleaved multi-threaded or distributed protocols where TLA+/Quint is required
- Running
dafny auditin CI without checking that findings equal0
Gotchas
dafny auditexits with status0even when it reports soundness findings; always enforce0 findingsviascripts/verify-dafny.sh.- In Dafny 4,
functionandpredicateare compiled by default; prefix specification-only helpers withghost function/ghost predicateso they carry zero runtime cost. - Mutable heap framing (
reads/modifies) is the #1 source of proof friction in Dafny—refactor into immutabledatatypestate transitions whenever mutation is not the property under test. - Wall-clock
--verification-time-limitvaries across machines; for stable CI, inspect assertion costs with--log-format textand pin--resource-limitviascripts/verify-dafny.sh --resource-limit <N>.
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
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.

