acsl-annotation-assistant
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Create ACSL (ANSI/ISO C Specification Language) formal annotations for
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- dsl-embeddingSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- garbage-collector-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- higher-order-abstract-syntaxSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- lexer-generatorSkill
- linear-type-implementerSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 30
Add complete function specifications with preconditions and postconditions:
- Distinctive: line 61
Add pointer validity and separation annotations:
- Distinctive: line 119
Start with the function-level specification:
- Distinctive: line 141
Create reusable logical definitions for:
- Distinctive: line 196
When generating annotations for WP verification:
- Very specific: line 197
Use assigns clauses to specify frame conditions
- Very specific: line 198
Prefer \valid over raw pointer checks
- Very specific: line 199
Use \separated for pointer disjointness
- Very specific: line 200
Add loop assigns for all loops
- Distinctive: line 229
Place contracts immediately before function declarations
- Distinctive: line 230
Place loop annotations immediately before loop headers
- Distinctive: line 236
Be precise: Avoid over-specification or under-specification
- Distinctive: line 239
Test incrementally: Verify annotations with Frama-C as you go
- Distinctive: line 240
Include rationale: Add comments explaining non-obvious specifications
≈ “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.
Files
ACSL Annotation Assistant
Generate comprehensive ACSL (ANSI/ISO C Specification Language) annotations for C/C++ programs to support formal verification with tools like Frama-C.
Core Capabilities
1. Function Contracts
Add complete function specifications with preconditions and postconditions:
/*@
requires \valid(array + (0..n-1));
requires n > 0;
ensures \result >= 0 && \result < n;
ensures \forall integer i; 0 <= i < n ==> array[\result] >= array[i];
assigns \nothing;
*/
int find_max_index(int *array, int n);2. Loop Annotations
Generate loop invariants, variants, and assigns clauses:
/*@
loop invariant 0 <= i <= n;
loop invariant \forall integer k; 0 <= k < i ==> sum == \sum(0, k, array);
loop assigns i, sum;
loop variant n - i;
*/
for (i = 0; i < n; i++) {
sum += array[i];
}3. Memory Safety Specifications
Add pointer validity and separation annotations:
/*@
requires \valid(dest + (0..n-1));
requires \valid_read(src + (0..n-1));
requires \separated(dest + (0..n-1), src + (0..n-1));
ensures \forall integer i; 0 <= i < n ==> dest[i] == \old(src[i]);
assigns dest[0..n-1];
*/
void memcpy_safe(char *dest, const char *src, size_t n);4. Assertions and Assumptions
Insert runtime and verification assertions:
//@ assert 0 <= index && index < array_length;
//@ assume divisor != 0;5. Axiomatic Definitions and Predicates
Define reusable logical predicates and axioms:
/*@
predicate sorted{L}(int *a, integer n) =
\forall integer i, j; 0 <= i <= j < n ==> a[i] <= a[j];
*/
/*@
axiomatic Sum {
logic integer sum{L}(int *a, integer low, integer high);
axiom sum_empty{L}:
\forall int *a, integer i; sum(a, i, i) == 0;
axiom sum_next{L}:
\forall int *a, integer low, high;
low < high ==> sum(a, low, high) == sum(a, low, high-1) + a[high-1];
}
*/Annotation Workflow
Step 1: Analyze the Function
Before annotating:
- Identify inputs, outputs, and side effects
- Determine memory access patterns
- Understand algorithmic properties (sorting, searching, etc.)
- Note any implicit assumptions
Step 2: Add Function Contract
Start with the function-level specification:
- Preconditions (
requires): What must be true when function is called - Postconditions (
ensures): What will be true when function returns - Assigns clause: What memory locations may be modified
- Behavioral specification: Normal and exceptional behaviors if applicable
Step 3: Annotate Loops
For each loop, specify:
- Loop invariant: Properties that hold before and after each iteration
- Loop variant: Decreasing measure proving termination
- Loop assigns: Memory modified within the loop
Step 4: Add Assertions
Insert intermediate assertions to:
- Document algorithmic properties
- Help verification tools
- Clarify complex logic
Step 5: Define Helper Predicates
Create reusable logical definitions for:
- Common patterns (sorted arrays, valid ranges)
- Domain-specific properties
- Complex mathematical relationships
Common ACSL Constructs
Memory Validity
\valid(ptr) // Single valid pointer
\valid(ptr + (low..high)) // Valid range
\valid_read(ptr) // Read-only validity
\separated(ptr1, ptr2) // No aliasingQuantifiers
\forall type var; condition ==> property
\exists type var; condition && propertyLogic Functions
\old(expr) // Value at function entry
\at(expr, Label) // Value at specific point
\result // Function return value
\nothing // Empty set (for assigns)Integer Ranges
\forall integer i; low <= i < high ==> array[i] >= 0Behaviors
/*@
behavior valid_input:
assumes n > 0;
requires \valid(array + (0..n-1));
ensures \result >= 0;
behavior invalid_input:
assumes n <= 0;
ensures \result == -1;
complete behaviors;
disjoint behaviors;
*/Verification Considerations
For Frama-C WP Plugin
When generating annotations for WP verification:
- Use
assignsclauses to specify frame conditions - Prefer
\validover raw pointer checks - Use
\separatedfor pointer disjointness - Add
loop assignsfor all loops - Include
loop variantfor termination proofs
Common Verification Patterns
Array bounds safety:
/*@ requires 0 <= index < length;
requires \valid(array + index);
*/Null pointer checks:
/*@ requires ptr != \null;
requires \valid(ptr);
*/Overflow prevention:
/*@ requires INT_MIN <= a + b <= INT_MAX; */Output Format
Generate annotations in standard ACSL comment syntax:
- Multi-line contracts:
/*@ ... */ - Single-line assertions:
//@ assertion - Place contracts immediately before function declarations
- Place loop annotations immediately before loop headers
- Include explanatory comments when annotations are complex
Best Practices
- Start simple: Begin with basic contracts, then refine
- Be precise: Avoid over-specification or under-specification
- Document assumptions: Make implicit assumptions explicit
- Use predicates: Factor out common patterns
- Test incrementally: Verify annotations with Frama-C as you go
- Include rationale: Add comments explaining non-obvious specifications
Example: Complete Annotated Function
/*@
predicate valid_array(int *a, integer n) =
\valid(a + (0..n-1)) && n > 0;
*/
/*@
requires valid_array(array, n);
ensures \result >= 0 && \result < n;
ensures \forall integer i; 0 <= i < n ==> array[\result] >= array[i];
assigns \nothing;
*/
int find_max_index(int *array, int n) {
int max_idx = 0;
/*@
loop invariant 0 <= i <= n;
loop invariant 0 <= max_idx < n;
loop invariant \forall integer k; 0 <= k < i ==>
array[max_idx] >= array[k];
loop assigns i, max_idx;
loop variant n - i;
*/
for (int i = 1; i < n; i++) {
if (array[i] > array[max_idx]) {
max_idx = i;
}
}
return max_idx;
}Resources
This skill includes reference materials for ACSL:
references/
acsl_reference.md- Comprehensive ACSL syntax referencecommon_patterns.md- Frequently used annotation patternsframa_c_integration.md- Tips for using with Frama-C
Load these references as needed for detailed syntax information or advanced patterns.
Research Tools & Artifacts
Real-world ACSL and formal verification tools:
| Tool | Why It Matters |
| Frama-C | Industrial C verification platform |
| WP plugin | Deductive verification for C |
| ** Jessie** | Deductive verification via Why3 |
| AST plugin | Abstract syntax tree analysis |
| Value analysis | Static value range analysis |
| E-ACSL | Runtime verification translation |
Key Verification Projects
- OpenSSL verification: Proving cryptographic primitives correct
- Sel4 microkernel: Proof of OS kernel correctness
- CompCert: Verified C compiler
Research Frontiers
Current active research in ACSL and C verification:
| Direction | Key Papers | Challenge |
| Automation | "Automatic Invariant Generation" (2019) | Generating loop invariants |
| SMT theories | "Linear Arithmetic in C" (2020) | Better arithmetic support |
| Concurrency | "Concurrent Separation Logic" | Verifying multi-threaded C |
| Ghost code | "Ghost State" (Iris) | Rich specification logic |
| Testing integration | "Deductive Testing" (2021) | Combining testing and proof |
Hot Topics
- AI-assisted specification: Using LLMs to suggest invariants
- Compositional verification: Verifying large codebases
- Incrementality: Fast re-verification after changes
Implementation Pitfalls
Common mistakes in ACSL annotation:
| Pitfall | Real Example | Prevention |
| Missing assigns | Frama-C reports warning | Always specify what changes |
| Weak invariants | Verification fails silently | Make invariants strong enough |
| Missing loop assigns | Incomplete frame | Annotate every loop |
| Overflow assumptions | Unsoundness in arithmetic | Use proper bounds |
| Separation violations | Aliasing bugs | Use \separated explicitly |
| Incomplete behaviors | Misses error cases | Use complete/disjoint behaviors |
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.

