Skip to main content
This guide shows you how to use AI coding assistants to accelerate assertion development. AI can generate high-quality assertion templates that follow Phylax best practices. Prerequisites:
  • pcl installed
  • credible-std added: forge install credible-std=https://github.com/phylaxsystems/credible-std/
  • Well-defined protocol invariants
  • An AI coding assistant (Cursor, Claude Code, Gemini Code, Codex, etc.)
What you’ll learn: How to prompt AI tools to generate assertions and tests for your protocol.
AI-generated assertions require careful review and testing. Always test thoroughly before deployment. AI accelerates development but doesn’t replace manual verification.

Step 1: Set Up AI Context

Add the Phylax documentation to your AI assistant’s context: For Cursor: Settings → Indexing & Docs → add https://docs.phylax.systems Add the rules file to your AI assistant’s context/rules file.
Phylax Assertion Rules

Step 2: Define Your Invariants

Before prompting AI, document your protocol’s invariants clearly:
  • Focus on security-critical invariants
  • Avoid invariants already enforced by require statements
  • Target properties that span multiple functions or calls
  • Use simple, clear language
Reference Aave’s invariants for examples of clear invariant documentation.
Good candidates for assertions:
  • State changes in the callstack
  • Price manipulation
  • Cross-function state inconsistencies
  • Properties that can’t be checked with simple require in your contracts

Step 3: Craft Your Prompt

Use this template:

Step 4: Generate Assertions

Example: Origin Protocol

Using Origin Protocol’s contracts with their invariant documentation:
The AI will implement assertions in a new assertions folder at the repository root.

Step 5: Review Generated Code

AI-generated assertions are typically good quality but require review:
  • Verify the logic matches your invariants
  • Check for efficient data retrieval and minimal gas usage
  • Ensure they follow Phylax best practices
  • Ask the AI for an overview of what each assertion covers
If corrections are needed, provide specific instructions. Add protocol-specific guidance to your rules file for better results.

Step 6: Generate Tests

Prompt the AI to create tests:
The AI will create tests in assertions/test. Review them carefully:
  • Verify scenarios are realistic
  • Ensure tests aren’t just assert(true)
  • Use failures to identify assertion bugs
  • Ask the AI to fix issues you discover

Recap

You’ve learned to accelerate assertion development with AI:
  1. Set up context: Add docs and rules to your AI assistant
  2. Define invariants: Document what properties to protect
  3. Craft prompts: Use structured templates for consistent results
  4. Generate: Let AI create assertion templates
  5. Review: Verify logic and efficiency
  6. Test: Generate and review test suites

Next Steps

Join the Phylax Telegram to share improvements to the rules file.

Write Your First Assertion

Manual assertion development

Testing Assertions

Core testing workflow

Fuzz Testing

Random input testing

Backtesting

Historical transaction testing