Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ https://semver.org/spec/v2.0.0.html[Semantic Versioning].

==== Fixed

* Source-policy audit (2026-11-15): the audit reported `POLICY CLEAN` for
`@ccall`, `@cfunction`, `llvmcall`, `cglobal`, `unsafe_wrap`,
`pointer_from_objref`, `include`, `include_string`, an alias of a forbidden
call, and `getfield(Base, :unsafe_load)`. It now rejects each of them. Every
name that starts with `unsafe_` is forbidden, in every position. The audit
is still a deny-list by name and is not a proof.
* The K9 badge publisher failed on every push to `main` in minted repos: it
wrote straight to the `governance-badges` branch, and the estate's
`Branch-Floor` ruleset (all branches, `code_coverage` requires a pull
Expand Down
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ passes exist.

* link:docs/architecture/APODEIXIS-VERIFICATION-DESIGN.adoc[Verification architecture] — hybrid frontend, four numeric tiers, memory discipline, FFI seam, worked example, and proof lifecycle.
* link:docs/architecture/APODEIXIS-MVP-IMPLEMENTATION-PLAN.adoc[MVP implementation plan] — existing package slice, ordered implementation work, and acceptance gates.
* link:docs/plan/ULTRAPLAN.adoc[Plan to v1.0.0]: release gates, order, models and effort.
* link:docs/architecture/APODEIXIS-ULTRAPLAN.adoc[Ultra-plan] — dependency-ordered work packages, acceptance gates, risks, and contributor handoff protocol.
* link:src/interface/Abi/README.adoc[ABI interface scaffolding] — current Idris2 ABI files and their limitations.

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/APODEIXIS-MVP-IMPLEMENTATION-PLAN.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ its fail-closed tests and independent evidence boundary are in place.
|Slice |State |Implementation tasks |Acceptance gate

|A. Package bootstrap and source policy
|Code present; Julia tests not yet run
|Code present; package tests pass (366 on Julia 1.12.1, 2026-11-15); CI runs Julia 1.9.4 and 1.12.1
|Run Julia 1.9+ CI; fix all package and parser API errors; test CLI exit codes;
publish findings as stable API; add parser version and source hash to output.
|`Pkg.test()` green on lowest and newest supported Julia; malicious macro
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/APODEIXIS-ULTRAPLAN.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ claim the whole package complete while its gate is red.
. Fix parser API or syntax issues; pin supported dependency ranges and decide
whether to commit a `Manifest.toml` for CI/dev tooling or keep the package as
a library without a committed lock.
. Add a Julia CI workflow using the repository's existing action pinning and
. Done: `.github/workflows/julia.yml` exists and is in `actions.lock`. The original step was:
add a Julia CI workflow using the repository's existing action pinning and
`actions.lock` conventions; include the Julia workflow in the lock file and
run the repository action-lock consistency check.
. Check formatter/linter policy after adding the workflow; do not bypass a red
Expand Down
94 changes: 94 additions & 0 deletions docs/plan/ULTRAPLAN.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: CC-BY-SA-4.0
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
= Apodeixis.jl: plan to v1.0.0
:revdate: 2026-11-15
:toc:

Apodeixis.jl is a Julia source-policy audit today. The goal is a verifier for
a closed Julia subset. This plan is the execution layer. The work packages
WP-00 to WP-11 and the milestones M0 to M8 stay in
link:../architecture/APODEIXIS-ULTRAPLAN.adoc[the detailed plan]. The slices A
to J stay in link:../architecture/APODEIXIS-MVP-IMPLEMENTATION-PLAN.adoc[the
MVP plan]. This file adds the v1.0.0 gates, the order, the models and the
effort.

The work that is shared with the sibling verifiers (`atoma`, `quintessence`,
`bactrian`, `canonry`, `chancel`) is in the family plan,
`docs/plan/FAMILY-ULTRAPLAN.adoc` in `hyperpolymath/atoma`. IDs F1 to F12 and
waves W0 to W5 come from that plan.

== Measured state on 2026-11-15

Tools: Julia 1.12.1, JuliaSyntax 1.0.2.

* `julia --project=. -e 'using Pkg; Pkg.test()'`: 366 passed, 0 failed.
* Not run here: the Julia 1.9.4 with JuliaSyntax 0.4 leg (CI runs it), the
Idris2 and Zig scaffold under `src/interface/`.

The detailed plan and the MVP plan say that the Julia tests were never run and
that a Julia workflow is still to be added. Both statements are out of date.
`.github/workflows/julia.yml` exists and the tests run.

== Holes

[cols="1,4,2",options="header"]
|===
| ID | Hole | State
| H0 | The audit reported `POLICY CLEAN` for `@ccall`, `@cfunction`, `llvmcall`, `cglobal`, `unsafe_wrap`, `pointer_from_objref`, `include`, `include_string`, an alias of a forbidden call, and `getfield(Base, :unsafe_load)`. | Closed. 19 tests fail without the fix.
| H1 | The audit is a deny-list by name. A name that the program builds from a string at run time is not visible. | Open. Closed by the typed-SSA front end (M2), which must use an allow-list.
| H2 | The mutation score for `@inbounds` is a number that the caller supplies. | Open. Slice A follow-up: bind it to evidence.
| H3 | No `Manifest.toml`, and `mise.toml` sets `julia = "latest"`. | Open. F6.
| H4 | `src/interface/` and `verification/proofs/` are template samples. They prove nothing about this package. | Open. Replace or remove in M6.
|===

== Definition of v1.0.0

The seven family gates apply. The text below is the Apodeixis reading.

[cols="1,4,3",options="header"]
|===
| Gate | Acceptance | Falsifier
| Language boundary | Closed subset on typed SSA from `code_typed`, with an allow-list. Dynamic dispatch, `eval` and unmodeled foreign calls fail closed. | A method added after verification changes behaviour and the evidence stays valid.
| Source connection | Obligations come from the specialised method body. The key binds the method instance, the Julia version and the world age. | A body, a dependency or a Julia version changes and old evidence is reused.
| Semantics | Numeric tiers 1 to 4 with no silent crossing. Arrays and loops with invariants. FFI through a checked ABI manifest. | An `Int` overflow or an out-of-bounds read is accepted.
| Replay | A source-derived obligation replays through ECHIDNA. Status PROVED never comes from a solver exit code alone. | UNKNOWN or a timeout becomes PROVED.
| Practical coverage | Three pilots: scalar kernel, array loop, one FFI wrapper. | A second package needs special cases.
| Assurance | Mutation evidence replaces the supplied score. Package tests and the gate run on both supported Julia versions. | A mutant survives because a check did not run.
| Release and estate | Registered in the General registry or documented as not registered. README, deed and changelog true. | A `POLICY CLEAN` result is described as a proof.
|===

== Sequence

[cols="1,4,1,1,3",options="header"]
|===
| Stage | Work | Lead | Size | Exit evidence
| A0 Truth (W0) | Correct the stale statements in the two plan documents. Decide the lock policy (H3). Add an audit benchmark on a fixed corpus (F5). | Sonnet; Haiku for the edits | S | The plan documents match the code. One benchmark baseline from a real run.
| A1 Evidence spine (W1) | Adopt the family status words and receipt schema (F3). Stable serialisation of `AuditReport`. Maps to WP-00, WP-01, slice A follow-up, M0. | Sonnet from an Opus schema | M | The audit emits a receipt with status INCOMPLETE through the kit.
| A2 Contracts and first obligation (W2) | `ContractSpec` parser (slice B, M1). Compiler adapter on `code_typed` (slice C, M2). One `@verified` scalar `Int` function to one obligation (slices D and E, M3 and M4). ECHIDNA replay (F7). | Opus | L | The W2 family exit evidence, with the reuse measures.
| A3 Arrays, loops, numeric tiers (W3) | Slices F and G, M5 and M7. Close H1 and H2. | Opus, advisor review of the tier rules | XL (split first) | A bounds counterexample and an overflow counterexample are rejected.
| A4 FFI seam (W3, F8) | Slice H, M6. Julia `ccall` wrappers checked against an ABI manifest. Zig code goes to `atoma`. Close H4. | Opus | L | A wrong layout or a retained pointer is rejected.
| A5 Receipts and bot (W4) | Slice J, M8, WP-11. Cache invalidation. | Sonnet from an Opus design | M | Stale evidence fails. Adversarial receipts fail.
| A6 Pilots and release (W5) | Three pilots. Release audit (F12). | Opus for pilots; Sonnet for release | L | All seven gates pass on the release commit.
|===

The mapping from slices to milestones is approximate. The detailed plan is the
authority for the content of each work package.

Sonnet does the implementation tasks inside each stage from an Opus brief.
Haiku runs the scout pass before each step. The advisor reviews the close of
each stage and each change to a status word.

== What Apodeixis.jl takes from the family, and gives

* Takes: the evidence kit (F3), the ECHIDNA client (F7), Zig checks from
`atoma` (F8).
* Gives: the numeric tier model. It is the natural owner of the Julia side of
an ECHIDNA coprocessor contract (F10), if the owner opens that work.
* The coprocessor is not wired today. No file in this repository refers to it.

== Stop points

* If the compiler adapter (M2) cannot give stable typed SSA across the two
supported Julia versions, narrow the supported versions. Do not weaken the
source connection gate.
* Do not start A3 before it is split into parts of size L or smaller.
67 changes: 60 additions & 7 deletions src/Apodeixis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,28 @@ const _FORBIDDEN_MACROS = Set((
Symbol("@generated"), Symbol("@eval"), Symbol("@fastmath"),
))

# Entries to foreign code. None has a checked ABI model yet.
const _FOREIGN_CALLS = Set((:ccall, :cglobal, :llvmcall))
const _FOREIGN_MACROS = Set((Symbol("@ccall"), Symbol("@cfunction")))

# Dynamic evaluation, code loading and raw object addresses. Every name that
# starts with `unsafe_` is forbidden as well (see `_is_forbidden_name`).
const _FORBIDDEN_CALLS = Set((
:eval, :invokelatest, :ccall, :unsafe_load, :unsafe_store!,
:eval, :invokelatest, :invoke_in_world, :include, :include_string,
:evalfile, :pointer_from_objref,
))

# snip: deny-list by name. A name that the program builds from a string at run
# time is not visible to a syntax audit; the planned typed-SSA frontend must
# replace this list with an allow-list.
_is_forbidden_name(name::Symbol) =
name in _FOREIGN_CALLS || name in _FORBIDDEN_CALLS ||
startswith(String(name), "unsafe_")

_referenced_name(x::Symbol) = x
_referenced_name(x::GlobalRef) = x.name
_referenced_name(_) = nothing

function _push_once!(findings::Vector{Finding}, code::Symbol, line::Int, message::String)
# A malformed or deeply nested syntax tree can encounter the same policy
# violation through multiple wrappers. Keep reports deterministic and tidy.
Expand All @@ -53,6 +71,26 @@ function _push_once!(findings::Vector{Finding}, code::Symbol, line::Int, message
return nothing
end

# A forbidden name is rejected wherever the program refers to it, not only in
# call position: `const f = unsafe_load`, `Base.unsafe_load` and
# `getfield(Base, :unsafe_load)` must not hide it. A quoted symbol that is only
# data (`x = :eval`) is not a reference.
const _REFLECTIVE_LOOKUPS = Set((:getfield, :getproperty, :getglobal))

function _report_forbidden_name!(findings::Vector{Finding}, name::Symbol, line::Int)
if name === :ccall
_push_once!(findings, :APX_UNMODELED_CCALL, line,
"ccall is not yet verified; use a checked ABI wrapper only after the FFI phase")
elseif name in _FOREIGN_CALLS
_push_once!(findings, :APX_UNMODELED_CCALL, line,
"$(name) enters foreign code without a checked ABI model")
else
_push_once!(findings, :APX_DYNAMIC_ESCAPE, line,
"$(name) is forbidden in the closed verified subset")
end
return nothing
end

function _callee_symbol(x)
x isa Symbol && return x
if x isa GlobalRef
Expand Down Expand Up @@ -95,19 +133,30 @@ function _walk!(x, verified::Bool, mutation_score, line::Int,
"lowered foreign calls require a checked Idris2/Zig ABI manifest")
elseif x.head === :call && !isempty(x.args)
callee = _callee_symbol(first(x.args))
if callee in _FORBIDDEN_CALLS
code = callee === :ccall ? :APX_UNMODELED_CCALL : :APX_DYNAMIC_ESCAPE
message = callee === :ccall ?
"ccall is not yet verified; use a checked ABI wrapper only after the FFI phase" :
"$(callee) is forbidden in the closed verified subset"
_push_once!(findings, code, line, message)
if callee isa Symbol && _is_forbidden_name(callee)
_report_forbidden_name!(findings, callee, line)
elseif callee in _REFLECTIVE_LOOKUPS
for arg in x.args[2:end]
if arg isa QuoteNode && arg.value isa Symbol && _is_forbidden_name(arg.value)
_report_forbidden_name!(findings, arg.value, line)
end
end
end
elseif x.head === :.
member = _callee_symbol(x)
if member isa Symbol && _is_forbidden_name(member)
_report_forbidden_name!(findings, member, line)
end
end

if x.head === :macrocall && !isempty(x.args)
macro_name = _macro_symbol(first(x.args))
line_arg = findfirst(arg -> arg isa LineNumberNode, x.args)
macro_line = line_arg === nothing ? line : Int(x.args[line_arg].line)
if macro_name in _FOREIGN_MACROS
_push_once!(findings, :APX_UNMODELED_CCALL, macro_line,
"$(macro_name) enters foreign code without a checked ABI model")
end
if macro_name in _FORBIDDEN_MACROS
_push_once!(findings, :APX_FORBIDDEN_MACRO, macro_line,
"$(macro_name) is forbidden in the verified subset")
Expand Down Expand Up @@ -156,6 +205,10 @@ function _walk!(x, verified::Bool, mutation_score, line::Int,
if arg isa LineNumberNode
current_line = Int(arg.line)
else
name = _referenced_name(arg)
if name isa Symbol && _is_forbidden_name(name)
_report_forbidden_name!(findings, name, current_line)
end
current_line = _walk!(arg, child_verified, mutation_score, current_line, findings)
end
end
Expand Down
38 changes: 38 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,44 @@ function invoke(args)
end
end

@testset "Forbidden names are rejected in every position" begin
foreign = (
"f(x) = @ccall strlen(x::Cstring)::Csize_t",
"f() = @cfunction(g, Cint, ())",
"f() = Base.llvmcall(\"ret void\", Cvoid, Tuple{})",
"f() = cglobal(:jl_options)",
)
for source in foreign
@test codes(audit_source(source)) == Set((:APX_UNMODELED_CCALL,))
end

escapes = (
"f(p) = unsafe_wrap(Array, p, 4)",
"f(x) = pointer_from_objref(x)",
"f(p) = unsafe_pointer_to_objref(p)",
"include(\"other.jl\")",
"f(s) = include_string(Main, s)",
"const load = unsafe_load\nf(p) = load(p)",
"import Base: unsafe_load as load",
"f(p) = getfield(Base, :unsafe_load)(p)",
"f(p) = map(Base.unsafe_load, p)",
"@verified function f(p)\n unsafe_wrap(Array, p, 4)\nend",
)
for source in escapes
@test codes(audit_source(source)) == Set((:APX_DYNAMIC_ESCAPE,))
end

# A foreign macro inside @verified keeps the unmodeled-macro finding too.
both = audit_source("@verified function f(x)\n @ccall strlen(x::Cstring)::Csize_t\nend")
@test codes(both) == Set((:APX_UNMODELED_CCALL, :APX_UNMODELED_MACRO))

# Names that only resemble a forbidden name, and quoted data, stay clean.
for source in ("safe_load(p) = p", "x = :unsafe_load", "evaluation = 1",
"s = \"unsafe_wrap(Array, p, 4)\"")
@test is_policy_clean(audit_source(source))
end
end

@testset "CLI argument handling and audit output" begin
for flag in ("--help", "-h")
result = CLIUnderTest.invoke([flag])
Expand Down
Loading