Overview
/formal-verify is a production command in the Formal Verification category of the Prismatic Platform that provides mathematically rigorous verification of system properties and invariants. Unlike testing, which can only demonstrate the presence of bugs, formal verification proves their absence for all possible inputs within a specified domain. This command bridges the gap between empirical software testing and mathematical proof, ensuring that critical system properties hold unconditionally.
The command operates under the L3 authority level and is executed by the formal-verification-specialist agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The L3 authority level reflects the command's ability to make definitive claims about system correctness -- claims that carry weight in the platform's Trinity Gate evaluation and NABLA epistemic framework.
Formal verification is a cornerstone of the QEVE (Quantum Epistemic Verification Engine) subsystem, which combines Lean4 theorem proving, NABLA axiom verification, and Monte Carlo simulation to produce multi-layered confidence assessments. The /formal-verify command provides direct access to this verification infrastructure, enabling operators to prove properties ranging from type safety and termination guarantees to protocol correctness and invariant preservation across system state transitions.
The platform currently maintains 629 Trinity Gate entities, each of which has passed the three-gate verification process: structural consistency (graph theory), logical consistency (rule-based), and formal necessity (modal logic + Lean4). The /formal-verify command is the primary tool for establishing and maintaining these formal guarantees.
Architecture
The formal verification pipeline is built on a multi-engine architecture that selects the appropriate verification strategy based on the property being verified.
Property Spec --> Parser --> Strategy Selector --> Verification Engine --> Trinity Gate
| |
Property Type Engine Selection
Classification (Lean4/Prolog/PBT)
|
+----------+----------+
| | |
Lean4 Prolog Property-
Proofs Logic Based TestVerification Engines
| Engine | Technology | Best For | Confidence Level |
|---|---|---|---|
| Lean4 Prover | Lean 4 | Mathematical proofs, type properties, induction | Formal proof (1.0) |
| Prolog Reasoner | SWI-Prolog | Logical relationships, protocol verification, rule systems | Logical proof (0.95) |
| Property-Based | StreamData | Statistical verification, boundary conditions, fuzzing | Statistical (0.90) |
| Model Checker | Custom | State machine verification, concurrency properties | Exhaustive (0.98) |
Property Classification
Properties are classified into categories that determine which verification engine is most appropriate:
| Category | Examples | Primary Engine |
|---|---|---|
| Type Safety | "All return values match @spec" | Lean4 + Dialyzer |
| Invariant | "Account balance never negative" | Lean4 + PBT |
| Protocol | "Messages are processed in order" | Prolog + Model Checker |
| Termination | "Recursive function always terminates" | Lean4 |
| Concurrency | "No deadlock in supervision tree" | Model Checker |
| Security | "No privilege escalation path exists" | Prolog + Lean4 |
Usage
Basic Usage
# Verify all registered properties for a module
/formal-verify PrismaticPerimeter.SecurityRating
# Verify a specific property
/formal-verify --property "score_always_in_range" --module PrismaticPerimeter.Scoring
# Verify all properties in an application
/formal-verify --app prismatic_perimeter
# Run Trinity Gate verification on a claim
/formal-verify --trinity "Security ratings are monotonically bounded between 300 and 900"Engine-Specific Verification
# Use Lean4 for mathematical proof
/formal-verify --engine lean4 --property "list_sort_preserves_length"
# Use Prolog for protocol verification
/formal-verify --engine prolog --property "message_ordering_guarantee"
# Use property-based testing for statistical verification
/formal-verify --engine pbt --property "json_roundtrip_identity" --iterations 100000
# Use model checker for concurrency properties
/formal-verify --engine model-check --property "no_deadlock" --module PrismaticSupervisorBatch Verification
# Verify all properties across the entire platform
/formal-verify --all --report
# Verify only properties that changed since last verification
/formal-verify --incremental
# Verify and generate Lean4 proof artifacts
/formal-verify --app prismatic_storage_core --emit-proofs --output proofs/Options & Parameters
| Option | Type | Default | Description |
|---|---|---|---|
--module | atom | none | Target Elixir module for verification |
--app | string | none | Target umbrella application |
--property | string | none | Specific property name to verify |
--engine | string | auto | Verification engine: lean4, prolog, pbt, model-check |
--trinity | string | none | Claim to evaluate through Trinity Gate |
--all | boolean | false | Verify all registered properties platform-wide |
--incremental | boolean | false | Only verify properties affected by recent changes |
--iterations | integer | 10000 | Number of iterations for property-based testing |
--timeout | integer | 300000 | Maximum verification time in milliseconds |
--emit-proofs | boolean | false | Generate proof artifacts (Lean4 files) |
--output | string | stdout | Directory for proof artifact output |
--report | boolean | false | Generate a comprehensive verification report |
--verbose | boolean | false | Show detailed verification steps and intermediate results |
Execution Flow
-
Property Resolution: Resolve the target properties from the specified module, app, or explicit property name. Properties are loaded from
@verifymodule attributes and the platform's property registry. -
Classification: Each property is classified by category (type safety, invariant, protocol, termination, concurrency, security) to determine the optimal verification strategy.
-
Engine Selection: Based on classification, the appropriate verification engine is selected. If
--engineis specified, that engine is used regardless of classification. -
Precondition Check: Verify that all preconditions for the chosen engine are met (e.g., Lean4 toolchain available, Prolog runtime accessible, StreamData dependency present).
-
Verification Execution: The selected engine executes the verification. For Lean4, this involves generating and checking a proof term. For Prolog, logical rules are evaluated. For PBT, random inputs are generated and tested.
-
Evidence Assembly: Verification results are packaged as evidence with confidence levels, provenance metadata, and proof artifacts.
-
Trinity Gate Evaluation: If
--trinityis specified, the evidence passes through all three Trinity Gate layers: structural consistency, logical consistency, and formal necessity. -
Report Generation: Results are formatted and output. Failed verifications include counterexamples when available.
Integration Points
| Component | Integration Type | Description |
|---|---|---|
| Trinity Gate | Core | Formal necessity gate requires proof from this command |
| NABLA Framework | Epistemic | Verification results feed into NABLA confidence calculations |
| QEVE | Engine | Part of the Quantum Epistemic Verification Engine |
| Lean4 | Prover | Lean4 theorem prover for mathematical proofs |
| Quality Gates | Enforcement | Formal verification can be required as a quality gate |
| White Team | Security | White Team verification campaigns use this command |
| Telemetry | Metrics | Verification results tracked as telemetry events |
| Prismatic Agents | Execution | Invoked by formal-verification-specialist agent |
Best Practices
Start with property-based testing, graduate to formal proofs. Use the PBT engine to quickly discover counterexamples and build confidence, then use Lean4 to establish formal guarantees for critical properties. This progression mirrors the NABLA confidence threshold escalation: exploratory (0.50) to standard (0.80) to critical (0.95).
Define properties close to the code they verify. Use @verify module attributes to declare properties inline with the modules they describe. This keeps properties synchronized with implementation changes and makes verification an integral part of the development workflow.
Use incremental verification in CI/CD. The --incremental flag dramatically reduces verification time by only checking properties affected by recent changes. Reserve --all verification for release candidates and milestone completions.
Leverage Trinity Gate for critical claims. Any claim that influences architectural decisions, security posture, or compliance status should pass Trinity Gate verification. The formal necessity gate ensures that the claim is not merely consistent but provably true.
Archive proof artifacts. Use --emit-proofs to generate Lean4 proof files that serve as machine-checkable evidence. These artifacts are valuable for compliance audits, security reviews, and knowledge transfer.
Error Handling
| Error | Cause | Resolution |
|---|---|---|
{:error, :property_not_found} | Specified property does not exist in the target module | Check property name spelling; use --verbose to list available properties |
{:error, :engine_unavailable} | Required verification engine is not installed | Install the missing engine (e.g., lean4 toolchain, SWI-Prolog) |
{:error, :verification_timeout} | Verification exceeded the timeout limit | Increase --timeout or simplify the property specification |
{:error, :counterexample_found} | Property-based testing found a counterexample | Examine the counterexample to identify the implementation bug |
{:error, :proof_incomplete} | Lean4 proof could not be completed automatically | Manual proof assistance may be required; check the generated .lean file |
{:error, :trinity_gate_failed} | Claim failed one or more Trinity Gate layers | Review which gate failed and provide additional evidence |
Advanced Usage
Custom Property Definitions
Define verifiable properties using the @verify attribute:
defmodule PrismaticPerimeter.Scoring do
@verify %{
name: "score_bounded",
type: :invariant,
property: "forall score : score >= 300 and score <= 900",
engine: :lean4
}
@spec calculate_score(map()) :: {:ok, integer()} | {:error, term()}
def calculate_score(evidence) do
# Implementation
end
endLean4 Proof Generation
# Generate and verify a Lean4 proof
/formal-verify --engine lean4 --property "sort_idempotent" --emit-proofs --output proofs/sort/
# The generated proof can be checked independently
lean proofs/sort/sort_idempotent.leanCompositional Verification
Verify complex system properties by composing simpler verified properties:
# Verify individual components
/formal-verify --property "input_validated" --module PrismaticAPI.Validator
/formal-verify --property "output_sanitized" --module PrismaticAPI.Renderer
# Verify the composed property
/formal-verify --trinity "API requests are safe from injection attacks" \
--evidence input_validated,output_sanitizedDoctrine Compliance
All commands operate under the NO MERCY, NO DOUBTS doctrine:
- NO MERCY: Zero tolerance for incomplete execution or quality violations. Failed verifications are treated as blocking issues that must be resolved before proceeding.
- NO DOUBTS: Full investigation before action, evidence-based results. Formal verification is the ultimate expression of NO DOUBTS -- mathematical proof eliminates doubt entirely.
The command is a direct implementation of the NABLA framework's seventh axiom (Provenance Mandatory): all verification results include complete provenance chains showing exactly how the conclusion was reached, which engines were used, and what evidence supports the claim.
Related Commands
- /lean - Execute Lean 4 code or prove a theorem with the lean-specialist agent
- /prolog - Prolog-based logical reasoning and inference operations
- /monte-carlo - Monte Carlo simulation for probabilistic analysis and risk assessment
- /quality-gates - Enforce quality gate checkpoints with zero-warning compilation validation
- /quality-enforce - Mandatory progressive quality debt elimination with AIAD enforcement
- /regression-check - Execute 25 custom Credo regression checks preventing 700+ violations
- /mycelialize-formal - Lean4 + Prolog formal verification for mathematically proven pattern propagation
Connect & Contribute
Created by Tomáš Korcak (korczis) | Open Source under GHL