Skip to content

x402agent/SolanaOS / skills/solana-formal-verification

qedgen

Flagged

Formally verify programs by writing Lean 4 proofs. Trigger this skill whenever the user wants to formally verify code, generate Lean 4 proofs, prove properties about algorithms or smart contracts, verify invariants, convert program logic into formal specifications, or anything involving Lean 4 and formal verification. Also trigger when the user mentions "qedgen", "lean proof", "formal proof", "verify my code", "prove correctness", "formal verification", or wants mathematical guarantees about their implementation.

FileKindSize
.gitignoreother753 B
.npmignoreother352 B
Cargo.lockmanifest46.3 KB
Cargo.tomlmanifest307 B
LICENSEother1.0 KB
README.mdmarkdown3.7 KB
SKILL.mdskill md10.8 KB
bin/leanstralexecutablescript6.2 MB
claude.mdmarkdown6.8 KB
crates/qedgen/Cargo.tomlmanifest544 B
crates/qedgen/lean_support/QEDGen.leanother166 B
crates/qedgen/lean_support/QEDGen/Solana.leanother166 B
crates/qedgen/lean_support/QEDGen/Solana/Account.leanother4.0 KB
crates/qedgen/lean_support/QEDGen/Solana/Authority.leanother285 B
crates/qedgen/lean_support/QEDGen/Solana/Cpi.leanother3.3 KB
crates/qedgen/lean_support/QEDGen/Solana/State.leanother1.9 KB
crates/qedgen/lean_support/QEDGen/Solana/Token.leanother1.4 KB
crates/qedgen/lean_support/QEDGen/Solana/Valid.leanother2.0 KB
crates/qedgen/lean_support/README.mdmarkdown2.8 KB
crates/qedgen/lean_support/lake-manifest.jsonconfig119 B
crates/qedgen/lean_support/lakefile.leanother112 B
crates/qedgen/lean_support/lean-toolchainother25 B
crates/qedgen/lean_support/test_lemmas.leanother1.2 KB
crates/qedgen/src/api.rsscript32.3 KB
crates/qedgen/src/consolidate.rsscript6.9 KB
crates/qedgen/src/main.rsscript4.1 KB
crates/qedgen/src/project.rsscript3.1 KB
crates/qedgen/src/spec.rsscript19.3 KB
crates/qedgen/src/validate.rsscript5.6 KB
crates/qedgen/templates/.gitignoreother29 B
crates/qedgen/templates/Main.leanother154 B
crates/qedgen/templates/PROMPT_TEMPLATE.mdmarkdown3.2 KB
crates/qedgen/templates/README.lean.mdmarkdown1.6 KB
crates/qedgen/templates/lakefile.leanother293 B
crates/qedgen/templates/lean-toolchainother25 B
docs/CNAMEother10 B
docs/index.htmlother10.9 KB
docs/llms-full.txtmarkdown8.7 KB
docs/llms.txtmarkdown2.1 KB
docs/logo-dark.svgother648 B
docs/logo-light.svgother648 B
docs/style.cssother7.6 KB
example/escrow/.gitignoreother67 B
example/escrow/.prettierignoreother61 B
example/escrow/Anchor.tomlconfig353 B
example/escrow/Cargo.lockmanifest72.8 KB
example/escrow/Cargo.tomlmanifest215 B
example/escrow/migrations/deploy.tsscript428 B
example/escrow/package.jsonmanifest528 B
example/escrow/programs/escrow/Cargo.tomlmanifest376 B
example/escrow/programs/escrow/Xargo.tomlconfig62 B
example/escrow/programs/escrow/src/lib.rsscript6.7 KB
example/escrow/tests/escrow.tsscript8.6 KB
example/escrow/tsconfig.jsonconfig205 B
example/percolator/.cargo/config.tomlconfig33 B
example/percolator/.gitignoreother320 B
example/percolator/Cargo.lockmanifest8.5 KB
example/percolator/Cargo.tomlmanifest639 B
example/percolator/LICENSEother11.1 KB
example/percolator/README.mdmarkdown4.9 KB
example/percolator/examples/offsets.rsscript1.3 KB
example/percolator/scripts/audit-proof-strength.mdmarkdown6.4 KB
example/percolator/scripts/proof-strength-audit-results.mdmarkdown89.2 KB
example/percolator/scripts/run_kani_full_audit.shexecutablescript1.2 KB
example/percolator/spec.mdmarkdown108.4 KB
example/percolator/src/i128.rsscript20.4 KB
example/percolator/src/percolator.rsscript139.2 KB
example/percolator/src/wide_math.rsscript59.8 KB
example/percolator/tests/amm_tests.rsscript7.4 KB
example/percolator/tests/common/mod.rsscript4.7 KB
example/percolator/tests/fuzzing.proptest-regressionsother4.7 KB
example/percolator/tests/fuzzing.rsscript43.1 KB
example/percolator/tests/proofs_arithmetic.rsscript17.1 KB
example/percolator/tests/proofs_audit.rsscript35.0 KB
example/percolator/tests/proofs_instructions.rsscript64.8 KB
example/percolator/tests/proofs_invariants.rsscript21.0 KB
example/percolator/tests/proofs_lazy_ak.rsscript22.4 KB
example/percolator/tests/proofs_liveness.rsscript17.1 KB
example/percolator/tests/proofs_safety.rsscript104.2 KB
example/percolator/tests/proofs_v1131.rsscript25.4 KB
example/percolator/tests/unit_tests.rsscript93.8 KB
install.shexecutablescript4.9 KB
package.jsonmanifest1.1 KB

crates/qedgen/src/consolidate.rs

View on GitHub
use anyhow::{Context, Result};
use std::fs;
use std::path::{Path, PathBuf};

const CONSOLIDATED_LAKEFILE: &str = r#"import Lake
open Lake DSL

package escrowProofs

require mathlib from git
  "https://github.com/leanprover-community/mathlib4.git" @ "v4.15.0"
require qedgenSupport from
  "./lean_support"

@[default_target]
lean_lib EscrowProofs where
  roots := #[`EscrowProofs]
"#;

const CONSOLIDATED_README: &str = r#"# Solana Program Lean Proofs

This directory contains formal verification proofs for the Solana program, generated using QEDGen.

## Building and Verifying

To build and verify all proofs:

```bash
lake build
```

This will verify all theorems and ensure they compile correctly.

## Structure

All proofs are contained in `EscrowProofs.lean`, organized into namespaces to avoid naming conflicts:
- Each proof has its own namespace
- Shared definitions from the QEDGen Solana library are imported at the top
- The `lean_support` directory contains the Solana modeling framework

## Generated Proofs

See `EscrowProofs.lean` for the complete list of theorems and their proofs.
"#;

const CONSOLIDATED_GITIGNORE: &str = r#"/.lake
/lake-manifest.json
/lakefile.olean
/lakefile.olean.trace
*.olean
*.trace
.lake
"#;

/// Find all Best.lean files in subdirectories of the given path
fn find_proof_files(input_dir: &Path) -> Result<Vec<PathBuf>> {
    let mut proof_files = Vec::new();

    if !input_dir.is_dir() {
        anyhow::bail!("Input path is not a directory: {}", input_dir.display());
    }

    for entry in fs::read_dir(input_dir)? {
        let entry = entry?;
        let path = entry.path();

        if path.is_dir() {
            let best_lean = path.join("Best.lean");
            if best_lean.exists() {
                proof_files.push(best_lean);
            }
        }
    }

    if proof_files.is_empty() {
        anyhow::bail!("No Best.lean files found in subdirectories of {}", input_dir.display());
    }

    proof_files.sort();
    Ok(proof_files)
}

/// Extract namespace from directory name (e.g., "cancel_access_control" -> "CancelAccessControl")
fn to_namespace(dir_name: &str) -> String {
    dir_name
        .split('_')
        .map(|word| {
            let mut chars = word.chars();
            match chars.next() {
                None => String::new(),
                Some(first) => first.to_uppercase().collect::<String>() + chars.as_str(),
            }
        })
        .collect()
}

/// Read a proof file, extract its imports, and wrap the body in a namespace
fn process_proof_file(proof_file: &Path) -> Result<(String, Vec<String>, String)> {
    let content = fs::read_to_string(proof_file)
        .with_context(|| format!("Failed to read {}", proof_file.display()))?;

    let parent = proof_file
        .parent()
        .and_then(|p| p.file_name())
        .and_then(|n| n.to_str())
        .ok_or_else(|| anyhow::anyhow!("Could not determine parent directory"))?;

    let namespace = to_namespace(parent);

    // Collect imports and find where the body starts
    let lines: Vec<&str> = content.lines().collect();
    let mut imports = Vec::new();
    let mut content_start = 0;

    for (i, line) in lines.iter().enumerate() {
        let trimmed = line.trim();
        if trimmed.starts_with("import ") {
            imports.push(trimmed.to_string());
        } else if !trimmed.is_empty() && !trimmed.starts_with("open ") && !trimmed.starts_with("--") {
            content_start = i;
            break;
        }
    }

    // Skip any remaining open/empty lines
    while content_start < lines.len() {
        let trimmed = lines[content_start].trim();
        if !trimmed.is_empty() && !trimmed.starts_with("open ") {
            break;
        }
        content_start += 1;
    }

    let proof_content = lines[content_start..].join("\n");

    Ok((namespace, imports, proof_content))
}

/// Consolidate multiple Lean proof projects into a single project
pub fn consolidate_proofs(input_dir: &Path, output_dir: &Path) -> Result<()> {
    // Create output directory
    fs::create_dir_all(output_dir)?;

    // Find all proof files
    let proof_files = find_proof_files(input_dir)?;
    println!("Found {} proof files to consolidate", proof_files.len());

    // Process all proof files and collect their imports
    let mut all_imports = std::collections::BTreeSet::new();
    let mut proofs = Vec::new();

    for proof_file in &proof_files {
        let (namespace, imports, content) = process_proof_file(proof_file)?;
        all_imports.extend(imports);
        proofs.push((namespace, content));
    }

    // Build the consolidated proof file
    let mut consolidated = String::new();

    // Add union of all imports
    for import in &all_imports {
        consolidated.push_str(import);
        consolidated.push('\n');
    }
    consolidated.push_str("\nopen QEDGen.Solana\n\n");

    // Write each proof in its namespace
    for (namespace, content) in &proofs {

        consolidated.push_str(&format!(
            "/- {separator}\n   {title}\n   {separator} -/\n\n",
            separator = "=".repeat(76),
            title = format!("{} Proof", namespace)
        ));

        consolidated.push_str(&format!("namespace {}\n\n", namespace));
        consolidated.push_str(&content);
        consolidated.push_str("\n\nend ");
        consolidated.push_str(&namespace);
        consolidated.push_str("\n\n");
    }

    // Write the consolidated proof file
    fs::write(output_dir.join("EscrowProofs.lean"), consolidated)?;

    // Copy lean_support from one of the proof directories
    let first_proof_dir = proof_files[0].parent().unwrap();
    let source_support = first_proof_dir.join("lean_support");
    let dest_support = output_dir.join("lean_support");

    if source_support.exists() {
        copy_dir_recursive(&source_support, &dest_support)?;
    }

    // Copy lean-toolchain
    let source_toolchain = first_proof_dir.join("lean-toolchain");
    if source_toolchain.exists() {
        fs::copy(&source_toolchain, output_dir.join("lean-toolchain"))?;
    }

    // Write lakefile, README, and .gitignore
    fs::write(output_dir.join("lakefile.lean"), CONSOLIDATED_LAKEFILE)?;
    fs::write(output_dir.join("README.md"), CONSOLIDATED_README)?;
    fs::write(output_dir.join(".gitignore"), CONSOLIDATED_GITIGNORE)?;

    println!("Consolidated proofs written to {}", output_dir.display());
    println!("  - EscrowProofs.lean");
    println!("  - lakefile.lean");
    println!("  - lean-toolchain");
    println!("  - lean_support/");
    println!("  - README.md");
    println!("  - .gitignore");

    Ok(())
}

/// Recursively copy a directory
fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<()> {
    if !dst.exists() {
        fs::create_dir_all(dst)?;
    }

    for entry in fs::read_dir(src)? {
        let entry = entry?;
        let path = entry.path();
        let dest_path = dst.join(entry.file_name());

        if path.is_dir() {
            copy_dir_recursive(&path, &dest_path)?;
        } else {
            fs::copy(&path, &dest_path)?;
        }
    }

    Ok(())
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall