From 025a099b91f59146e284c5cc6b5f2badacdbda7d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 18:16:13 +0000 Subject: [PATCH 1/4] chore(abi): delete the seven shadow copies of packaged ABI modules (A5) Owner ruling on open question A5: delete the stale copies, salvage the rest. Each file sat at the src/abi/ root outside echidnaabi.ipkg, so nothing type-checked it. Each one was diffed against the packaged module it shadows: BojForeign.idr = Boj/Foreign.idr (body identical) OverlayForeign.idr = Overlay/Foreign.idr (body identical) TentaclesForeign.idr = Tentacles/Foreign.idr (body identical) TypeLLForeign.idr = TypeLL/Foreign.idr (body identical) Types.idr = EchidnaABI/Types.idr (body identical) Layout.idr = EchidnaABI/Layout.idr (body identical) Foreign.idr older EchidnaABI/Foreign.idr: stale module name Echidna.ABI.Foreign, no Result type, AnyPtr callback Comments that named a shadow now name the packaged module: the four generated/abi headers (no generator for them exists in the tree), four Zig FFI sources, the L1 Cap'n Proto handover note and issue echidna-04. Nothing else imported these files. src/rust/corpus/profile.rs matches only on fixture paths under a temporary root, and reports/ are historical snapshots, so neither changes. PROOF-STATUS R2 is updated. CoprocessorForeign and NeSyAssistTesting follow in the next two PRs of this stack. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3 --- docs/PROOF-STATUS.adoc | 15 +- docs/handover/L1-CAPNPROTO-PROMPT.adoc | 2 +- ffi/zig/src/boj.zig | 2 +- ffi/zig/src/main.zig | 4 +- ffi/zig/src/tentacles.zig | 2 +- ffi/zig/src/typell.zig | 2 +- generated/abi/echidna_boj.h | 2 +- generated/abi/echidna_overlay.h | 2 +- generated/abi/echidna_tentacles.h | 2 +- generated/abi/echidna_typell.h | 2 +- issues/echidna-04-ffi-abi-bridge.md | 2 +- src/abi/BojForeign.idr | 271 ---------- src/abi/Foreign.idr | 217 -------- src/abi/Layout.idr | 236 --------- src/abi/OverlayForeign.idr | 522 -------------------- src/abi/TentaclesForeign.idr | 350 ------------- src/abi/TypeLLForeign.idr | 262 ---------- src/abi/Types.idr | 655 ------------------------- 18 files changed, 19 insertions(+), 2531 deletions(-) delete mode 100644 src/abi/BojForeign.idr delete mode 100644 src/abi/Foreign.idr delete mode 100644 src/abi/Layout.idr delete mode 100644 src/abi/OverlayForeign.idr delete mode 100644 src/abi/TentaclesForeign.idr delete mode 100644 src/abi/TypeLLForeign.idr delete mode 100644 src/abi/Types.idr diff --git a/docs/PROOF-STATUS.adoc b/docs/PROOF-STATUS.adoc index 9cf5dfc5..65c0e41c 100644 --- a/docs/PROOF-STATUS.adoc +++ b/docs/PROOF-STATUS.adoc @@ -237,13 +237,14 @@ receipt-time audit, not an enforced property: `+idris2-abi-ci.yml+` greps and `+prim__crash+`, and checks neither `+postulate+` nor `+verification/proofs/idris2/+`. *Limit:* `+EchidnaABI.CapnSchemas+` was outside the package and failed to build; hyperpolymath/echidna#472 fixes it and -gates it. Nine other `+.idr+` files at the `+src/abi/+` root are outside the -package: `+BojForeign+`, `+OverlayForeign+`, `+TentaclesForeign+`, -`+TypeLLForeign+`, `+Types+`, `+Layout+` and `+Foreign+` (shadow copies of -packaged modules), `+CoprocessorForeign+` (an orphan whose module name does not -match its path) and `+NeSyAssistTesting+` (does not parse, and states an -empirical claim rather than a provable one). They carry no row until the owner -decides their fate (open question A5). *Audit 2026-11-09 of +gates it. Two other `+.idr+` files at the `+src/abi/+` root are outside the +package: `+CoprocessorForeign+` (an orphan whose module name does not match its +path) and `+NeSyAssistTesting+` (does not parse, and states an empirical claim +rather than a provable one). They carry no row. Owner ruling on A5: salvage the +first into the package if it type-checks, and move the second to `+tests/+` as +a non-proof fixture. The seven shadow copies of packaged modules +(`+BojForeign+`, `+OverlayForeign+`, `+TentaclesForeign+`, `+TypeLLForeign+`, +`+Types+`, `+Layout+`, `+Foreign+`) are deleted. *Audit 2026-11-09 of `+verification/proofs/idris2/+`:* several modules prove less than their names say: `+TrustLevelSoundness+` holds by definition of a local function that disagrees with Rust; `+DispatchCorrectness+` never mentions diff --git a/docs/handover/L1-CAPNPROTO-PROMPT.adoc b/docs/handover/L1-CAPNPROTO-PROMPT.adoc index 3e5623ad..72b289d8 100644 --- a/docs/handover/L1-CAPNPROTO-PROMPT.adoc +++ b/docs/handover/L1-CAPNPROTO-PROMPT.adoc @@ -52,7 +52,7 @@ wire-drift engine. See open-question #2 resolution below. * `+src/abi/CapnSchemas.idr+` — formal proofs that schema round-trip preserves meaning * Zero `+believe_me+` (per estate rule); constructive proofs only -* Coordinate with `+src/abi/Types.idr+` / `+src/abi/Foreign.idr+` +* Coordinate with `+src/abi/EchidnaABI/Types.idr+` / `+src/abi/EchidnaABI/Foreign.idr+` ==== Zig FFI bridge diff --git a/ffi/zig/src/boj.zig b/ffi/zig/src/boj.zig index bddcda30..7160f04a 100644 --- a/ffi/zig/src/boj.zig +++ b/ffi/zig/src/boj.zig @@ -9,7 +9,7 @@ // running in a BoJ server instance. // // Architecture: -// Idris2 ABI (BojForeign.idr) --> Zig FFI (boj.zig) --> C-ABI exports --> zig adapter (port 7700) +// Idris2 ABI (Boj/Foreign.idr) --> Zig FFI (boj.zig) --> C-ABI exports --> zig adapter (port 7700) // // The BoJ server itself lives at hyperpolymath/boj-server with its own ABI+FFI. // This module is the ECHIDNA-side client bridge. diff --git a/ffi/zig/src/main.zig b/ffi/zig/src/main.zig index 7df0597c..0d8761fa 100644 --- a/ffi/zig/src/main.zig +++ b/ffi/zig/src/main.zig @@ -1,6 +1,6 @@ // ECHIDNA FFI Implementation // -// This module implements the C-compatible FFI declared in src/abi/Foreign.idr +// This module implements the C-compatible FFI declared in src/abi/EchidnaABI/Foreign.idr // All types and layouts must match the Idris2 ABI definitions. // // SPDX-License-Identifier: MPL-2.0 @@ -30,7 +30,7 @@ fn clearError() void { } //============================================================================== -// Core Types (must match src/abi/Types.idr) +// Core Types (must match src/abi/EchidnaABI/Types.idr) //============================================================================== /// Result codes (must match Idris2 Result type) diff --git a/ffi/zig/src/tentacles.zig b/ffi/zig/src/tentacles.zig index fa071d36..c45c9946 100644 --- a/ffi/zig/src/tentacles.zig +++ b/ffi/zig/src/tentacles.zig @@ -8,7 +8,7 @@ // streaming events to external consumers (PanLL, CLI, etc.). // // Architecture: -// Idris2 ABI (TentaclesForeign.idr) --> Zig FFI (tentacles.zig) --> C-ABI --> zig adapter +// Idris2 ABI (Tentacles/Foreign.idr) --> Zig FFI (tentacles.zig) --> C-ABI --> zig adapter // // Each agent maintains: // - Status (idle/busy/error/disabled) diff --git a/ffi/zig/src/typell.zig b/ffi/zig/src/typell.zig index 5f883d44..5fadcea5 100644 --- a/ffi/zig/src/typell.zig +++ b/ffi/zig/src/typell.zig @@ -8,7 +8,7 @@ // type inference, refinement types, and type-level evaluation. // // Architecture: -// Idris2 ABI (TypeLLForeign.idr) --> Zig FFI (typell.zig) --> C-ABI exports --> zig adapter (port 7800) +// Idris2 ABI (TypeLL/Foreign.idr) --> Zig FFI (typell.zig) --> C-ABI exports --> zig adapter (port 7800) const std = @import("std"); const builtin = @import("builtin"); diff --git a/generated/abi/echidna_boj.h b/generated/abi/echidna_boj.h index ae4023ed..d6fe9eda 100644 --- a/generated/abi/echidna_boj.h +++ b/generated/abi/echidna_boj.h @@ -7,7 +7,7 @@ * Provides cartridge management and service discovery for the BoJ runtime. * * Source: ffi/zig/src/boj.zig - * ABI: src/abi/BojForeign.idr + * ABI: src/abi/Boj/Foreign.idr * * DO NOT EDIT — regenerate from the Zig FFI source. */ diff --git a/generated/abi/echidna_overlay.h b/generated/abi/echidna_overlay.h index d4802dfd..5bf8e61e 100644 --- a/generated/abi/echidna_overlay.h +++ b/generated/abi/echidna_overlay.h @@ -7,7 +7,7 @@ * Covers Tor, IPFS, and Ethereum overlay network integrations. * * Source: ffi/zig/src/overlay.zig - * ABI: src/abi/OverlayForeign.idr + * ABI: src/abi/Overlay/Foreign.idr * * DO NOT EDIT — regenerate from the Zig FFI source. */ diff --git a/generated/abi/echidna_tentacles.h b/generated/abi/echidna_tentacles.h index c927a934..dc36d1c6 100644 --- a/generated/abi/echidna_tentacles.h +++ b/generated/abi/echidna_tentacles.h @@ -7,7 +7,7 @@ * Provides compiler agent management, task dispatch, OODA tracking, and events. * * Source: ffi/zig/src/tentacles.zig - * ABI: src/abi/TentaclesForeign.idr + * ABI: src/abi/Tentacles/Foreign.idr * * DO NOT EDIT — regenerate from the Zig FFI source. */ diff --git a/generated/abi/echidna_typell.h b/generated/abi/echidna_typell.h index 924e822f..04f6244f 100644 --- a/generated/abi/echidna_typell.h +++ b/generated/abi/echidna_typell.h @@ -7,7 +7,7 @@ * Provides type checking, inference, refinement, and type-level computation. * * Source: ffi/zig/src/typell.zig - * ABI: src/abi/TypeLLForeign.idr + * ABI: src/abi/TypeLL/Foreign.idr * * DO NOT EDIT — regenerate from the Zig FFI source. */ diff --git a/issues/echidna-04-ffi-abi-bridge.md b/issues/echidna-04-ffi-abi-bridge.md index 79d80c6b..17ce489d 100644 --- a/issues/echidna-04-ffi-abi-bridge.md +++ b/issues/echidna-04-ffi-abi-bridge.md @@ -14,7 +14,7 @@ Write the specification for a C-ABI boundary through which a metaheuristics engi ## Context -- `src/abi/` holds the Idris2 ABI (`echidnaabi.ipkg`, `EchidnaABI/`, `Types.idr`, `Layout.idr`, and per-subsystem `*Foreign.idr` modules such as `CoprocessorForeign.idr`, `OverlayForeign.idr`, `TentaclesForeign.idr`). +- `src/abi/` holds the Idris2 ABI (`echidnaabi.ipkg`, `EchidnaABI/`, and per-subsystem `/Foreign.idr` modules such as `Overlay/Foreign.idr` and `Tentacles/Foreign.idr`). - `ffi/zig/` (`build.zig`, `src/main.zig`, `src/boj.zig`, `src/capnp_bridge.zig`, `src/provers/`) and `src/zig_ffi/` (`chapel_bridge.zig`, `chapel_ffi_exports.h`) are the existing Zig bridges. - `CLAUDE.md` states that Idris2 ABI modules must have zero `believe_me`, zero postulates and zero admits, enforced by `idris2-abi-ci.yml`. The specification must satisfy the same gate. - The Rust side has an existing `src/rust/ffi/` module. Reuse its conventions for pointer ownership and error codes. diff --git a/src/abi/BojForeign.idr b/src/abi/BojForeign.idr deleted file mode 100644 index 6ce38ca0..00000000 --- a/src/abi/BojForeign.idr +++ /dev/null @@ -1,271 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) --- --- ECHIDNA BoJ Client ABI Foreign Function Declarations --- --- Declares all C-compatible functions exported by the BoJ client FFI layer --- (ffi/zig/src/boj.zig) for cartridge management and service discovery. --- --- NO believe-me anywhere. All safety is enforced by types. - -module Boj.Foreign - -%default total - --------------------------------------------------------------------------------- --- Result types --------------------------------------------------------------------------------- - -||| Convert a C int return code to success/failure. -public export -data BojResult : Type where - BojOk : BojResult - BojFailed : (code : Int) -> BojResult - -public export -bojResult : Int -> BojResult -bojResult 0 = BojOk -bojResult n = BojFailed n - -||| Cartridge lifecycle status (matches Zig enum). -public export -data CartridgeStatus = Development | Ready | Deprecated | Faulty - -public export -cartridgeStatusFromInt : Int -> CartridgeStatus -cartridgeStatusFromInt 0 = Development -cartridgeStatusFromInt 1 = Ready -cartridgeStatusFromInt 2 = Deprecated -cartridgeStatusFromInt _ = Faulty - -||| BoJ connection status. -public export -data BojConnectionStatus = BojDisconnected | BojConnecting | BojConnected | BojError String - -public export -bojStatusFromInt : Int -> BojConnectionStatus -bojStatusFromInt 0 = BojDisconnected -bojStatusFromInt 1 = BojConnecting -bojStatusFromInt 2 = BojConnected -bojStatusFromInt _ = BojError "unknown" - -||| String helper -export -%foreign "support:idris2_getString, libidris2_support" -prim__getString : Bits64 -> String - --------------------------------------------------------------------------------- --- Connection Functions --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_connect, libechidna_boj" -prim__bojConnect : Bits64 -> Bits64 -> PrimIO Int - -export -bojConnect : (configPtr : Bits64) -> (configLen : Bits64) -> IO BojResult -bojConnect ptr len = do - rc <- primIO (prim__bojConnect ptr len) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_disconnect, libechidna_boj" -prim__bojDisconnect : PrimIO () - -export -bojDisconnect : IO () -bojDisconnect = primIO prim__bojDisconnect - -export -%foreign "C:echidna_boj_status, libechidna_boj" -prim__bojStatus : PrimIO Int - -export -bojStatus : IO BojConnectionStatus -bojStatus = do - code <- primIO prim__bojStatus - pure (bojStatusFromInt code) - --------------------------------------------------------------------------------- --- Health and Discovery --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_health, libechidna_boj" -prim__bojHealth : Bits64 -> Bits64 -> PrimIO Int - -export -bojHealth : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojHealth outPtr outLen = do - rc <- primIO (prim__bojHealth outPtr outLen) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_list_cartridges, libechidna_boj" -prim__bojListCartridges : Bits64 -> Bits64 -> PrimIO Int - -export -bojListCartridges : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojListCartridges outPtr outLen = do - rc <- primIO (prim__bojListCartridges outPtr outLen) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_get_cartridge, libechidna_boj" -prim__bojGetCartridge : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -bojGetCartridge : (namePtr : Bits64) -> (nameLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojGetCartridge nPtr nLen outPtr outLen = do - rc <- primIO (prim__bojGetCartridge nPtr nLen outPtr outLen) - pure (bojResult rc) - --------------------------------------------------------------------------------- --- Cartridge Management --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_load_cartridge, libechidna_boj" -prim__bojLoadCartridge : Bits64 -> Bits64 -> PrimIO Int - -export -bojLoadCartridge : (namePtr : Bits64) -> (nameLen : Bits64) -> IO BojResult -bojLoadCartridge ptr len = do - rc <- primIO (prim__bojLoadCartridge ptr len) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_unload_cartridge, libechidna_boj" -prim__bojUnloadCartridge : Bits64 -> Bits64 -> PrimIO Int - -export -bojUnloadCartridge : (namePtr : Bits64) -> (nameLen : Bits64) -> IO BojResult -bojUnloadCartridge ptr len = do - rc <- primIO (prim__bojUnloadCartridge ptr len) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_invoke, libechidna_boj" -prim__bojInvoke : Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -bojInvoke : (namePtr : Bits64) -> (nameLen : Bits64) -> (toolPtr : Bits64) -> (toolLen : Bits64) -> (argsPtr : Bits64) -> (argsLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojInvoke nP nL tP tL aP aL oP oL = do - rc <- primIO (prim__bojInvoke nP nL tP tL aP aL oP oL) - pure (bojResult rc) - --------------------------------------------------------------------------------- --- Topology and Federation --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_topology, libechidna_boj" -prim__bojTopology : Bits64 -> Bits64 -> PrimIO Int - -export -bojTopology : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojTopology outPtr outLen = do - rc <- primIO (prim__bojTopology outPtr outLen) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_umoja_status, libechidna_boj" -prim__bojUmojaStatus : Bits64 -> Bits64 -> PrimIO Int - -export -bojUmojaStatus : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO BojResult -bojUmojaStatus outPtr outLen = do - rc <- primIO (prim__bojUmojaStatus outPtr outLen) - pure (bojResult rc) - --------------------------------------------------------------------------------- --- Unified --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_version, libechidna_boj" -prim__bojVersion : PrimIO Bits64 - -export -bojVersion : IO String -bojVersion = do - ptr <- primIO prim__bojVersion - pure (if ptr == 0 then "unknown" else prim__getString ptr) - -export -%foreign "C:echidna_boj_last_error, libechidna_boj" -prim__bojLastError : PrimIO Bits64 - -export -bojLastError : IO (Maybe String) -bojLastError = do - ptr <- primIO prim__bojLastError - pure (if ptr == 0 then Nothing else Just (prim__getString ptr)) - -export -%foreign "C:echidna_boj_cartridge_count, libechidna_boj" -prim__bojCartridgeCount : PrimIO Int - -export -bojCartridgeCount : IO Int -bojCartridgeCount = primIO prim__bojCartridgeCount - --------------------------------------------------------------------------------- --- Callback Registration --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_boj_register_on_status_change, libechidna_boj" -prim__bojRegisterOnStatusChange : Bits64 -> PrimIO Int - -export -registerBojOnStatusChange : (callbackPtr : Bits64) -> IO BojResult -registerBojOnStatusChange ptr = do - rc <- primIO (prim__bojRegisterOnStatusChange ptr) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_register_on_cartridge_change, libechidna_boj" -prim__bojRegisterOnCartridgeChange : Bits64 -> PrimIO Int - -export -registerBojOnCartridgeChange : (callbackPtr : Bits64) -> IO BojResult -registerBojOnCartridgeChange ptr = do - rc <- primIO (prim__bojRegisterOnCartridgeChange ptr) - pure (bojResult rc) - -export -%foreign "C:echidna_boj_unregister_all_callbacks, libechidna_boj" -prim__bojUnregisterAllCallbacks : PrimIO Int - -export -bojUnregisterAllCallbacks : IO BojResult -bojUnregisterAllCallbacks = do - rc <- primIO prim__bojUnregisterAllCallbacks - pure (bojResult rc) - -export -%foreign "C:echidna_boj_callback_count, libechidna_boj" -prim__bojCallbackCount : PrimIO Int - -export -bojCallbackCount : IO Int -bojCallbackCount = primIO prim__bojCallbackCount - --------------------------------------------------------------------------------- --- Error Code Descriptions --------------------------------------------------------------------------------- - -public export -bojErrorDescription : Int -> String -bojErrorDescription 0 = "Success" -bojErrorDescription (-200) = "Not connected: BoJ server not connected" -bojErrorDescription (-201) = "Server unavailable: BoJ server not reachable" -bojErrorDescription (-202) = "Cartridge not found" -bojErrorDescription (-203) = "Cartridge not ready: status is not Ready" -bojErrorDescription (-204) = "Invoke failed: cartridge tool invocation error" -bojErrorDescription (-205) = "Invalid argument" -bojErrorDescription (-206) = "Buffer too small" -bojErrorDescription (-207) = "Timeout" -bojErrorDescription (-299) = "Unknown BoJ error" -bojErrorDescription n = "Unrecognised error code: " ++ show n diff --git a/src/abi/Foreign.idr b/src/abi/Foreign.idr deleted file mode 100644 index 76b9dba5..00000000 --- a/src/abi/Foreign.idr +++ /dev/null @@ -1,217 +0,0 @@ -||| SPDX-License-Identifier: MPL-2.0 -||| Foreign Function Interface Declarations for ECHIDNA -||| -||| This module declares all C-compatible functions that will be -||| implemented in the Zig FFI layer. -||| -||| All functions are declared here with type signatures and safety proofs. -||| Implementations live in ffi/zig/ - -module Echidna.ABI.Foreign - -import Echidna.ABI.Types -import Echidna.ABI.Layout - -%default total - --------------------------------------------------------------------------------- --- Library Lifecycle --------------------------------------------------------------------------------- - -||| Initialize the library -||| Returns a handle to the library instance, or Nothing on failure -export -%foreign "C:echidna_init, libechidna" -prim__init : PrimIO Bits64 - -||| Safe wrapper for library initialization -export -init : IO (Maybe Handle) -init = do - ptr <- primIO prim__init - pure (createHandle ptr) - -||| Clean up library resources -export -%foreign "C:echidna_free, libechidna" -prim__free : Bits64 -> PrimIO () - -||| Safe wrapper for cleanup -export -free : Handle -> IO () -free h = primIO (prim__free (handlePtr h)) - --------------------------------------------------------------------------------- --- Core Operations --------------------------------------------------------------------------------- - -||| Example operation: process data -export -%foreign "C:echidna_process, libechidna" -prim__process : Bits64 -> Bits32 -> PrimIO Bits32 - -||| Safe wrapper with error handling -export -process : Handle -> Bits32 -> IO (Either Result Bits32) -process h input = do - result <- primIO (prim__process (handlePtr h) input) - pure $ case result of - 0 => Left Error - n => Right n - --------------------------------------------------------------------------------- --- String Operations --------------------------------------------------------------------------------- - -||| Convert C string to Idris String -export -%foreign "support:idris2_getString, libidris2_support" -prim__getString : Bits64 -> String - -||| Free C string -export -%foreign "C:echidna_free_string, libechidna" -prim__freeString : Bits64 -> PrimIO () - -||| Get string result from library -export -%foreign "C:echidna_get_string, libechidna" -prim__getResult : Bits64 -> PrimIO Bits64 - -||| Safe string getter -export -getString : Handle -> IO (Maybe String) -getString h = do - ptr <- primIO (prim__getResult (handlePtr h)) - if ptr == 0 - then pure Nothing - else do - let str = prim__getString ptr - primIO (prim__freeString ptr) - pure (Just str) - --------------------------------------------------------------------------------- --- Array/Buffer Operations --------------------------------------------------------------------------------- - -||| Process array data -export -%foreign "C:echidna_process_array, libechidna" -prim__processArray : Bits64 -> Bits64 -> Bits32 -> PrimIO Bits32 - -||| Safe array processor -export -processArray : Handle -> (buffer : Bits64) -> (len : Bits32) -> IO (Either Result ()) -processArray h buf len = do - result <- primIO (prim__processArray (handlePtr h) buf len) - pure $ case resultFromInt result of - Just Ok => Right () - Just err => Left err - Nothing => Left Error - where - resultFromInt : Bits32 -> Maybe Result - resultFromInt 0 = Just Ok - resultFromInt 1 = Just Error - resultFromInt 2 = Just InvalidParam - resultFromInt 3 = Just OutOfMemory - resultFromInt 4 = Just NullPointer - resultFromInt _ = Nothing - --------------------------------------------------------------------------------- --- Error Handling --------------------------------------------------------------------------------- - -||| Get last error message -export -%foreign "C:echidna_last_error, libechidna" -prim__lastError : PrimIO Bits64 - -||| Retrieve last error as string -export -lastError : IO (Maybe String) -lastError = do - ptr <- primIO prim__lastError - if ptr == 0 - then pure Nothing - else pure (Just (prim__getString ptr)) - -||| Get error description for result code -export -errorDescription : Result -> String -errorDescription Ok = "Success" -errorDescription Error = "Generic error" -errorDescription InvalidParam = "Invalid parameter" -errorDescription OutOfMemory = "Out of memory" -errorDescription NullPointer = "Null pointer" - --------------------------------------------------------------------------------- --- Version Information --------------------------------------------------------------------------------- - -||| Get library version -export -%foreign "C:echidna_version, libechidna" -prim__version : PrimIO Bits64 - -||| Get version as string -export -version : IO String -version = do - ptr <- primIO prim__version - pure (prim__getString ptr) - -||| Get library build info -export -%foreign "C:echidna_build_info, libechidna" -prim__buildInfo : PrimIO Bits64 - -||| Get build information -export -buildInfo : IO String -buildInfo = do - ptr <- primIO prim__buildInfo - pure (prim__getString ptr) - --------------------------------------------------------------------------------- --- Callback Support --------------------------------------------------------------------------------- - -||| Callback function type (C ABI) -public export -Callback : Type -Callback = Bits64 -> Bits32 -> Bits32 - -||| Register a callback -export -%foreign "C:echidna_register_callback, libechidna" -prim__registerCallback : Bits64 -> AnyPtr -> PrimIO Bits32 - -||| Safe callback registration -export -registerCallback : Handle -> Callback -> IO (Either Result ()) -registerCallback h cb = do - result <- primIO (prim__registerCallback (handlePtr h) (cast cb)) - pure $ case resultFromInt result of - Just Ok => Right () - Just err => Left err - Nothing => Left Error - where - resultFromInt : Bits32 -> Maybe Result - resultFromInt 0 = Just Ok - resultFromInt _ = Just Error - --------------------------------------------------------------------------------- --- Utility Functions --------------------------------------------------------------------------------- - -||| Check if library is initialized -export -%foreign "C:echidna_is_initialized, libechidna" -prim__isInitialized : Bits64 -> PrimIO Bits32 - -||| Check initialization status -export -isInitialized : Handle -> IO Bool -isInitialized h = do - result <- primIO (prim__isInitialized (handlePtr h)) - pure (result /= 0) diff --git a/src/abi/Layout.idr b/src/abi/Layout.idr deleted file mode 100644 index 08f7771b..00000000 --- a/src/abi/Layout.idr +++ /dev/null @@ -1,236 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell - -||| ECHIDNA ABI Memory Layout Proofs -||| -||| Formal proofs about memory layout, alignment, and padding for the -||| C-compatible FFI structs defined in src/rust/ffi/mod.rs. Every layout -||| assertion is backed by a constructive proof (no believe-me). -||| -||| Reference structs (Rust repr(C)): -||| FfiStringSlice — ptr(8) + len(8) = 16 bytes, align 8 -||| FfiOwnedString — ptr(8) + len(8) + cap(8) = 24 bytes, align 8 -||| FfiSerializedTerm — kind(1) + pad(3) + dlen(4) + dptr(8) = 16 bytes, align 8 -||| FfiProverConfig — exec_path(16) + lib_ptrs(8) + lib_len(8) + timeout(8) + neural(1) + pad(7) = 48 bytes, align 8 -||| FfiTactic — kind(1) + pad(3) + arg_len(4) + arg(8) = 16 bytes, align 8 -||| FfiTacticResult — kind(1) + pad(3) + msg_len(4) + msg(8) + state(8) = 24 bytes, align 8 - -module EchidnaABI.Layout - -import EchidnaABI.Types -import Data.Vect -import Data.So - -%default total - --------------------------------------------------------------------------------- --- Alignment Utilities --------------------------------------------------------------------------------- - -||| Calculate padding needed to reach the next alignment boundary -public export -paddingFor : (offset : Nat) -> (align : Nat) -> {auto 0 ok : So (align > 0)} -> Nat -paddingFor offset align = - let remainder = offset `mod` align - in if remainder == 0 - then 0 - else minus align remainder - -||| Round up to the next alignment boundary -public export -alignUp : (sz : Nat) -> (align : Nat) -> {auto 0 ok : So (align > 0)} -> Nat -alignUp sz align = sz + paddingFor sz align - -||| Proof that alignUp never shrinks the size -public export -alignUpGe : (s : Nat) -> (a : Nat) -> {auto 0 ok : So (a > 0)} -> LTE s (alignUp s a) -alignUpGe s a = lteAddRight s - --------------------------------------------------------------------------------- --- Struct Field Descriptors --------------------------------------------------------------------------------- - -||| A field in a C struct with its byte offset, byte size, and alignment -public export -record Field where - constructor MkField - name : String - offset : Nat - size : Nat - alignment : Nat - -||| The byte offset immediately after a field -public export -fieldEnd : Field -> Nat -fieldEnd f = f.offset + f.size - --------------------------------------------------------------------------------- --- Divisibility and Verified Layout --------------------------------------------------------------------------------- - -||| Divisibility witness: proof that a = k * b for some k. -||| Used to prove struct sizes are multiples of their alignment. -public export -data DivisibleBy : (a : Nat) -> (b : Nat) -> Type where - MkDivisible : {k : Nat} -> a = k * b -> DivisibleBy a b - -||| A verified struct layout: fields + size + alignment + proof that -||| the total size is a multiple of the alignment. The proof is checked -||| at construction time via Refl, ensuring correctness without believe-me. -public export -record VerifiedLayout (n : Nat) where - constructor MkVerifiedLayout - fields : Vect n Field - totalSize : Nat - structAlign : Nat - 0 sizeOk : DivisibleBy totalSize structAlign - --------------------------------------------------------------------------------- --- FfiStringSlice Layout --- Rust: #[repr(C)] struct FfiStringSlice { ptr: *const u8, len: usize } --- On 64-bit: ptr at offset 0 (8 bytes), len at offset 8 (8 bytes) --- Total: 16 bytes, alignment: 8 --- Proof: 16 = 2 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiStringSlice (16 bytes, align 8) -public export -ffiStringSliceLayout : VerifiedLayout 2 -ffiStringSliceLayout = MkVerifiedLayout - [ MkField "ptr" 0 8 8 - , MkField "len" 8 8 8 - ] - 16 8 (MkDivisible {k=2} Refl) - --------------------------------------------------------------------------------- --- FfiOwnedString Layout --- Rust: #[repr(C)] struct FfiOwnedString { ptr: *mut u8, len: usize, capacity: usize } --- On 64-bit: ptr(0,8) + len(8,8) + capacity(16,8) = 24 bytes, align 8 --- Proof: 24 = 3 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiOwnedString (24 bytes, align 8) -public export -ffiOwnedStringLayout : VerifiedLayout 3 -ffiOwnedStringLayout = MkVerifiedLayout - [ MkField "ptr" 0 8 8 - , MkField "len" 8 8 8 - , MkField "capacity" 16 8 8 - ] - 24 8 (MkDivisible {k=3} Refl) - --------------------------------------------------------------------------------- --- FfiSerializedTerm Layout --- Rust: #[repr(C)] struct FfiSerializedTerm { --- kind: FfiTermKind, // u8, offset 0 --- _padding: [u8; 3], // 3 bytes padding, offset 1 --- data_len: u32, // 4 bytes, offset 4 --- data: *const u8, // 8 bytes, offset 8 --- } --- Total: 16 bytes, align 8 --- Proof: 16 = 2 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiSerializedTerm (16 bytes, align 8) -public export -ffiSerializedTermLayout : VerifiedLayout 4 -ffiSerializedTermLayout = MkVerifiedLayout - [ MkField "kind" 0 1 1 - , MkField "_padding" 1 3 1 - , MkField "data_len" 4 4 4 - , MkField "data" 8 8 8 - ] - 16 8 (MkDivisible {k=2} Refl) - --------------------------------------------------------------------------------- --- FfiProverConfig Layout --- Rust: #[repr(C)] struct FfiProverConfig { --- executable_path: FfiStringSlice, // 16 bytes, offset 0 --- library_paths: *const FfiStringSlice, // 8 bytes, offset 16 --- library_paths_len: usize, // 8 bytes, offset 24 --- timeout_ms: u64, // 8 bytes, offset 32 --- neural_enabled: bool, // 1 byte, offset 40 --- _padding: [u8; 7], // 7 bytes, offset 41 --- } --- Total: 48 bytes, align 8 --- Proof: 48 = 6 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiProverConfig (48 bytes, align 8) -public export -ffiProverConfigLayout : VerifiedLayout 6 -ffiProverConfigLayout = MkVerifiedLayout - [ MkField "executable_path" 0 16 8 - , MkField "library_paths" 16 8 8 - , MkField "library_paths_len" 24 8 8 - , MkField "timeout_ms" 32 8 8 - , MkField "neural_enabled" 40 1 1 - , MkField "_padding" 41 7 1 - ] - 48 8 (MkDivisible {k=6} Refl) - --------------------------------------------------------------------------------- --- FfiTactic Layout --- Rust: #[repr(C)] struct FfiTactic { --- kind: FfiTacticKind, // u8, offset 0 --- _padding: [u8; 3], // 3 bytes, offset 1 --- arg_len: u32, // 4 bytes, offset 4 --- arg: *const u8, // 8 bytes, offset 8 --- } --- Total: 16 bytes, align 8 --- Proof: 16 = 2 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiTactic (16 bytes, align 8) -public export -ffiTacticLayout : VerifiedLayout 4 -ffiTacticLayout = MkVerifiedLayout - [ MkField "kind" 0 1 1 - , MkField "_padding" 1 3 1 - , MkField "arg_len" 4 4 4 - , MkField "arg" 8 8 8 - ] - 16 8 (MkDivisible {k=2} Refl) - --------------------------------------------------------------------------------- --- FfiTacticResult Layout --- Rust: #[repr(C)] struct FfiTacticResult { --- kind: FfiTacticResultKind, // u8, offset 0 --- _padding: [u8; 3], // 3 bytes, offset 1 --- message_len: u32, // 4 bytes, offset 4 --- message: *const u8, // 8 bytes, offset 8 --- new_state: *mut c_void, // 8 bytes, offset 16 --- } --- Total: 24 bytes, align 8 --- Proof: 24 = 3 * 8 ✓ --------------------------------------------------------------------------------- - -||| Verified layout for FfiTacticResult (24 bytes, align 8) -public export -ffiTacticResultLayout : VerifiedLayout 5 -ffiTacticResultLayout = MkVerifiedLayout - [ MkField "kind" 0 1 1 - , MkField "_padding" 1 3 1 - , MkField "message_len" 4 4 4 - , MkField "message" 8 8 8 - , MkField "new_state" 16 8 8 - ] - 24 8 (MkDivisible {k=3} Refl) - --------------------------------------------------------------------------------- --- Platform-Specific Size Assertions --------------------------------------------------------------------------------- - -||| On 64-bit platforms, pointers are 8 bytes -public export -ptrSize64 : (p : Platform) -> Not (p = WASM) -> ptrSize p = 64 -ptrSize64 Linux contra = Refl -ptrSize64 Windows contra = Refl -ptrSize64 MacOS contra = Refl -ptrSize64 BSD contra = Refl -ptrSize64 WASM contra = absurd (contra Refl) - -||| On WASM, pointers are 4 bytes (32-bit) -public export -ptrSizeWASM : ptrSize WASM = 32 -ptrSizeWASM = Refl diff --git a/src/abi/OverlayForeign.idr b/src/abi/OverlayForeign.idr deleted file mode 100644 index 613f12f8..00000000 --- a/src/abi/OverlayForeign.idr +++ /dev/null @@ -1,522 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) --- --- ECHIDNA Overlay ABI Foreign Function Declarations --- --- Declares all C-compatible functions exported by the overlay FFI layer --- (ffi/zig/src/overlay.zig) for Tor, IPFS, and Ethereum overlay networks. --- --- Every FFI function has: --- 1. A raw PrimIO declaration matching the C symbol --- 2. A safe Idris2 wrapper with proper error handling --- 3. Return type mapped to OverlayStatus or Int (0 = success, negative = error) --- --- NO believe-me anywhere. All safety is enforced by types. - -module Overlay.Foreign - -import Overlay - -%default total - --------------------------------------------------------------------------------- --- Helper: interpret overlay error codes --------------------------------------------------------------------------------- - -||| Convert a C int return code to a success/failure result. -||| 0 = success, negative = error code from OverlayError enum. -public export -data OverlayResult : Type where - OverlayOk : OverlayResult - OverlayFailed : (code : Int) -> OverlayResult - -||| Interpret an FFI return code -public export -overlayResult : Int -> OverlayResult -overlayResult 0 = OverlayOk -overlayResult n = OverlayFailed n - -||| Convert raw status int to OverlayStatus -public export -overlayStatusFromInt : Int -> OverlayStatus -overlayStatusFromInt 0 = OverlayDisconnected -overlayStatusFromInt 1 = OverlayConnecting -overlayStatusFromInt 2 = OverlayConnected -overlayStatusFromInt _ = OverlayError "unknown" - -||| String helper (reuse from Foreign.idr pattern) -export -%foreign "support:idris2_getString, libidris2_support" -prim__getString : Bits64 -> String - --------------------------------------------------------------------------------- --- Unified Overlay Functions --------------------------------------------------------------------------------- - -||| Get overlay module version string. -||| C: const char* echidna_overlay_version(void); -export -%foreign "C:echidna_overlay_version, libechidna_overlay" -prim__overlayVersion : PrimIO Bits64 - -||| Safe wrapper: overlay version -export -overlayVersion : IO String -overlayVersion = do - ptr <- primIO prim__overlayVersion - pure (if ptr == 0 then "unknown" else prim__getString ptr) - -||| Get overlay kind name. -||| C: const char* echidna_overlay_kind_name(int kind); -export -%foreign "C:echidna_overlay_kind_name, libechidna_overlay" -prim__overlayKindName : Int -> PrimIO Bits64 - -||| Safe wrapper: kind name -export -overlayKindName : OverlayKind -> IO String -overlayKindName kind = do - ptr <- primIO (prim__overlayKindName (overlayKindToInt kind)) - pure (if ptr == 0 then "Unknown" else prim__getString ptr) - -||| Get last overlay error message. -||| C: const char* echidna_overlay_last_error(void); -export -%foreign "C:echidna_overlay_last_error, libechidna_overlay" -prim__overlayLastError : PrimIO Bits64 - -||| Safe wrapper: last error -export -overlayLastError : IO (Maybe String) -overlayLastError = do - ptr <- primIO prim__overlayLastError - pure (if ptr == 0 then Nothing else Just (prim__getString ptr)) - --------------------------------------------------------------------------------- --- Tor Foreign Functions --------------------------------------------------------------------------------- - -||| Connect to Tor control port. -||| C: int echidna_tor_connect(const uint8_t* config_ptr, size_t config_len); -export -%foreign "C:echidna_tor_connect, libechidna_overlay" -prim__torConnect : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: connect to Tor -export -torConnect : (configPtr : Bits64) -> (configLen : Bits64) -> IO OverlayResult -torConnect ptr len = do - rc <- primIO (prim__torConnect ptr len) - pure (overlayResult rc) - -||| Disconnect from Tor. -||| C: void echidna_tor_disconnect(void); -export -%foreign "C:echidna_tor_disconnect, libechidna_overlay" -prim__torDisconnect : PrimIO () - -||| Safe wrapper: disconnect from Tor -export -torDisconnect : IO () -torDisconnect = primIO prim__torDisconnect - -||| Create a Tor hidden service. -||| C: int echidna_tor_create_hidden_service(int port, int target_port, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_tor_create_hidden_service, libechidna_overlay" -prim__torCreateHiddenService : Int -> Int -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: create hidden service -export -torCreateHiddenService : (port : Int) -> (targetPort : Int) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -torCreateHiddenService port tp outPtr outLenPtr = do - rc <- primIO (prim__torCreateHiddenService port tp outPtr outLenPtr) - pure (overlayResult rc) - -||| Destroy a Tor hidden service. -||| C: int echidna_tor_destroy_hidden_service(const uint8_t* onion_ptr, size_t onion_len); -export -%foreign "C:echidna_tor_destroy_hidden_service, libechidna_overlay" -prim__torDestroyHiddenService : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: destroy hidden service -export -torDestroyHiddenService : (onionPtr : Bits64) -> (onionLen : Bits64) -> IO OverlayResult -torDestroyHiddenService ptr len = do - rc <- primIO (prim__torDestroyHiddenService ptr len) - pure (overlayResult rc) - -||| Get Tor circuit information. -||| C: int echidna_tor_get_circuit(int circuit_id, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_tor_get_circuit, libechidna_overlay" -prim__torGetCircuit : Int -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: get circuit -export -torGetCircuit : (circuitId : Int) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -torGetCircuit cid outPtr outLen = do - rc <- primIO (prim__torGetCircuit cid outPtr outLen) - pure (overlayResult rc) - -||| List all active Tor circuits. -||| C: int echidna_tor_list_circuits(uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_tor_list_circuits, libechidna_overlay" -prim__torListCircuits : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: list circuits -export -torListCircuits : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -torListCircuits outPtr outLen = do - rc <- primIO (prim__torListCircuits outPtr outLen) - pure (overlayResult rc) - -||| Resolve a hostname through Tor. -||| C: int echidna_tor_resolve(const uint8_t* hostname_ptr, size_t hostname_len, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_tor_resolve, libechidna_overlay" -prim__torResolve : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: resolve via Tor -export -torResolve : (hostnamePtr : Bits64) -> (hostnameLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -torResolve hPtr hLen outPtr outLen = do - rc <- primIO (prim__torResolve hPtr hLen outPtr outLen) - pure (overlayResult rc) - -||| Get Tor connection status. -||| C: int echidna_tor_status(void); -export -%foreign "C:echidna_tor_status, libechidna_overlay" -prim__torStatus : PrimIO Int - -||| Safe wrapper: Tor status -export -torStatus : IO OverlayStatus -torStatus = do - code <- primIO prim__torStatus - pure (overlayStatusFromInt code) - -||| Get count of active hidden services. -||| C: int echidna_tor_hidden_service_count(void); -export -%foreign "C:echidna_tor_hidden_service_count, libechidna_overlay" -prim__torHiddenServiceCount : PrimIO Int - -||| Safe wrapper: hidden service count -export -torHiddenServiceCount : IO Int -torHiddenServiceCount = primIO prim__torHiddenServiceCount - --------------------------------------------------------------------------------- --- IPFS Foreign Functions --------------------------------------------------------------------------------- - -||| Connect to IPFS. -||| C: int echidna_ipfs_connect(const uint8_t* config_ptr, size_t config_len); -export -%foreign "C:echidna_ipfs_connect, libechidna_overlay" -prim__ipfsConnect : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: connect to IPFS -export -ipfsConnect : (configPtr : Bits64) -> (configLen : Bits64) -> IO OverlayResult -ipfsConnect ptr len = do - rc <- primIO (prim__ipfsConnect ptr len) - pure (overlayResult rc) - -||| Disconnect from IPFS. -||| C: void echidna_ipfs_disconnect(void); -export -%foreign "C:echidna_ipfs_disconnect, libechidna_overlay" -prim__ipfsDisconnect : PrimIO () - -||| Safe wrapper: disconnect from IPFS -export -ipfsDisconnect : IO () -ipfsDisconnect = primIO prim__ipfsDisconnect - -||| Add content to IPFS. -||| C: int echidna_ipfs_add(const uint8_t* data_ptr, size_t data_len, uint8_t* out_cid_ptr, size_t* out_cid_len); -export -%foreign "C:echidna_ipfs_add, libechidna_overlay" -prim__ipfsAdd : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: add content to IPFS -export -ipfsAdd : (dataPtr : Bits64) -> (dataLen : Bits64) -> (outCidPtr : Bits64) -> (outCidLenPtr : Bits64) -> IO OverlayResult -ipfsAdd dPtr dLen cPtr cLen = do - rc <- primIO (prim__ipfsAdd dPtr dLen cPtr cLen) - pure (overlayResult rc) - -||| Retrieve content from IPFS. -||| C: int echidna_ipfs_cat(const uint8_t* cid_ptr, size_t cid_len, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_ipfs_cat, libechidna_overlay" -prim__ipfsCat : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: cat content from IPFS -export -ipfsCat : (cidPtr : Bits64) -> (cidLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -ipfsCat cPtr cLen outPtr outLen = do - rc <- primIO (prim__ipfsCat cPtr cLen outPtr outLen) - pure (overlayResult rc) - -||| Pin content on IPFS. -||| C: int echidna_ipfs_pin(const uint8_t* cid_ptr, size_t cid_len); -export -%foreign "C:echidna_ipfs_pin, libechidna_overlay" -prim__ipfsPin : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: pin content -export -ipfsPin : (cidPtr : Bits64) -> (cidLen : Bits64) -> IO OverlayResult -ipfsPin ptr len = do - rc <- primIO (prim__ipfsPin ptr len) - pure (overlayResult rc) - -||| Unpin content from IPFS. -||| C: int echidna_ipfs_unpin(const uint8_t* cid_ptr, size_t cid_len); -export -%foreign "C:echidna_ipfs_unpin, libechidna_overlay" -prim__ipfsUnpin : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: unpin content -export -ipfsUnpin : (cidPtr : Bits64) -> (cidLen : Bits64) -> IO OverlayResult -ipfsUnpin ptr len = do - rc <- primIO (prim__ipfsUnpin ptr len) - pure (overlayResult rc) - -||| Get IPFS DAG node. -||| C: int echidna_ipfs_dag_get(const uint8_t* cid_ptr, size_t cid_len, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_ipfs_dag_get, libechidna_overlay" -prim__ipfsDagGet : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: get DAG node -export -ipfsDagGet : (cidPtr : Bits64) -> (cidLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -ipfsDagGet cPtr cLen outPtr outLen = do - rc <- primIO (prim__ipfsDagGet cPtr cLen outPtr outLen) - pure (overlayResult rc) - -||| Get IPFS connection status. -||| C: int echidna_ipfs_status(void); -export -%foreign "C:echidna_ipfs_status, libechidna_overlay" -prim__ipfsStatus : PrimIO Int - -||| Safe wrapper: IPFS status -export -ipfsStatus : IO OverlayStatus -ipfsStatus = do - code <- primIO prim__ipfsStatus - pure (overlayStatusFromInt code) - -||| Get count of pinned items. -||| C: int echidna_ipfs_pin_count(void); -export -%foreign "C:echidna_ipfs_pin_count, libechidna_overlay" -prim__ipfsPinCount : PrimIO Int - -||| Safe wrapper: pin count -export -ipfsPinCount : IO Int -ipfsPinCount = primIO prim__ipfsPinCount - --------------------------------------------------------------------------------- --- Ethereum Foreign Functions (stubbed — Aerie future use) --------------------------------------------------------------------------------- - -||| Connect to Ethereum. -||| C: int echidna_eth_connect(const uint8_t* config_ptr, size_t config_len); -export -%foreign "C:echidna_eth_connect, libechidna_overlay" -prim__ethConnect : Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: connect to Ethereum -export -ethConnect : (configPtr : Bits64) -> (configLen : Bits64) -> IO OverlayResult -ethConnect ptr len = do - rc <- primIO (prim__ethConnect ptr len) - pure (overlayResult rc) - -||| Disconnect from Ethereum. -||| C: void echidna_eth_disconnect(void); -export -%foreign "C:echidna_eth_disconnect, libechidna_overlay" -prim__ethDisconnect : PrimIO () - -||| Safe wrapper: disconnect from Ethereum -export -ethDisconnect : IO () -ethDisconnect = primIO prim__ethDisconnect - -||| Timestamp proof on-chain. -||| C: int echidna_eth_timestamp_proof(const uint8_t* hash_ptr, size_t hash_len, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_eth_timestamp_proof, libechidna_overlay" -prim__ethTimestampProof : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: timestamp proof -export -ethTimestampProof : (hashPtr : Bits64) -> (hashLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -ethTimestampProof hPtr hLen outPtr outLen = do - rc <- primIO (prim__ethTimestampProof hPtr hLen outPtr outLen) - pure (overlayResult rc) - -||| Verify timestamp on-chain. -||| C: int echidna_eth_verify_timestamp(const uint8_t* tx_ptr, size_t tx_len, uint8_t* out_ptr, size_t* out_len); -export -%foreign "C:echidna_eth_verify_timestamp, libechidna_overlay" -prim__ethVerifyTimestamp : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -||| Safe wrapper: verify timestamp -export -ethVerifyTimestamp : (txHashPtr : Bits64) -> (txHashLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO OverlayResult -ethVerifyTimestamp tPtr tLen outPtr outLen = do - rc <- primIO (prim__ethVerifyTimestamp tPtr tLen outPtr outLen) - pure (overlayResult rc) - -||| Get Ethereum connection status. -||| C: int echidna_eth_status(void); -export -%foreign "C:echidna_eth_status, libechidna_overlay" -prim__ethStatus : PrimIO Int - -||| Safe wrapper: Ethereum status -export -ethStatus : IO OverlayStatus -ethStatus = do - code <- primIO prim__ethStatus - pure (overlayStatusFromInt code) - --------------------------------------------------------------------------------- --- Callback Registration Foreign Functions (Bidirectional ABI ↔ FFI) --------------------------------------------------------------------------------- --- --- These functions register callbacks from the ABI layer into the FFI layer. --- The FFI invokes these callbacks on state changes, errors, and progress events. --- --- Architecture: --- Idris2 ABI (here) → registers callback ptr → Zig FFI stores it → --- Zig fires callback on event → Idris2 handler runs --- --- Callback function pointer types (C calling convention): --- OnStatusChange: (kind: Int, old_status: Int, new_status: Int) -> () --- OnError: (kind: Int, error_code: Int, msg_ptr: Ptr, msg_len: Bits64) -> () --- OnProgress: (kind: Int, op_id: Int, bytes_done: Bits64, bytes_total: Bits64) -> () --- OnCircuitChange: (circuit_id: Int, old_status: Int, new_status: Int) -> () --- OnPinChange: (cid_ptr: Ptr, cid_len: Bits64, old_status: Int, new_status: Int) -> () - -||| Register a callback for overlay status changes. -||| C: int echidna_overlay_register_on_status_change(void* callback); -||| Pass a null pointer (0) to unregister. -export -%foreign "C:echidna_overlay_register_on_status_change, libechidna_overlay" -prim__registerOnStatusChange : Bits64 -> PrimIO Int - -||| Safe wrapper: register status change callback -export -registerOnStatusChange : (callbackPtr : Bits64) -> IO OverlayResult -registerOnStatusChange ptr = do - rc <- primIO (prim__registerOnStatusChange ptr) - pure (overlayResult rc) - -||| Register a callback for overlay errors. -||| C: int echidna_overlay_register_on_error(void* callback); -export -%foreign "C:echidna_overlay_register_on_error, libechidna_overlay" -prim__registerOnError : Bits64 -> PrimIO Int - -||| Safe wrapper: register error callback -export -registerOnError : (callbackPtr : Bits64) -> IO OverlayResult -registerOnError ptr = do - rc <- primIO (prim__registerOnError ptr) - pure (overlayResult rc) - -||| Register a callback for progress events. -||| C: int echidna_overlay_register_on_progress(void* callback); -export -%foreign "C:echidna_overlay_register_on_progress, libechidna_overlay" -prim__registerOnProgress : Bits64 -> PrimIO Int - -||| Safe wrapper: register progress callback -export -registerOnProgress : (callbackPtr : Bits64) -> IO OverlayResult -registerOnProgress ptr = do - rc <- primIO (prim__registerOnProgress ptr) - pure (overlayResult rc) - -||| Register a callback for Tor circuit changes. -||| C: int echidna_overlay_register_on_circuit_change(void* callback); -export -%foreign "C:echidna_overlay_register_on_circuit_change, libechidna_overlay" -prim__registerOnCircuitChange : Bits64 -> PrimIO Int - -||| Safe wrapper: register circuit change callback -export -registerOnCircuitChange : (callbackPtr : Bits64) -> IO OverlayResult -registerOnCircuitChange ptr = do - rc <- primIO (prim__registerOnCircuitChange ptr) - pure (overlayResult rc) - -||| Register a callback for IPFS pin status changes. -||| C: int echidna_overlay_register_on_pin_change(void* callback); -export -%foreign "C:echidna_overlay_register_on_pin_change, libechidna_overlay" -prim__registerOnPinChange : Bits64 -> PrimIO Int - -||| Safe wrapper: register pin change callback -export -registerOnPinChange : (callbackPtr : Bits64) -> IO OverlayResult -registerOnPinChange ptr = do - rc <- primIO (prim__registerOnPinChange ptr) - pure (overlayResult rc) - -||| Unregister all callbacks at once. -||| C: int echidna_overlay_unregister_all_callbacks(void); -export -%foreign "C:echidna_overlay_unregister_all_callbacks, libechidna_overlay" -prim__unregisterAllCallbacks : PrimIO Int - -||| Safe wrapper: unregister all callbacks -export -unregisterAllCallbacks : IO OverlayResult -unregisterAllCallbacks = do - rc <- primIO prim__unregisterAllCallbacks - pure (overlayResult rc) - -||| Get the number of currently registered callbacks (0-5). -||| C: int echidna_overlay_callback_count(void); -export -%foreign "C:echidna_overlay_callback_count, libechidna_overlay" -prim__callbackCount : PrimIO Int - -||| Safe wrapper: callback count -export -callbackCount : IO Int -callbackCount = primIO prim__callbackCount - --------------------------------------------------------------------------------- --- Error Code Descriptions --------------------------------------------------------------------------------- - -||| Human-readable descriptions for overlay error codes -public export -overlayErrorDescription : Int -> String -overlayErrorDescription 0 = "Success" -overlayErrorDescription (-100) = "Not connected: overlay network not connected" -overlayErrorDescription (-101) = "Connection refused: daemon rejected connection" -overlayErrorDescription (-102) = "Timeout: operation timed out" -overlayErrorDescription (-103) = "Invalid argument: parameter was null or out of range" -overlayErrorDescription (-104) = "Not found: requested resource not found" -overlayErrorDescription (-105) = "Buffer too small: output buffer insufficient" -overlayErrorDescription (-106) = "Daemon not running: overlay daemon not available" -overlayErrorDescription (-107) = "Authentication failed: control port auth rejected" -overlayErrorDescription (-108) = "Not implemented: feature not yet available" -overlayErrorDescription (-199) = "Unknown overlay error" -overlayErrorDescription n = "Unrecognised error code: " ++ show n diff --git a/src/abi/TentaclesForeign.idr b/src/abi/TentaclesForeign.idr deleted file mode 100644 index df5bf6a2..00000000 --- a/src/abi/TentaclesForeign.idr +++ /dev/null @@ -1,350 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) --- --- ECHIDNA Tentacles ABI Foreign Function Declarations --- --- Declares all C-compatible functions exported by the Tentacles FFI layer --- (ffi/zig/src/tentacles.zig) for agent management, task dispatch, OODA --- phase tracking, and event streaming. --- --- The 7-Tentacles system maps compiler subsystems to colour-coded agents: --- Red=Parser, Orange=Concurrency, Yellow=TypeSystem, Green=ASTArchitect, --- Blue=Auditor, Indigo=Metaprogrammer, Violet=Governance --- --- NO believe-me anywhere. All safety is enforced by types. - -module Tentacles.Foreign - -%default total - --------------------------------------------------------------------------------- --- Agent identifiers (matching Zig enum) --------------------------------------------------------------------------------- - -||| Tentacle agent colour identifier. -public export -data TentacleId = Red | Orange | Yellow | Green | Blue | Indigo | Violet - -public export -tentacleIdToInt : TentacleId -> Int -tentacleIdToInt Red = 0 -tentacleIdToInt Orange = 1 -tentacleIdToInt Yellow = 2 -tentacleIdToInt Green = 3 -tentacleIdToInt Blue = 4 -tentacleIdToInt Indigo = 5 -tentacleIdToInt Violet = 6 - -public export -tentacleIdFromInt : Int -> Maybe TentacleId -tentacleIdFromInt 0 = Just Red -tentacleIdFromInt 1 = Just Orange -tentacleIdFromInt 2 = Just Yellow -tentacleIdFromInt 3 = Just Green -tentacleIdFromInt 4 = Just Blue -tentacleIdFromInt 5 = Just Indigo -tentacleIdFromInt 6 = Just Violet -tentacleIdFromInt _ = Nothing - -||| OODA loop phase. -public export -data OodaPhase = Observe | Orient | Decide | Act - -public export -oodaPhaseToInt : OodaPhase -> Int -oodaPhaseToInt Observe = 0 -oodaPhaseToInt Orient = 1 -oodaPhaseToInt Decide = 2 -oodaPhaseToInt Act = 3 - -public export -oodaPhaseFromInt : Int -> Maybe OodaPhase -oodaPhaseFromInt 0 = Just Observe -oodaPhaseFromInt 1 = Just Orient -oodaPhaseFromInt 2 = Just Decide -oodaPhaseFromInt 3 = Just Act -oodaPhaseFromInt _ = Nothing - -||| Progressive reveal stage. -public export -data TentacleStage = Cuttle | Squidlet | Duet | Octopus - -public export -stageToInt : TentacleStage -> Int -stageToInt Cuttle = 0 -stageToInt Squidlet = 1 -stageToInt Duet = 2 -stageToInt Octopus = 3 - -public export -stageFromInt : Int -> Maybe TentacleStage -stageFromInt 0 = Just Cuttle -stageFromInt 1 = Just Squidlet -stageFromInt 2 = Just Duet -stageFromInt 3 = Just Octopus -stageFromInt _ = Nothing - --------------------------------------------------------------------------------- --- Result types --------------------------------------------------------------------------------- - -||| Convert a C int return code to success/failure. -public export -data TentaclesResult : Type where - TentaclesOk : TentaclesResult - TentaclesFailed : (code : Int) -> TentaclesResult - -public export -tentaclesResult : Int -> TentaclesResult -tentaclesResult 0 = TentaclesOk -tentaclesResult n = TentaclesFailed n - -||| Agent status values. -public export -data AgentStatus = AgentIdle | AgentBusy | AgentError | AgentDisabled - -public export -agentStatusFromInt : Int -> AgentStatus -agentStatusFromInt 0 = AgentIdle -agentStatusFromInt 1 = AgentBusy -agentStatusFromInt 2 = AgentError -agentStatusFromInt _ = AgentDisabled - -||| String helper -export -%foreign "support:idris2_getString, libidris2_support" -prim__getString : Bits64 -> String - --------------------------------------------------------------------------------- --- Initialisation --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_init, libechidna_tentacles" -prim__tentaclesInit : PrimIO Int - -export -tentaclesInit : IO TentaclesResult -tentaclesInit = do - rc <- primIO prim__tentaclesInit - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_shutdown, libechidna_tentacles" -prim__tentaclesShutdown : PrimIO () - -export -tentaclesShutdown : IO () -tentaclesShutdown = primIO prim__tentaclesShutdown - --------------------------------------------------------------------------------- --- Agent queries --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_agent_status, libechidna_tentacles" -prim__agentStatus : Int -> PrimIO Int - -export -agentStatus : TentacleId -> IO AgentStatus -agentStatus tid = do - code <- primIO (prim__agentStatus (tentacleIdToInt tid)) - pure (agentStatusFromInt code) - -export -%foreign "C:echidna_tentacles_agent_phase, libechidna_tentacles" -prim__agentPhase : Int -> PrimIO Int - -export -agentPhase : TentacleId -> IO (Maybe OodaPhase) -agentPhase tid = do - code <- primIO (prim__agentPhase (tentacleIdToInt tid)) - pure (oodaPhaseFromInt code) - -export -%foreign "C:echidna_tentacles_agent_stage, libechidna_tentacles" -prim__agentStage : Int -> PrimIO Int - -export -agentStage : TentacleId -> IO (Maybe TentacleStage) -agentStage tid = do - code <- primIO (prim__agentStage (tentacleIdToInt tid)) - pure (stageFromInt code) - --------------------------------------------------------------------------------- --- Task dispatch --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_dispatch_task, libechidna_tentacles" -prim__dispatchTask : Int -> Bits64 -> Bits64 -> PrimIO Int - -export -dispatchTask : TentacleId -> (taskPtr : Bits64) -> (taskLen : Bits64) -> IO TentaclesResult -dispatchTask tid ptr len = do - rc <- primIO (prim__dispatchTask (tentacleIdToInt tid) ptr len) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_cancel_task, libechidna_tentacles" -prim__cancelTask : Int -> PrimIO Int - -export -cancelTask : TentacleId -> IO TentaclesResult -cancelTask tid = do - rc <- primIO (prim__cancelTask (tentacleIdToInt tid)) - pure (tentaclesResult rc) - --------------------------------------------------------------------------------- --- Stage management --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_set_global_stage, libechidna_tentacles" -prim__setGlobalStage : Int -> PrimIO Int - -export -setGlobalStage : TentacleStage -> IO TentaclesResult -setGlobalStage stage = do - rc <- primIO (prim__setGlobalStage (stageToInt stage)) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_get_global_stage, libechidna_tentacles" -prim__getGlobalStage : PrimIO Int - -export -getGlobalStage : IO (Maybe TentacleStage) -getGlobalStage = do - code <- primIO prim__getGlobalStage - pure (stageFromInt code) - --------------------------------------------------------------------------------- --- Event polling --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_poll_events, libechidna_tentacles" -prim__pollEvents : Bits64 -> Bits64 -> PrimIO Int - -export -pollEvents : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TentaclesResult -pollEvents outPtr outLen = do - rc <- primIO (prim__pollEvents outPtr outLen) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_event_count, libechidna_tentacles" -prim__eventCount : PrimIO Int - -export -eventCount : IO Int -eventCount = primIO prim__eventCount - --------------------------------------------------------------------------------- --- Broadcast --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_broadcast, libechidna_tentacles" -prim__broadcast : Int -> Bits64 -> Bits64 -> PrimIO Int - -export -broadcast : TentacleId -> (payloadPtr : Bits64) -> (payloadLen : Bits64) -> IO TentaclesResult -broadcast tid ptr len = do - rc <- primIO (prim__broadcast (tentacleIdToInt tid) ptr len) - pure (tentaclesResult rc) - --------------------------------------------------------------------------------- --- Callback registration --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_register_on_phase_change, libechidna_tentacles" -prim__registerOnPhaseChange : Bits64 -> PrimIO Int - -export -registerOnPhaseChange : (callbackPtr : Bits64) -> IO TentaclesResult -registerOnPhaseChange ptr = do - rc <- primIO (prim__registerOnPhaseChange ptr) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_register_on_task_complete, libechidna_tentacles" -prim__registerOnTaskComplete : Bits64 -> PrimIO Int - -export -registerOnTaskComplete : (callbackPtr : Bits64) -> IO TentaclesResult -registerOnTaskComplete ptr = do - rc <- primIO (prim__registerOnTaskComplete ptr) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_register_on_error, libechidna_tentacles" -prim__registerOnError : Bits64 -> PrimIO Int - -export -registerOnError : (callbackPtr : Bits64) -> IO TentaclesResult -registerOnError ptr = do - rc <- primIO (prim__registerOnError ptr) - pure (tentaclesResult rc) - -export -%foreign "C:echidna_tentacles_unregister_all_callbacks, libechidna_tentacles" -prim__unregisterAllCallbacks : PrimIO Int - -export -unregisterAllCallbacks : IO TentaclesResult -unregisterAllCallbacks = do - rc <- primIO prim__unregisterAllCallbacks - pure (tentaclesResult rc) - --------------------------------------------------------------------------------- --- Unified --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_tentacles_version, libechidna_tentacles" -prim__tentaclesVersion : PrimIO Bits64 - -export -tentaclesVersion : IO String -tentaclesVersion = do - ptr <- primIO prim__tentaclesVersion - pure (if ptr == 0 then "unknown" else prim__getString ptr) - -export -%foreign "C:echidna_tentacles_last_error, libechidna_tentacles" -prim__tentaclesLastError : PrimIO Bits64 - -export -tentaclesLastError : IO (Maybe String) -tentaclesLastError = do - ptr <- primIO prim__tentaclesLastError - pure (if ptr == 0 then Nothing else Just (prim__getString ptr)) - -export -%foreign "C:echidna_tentacles_agent_count, libechidna_tentacles" -prim__agentCount : PrimIO Int - -export -agentCount : IO Int -agentCount = primIO prim__agentCount - --------------------------------------------------------------------------------- --- Error Code Descriptions --------------------------------------------------------------------------------- - -public export -tentaclesErrorDescription : Int -> String -tentaclesErrorDescription 0 = "Success" -tentaclesErrorDescription (-300) = "Not initialised: tentacles system not started" -tentaclesErrorDescription (-301) = "Invalid agent: unknown tentacle ID" -tentaclesErrorDescription (-302) = "Agent busy: task already in progress" -tentaclesErrorDescription (-303) = "Agent error: agent in error state" -tentaclesErrorDescription (-304) = "Task failed: task execution error" -tentaclesErrorDescription (-305) = "Invalid stage: unknown stage value" -tentaclesErrorDescription (-306) = "Buffer too small" -tentaclesErrorDescription (-307) = "Broadcast failed" -tentaclesErrorDescription (-399) = "Unknown tentacles error" -tentaclesErrorDescription n = "Unrecognised error code: " ++ show n diff --git a/src/abi/TypeLLForeign.idr b/src/abi/TypeLLForeign.idr deleted file mode 100644 index ffc025bc..00000000 --- a/src/abi/TypeLLForeign.idr +++ /dev/null @@ -1,262 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) --- --- ECHIDNA TypeLL Client ABI Foreign Function Declarations --- --- Declares all C-compatible functions exported by the TypeLL client FFI layer --- (ffi/zig/src/typell.zig) for type checking and type-level computation. --- --- NO believe-me anywhere. All safety is enforced by types. - -module TypeLL.Foreign - -%default total - --------------------------------------------------------------------------------- --- Result types --------------------------------------------------------------------------------- - -public export -data TypeLLResult : Type where - TypeLLOk : TypeLLResult - TypeLLFailed : (code : Int) -> TypeLLResult - -public export -typellResult : Int -> TypeLLResult -typellResult 0 = TypeLLOk -typellResult n = TypeLLFailed n - -||| Type checking result (matches Zig CheckResult enum). -public export -data CheckResultKind = WellTyped | TypeMismatch | UnboundVariable | UniverseInconsistency | OccursCheckFailed | Ambiguous - -public export -checkResultFromInt : Int -> CheckResultKind -checkResultFromInt 0 = WellTyped -checkResultFromInt 1 = TypeMismatch -checkResultFromInt 2 = UnboundVariable -checkResultFromInt 3 = UniverseInconsistency -checkResultFromInt 4 = OccursCheckFailed -checkResultFromInt _ = Ambiguous - -||| Type universe levels. -public export -data UniverseLevel = Type0 | Type1 | Type2 | TypeOmega - -public export -universeFromInt : Int -> UniverseLevel -universeFromInt 0 = Type0 -universeFromInt 1 = Type1 -universeFromInt 2 = Type2 -universeFromInt _ = TypeOmega - -||| TypeLL connection status. -public export -data TypeLLConnectionStatus = TypeLLDisconnected | TypeLLConnecting | TypeLLConnected | TypeLLError String - -public export -typellStatusFromInt : Int -> TypeLLConnectionStatus -typellStatusFromInt 0 = TypeLLDisconnected -typellStatusFromInt 1 = TypeLLConnecting -typellStatusFromInt 2 = TypeLLConnected -typellStatusFromInt _ = TypeLLError "unknown" - -||| String helper -export -%foreign "support:idris2_getString, libidris2_support" -prim__getString : Bits64 -> String - --------------------------------------------------------------------------------- --- Connection Functions --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_typell_connect, libechidna_typell" -prim__typellConnect : Bits64 -> Bits64 -> PrimIO Int - -export -typellConnect : (configPtr : Bits64) -> (configLen : Bits64) -> IO TypeLLResult -typellConnect ptr len = do - rc <- primIO (prim__typellConnect ptr len) - pure (typellResult rc) - -export -%foreign "C:echidna_typell_disconnect, libechidna_typell" -prim__typellDisconnect : PrimIO () - -export -typellDisconnect : IO () -typellDisconnect = primIO prim__typellDisconnect - -export -%foreign "C:echidna_typell_status, libechidna_typell" -prim__typellStatus : PrimIO Int - -export -typellStatus : IO TypeLLConnectionStatus -typellStatus = do - code <- primIO prim__typellStatus - pure (typellStatusFromInt code) - -export -%foreign "C:echidna_typell_health, libechidna_typell" -prim__typellHealth : Bits64 -> Bits64 -> PrimIO Int - -export -typellHealth : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellHealth outPtr outLen = do - rc <- primIO (prim__typellHealth outPtr outLen) - pure (typellResult rc) - --------------------------------------------------------------------------------- --- Type Operations --------------------------------------------------------------------------------- - -||| Type-check an expression. -export -%foreign "C:echidna_typell_check, libechidna_typell" -prim__typellCheck : Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -typellCheck : (exprPtr : Bits64) -> (exprLen : Bits64) -> (ctxPtr : Bits64) -> (ctxLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellCheck eP eL cP cL oP oL = do - rc <- primIO (prim__typellCheck eP eL cP cL oP oL) - pure (typellResult rc) - -||| Infer the type of an expression. -export -%foreign "C:echidna_typell_infer, libechidna_typell" -prim__typellInfer : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -typellInfer : (exprPtr : Bits64) -> (exprLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellInfer eP eL oP oL = do - rc <- primIO (prim__typellInfer eP eL oP oL) - pure (typellResult rc) - -||| Apply refinement types. -export -%foreign "C:echidna_typell_refine, libechidna_typell" -prim__typellRefine : Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -typellRefine : (specPtr : Bits64) -> (specLen : Bits64) -> (consPtr : Bits64) -> (consLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellRefine sP sL cP cL oP oL = do - rc <- primIO (prim__typellRefine sP sL cP cL oP oL) - pure (typellResult rc) - -||| Evaluate a type-level computation. -export -%foreign "C:echidna_typell_compute, libechidna_typell" -prim__typellCompute : Bits64 -> Bits64 -> Bits64 -> Bits64 -> PrimIO Int - -export -typellCompute : (termPtr : Bits64) -> (termLen : Bits64) -> (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellCompute tP tL oP oL = do - rc <- primIO (prim__typellCompute tP tL oP oL) - pure (typellResult rc) - -||| List available type signatures. -export -%foreign "C:echidna_typell_list_signatures, libechidna_typell" -prim__typellListSignatures : Bits64 -> Bits64 -> PrimIO Int - -export -typellListSignatures : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellListSignatures oP oL = do - rc <- primIO (prim__typellListSignatures oP oL) - pure (typellResult rc) - -||| Get type universe hierarchy. -export -%foreign "C:echidna_typell_universes, libechidna_typell" -prim__typellUniverses : Bits64 -> Bits64 -> PrimIO Int - -export -typellUniverses : (outPtr : Bits64) -> (outLenPtr : Bits64) -> IO TypeLLResult -typellUniverses oP oL = do - rc <- primIO (prim__typellUniverses oP oL) - pure (typellResult rc) - --------------------------------------------------------------------------------- --- Unified --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_typell_version, libechidna_typell" -prim__typellVersion : PrimIO Bits64 - -export -typellVersion : IO String -typellVersion = do - ptr <- primIO prim__typellVersion - pure (if ptr == 0 then "unknown" else prim__getString ptr) - -export -%foreign "C:echidna_typell_last_error, libechidna_typell" -prim__typellLastError : PrimIO Bits64 - -export -typellLastError : IO (Maybe String) -typellLastError = do - ptr <- primIO prim__typellLastError - pure (if ptr == 0 then Nothing else Just (prim__getString ptr)) - --------------------------------------------------------------------------------- --- Callback Registration --------------------------------------------------------------------------------- - -export -%foreign "C:echidna_typell_register_on_status_change, libechidna_typell" -prim__typellRegisterOnStatusChange : Bits64 -> PrimIO Int - -export -registerTypeLLOnStatusChange : (callbackPtr : Bits64) -> IO TypeLLResult -registerTypeLLOnStatusChange ptr = do - rc <- primIO (prim__typellRegisterOnStatusChange ptr) - pure (typellResult rc) - -export -%foreign "C:echidna_typell_register_on_check_complete, libechidna_typell" -prim__typellRegisterOnCheckComplete : Bits64 -> PrimIO Int - -export -registerTypeLLOnCheckComplete : (callbackPtr : Bits64) -> IO TypeLLResult -registerTypeLLOnCheckComplete ptr = do - rc <- primIO (prim__typellRegisterOnCheckComplete ptr) - pure (typellResult rc) - -export -%foreign "C:echidna_typell_unregister_all_callbacks, libechidna_typell" -prim__typellUnregisterAllCallbacks : PrimIO Int - -export -typellUnregisterAllCallbacks : IO TypeLLResult -typellUnregisterAllCallbacks = do - rc <- primIO prim__typellUnregisterAllCallbacks - pure (typellResult rc) - -export -%foreign "C:echidna_typell_callback_count, libechidna_typell" -prim__typellCallbackCount : PrimIO Int - -export -typellCallbackCount : IO Int -typellCallbackCount = primIO prim__typellCallbackCount - --------------------------------------------------------------------------------- --- Error Code Descriptions --------------------------------------------------------------------------------- - -public export -typellErrorDescription : Int -> String -typellErrorDescription 0 = "Success" -typellErrorDescription (-300) = "Not connected: TypeLL server not connected" -typellErrorDescription (-301) = "Type error: expression does not type-check" -typellErrorDescription (-302) = "Parse error: invalid expression syntax" -typellErrorDescription (-303) = "Invalid argument" -typellErrorDescription (-304) = "Buffer too small" -typellErrorDescription (-305) = "Timeout" -typellErrorDescription (-306) = "Not implemented" -typellErrorDescription (-399) = "Unknown TypeLL error" -typellErrorDescription n = "Unrecognised error code: " ++ show n diff --git a/src/abi/Types.idr b/src/abi/Types.idr deleted file mode 100644 index 605deae1..00000000 --- a/src/abi/Types.idr +++ /dev/null @@ -1,655 +0,0 @@ --- SPDX-License-Identifier: MPL-2.0 --- Copyright (c) 2026 Jonathan D.A. Jewell - -||| ECHIDNA ABI Type Definitions -||| -||| Formal type definitions with dependent type proofs for the ECHIDNA -||| theorem proving platform's Application Binary Interface. All types -||| mirror the Rust core (src/rust/core.rs, provers/mod.rs, ffi/mod.rs, -||| dispatch.rs) and carry compile-time correctness guarantees. -||| -||| NO believe-me — every proof is constructive (Refl or witness). - -module EchidnaABI.Types - -import Data.Bits -import Data.So -import Data.Vect -import Data.Fin - -%default total - --------------------------------------------------------------------------------- --- Platform Detection --------------------------------------------------------------------------------- - -||| Supported platforms for the ECHIDNA ABI -public export -data Platform = Linux | Windows | MacOS | BSD | WASM - -||| Compile-time platform detection (default to Linux; override via flags) -public export -thisPlatform : Platform -thisPlatform = Linux - -||| Pointer size in bits for each platform -public export -ptrSize : Platform -> Nat -ptrSize WASM = 32 -ptrSize _ = 64 - -||| C size_t type varies by platform -public export -CSize : Platform -> Type -CSize WASM = Bits32 -CSize _ = Bits64 - --------------------------------------------------------------------------------- --- ProverKind (30 variants across 8 tiers) --------------------------------------------------------------------------------- - -||| All 30 supported theorem prover backends. -||| Matches src/rust/provers/mod.rs ProverKind enum exactly. -public export -data ProverKind - -- Tier 1: Original + SMT solvers - = Agda | Coq | Lean | Isabelle | Z3 | CVC5 - -- Tier 2: "Big Six" completion - | Metamath | HOLLight | Mizar - -- Tier 3: Additional coverage - | PVS | ACL2 - -- Tier 4: Advanced - | HOL4 - -- Extended (Tier 1 capability) - | Idris2 - -- Tier 5: First-Order ATPs - | Vampire | EProver | SPASS | AltErgo - -- Tier 6: Dependent types + effects, auto-active, orchestration - | FStar | Dafny | Why3 - -- Tier 7: Specialised / niche - | TLAPS | Twelf | Nuprl | Minlog | Imandra - -- Tier 8: Constraint solvers - | GLPK | SCIP | MiniZinc | Chuffed | ORTools - -||| Convert ProverKind to its C-compatible u8 discriminant. -||| Matches the kind_from_u8 mapping in src/rust/ffi/mod.rs, extended -||| for the full 30 provers. -public export -proverKindToU8 : ProverKind -> Bits8 -proverKindToU8 Agda = 0 -proverKindToU8 Coq = 1 -proverKindToU8 Lean = 2 -proverKindToU8 Isabelle = 3 -proverKindToU8 Z3 = 4 -proverKindToU8 CVC5 = 5 -proverKindToU8 Metamath = 6 -proverKindToU8 HOLLight = 7 -proverKindToU8 Mizar = 8 -proverKindToU8 PVS = 9 -proverKindToU8 ACL2 = 10 -proverKindToU8 HOL4 = 11 -proverKindToU8 Idris2 = 12 -proverKindToU8 Vampire = 13 -proverKindToU8 EProver = 14 -proverKindToU8 SPASS = 15 -proverKindToU8 AltErgo = 16 -proverKindToU8 FStar = 17 -proverKindToU8 Dafny = 18 -proverKindToU8 Why3 = 19 -proverKindToU8 TLAPS = 20 -proverKindToU8 Twelf = 21 -proverKindToU8 Nuprl = 22 -proverKindToU8 Minlog = 23 -proverKindToU8 Imandra = 24 -proverKindToU8 GLPK = 25 -proverKindToU8 SCIP = 26 -proverKindToU8 MiniZinc = 27 -proverKindToU8 Chuffed = 28 -proverKindToU8 ORTools = 29 - -||| Parse a u8 discriminant back to ProverKind -public export -proverKindFromU8 : Bits8 -> Maybe ProverKind -proverKindFromU8 0 = Just Agda -proverKindFromU8 1 = Just Coq -proverKindFromU8 2 = Just Lean -proverKindFromU8 3 = Just Isabelle -proverKindFromU8 4 = Just Z3 -proverKindFromU8 5 = Just CVC5 -proverKindFromU8 6 = Just Metamath -proverKindFromU8 7 = Just HOLLight -proverKindFromU8 8 = Just Mizar -proverKindFromU8 9 = Just PVS -proverKindFromU8 10 = Just ACL2 -proverKindFromU8 11 = Just HOL4 -proverKindFromU8 12 = Just Idris2 -proverKindFromU8 13 = Just Vampire -proverKindFromU8 14 = Just EProver -proverKindFromU8 15 = Just SPASS -proverKindFromU8 16 = Just AltErgo -proverKindFromU8 17 = Just FStar -proverKindFromU8 18 = Just Dafny -proverKindFromU8 19 = Just Why3 -proverKindFromU8 20 = Just TLAPS -proverKindFromU8 21 = Just Twelf -proverKindFromU8 22 = Just Nuprl -proverKindFromU8 23 = Just Minlog -proverKindFromU8 24 = Just Imandra -proverKindFromU8 25 = Just GLPK -proverKindFromU8 26 = Just SCIP -proverKindFromU8 27 = Just MiniZinc -proverKindFromU8 28 = Just Chuffed -proverKindFromU8 29 = Just ORTools -proverKindFromU8 _ = Nothing - -||| Roundtrip proof: encoding then decoding a ProverKind recovers the -||| original value. -public export -proverKindRoundtrip : (k : ProverKind) -> proverKindFromU8 (proverKindToU8 k) = Just k -proverKindRoundtrip Agda = Refl -proverKindRoundtrip Coq = Refl -proverKindRoundtrip Lean = Refl -proverKindRoundtrip Isabelle = Refl -proverKindRoundtrip Z3 = Refl -proverKindRoundtrip CVC5 = Refl -proverKindRoundtrip Metamath = Refl -proverKindRoundtrip HOLLight = Refl -proverKindRoundtrip Mizar = Refl -proverKindRoundtrip PVS = Refl -proverKindRoundtrip ACL2 = Refl -proverKindRoundtrip HOL4 = Refl -proverKindRoundtrip Idris2 = Refl -proverKindRoundtrip Vampire = Refl -proverKindRoundtrip EProver = Refl -proverKindRoundtrip SPASS = Refl -proverKindRoundtrip AltErgo = Refl -proverKindRoundtrip FStar = Refl -proverKindRoundtrip Dafny = Refl -proverKindRoundtrip Why3 = Refl -proverKindRoundtrip TLAPS = Refl -proverKindRoundtrip Twelf = Refl -proverKindRoundtrip Nuprl = Refl -proverKindRoundtrip Minlog = Refl -proverKindRoundtrip Imandra = Refl -proverKindRoundtrip GLPK = Refl -proverKindRoundtrip SCIP = Refl -proverKindRoundtrip MiniZinc = Refl -proverKindRoundtrip Chuffed = Refl -proverKindRoundtrip ORTools = Refl - -||| Structural equality for ProverKind via ordinal comparison -public export -Eq ProverKind where - a == b = proverKindToU8 a == proverKindToU8 b - --------------------------------------------------------------------------------- --- ProverTier (8 tiers) --------------------------------------------------------------------------------- - -||| Prover capability tiers (1 = highest capability, 8 = constraint solvers). -||| Matches ProverKind::tier() in src/rust/provers/mod.rs. -public export -data ProverTier = Tier1 | Tier2 | Tier3 | Tier4 | Tier5 | Tier6 | Tier7 | Tier8 - -||| Map each prover to its tier. -||| Faithfully reflects the Rust tier() method. -public export -proverTier : ProverKind -> ProverTier -proverTier Agda = Tier1 -proverTier Coq = Tier1 -proverTier Lean = Tier1 -proverTier Isabelle = Tier1 -proverTier Z3 = Tier1 -proverTier CVC5 = Tier1 -proverTier Idris2 = Tier1 -proverTier FStar = Tier1 -proverTier Metamath = Tier2 -proverTier HOLLight = Tier2 -proverTier Mizar = Tier2 -proverTier Dafny = Tier2 -proverTier Why3 = Tier2 -proverTier TLAPS = Tier2 -proverTier Imandra = Tier2 -proverTier PVS = Tier3 -proverTier ACL2 = Tier3 -proverTier HOL4 = Tier4 -proverTier Twelf = Tier4 -proverTier Nuprl = Tier4 -proverTier Minlog = Tier4 -proverTier Vampire = Tier5 -proverTier EProver = Tier5 -proverTier SPASS = Tier5 -proverTier AltErgo = Tier5 -proverTier GLPK = Tier5 -proverTier SCIP = Tier5 -proverTier MiniZinc = Tier5 -proverTier Chuffed = Tier5 -proverTier ORTools = Tier5 --- Note: Rust code assigns some tier 6/7/8 provers to other numeric tiers --- in the tier() method. We follow the COMMENT-based tier groupings for --- semantic accuracy: the code's numeric returns are an implementation --- quirk. The type system here captures the design-intent tiers. - -||| Tier to numeric value for FFI -public export -tierToNat : ProverTier -> Nat -tierToNat Tier1 = 1 -tierToNat Tier2 = 2 -tierToNat Tier3 = 3 -tierToNat Tier4 = 4 -tierToNat Tier5 = 5 -tierToNat Tier6 = 6 -tierToNat Tier7 = 7 -tierToNat Tier8 = 8 - -||| Proof that tier numbers are bounded [1..8] -public export -tierBounded : (t : ProverTier) -> So (tierToNat t >= 1 && tierToNat t <= 8) -tierBounded Tier1 = Oh -tierBounded Tier2 = Oh -tierBounded Tier3 = Oh -tierBounded Tier4 = Oh -tierBounded Tier5 = Oh -tierBounded Tier6 = Oh -tierBounded Tier7 = Oh -tierBounded Tier8 = Oh - --------------------------------------------------------------------------------- --- FfiStatus (matches src/rust/ffi/mod.rs) --------------------------------------------------------------------------------- - -||| FFI status codes matching the Rust FfiStatus enum. -||| Negative values are errors; 0 is success. -public export -data FfiStatus - = FfiOk - | FfiErrorInvalidHandle - | FfiErrorInvalidArgument - | FfiErrorProverNotFound - | FfiErrorParseFailure - | FfiErrorTacticFailure - | FfiErrorVerificationFailure - | FfiErrorOutOfMemory - | FfiErrorTimeout - | FfiErrorNotImplemented - | FfiErrorNotInitialized - | FfiErrorUnknown - -||| Convert FfiStatus to its C-compatible i32 value. -||| Matches the repr(i32) discriminants from Rust. -public export -ffiStatusToI32 : FfiStatus -> Int32 -ffiStatusToI32 FfiOk = 0 -ffiStatusToI32 FfiErrorInvalidHandle = -1 -ffiStatusToI32 FfiErrorInvalidArgument = -2 -ffiStatusToI32 FfiErrorProverNotFound = -3 -ffiStatusToI32 FfiErrorParseFailure = -4 -ffiStatusToI32 FfiErrorTacticFailure = -5 -ffiStatusToI32 FfiErrorVerificationFailure = -6 -ffiStatusToI32 FfiErrorOutOfMemory = -7 -ffiStatusToI32 FfiErrorTimeout = -8 -ffiStatusToI32 FfiErrorNotImplemented = -9 -ffiStatusToI32 FfiErrorNotInitialized = -10 -ffiStatusToI32 FfiErrorUnknown = -99 - -||| Parse an i32 back to FfiStatus -public export -ffiStatusFromI32 : Int32 -> Maybe FfiStatus -ffiStatusFromI32 0 = Just FfiOk -ffiStatusFromI32 (-1) = Just FfiErrorInvalidHandle -ffiStatusFromI32 (-2) = Just FfiErrorInvalidArgument -ffiStatusFromI32 (-3) = Just FfiErrorProverNotFound -ffiStatusFromI32 (-4) = Just FfiErrorParseFailure -ffiStatusFromI32 (-5) = Just FfiErrorTacticFailure -ffiStatusFromI32 (-6) = Just FfiErrorVerificationFailure -ffiStatusFromI32 (-7) = Just FfiErrorOutOfMemory -ffiStatusFromI32 (-8) = Just FfiErrorTimeout -ffiStatusFromI32 (-9) = Just FfiErrorNotImplemented -ffiStatusFromI32 (-10) = Just FfiErrorNotInitialized -ffiStatusFromI32 (-99) = Just FfiErrorUnknown -ffiStatusFromI32 _ = Nothing - -||| Predicate: is this status a success? -public export -isSuccess : FfiStatus -> Bool -isSuccess FfiOk = True -isSuccess _ = False - -||| Predicate: is this status an error? -public export -isError : FfiStatus -> Bool -isError = not . isSuccess - -||| Structural equality for FfiStatus via integer comparison -public export -Eq FfiStatus where - a == b = ffiStatusToI32 a == ffiStatusToI32 b - --------------------------------------------------------------------------------- --- ProofPhase (proof lifecycle state machine) --------------------------------------------------------------------------------- - -||| Phases of the proof verification lifecycle. -||| Models the dispatch pipeline from src/rust/dispatch.rs. -public export -data ProofPhase = Idle | Parsing | Verifying | Dispatching | Complete | Failed - -||| Valid phase transitions (state machine edges). -||| Only certain transitions are allowed; this type encodes the -||| proof that a transition is legitimate. -public export -data ValidTransition : ProofPhase -> ProofPhase -> Type where - ||| An idle prover may begin parsing - IdleToParsing : ValidTransition Idle Parsing - ||| Parsing may succeed and move to verification - ParsingToVerifying : ValidTransition Parsing Verifying - ||| Parsing may fail - ParsingToFailed : ValidTransition Parsing Failed - ||| Verification may proceed to dispatch (cross-check) - VerifyToDispatching : ValidTransition Verifying Dispatching - ||| Verification may complete directly - VerifyToComplete : ValidTransition Verifying Complete - ||| Verification may fail - VerifyToFailed : ValidTransition Verifying Failed - ||| Dispatch may complete - DispatchToComplete : ValidTransition Dispatching Complete - ||| Dispatch may fail - DispatchToFailed : ValidTransition Dispatching Failed - ||| A failed proof may be reset to idle - FailedToIdle : ValidTransition Failed Idle - ||| A completed proof may be reset to idle - CompleteToIdle : ValidTransition Complete Idle - -||| Proof that Idle is a valid starting phase -public export -idleIsInitial : (p : ProofPhase) -> p = Idle -> ValidTransition Idle Parsing -idleIsInitial Idle Refl = IdleToParsing - -||| Proof that Complete and Failed are terminal phases (no forward transitions -||| except reset to Idle) -public export -completeIsTerminal : (next : ProofPhase) -> ValidTransition Complete next -> next = Idle -completeIsTerminal Idle CompleteToIdle = Refl - -public export -failedIsTerminal : (next : ProofPhase) -> ValidTransition Failed next -> next = Idle -failedIsTerminal Idle FailedToIdle = Refl - --------------------------------------------------------------------------------- --- TrustLevel (matches src/rust/verification/confidence.rs) --------------------------------------------------------------------------------- - -||| Trust levels for verified proofs. -||| Matches the 5-level hierarchy from confidence.rs. -public export -data TrustLevel - = Untrusted - | TrustLevel1 -- Large-TCB, unchecked, or dangerous axioms - | TrustLevel2 -- Single prover, no certificate, no dangerous axioms - | TrustLevel3 -- Single prover with proof certificate - | TrustLevel4 -- Small-kernel system with proof certificate - | TrustLevel5 -- Cross-checked by 2+ independent small-kernel systems - -||| Convert TrustLevel to its numeric value -public export -trustLevelToNat : TrustLevel -> Nat -trustLevelToNat Untrusted = 0 -trustLevelToNat TrustLevel1 = 1 -trustLevelToNat TrustLevel2 = 2 -trustLevelToNat TrustLevel3 = 3 -trustLevelToNat TrustLevel4 = 4 -trustLevelToNat TrustLevel5 = 5 - -public export -Eq TrustLevel where - a == b = trustLevelToNat a == trustLevelToNat b - -||| TrustLevel ordering (higher is more trustworthy) -public export -Ord TrustLevel where - compare a b = compare (trustLevelToNat a) (trustLevelToNat b) - -||| Proof that TrustLevel5 is the maximum trust level -public export -trustLevel5IsMax : (t : TrustLevel) -> So (trustLevelToNat t <= 5) -trustLevel5IsMax Untrusted = Oh -trustLevel5IsMax TrustLevel1 = Oh -trustLevel5IsMax TrustLevel2 = Oh -trustLevel5IsMax TrustLevel3 = Oh -trustLevel5IsMax TrustLevel4 = Oh -trustLevel5IsMax TrustLevel5 = Oh - -||| A proof that meets a minimum trust level -public export -data MeetsMinTrust : (minimum : TrustLevel) -> (actual : TrustLevel) -> Type where - TrustMet : So (trustLevelToNat actual >= trustLevelToNat minimum) -> - MeetsMinTrust minimum actual - --------------------------------------------------------------------------------- --- IsUnbreakable (proof witness for soundness) --------------------------------------------------------------------------------- - -||| A proof witness asserting that a verification result cannot be -||| undermined. Requires: the prover is a small-kernel system -||| (Tier 1), the proof was verified, and trust >= Level4. -public export -data IsUnbreakable : ProverKind -> TrustLevel -> Type where - MkUnbreakable : - (prover : ProverKind) -> - (trust : TrustLevel) -> - {auto 0 isTier1 : proverTier prover = Tier1} -> - {auto 0 highTrust : So (trustLevelToNat trust >= 4)} -> - IsUnbreakable prover trust - -||| Lean proofs at TrustLevel4+ are unbreakable -public export -leanIsUnbreakable : IsUnbreakable Lean TrustLevel4 -leanIsUnbreakable = MkUnbreakable Lean TrustLevel4 - -||| Coq proofs at TrustLevel5 are unbreakable -public export -coqIsUnbreakable : IsUnbreakable Coq TrustLevel5 -coqIsUnbreakable = MkUnbreakable Coq TrustLevel5 - --------------------------------------------------------------------------------- --- FfiTermKind (matches src/rust/ffi/mod.rs FfiTermKind) --------------------------------------------------------------------------------- - -||| Term kinds for FFI serialisation. -||| Matches the repr(u8) FfiTermKind enum from Rust. -public export -data FfiTermKind - = TermVar -- 0 - | TermConst -- 1 - | TermApp -- 2 - | TermLambda -- 3 - | TermPi -- 4 - | TermType -- 5 - | TermSort -- 6 - | TermLet -- 7 - | TermMatch -- 8 - | TermFix -- 9 - | TermHole -- 10 - | TermMeta -- 11 - | TermProverSpecific -- 12 - -||| Convert FfiTermKind to u8 -public export -termKindToU8 : FfiTermKind -> Bits8 -termKindToU8 TermVar = 0 -termKindToU8 TermConst = 1 -termKindToU8 TermApp = 2 -termKindToU8 TermLambda = 3 -termKindToU8 TermPi = 4 -termKindToU8 TermType = 5 -termKindToU8 TermSort = 6 -termKindToU8 TermLet = 7 -termKindToU8 TermMatch = 8 -termKindToU8 TermFix = 9 -termKindToU8 TermHole = 10 -termKindToU8 TermMeta = 11 -termKindToU8 TermProverSpecific = 12 - -||| Parse u8 back to FfiTermKind -public export -termKindFromU8 : Bits8 -> Maybe FfiTermKind -termKindFromU8 0 = Just TermVar -termKindFromU8 1 = Just TermConst -termKindFromU8 2 = Just TermApp -termKindFromU8 3 = Just TermLambda -termKindFromU8 4 = Just TermPi -termKindFromU8 5 = Just TermType -termKindFromU8 6 = Just TermSort -termKindFromU8 7 = Just TermLet -termKindFromU8 8 = Just TermMatch -termKindFromU8 9 = Just TermFix -termKindFromU8 10 = Just TermHole -termKindFromU8 11 = Just TermMeta -termKindFromU8 12 = Just TermProverSpecific -termKindFromU8 _ = Nothing - -||| Roundtrip proof for FfiTermKind -public export -termKindRoundtrip : (k : FfiTermKind) -> termKindFromU8 (termKindToU8 k) = Just k -termKindRoundtrip TermVar = Refl -termKindRoundtrip TermConst = Refl -termKindRoundtrip TermApp = Refl -termKindRoundtrip TermLambda = Refl -termKindRoundtrip TermPi = Refl -termKindRoundtrip TermType = Refl -termKindRoundtrip TermSort = Refl -termKindRoundtrip TermLet = Refl -termKindRoundtrip TermMatch = Refl -termKindRoundtrip TermFix = Refl -termKindRoundtrip TermHole = Refl -termKindRoundtrip TermMeta = Refl -termKindRoundtrip TermProverSpecific = Refl - --------------------------------------------------------------------------------- --- FfiTacticKind (matches src/rust/ffi/mod.rs FfiTacticKind) --------------------------------------------------------------------------------- - -||| Tactic kinds for FFI serialisation. -||| Matches the repr(u8) FfiTacticKind enum from Rust. -public export -data FfiTacticKind - = TacticApply -- 0 - | TacticIntro -- 1 - | TacticCases -- 2 - | TacticInduction -- 3 - | TacticRewrite -- 4 - | TacticSimplify -- 5 - | TacticReflexivity -- 6 - | TacticAssumption -- 7 - | TacticExact -- 8 - | TacticCustom -- 9 - -||| Convert FfiTacticKind to u8 -public export -tacticKindToU8 : FfiTacticKind -> Bits8 -tacticKindToU8 TacticApply = 0 -tacticKindToU8 TacticIntro = 1 -tacticKindToU8 TacticCases = 2 -tacticKindToU8 TacticInduction = 3 -tacticKindToU8 TacticRewrite = 4 -tacticKindToU8 TacticSimplify = 5 -tacticKindToU8 TacticReflexivity = 6 -tacticKindToU8 TacticAssumption = 7 -tacticKindToU8 TacticExact = 8 -tacticKindToU8 TacticCustom = 9 - --------------------------------------------------------------------------------- --- Opaque Handle (non-null pointer wrapper) --------------------------------------------------------------------------------- - -||| Opaque handle to a prover instance or proof state. -||| The So constraint witnesses that the pointer is non-zero. -public export -data Handle : Type where - MkHandle : (ptr : Bits64) -> (0 nonNull : So (not (ptr == 0))) -> Handle - -||| Safely create a handle from a raw pointer value. -||| Returns Nothing if the pointer is null (0). -public export -createHandle : Bits64 -> Maybe Handle -createHandle ptr with (choose (not (ptr == 0))) - createHandle ptr | Left prf = Just (MkHandle ptr prf) - createHandle ptr | Right _ = Nothing - -||| Extract the raw pointer from a handle. -||| The caller may pass this to C/Zig FFI functions. -public export -handlePtr : Handle -> Bits64 -handlePtr (MkHandle ptr _) = ptr - -||| Type-level witness: any Handle's pointer is non-null. -||| The proof is erased (quantity 0) so it cannot be extracted at runtime, -||| but it can be used in dependent type signatures to rule out null handles. -public export -0 handleNonNull : (h : Handle) -> So (not (handlePtr h == 0)) -handleNonNull (MkHandle _ prf) = prf - --------------------------------------------------------------------------------- --- ProverConfig (matches ProverConfig in provers/mod.rs + FfiProverConfig) --------------------------------------------------------------------------------- - -||| Configuration for a prover backend, suitable for FFI transfer. -||| Mirrors FfiProverConfig from src/rust/ffi/mod.rs. -public export -record ProverConfig where - constructor MkProverConfig - ||| Timeout in milliseconds (default 30000) - timeout_ms : Bits64 - ||| Whether neural premise selection is enabled - neural_enabled : Bool - ||| Whether to cross-check with additional provers - cross_check : Bool - -||| Default prover configuration (30s timeout, neural enabled, no cross-check) -public export -defaultProverConfig : ProverConfig -defaultProverConfig = MkProverConfig 30000 True False - --------------------------------------------------------------------------------- --- DispatchConfig (matches src/rust/dispatch.rs) --------------------------------------------------------------------------------- - -||| Configuration for the trust-hardening dispatch pipeline. -||| Mirrors DispatchConfig from src/rust/dispatch.rs. -public export -record DispatchConfig where - constructor MkDispatchConfig - ||| Enable cross-checking (portfolio solving) - cross_check : Bool - ||| Minimum trust level required for acceptance - min_trust_level : TrustLevel - ||| Enable axiom usage tracking - track_axioms : Bool - ||| Enable proof certificate generation - generate_certificates : Bool - ||| Timeout per prover in seconds - timeout : Bits64 - -||| Default dispatch configuration -||| Matches DispatchConfig::default() from Rust -public export -defaultDispatchConfig : DispatchConfig -defaultDispatchConfig = MkDispatchConfig False TrustLevel2 True False 300 - --------------------------------------------------------------------------------- --- FfiTacticResultKind (matches src/rust/ffi/mod.rs) --------------------------------------------------------------------------------- - -||| Outcome of applying a tactic through FFI -public export -data FfiTacticResultKind - = TacticSuccess -- 0: tactic applied, new state produced - | TacticError -- 1: tactic failed - | TacticQED -- 2: proof complete - -||| Convert to u8 -public export -tacticResultKindToU8 : FfiTacticResultKind -> Bits8 -tacticResultKindToU8 TacticSuccess = 0 -tacticResultKindToU8 TacticError = 1 -tacticResultKindToU8 TacticQED = 2 From 0bf4a026dbd9616a0abbbe418917ec02755e8f4c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 18:19:03 +0000 Subject: [PATCH 2/4] fix(abi): package Coprocessor.Foreign at its module path (A5) src/abi/CoprocessorForeign.idr declared `module Coprocessor.Foreign`, so its module name did not match its path and the package could not list it. Nothing type-checked it. Owner ruling on A5: salvage it into the package if it type-checks. - git mv to src/abi/Coprocessor/Foreign.idr (contents unchanged; the module declares %default total and uses no believe_me, assert_total or postulate). - echidnaabi.ipkg lists Coprocessor.Foreign, so idris2-abi-ci type-checks it. This PR's ABI job is the type-check. If it fails, the module comes out again rather than being forced through. - w0.sh check 07b now looks for Coprocessor/Foreign.idr. At the old path the check would skip the moved file and pass vacuously. The selftest is updated (68 cases, 0 failed). - The SPARK spec comments and PROOF-STATUS R2 name the new path. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3 --- docs/PROOF-STATUS.adoc | 13 +++++++------ scripts/gates/w0.selftest.sh | 10 +++++----- scripts/gates/w0.sh | 4 ++-- .../Foreign.idr} | 0 src/abi/echidnaabi.ipkg | 1 + src/ada/spark/coprocessor_safety.ads | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) rename src/abi/{CoprocessorForeign.idr => Coprocessor/Foreign.idr} (100%) diff --git a/docs/PROOF-STATUS.adoc b/docs/PROOF-STATUS.adoc index 65c0e41c..394154dc 100644 --- a/docs/PROOF-STATUS.adoc +++ b/docs/PROOF-STATUS.adoc @@ -237,12 +237,13 @@ receipt-time audit, not an enforced property: `+idris2-abi-ci.yml+` greps and `+prim__crash+`, and checks neither `+postulate+` nor `+verification/proofs/idris2/+`. *Limit:* `+EchidnaABI.CapnSchemas+` was outside the package and failed to build; hyperpolymath/echidna#472 fixes it and -gates it. Two other `+.idr+` files at the `+src/abi/+` root are outside the -package: `+CoprocessorForeign+` (an orphan whose module name does not match its -path) and `+NeSyAssistTesting+` (does not parse, and states an empirical claim -rather than a provable one). They carry no row. Owner ruling on A5: salvage the -first into the package if it type-checks, and move the second to `+tests/+` as -a non-proof fixture. The seven shadow copies of packaged modules +gates it. `+Coprocessor.Foreign+` (formerly the orphan `+CoprocessorForeign.idr+`, +whose module name did not match its path) now sits at its module path and is +listed in the package, so the ABI job type-checks it. Its receipt is that job's +first green run after the move. One other `+.idr+` file at the `+src/abi/+` root +is outside the package: `+NeSyAssistTesting+` (does not parse, and states an +empirical claim rather than a provable one). It carries no row. Owner ruling on +A5: move it to `+tests/+` as a non-proof fixture. The seven shadow copies of packaged modules (`+BojForeign+`, `+OverlayForeign+`, `+TentaclesForeign+`, `+TypeLLForeign+`, `+Types+`, `+Layout+`, `+Foreign+`) are deleted. *Audit 2026-11-09 of `+verification/proofs/idris2/+`:* several modules prove less than their names say: diff --git a/scripts/gates/w0.selftest.sh b/scripts/gates/w0.selftest.sh index c041c17a..f418afd8 100755 --- a/scripts/gates/w0.selftest.sh +++ b/scripts/gates/w0.selftest.sh @@ -381,10 +381,10 @@ expect "a claims.json whose root is an array fails 13" FAIL 13-lean-build-record # ----------------------------------------------- check 7: Idris/Agda hygiene new_repo -mkdir -p "$R/.github/workflows" "$R/src/abi/EchidnaABI" "$R/meta-checker/src/Echidna" "$R/scripts/ci" +mkdir -p "$R/.github/workflows" "$R/src/abi/EchidnaABI" "$R/src/abi/Coprocessor" "$R/meta-checker/src/Echidna" "$R/scripts/ci" printf '# for pattern in postulate; do grep\nrun: echo\n' > "$R/.github/workflows/idris2-abi-ci.yml" -printf 'package x\nmodules = EchidnaABI.CapnSchemas, CoprocessorForeign\n' > "$R/src/abi/echidnaabi.ipkg" -touch "$R/src/abi/EchidnaABI/CapnSchemas.idr" "$R/src/abi/CoprocessorForeign.idr" +printf 'package x\nmodules = EchidnaABI.CapnSchemas, Coprocessor.Foreign\n' > "$R/src/abi/echidnaabi.ipkg" +touch "$R/src/abi/EchidnaABI/CapnSchemas.idr" "$R/src/abi/Coprocessor/Foreign.idr" printf 'module Echidna.MetaChecker where\n{- import Echidna.AxiomTrackerCompleteness -}\n' > "$R/meta-checker/src/Echidna/MetaChecker.agda" printf 'run: bash scripts/ci/check-agda.sh\n' > "$R/.github/workflows/agda-meta-checker.yml" printf 'agda --safe src/Echidna/MetaChecker.agda\n' > "$R/scripts/ci/check-agda.sh" @@ -393,11 +393,11 @@ expect "a postulate grep inside a comment fails 07a" FAIL 07a-idris-postulate-gr expect "the one-line modules layout passes 07b" PASS 07b-ipkg-coverage expect "an import inside a block comment fails 07c" FAIL 07c-meta-checker-completeness printf 'run: |\n for pattern in believe_me postulate; do grep -rn "$pattern" src/abi; done\n' > "$R/.github/workflows/idris2-abi-ci.yml" -printf 'package x\nmodules = Main\n , EchidnaABI.CapnSchemas\ndepends = base\n , CoprocessorForeign\n' > "$R/src/abi/echidnaabi.ipkg" +printf 'package x\nmodules = Main\n , EchidnaABI.CapnSchemas\ndepends = base\n , Coprocessor.Foreign\n' > "$R/src/abi/echidnaabi.ipkg" printf 'module Echidna.MetaChecker where\nopen import Echidna.AxiomTrackerCompleteness public\n' > "$R/meta-checker/src/Echidna/MetaChecker.agda" gate 7 expect "a real postulate grep passes 07a" PASS 07a-idris-postulate-grep -expect "a module listed under depends does not count for 07b" FAIL 07b-ipkg-coverage "CoprocessorForeign" +expect "a module listed under depends does not count for 07b" FAIL 07b-ipkg-coverage "Coprocessor.Foreign" expect "a real import checked through check-agda.sh passes 07c" PASS 07c-meta-checker-completeness # Inline `#` comments: a mention after code on the line does not count. diff --git a/scripts/gates/w0.sh b/scripts/gates/w0.sh index b922d5fc..ef9a5337 100755 --- a/scripts/gates/w0.sh +++ b/scripts/gates/w0.sh @@ -421,13 +421,13 @@ check_7() { fail "07b-ipkg-coverage" "$ipkg is missing" else mods=$(ipkg_modules "$ipkg") - for rel in EchidnaABI/CapnSchemas.idr CoprocessorForeign.idr; do + for rel in EchidnaABI/CapnSchemas.idr Coprocessor/Foreign.idr; do [ -f "src/abi/$rel" ] || continue mod=$(sed 's/\.idr$//; s#/#.#g' <<<"$rel") grep -qxF "$mod" <<<"$mods" || missing+=("$mod") done if [ ${#missing[@]} -eq 0 ]; then - pass "07b-ipkg-coverage" "CapnSchemas and CoprocessorForeign are in $ipkg or deleted" + pass "07b-ipkg-coverage" "CapnSchemas and Coprocessor.Foreign are in $ipkg or deleted" else fail "07b-ipkg-coverage" "present but not in $ipkg: ${missing[*]}" fi diff --git a/src/abi/CoprocessorForeign.idr b/src/abi/Coprocessor/Foreign.idr similarity index 100% rename from src/abi/CoprocessorForeign.idr rename to src/abi/Coprocessor/Foreign.idr diff --git a/src/abi/echidnaabi.ipkg b/src/abi/echidnaabi.ipkg index 0ca1eac8..b73bc13d 100644 --- a/src/abi/echidnaabi.ipkg +++ b/src/abi/echidnaabi.ipkg @@ -39,3 +39,4 @@ modules = EchidnaABI.AxiomTracker , Boj.Foreign , TypeLL.Foreign , Tentacles.Foreign + , Coprocessor.Foreign diff --git a/src/ada/spark/coprocessor_safety.ads b/src/ada/spark/coprocessor_safety.ads index d919d801..2fa3dc80 100644 --- a/src/ada/spark/coprocessor_safety.ads +++ b/src/ada/spark/coprocessor_safety.ads @@ -6,7 +6,7 @@ -- -- Mirrors: -- src/rust/coprocessor/trust.rs (CoprocessorTrustTier) --- src/abi/CoprocessorForeign.idr (CoprocessorTrustTier + isSelfSufficient) +-- src/abi/Coprocessor/Foreign.idr (CoprocessorTrustTier + isSelfSufficient) -- -- The two soundness obligations GNATprove discharges automatically: -- @@ -70,7 +70,7 @@ package Coprocessor_Safety with SPARK_Mode => On is -- Encode / Decode -- -- Round-trip property: Decode (Encode (T)) = T for every T. - -- Mirrors `encodeDecodeId` in CoprocessorForeign.idr. + -- Mirrors `encodeDecodeId` in Coprocessor/Foreign.idr. -- ----------------------------------------------------------------------- subtype Tier_Code is Natural range 1 .. 5; From 5d7c8f61ed8548e09dd61fbc891eee5f4ab9fdc1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 18:19:25 +0000 Subject: [PATCH 3/4] chore(abi): move NeSyAssistTesting to a non-proof fixture (A5) src/abi/NeSyAssistTesting.idr does not parse. It states an empirical property of the neural ranker, which no proof can establish. Owner ruling on A5: move it to tests/ as a non-proof fixture. - git mv to tests/fixtures/non-proof/, with a README that says nothing there is a proof or is type-checked. - After this stack, every .idr file under src/abi/ is listed in echidnaabi.ipkg (checked by script). PROOF-STATUS R2 and the wiki Home table say so; the wiki row no longer names CapnSchemas, which #472 packaged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3 --- docs/PROOF-STATUS.adoc | 8 ++++---- docs/wikis/Home.md | 2 +- .../fixtures/non-proof}/NeSyAssistTesting.idr | 0 tests/fixtures/non-proof/README.adoc | 11 +++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) rename {src/abi => tests/fixtures/non-proof}/NeSyAssistTesting.idr (100%) create mode 100644 tests/fixtures/non-proof/README.adoc diff --git a/docs/PROOF-STATUS.adoc b/docs/PROOF-STATUS.adoc index 394154dc..f213f41b 100644 --- a/docs/PROOF-STATUS.adoc +++ b/docs/PROOF-STATUS.adoc @@ -240,10 +240,10 @@ outside the package and failed to build; hyperpolymath/echidna#472 fixes it and gates it. `+Coprocessor.Foreign+` (formerly the orphan `+CoprocessorForeign.idr+`, whose module name did not match its path) now sits at its module path and is listed in the package, so the ABI job type-checks it. Its receipt is that job's -first green run after the move. One other `+.idr+` file at the `+src/abi/+` root -is outside the package: `+NeSyAssistTesting+` (does not parse, and states an -empirical claim rather than a provable one). It carries no row. Owner ruling on -A5: move it to `+tests/+` as a non-proof fixture. The seven shadow copies of packaged modules +first green run after the move. `+NeSyAssistTesting.idr+` (does not parse, and +states an empirical claim rather than a provable one) moved to +`+tests/fixtures/non-proof/+` by owner ruling on A5; it carries no row. Every +`+.idr+` file under `+src/abi/+` is now in the package. The seven shadow copies of packaged modules (`+BojForeign+`, `+OverlayForeign+`, `+TentaclesForeign+`, `+TypeLLForeign+`, `+Types+`, `+Layout+`, `+Foreign+`) are deleted. *Audit 2026-11-09 of `+verification/proofs/idris2/+`:* several modules prove less than their names say: diff --git a/docs/wikis/Home.md b/docs/wikis/Home.md index de773e9c..1657b976 100644 --- a/docs/wikis/Home.md +++ b/docs/wikis/Home.md @@ -46,7 +46,7 @@ commit. | 12 core backends (`GET /api/provers`) | implemented, wired, live-tested (T1/T2 live-prover matrices green) | — | | Wider backend surface (see [`docs/PROVER_COUNT.adoc`](https://github.com/hyperpolymath/echidna/blob/main/docs/PROVER_COUNT.adoc)) | implemented | Tier-4 backends are mock-only; the HP-ecosystem type-checker backends call `typell --discipline` / `tropical-type-check`, which upstream does not provide, so they are **not wired** | | Trust pipeline (integrity, certificates, axioms, confidence, mutation, Pareto, statistics) | implemented, wired into `dispatch.rs`, unit-tested | not proved | -| Idris2 ABI (`src/abi/`) | type-checked, totality-checked (`%default total` in every packaged module), CI-gated (`idris2-abi-ci.yml`, runs when `src/abi/` changes) | `CapnSchemas.idr` and `NeSyAssistTesting.idr` are outside the package, so CI does not check them | +| Idris2 ABI (`src/abi/`) | type-checked, totality-checked (`%default total` in every packaged module), CI-gated (`idris2-abi-ci.yml`, runs when `src/abi/` changes) | Every `.idr` file under `src/abi/` is in the package. `NeSyAssistTesting.idr` (it does not parse) moved to `tests/fixtures/non-proof/` and is not a proof | | Dogfood proof corpus (`proofs/{coq,lean,agda}`) | CI-gated (`dogfood-proofs-ci.yml`) | — | | Agda meta-checker | implemented | its workflow was in `startup_failure` on `main` | | Creusot trust kernel (`crates/echidna-core-creusot`) | annotations **stated**; stable-Rust test mirror runs in CI | **not proved**: no obligation has been discharged; the Creusot job is manual-only | diff --git a/src/abi/NeSyAssistTesting.idr b/tests/fixtures/non-proof/NeSyAssistTesting.idr similarity index 100% rename from src/abi/NeSyAssistTesting.idr rename to tests/fixtures/non-proof/NeSyAssistTesting.idr diff --git a/tests/fixtures/non-proof/README.adoc b/tests/fixtures/non-proof/README.adoc new file mode 100644 index 00000000..26f9c621 --- /dev/null +++ b/tests/fixtures/non-proof/README.adoc @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += Non-proof fixtures + +Files here are kept for reference only. They are *not* proofs, no CI job +type-checks them, and no proof-status row cites them. + +`NeSyAssistTesting.idr`:: Moved from `src/abi/` by owner ruling on open +question A5. It does not parse. It states an empirical property of the neural +ranker, which a proof cannot establish, so it is not a proof obligation. If +that property is wanted, test it against the ranker; do not restore this file +to the ABI package. From b961411c216b51ca19e9a0792213a80dc86ec298 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:40:19 +0000 Subject: [PATCH 4/4] fix(abi): package Coprocessor.Foreign at its module path (A5, 2/3) (#512) ## Why `src/abi/CoprocessorForeign.idr` declared `module Coprocessor.Foreign`. Its module name did not match its path, so the package could not list it, and nothing type-checked it. Owner ruling on A5: put it in the package if it type-checks. ## What - `git mv` to `src/abi/Coprocessor/Foreign.idr`. The contents are unchanged. The module declares `%default total` and uses no `believe_me`, `assert_total` or `postulate`. - `echidnaabi.ipkg` lists `Coprocessor.Foreign`. **This PR's ABI type-check job is the test.** If it fails, the module comes out again; it is not forced through. - `scripts/gates/w0.sh` check 07b now looks for `Coprocessor/Foreign.idr`. At the old path the check would skip the moved file and pass vacuously. The self-test is updated: `bash scripts/gates/w0.selftest.sh` gives 68 cases, 0 failed. - The SPARK spec comments (`coprocessor_safety.ads`) and PROOF-STATUS R2 name the new path. `idris2` is not available in this session, so the type-check is left to CI. Stacked on the A5 PR 1/3 branch (`claude/new-session-th4e9w-a5-shadows`). --- _Generated by [Claude Code](https://claude.ai/code/session_019a95kk88TZ1iegsBK3kox3)_ Co-authored-by: Claude --- docs/PROOF-STATUS.adoc | 13 +++++++------ scripts/gates/w0.selftest.sh | 10 +++++----- scripts/gates/w0.sh | 4 ++-- .../Foreign.idr} | 0 src/abi/echidnaabi.ipkg | 1 + src/ada/spark/coprocessor_safety.ads | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) rename src/abi/{CoprocessorForeign.idr => Coprocessor/Foreign.idr} (100%) diff --git a/docs/PROOF-STATUS.adoc b/docs/PROOF-STATUS.adoc index 65c0e41c..394154dc 100644 --- a/docs/PROOF-STATUS.adoc +++ b/docs/PROOF-STATUS.adoc @@ -237,12 +237,13 @@ receipt-time audit, not an enforced property: `+idris2-abi-ci.yml+` greps and `+prim__crash+`, and checks neither `+postulate+` nor `+verification/proofs/idris2/+`. *Limit:* `+EchidnaABI.CapnSchemas+` was outside the package and failed to build; hyperpolymath/echidna#472 fixes it and -gates it. Two other `+.idr+` files at the `+src/abi/+` root are outside the -package: `+CoprocessorForeign+` (an orphan whose module name does not match its -path) and `+NeSyAssistTesting+` (does not parse, and states an empirical claim -rather than a provable one). They carry no row. Owner ruling on A5: salvage the -first into the package if it type-checks, and move the second to `+tests/+` as -a non-proof fixture. The seven shadow copies of packaged modules +gates it. `+Coprocessor.Foreign+` (formerly the orphan `+CoprocessorForeign.idr+`, +whose module name did not match its path) now sits at its module path and is +listed in the package, so the ABI job type-checks it. Its receipt is that job's +first green run after the move. One other `+.idr+` file at the `+src/abi/+` root +is outside the package: `+NeSyAssistTesting+` (does not parse, and states an +empirical claim rather than a provable one). It carries no row. Owner ruling on +A5: move it to `+tests/+` as a non-proof fixture. The seven shadow copies of packaged modules (`+BojForeign+`, `+OverlayForeign+`, `+TentaclesForeign+`, `+TypeLLForeign+`, `+Types+`, `+Layout+`, `+Foreign+`) are deleted. *Audit 2026-11-09 of `+verification/proofs/idris2/+`:* several modules prove less than their names say: diff --git a/scripts/gates/w0.selftest.sh b/scripts/gates/w0.selftest.sh index c041c17a..f418afd8 100755 --- a/scripts/gates/w0.selftest.sh +++ b/scripts/gates/w0.selftest.sh @@ -381,10 +381,10 @@ expect "a claims.json whose root is an array fails 13" FAIL 13-lean-build-record # ----------------------------------------------- check 7: Idris/Agda hygiene new_repo -mkdir -p "$R/.github/workflows" "$R/src/abi/EchidnaABI" "$R/meta-checker/src/Echidna" "$R/scripts/ci" +mkdir -p "$R/.github/workflows" "$R/src/abi/EchidnaABI" "$R/src/abi/Coprocessor" "$R/meta-checker/src/Echidna" "$R/scripts/ci" printf '# for pattern in postulate; do grep\nrun: echo\n' > "$R/.github/workflows/idris2-abi-ci.yml" -printf 'package x\nmodules = EchidnaABI.CapnSchemas, CoprocessorForeign\n' > "$R/src/abi/echidnaabi.ipkg" -touch "$R/src/abi/EchidnaABI/CapnSchemas.idr" "$R/src/abi/CoprocessorForeign.idr" +printf 'package x\nmodules = EchidnaABI.CapnSchemas, Coprocessor.Foreign\n' > "$R/src/abi/echidnaabi.ipkg" +touch "$R/src/abi/EchidnaABI/CapnSchemas.idr" "$R/src/abi/Coprocessor/Foreign.idr" printf 'module Echidna.MetaChecker where\n{- import Echidna.AxiomTrackerCompleteness -}\n' > "$R/meta-checker/src/Echidna/MetaChecker.agda" printf 'run: bash scripts/ci/check-agda.sh\n' > "$R/.github/workflows/agda-meta-checker.yml" printf 'agda --safe src/Echidna/MetaChecker.agda\n' > "$R/scripts/ci/check-agda.sh" @@ -393,11 +393,11 @@ expect "a postulate grep inside a comment fails 07a" FAIL 07a-idris-postulate-gr expect "the one-line modules layout passes 07b" PASS 07b-ipkg-coverage expect "an import inside a block comment fails 07c" FAIL 07c-meta-checker-completeness printf 'run: |\n for pattern in believe_me postulate; do grep -rn "$pattern" src/abi; done\n' > "$R/.github/workflows/idris2-abi-ci.yml" -printf 'package x\nmodules = Main\n , EchidnaABI.CapnSchemas\ndepends = base\n , CoprocessorForeign\n' > "$R/src/abi/echidnaabi.ipkg" +printf 'package x\nmodules = Main\n , EchidnaABI.CapnSchemas\ndepends = base\n , Coprocessor.Foreign\n' > "$R/src/abi/echidnaabi.ipkg" printf 'module Echidna.MetaChecker where\nopen import Echidna.AxiomTrackerCompleteness public\n' > "$R/meta-checker/src/Echidna/MetaChecker.agda" gate 7 expect "a real postulate grep passes 07a" PASS 07a-idris-postulate-grep -expect "a module listed under depends does not count for 07b" FAIL 07b-ipkg-coverage "CoprocessorForeign" +expect "a module listed under depends does not count for 07b" FAIL 07b-ipkg-coverage "Coprocessor.Foreign" expect "a real import checked through check-agda.sh passes 07c" PASS 07c-meta-checker-completeness # Inline `#` comments: a mention after code on the line does not count. diff --git a/scripts/gates/w0.sh b/scripts/gates/w0.sh index b922d5fc..ef9a5337 100755 --- a/scripts/gates/w0.sh +++ b/scripts/gates/w0.sh @@ -421,13 +421,13 @@ check_7() { fail "07b-ipkg-coverage" "$ipkg is missing" else mods=$(ipkg_modules "$ipkg") - for rel in EchidnaABI/CapnSchemas.idr CoprocessorForeign.idr; do + for rel in EchidnaABI/CapnSchemas.idr Coprocessor/Foreign.idr; do [ -f "src/abi/$rel" ] || continue mod=$(sed 's/\.idr$//; s#/#.#g' <<<"$rel") grep -qxF "$mod" <<<"$mods" || missing+=("$mod") done if [ ${#missing[@]} -eq 0 ]; then - pass "07b-ipkg-coverage" "CapnSchemas and CoprocessorForeign are in $ipkg or deleted" + pass "07b-ipkg-coverage" "CapnSchemas and Coprocessor.Foreign are in $ipkg or deleted" else fail "07b-ipkg-coverage" "present but not in $ipkg: ${missing[*]}" fi diff --git a/src/abi/CoprocessorForeign.idr b/src/abi/Coprocessor/Foreign.idr similarity index 100% rename from src/abi/CoprocessorForeign.idr rename to src/abi/Coprocessor/Foreign.idr diff --git a/src/abi/echidnaabi.ipkg b/src/abi/echidnaabi.ipkg index 0ca1eac8..b73bc13d 100644 --- a/src/abi/echidnaabi.ipkg +++ b/src/abi/echidnaabi.ipkg @@ -39,3 +39,4 @@ modules = EchidnaABI.AxiomTracker , Boj.Foreign , TypeLL.Foreign , Tentacles.Foreign + , Coprocessor.Foreign diff --git a/src/ada/spark/coprocessor_safety.ads b/src/ada/spark/coprocessor_safety.ads index d919d801..2fa3dc80 100644 --- a/src/ada/spark/coprocessor_safety.ads +++ b/src/ada/spark/coprocessor_safety.ads @@ -6,7 +6,7 @@ -- -- Mirrors: -- src/rust/coprocessor/trust.rs (CoprocessorTrustTier) --- src/abi/CoprocessorForeign.idr (CoprocessorTrustTier + isSelfSufficient) +-- src/abi/Coprocessor/Foreign.idr (CoprocessorTrustTier + isSelfSufficient) -- -- The two soundness obligations GNATprove discharges automatically: -- @@ -70,7 +70,7 @@ package Coprocessor_Safety with SPARK_Mode => On is -- Encode / Decode -- -- Round-trip property: Decode (Encode (T)) = T for every T. - -- Mirrors `encodeDecodeId` in CoprocessorForeign.idr. + -- Mirrors `encodeDecodeId` in Coprocessor/Foreign.idr. -- ----------------------------------------------------------------------- subtype Tier_Code is Natural range 1 .. 5;