Skip to content

x402agent/SolanaOS / skills/qedgen

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
Cargo.lockmanifest38.2 KB
Cargo.tomlmanifest347 B
LICENSEother1.0 KB
README.mdmarkdown4.1 KB
SKILL.mdskill md21.0 KB
claude.mdmarkdown9.7 KB
crates/qedgen/Cargo.tomlmanifest544 B
crates/qedgen/src/api.rsscript38.9 KB
crates/qedgen/src/asm2lean.rsscript26.2 KB
crates/qedgen/src/consolidate.rsscript6.2 KB
crates/qedgen/src/main.rsscript4.7 KB
crates/qedgen/src/project.rsscript3.0 KB
crates/qedgen/src/spec.rsscript19.4 KB
crates/qedgen/src/validate.rsscript5.6 KB
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.leanother292 B
crates/qedgen/templates/lean-toolchainother25 B
docs/CNAMEother10 B
docs/index.htmlother11.6 KB
docs/llms-full.txtmarkdown8.7 KB
docs/llms.txtmarkdown2.1 KB
docs/logo-dark.svgother648 B
docs/logo-light.svgother648 B
docs/qgn_demo.htmlother69.3 KB
docs/style.cssother8.1 KB
examples/rust/escrow/Anchor.tomlconfig353 B
examples/rust/escrow/Cargo.lockmanifest72.8 KB
examples/rust/escrow/Cargo.tomlmanifest215 B
examples/rust/escrow/migrations/deploy.tsscript428 B
examples/rust/escrow/package.jsonmanifest528 B
examples/rust/escrow/programs/escrow/Cargo.tomlmanifest376 B
examples/rust/escrow/programs/escrow/Xargo.tomlconfig62 B
examples/rust/escrow/programs/escrow/src/lib.rsscript6.7 KB
examples/rust/escrow/tests/escrow.tsscript8.6 KB
examples/rust/escrow/tsconfig.jsonconfig205 B
examples/rust/percolator/Cargo.lockmanifest8.5 KB
examples/rust/percolator/Cargo.tomlmanifest639 B
examples/rust/percolator/LICENSEother11.1 KB
examples/rust/percolator/README.mdmarkdown4.9 KB
examples/rust/percolator/examples/offsets.rsscript1.3 KB
examples/rust/percolator/scripts/audit-proof-strength.mdmarkdown6.4 KB
examples/rust/percolator/scripts/proof-strength-audit-results.mdmarkdown89.2 KB
examples/rust/percolator/scripts/run_kani_full_audit.shexecutablescript1.2 KB
examples/rust/percolator/spec.mdmarkdown108.4 KB
examples/rust/percolator/src/i128.rsscript20.4 KB
examples/rust/percolator/src/percolator.rsscript139.3 KB
examples/rust/percolator/src/wide_math.rsscript59.8 KB
examples/rust/percolator/tests/amm_tests.rsscript7.4 KB
examples/rust/percolator/tests/common/mod.rsscript4.7 KB
examples/rust/percolator/tests/fuzzing.proptest-regressionsother4.7 KB
examples/rust/percolator/tests/fuzzing.rsscript43.1 KB
examples/rust/percolator/tests/proofs_arithmetic.rsscript17.1 KB
examples/rust/percolator/tests/proofs_audit.rsscript35.0 KB
examples/rust/percolator/tests/proofs_instructions.rsscript64.8 KB
examples/rust/percolator/tests/proofs_invariants.rsscript21.0 KB
examples/rust/percolator/tests/proofs_lazy_ak.rsscript22.4 KB
examples/rust/percolator/tests/proofs_liveness.rsscript17.1 KB
examples/rust/percolator/tests/proofs_safety.rsscript104.2 KB
examples/rust/percolator/tests/proofs_v1131.rsscript25.4 KB
examples/rust/percolator/tests/unit_tests.rsscript93.8 KB
examples/sbpf/counter/src/counter.sother22.9 KB
examples/sbpf/slippage/src/asm-slippage/asm-slippage.sother698 B
examples/sbpf/transfer/src/transfer.sother2.4 KB
examples/sbpf/tree/src/tree.sother61.1 KB
install.shexecutablescript5.5 KB
lean_solana/QEDGen.leanother165 B
lean_solana/QEDGen/Solana.leanother165 B
lean_solana/QEDGen/Solana/Account.leanother4.0 KB
lean_solana/QEDGen/Solana/Authority.leanother285 B
lean_solana/QEDGen/Solana/Cpi.leanother9.0 KB
lean_solana/QEDGen/Solana/SBPF.leanother130 B
lean_solana/QEDGen/Solana/SBPF/Execute.leanother12.2 KB
lean_solana/QEDGen/Solana/SBPF/ISA.leanother5.1 KB
lean_solana/QEDGen/Solana/SBPF/Memory.leanother6.1 KB
lean_solana/QEDGen/Solana/SBPF/Tactic.leanother2.3 KB
lean_solana/QEDGen/Solana/State.leanother1.9 KB
lean_solana/QEDGen/Solana/Valid.leanother2.0 KB
lean_solana/README.mdmarkdown2.5 KB
lean_solana/lake-manifest.jsonconfig119 B
lean_solana/lakefile.leanother112 B
lean_solana/lean-toolchainother25 B
lean_solana/test_lemmas.leanother2.3 KB
package.jsonmanifest762 B
tools/qedgenexecutablescript357 B

lean_solana/QEDGen/Solana/SBPF/Memory.lean

View on GitHub
-- Flat byte-addressable memory model for sBPF verification
--
-- sBPF uses a flat address space partitioned into 5 regions:
--   0x000000000 : Read-only data (.rodata)
--   0x100000000 : Bytecode
--   0x200000000 : Stack
--   0x300000000 : Heap
--   0x400000000 : Input buffer (serialized accounts + instruction data)
--
-- Programs receive a pointer to the input buffer in r1 at entry.

import QEDGen.Solana.SBPF.ISA

namespace QEDGen.Solana.SBPF.Memory

open QEDGen.Solana.SBPF

/-! ## Memory type -/

/-- Byte-addressable memory: maps addresses to byte values (0-255) -/
abbrev Mem := Nat → Nat

/-! ## Region base addresses -/

def RODATA_START   : Nat := 0x000000000
def BYTECODE_START : Nat := 0x100000000
def STACK_START    : Nat := 0x200000000
def HEAP_START     : Nat := 0x300000000
def INPUT_START    : Nat := 0x400000000

/-! ## Effective address computation -/

/-- Compute effective address from base register value and signed offset.

    NOTE: Int.toNat clamps negative results to 0. In real sBPF, a negative
    effective address would be caught by the memory region bounds check
    (which we do not model). All verified programs use non-negative offsets,
    so this clamping is unreachable in practice. -/
def effectiveAddr (base : Nat) (off : Int) : Nat :=
  Int.toNat ((↑base : Int) + off)

/-! ## Read operations (little-endian) -/

/-- Read 1 byte -/
def readU8 (mem : Mem) (addr : Nat) : Nat :=
  mem addr % 256

/-- Read 2 bytes little-endian -/
def readU16 (mem : Mem) (addr : Nat) : Nat :=
  mem addr % 256 +
  mem (addr + 1) % 256 * 0x100

/-- Read 4 bytes little-endian -/
def readU32 (mem : Mem) (addr : Nat) : Nat :=
  mem addr % 256 +
  mem (addr + 1) % 256 * 0x100 +
  mem (addr + 2) % 256 * 0x10000 +
  mem (addr + 3) % 256 * 0x1000000

/-- Read 8 bytes little-endian -/
def readU64 (mem : Mem) (addr : Nat) : Nat :=
  mem addr % 256 +
  mem (addr + 1) % 256 * 0x100 +
  mem (addr + 2) % 256 * 0x10000 +
  mem (addr + 3) % 256 * 0x1000000 +
  mem (addr + 4) % 256 * 0x100000000 +
  mem (addr + 5) % 256 * 0x10000000000 +
  mem (addr + 6) % 256 * 0x1000000000000 +
  mem (addr + 7) % 256 * 0x100000000000000

/-! ## Write operations (little-endian) -/

/-- Write 1 byte -/
def writeU8 (mem : Mem) (addr val : Nat) : Mem :=
  fun a => if a = addr then val % 256 else mem a

/-- Write 2 bytes little-endian -/
def writeU16 (mem : Mem) (addr val : Nat) : Mem :=
  fun a =>
    if a = addr     then val % 0x100
    else if a = addr + 1 then val / 0x100 % 0x100
    else mem a

/-- Write 4 bytes little-endian -/
def writeU32 (mem : Mem) (addr val : Nat) : Mem :=
  fun a =>
    if a = addr     then val % 0x100
    else if a = addr + 1 then val / 0x100 % 0x100
    else if a = addr + 2 then val / 0x10000 % 0x100
    else if a = addr + 3 then val / 0x1000000 % 0x100
    else mem a

/-- Write 8 bytes little-endian -/
def writeU64 (mem : Mem) (addr val : Nat) : Mem :=
  fun a =>
    if a = addr     then val % 0x100
    else if a = addr + 1 then val / 0x100 % 0x100
    else if a = addr + 2 then val / 0x10000 % 0x100
    else if a = addr + 3 then val / 0x1000000 % 0x100
    else if a = addr + 4 then val / 0x100000000 % 0x100
    else if a = addr + 5 then val / 0x10000000000 % 0x100
    else if a = addr + 6 then val / 0x1000000000000 % 0x100
    else if a = addr + 7 then val / 0x100000000000000 % 0x100
    else mem a

/-! ## Generic read/write by width -/

/-- Read N bytes from memory according to width -/
def readByWidth (mem : Mem) (addr : Nat) : QEDGen.Solana.SBPF.Width → Nat
  | .byte  => readU8 mem addr
  | .half  => readU16 mem addr
  | .word  => readU32 mem addr
  | .dword => readU64 mem addr

/-- Write N bytes to memory according to width -/
def writeByWidth (mem : Mem) (addr val : Nat) : QEDGen.Solana.SBPF.Width → Mem
  | .byte  => writeU8 mem addr val
  | .half  => writeU16 mem addr val
  | .word  => writeU32 mem addr val
  | .dword => writeU64 mem addr val

/-! ## Memory axioms

These are provable from the concrete definitions above via byte decomposition
lemmas, but stated as axioms to keep proofs tractable. The key property is that
little-endian encode/decode is a round-trip for values within range. -/

/-- Reading back a U64 from the address it was just written to yields the original value -/
axiom readU64_writeU64_same (mem : Mem) (addr val : Nat)
    (h : val < 2 ^ 64) :
    readU64 (writeU64 mem addr val) addr = val

/-- Writing a U64 does not affect reads from non-overlapping addresses -/
axiom readU64_writeU64_disjoint (mem : Mem) (rAddr wAddr val : Nat)
    (h : rAddr + 8 ≤ wAddr ∨ wAddr + 8 ≤ rAddr) :
    readU64 (writeU64 mem wAddr val) rAddr = readU64 mem rAddr

/-- Writing a U64 does not affect individual byte reads outside the written range -/
axiom readU8_writeU64_outside (mem : Mem) (bAddr wAddr val : Nat)
    (h : bAddr < wAddr ∨ wAddr + 8 ≤ bAddr) :
    readU8 (writeU64 mem wAddr val) bAddr = readU8 mem bAddr

/-- Writing a U8 does not affect U64 reads from non-overlapping addresses -/
axiom readU64_writeU8_disjoint (mem : Mem) (rAddr wAddr val : Nat)
    (h : wAddr < rAddr ∨ rAddr + 8 ≤ wAddr) :
    readU64 (writeU8 mem wAddr val) rAddr = readU64 mem rAddr

/-! ## Input buffer layout helpers

The Solana runtime serializes accounts into the input buffer with a fixed
layout per account. Offsets are relative to the start of each account record.
The exact absolute offsets depend on preceding account data sizes, so programs
define them as .equ constants. -/

/-- Offsets within a single account record (relative to account start) -/
structure AccountLayout where
  header   : Nat  -- 8 bytes: dup marker, is_signer, is_writable, executable, ...
  key      : Nat  -- 32 bytes: account pubkey
  owner    : Nat  -- 32 bytes: owner program pubkey
  lamports : Nat  -- 8 bytes: lamport balance (u64 LE)
  dataLen  : Nat  -- 8 bytes: account data length (u64 LE)
  data     : Nat  -- variable: account data bytes

/-- Standard account layout (offsets from account start, after the num_accounts u64) -/
def standardAccountLayout : AccountLayout where
  header   := 0x00
  key      := 0x08
  owner    := 0x28
  lamports := 0x48
  dataLen  := 0x50
  data     := 0x58

end QEDGen.Solana.SBPF.Memory
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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated 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: 322kUpdated Claude CodeCodexVerifiedInstall