Files
zeekay b0ba9d20bd p3q: add p3q-c-abi crate — callable C ABI for the strict-PQ verifier
Adds a thin extern "C" shim crate that lets non-Rust callers (luxcpp,
multichain-cpp, cevm precompiles) invoke the strict-PQ verifier
without re-implementing the wire format. Single entry point:

    int32_t p3q_verify(const uint8_t* public_input,
                       uintptr_t      public_input_len,
                       const uint8_t* proof,
                       uintptr_t      proof_len);

The shim:

  * validates (ptr, len) pairs (NULL with non-zero len -> P3Q_ERR_NULL_PTR;
    NULL with len=0 is legal and yields an empty slice),
  * forwards to p3q_verifier::verify,
  * maps every P3qError variant onto a stable integer (P3Q_OK,
    P3Q_REJECTED, P3Q_ERR_PARSE, P3Q_ERR_UNSUPPORTED_PROFILE,
    P3Q_ERR_MERKLE, P3Q_ERR_FRI, P3Q_ERR_STARK, P3Q_ERR_TRANSCRIPT,
    P3Q_ERR_FIELD, P3Q_ERR_CIRCUIT, P3Q_ERR_PANIC),
  * catches every Rust panic at the FFI boundary via
    std::panic::catch_unwind so a panic NEVER crosses into C.

build.rs runs cbindgen on every build to regenerate
crates/p3q-c-abi/include/lux/p3q.h so the header stays in lockstep
with src/lib.rs — never edit it by hand.

The verifier body in p3q v0.0.1 is the documented "not yet
audit-gated" stub: any structurally valid proof currently returns
P3Q_ERR_STARK ("verifier body not yet audit-gated"). When the
audited verifier lands in v0.1.0, callers automatically pick up
real verification — no C ABI churn.

Install path:
    /opt/homebrew/lib/libp3q.dylib        (cdylib, install_name set)
    /opt/homebrew/include/lux/p3q.h       (cbindgen-generated)

unsafe_code is allow'd in this one crate because every extern "C" fn
must reconstitute &[u8] from raw pointers. Each unsafe block is
paired with the catch_unwind boundary; the rest of the p3q workspace
keeps the forbid(unsafe_code) lint.

9/9 unit tests pass (cargo test -p p3q-c-abi --release).
2026-05-30 17:18:08 -07:00

29 lines
949 B
TOML

language = "C"
header = """
// =============================================================================
// lux/p3q.h - P3Q strict-PQ verifier C ABI
// =============================================================================
//
// Generated by cbindgen from p3q-c-abi. DO NOT EDIT — regenerated on
// every build of the crate.
//
// Linkage: -lp3q (cdylib) on macOS/Linux
// -lp3q.lib on Windows
// Headers: /opt/homebrew/include/lux/p3q.h
//
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2024-2026 Lux Industries Inc.
// =============================================================================
"""
include_guard = "LUX_P3Q_H"
autogen_warning = "// WARNING: regenerated by cbindgen — edits will be lost."
no_includes = false
sys_includes = ["stdint.h", "stddef.h"]
[export]
prefix = ""
item_types = ["constants", "globals", "functions"]
[parse]
parse_deps = false