Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9cb2380
Parse the JavaScript grammar by recursive descent over the lexer (7.3)
atiernan Nov 18, 2026
355f705
Prove the parser's arena well formed, inside the source and within th…
atiernan Nov 18, 2026
b1184f0
Reject what the early errors of the spec reject, and test the parser …
atiernan Nov 18, 2026
908da60
Bound the parser's recursion and test hostile and shaped input (7.3)
atiernan Nov 18, 2026
9d0d9e0
Parse the Test262 harness, state what the parser proves and where it …
atiernan Nov 18, 2026
472323e
Place the absent import options where the spec does, and test the ord…
atiernan Nov 18, 2026
c2fe3a5
Parse on this thread when no thread with a large stack can be had (7.3)
atiernan Nov 18, 2026
bf1d81c
Extend the corpus of programs the parser accepts and rejects (7.3)
atiernan Nov 18, 2026
e49f07e
clazel-codecheck: the x86-64 validator's spec and contract (J.6)
atiernan Nov 18, 2026
af38ea6
clazel-codecheck: examples, lemmas and mutations for the validator spec
atiernan Nov 18, 2026
f17fdf1
clazel-codecheck: certify the jump-target and basic-block mutations
atiernan Nov 18, 2026
d47fe2a
Follow the spec's fixes: static-block await, absent import parts (7.3)
atiernan Nov 18, 2026
980e6c1
Merge claude/lir-spec into claude/js-parser-impl
atiernan Nov 18, 2026
de12bc5
Merge claude/lir-spec into claude/codecheck-x64
atiernan Nov 18, 2026
db27273
Merge claude/codecheck-x64 into claude/js-parser-impl
atiernan Nov 18, 2026
cb5d9fc
Prove the leaf and binary-operator rules of the grammar derive what t…
atiernan Nov 18, 2026
9b2c764
Prove more rules of the grammar, and check parsed leaves against the …
atiernan Nov 18, 2026
be1f9f9
Use is_empty in check_leaf (7.3)
atiernan Nov 18, 2026
df957f2
Specify the early errors on exports of section 16.2.1.1 (7.3)
atiernan Nov 18, 2026
8fa4d4e
Reject duplicate and undeclared exports and ill-formed export names (…
atiernan Nov 18, 2026
78e68b1
Make the export rules' certificates computable (7.3)
atiernan Nov 18, 2026
0e9cfe2
Prove the statement, root and list rules the whole-arena derivation c…
atiernan Nov 18, 2026
af3089e
Check literal leaves of the arena against the tokens (7.3)
atiernan Nov 18, 2026
275d68e
Check binary-operator nodes of the arena against the tokens (7.3)
atiernan Nov 18, 2026
157aab8
Check parenthesized, expression-statement and empty-statement nodes a…
atiernan Nov 18, 2026
25c2257
Check that the items of the root derive the whole token stream (7.3)
atiernan Nov 18, 2026
a6561af
Check the whole arena against the tokens, bottom-up, for the covered …
atiernan Nov 18, 2026
eb06366
Run the proven derivation check on every arena the parser builds (7.3)
atiernan Nov 18, 2026
cdca5b8
Prove the table of operator texts equal to the specification's (7.3)
atiernan Nov 18, 2026
b13fc5c
clazel-codecheck: an executable x86-64 validator and hostile tests (J.6)
atiernan Nov 18, 2026
ea46cb5
Check every binary level of the arena against the tokens, in and inst…
atiernan Nov 18, 2026
36afa89
Check unary, conditional, assignment and member-dot nodes against the…
atiernan Nov 18, 2026
3a4cd0b
Check identifier references, binding identifiers and labels, with the…
atiernan Nov 18, 2026
81c5c74
clazel-x64: a specification-level decoder; the encoding is a prefix code
atiernan Nov 18, 2026
ea2ae6a
clazel-codecheck: say in the crate docs what exec.rs is and is not
atiernan Nov 18, 2026
b69a1e3
Check comma-separated lists of the arena against the tokens (7.3)
atiernan Nov 18, 2026
fa59219
Check arguments, calls, comma expressions, spread elements and this/n…
atiernan Nov 18, 2026
c396491
Let the processed-node invariant hold Absent nodes, which their paren…
atiernan Nov 18, 2026
29948f5
Check variable, let and const declarations against the tokens (7.3)
atiernan Nov 18, 2026
775ec87
Check blocks and if statements against the tokens (7.3)
atiernan Nov 18, 2026
17d1958
Merge claude/codecheck-x64 into claude/parser-codecheck
atiernan Nov 18, 2026
f02b96b
Merge claude/js-parser-impl into claude/parser-codecheck
atiernan Nov 18, 2026
2210359
Check while, do-while, throw, break, continue, labelled, try, switch …
atiernan Nov 18, 2026
37e3d66
Carry a context per node in the arena check (7.3)
atiernan Nov 18, 2026
22e88fd
clazel-x64: a verified executable encoder
atiernan Nov 18, 2026
dec6f71
clazel-x64: a verified executable decoder
atiernan Nov 18, 2026
92406bb
clazel-codecheck: a verified decode-all loop
atiernan Nov 18, 2026
73996c0
Spec: rest_only_last ranges over 0 <= k, k + 1 < len (7.3)
atiernan Nov 18, 2026
8901c20
Merge claude/codecheck-x64 into claude/parser-codecheck
atiernan Nov 18, 2026
0c829d1
clazel-codecheck: verified executable unit checks
atiernan Nov 18, 2026
06b78f2
clazel-codecheck: the executable unit scan refines the spec scan
atiernan Nov 18, 2026
0369dd1
Check functions, arrow functions, return, yield and await against the…
atiernan Nov 18, 2026
17fd5ac
Merge claude/js-parser-impl-2 into claude/parser-codecheck
atiernan Nov 18, 2026
393df8a
clazel-codecheck: the validator is verified sound; exec.rs is gone
atiernan Nov 18, 2026
953f171
clazel-codecheck: the decomposition is unique and accepted targets li…
atiernan Nov 18, 2026
bf31cbf
clazel-codecheck: the validator is verified complete, and meets the c…
atiernan Nov 18, 2026
a3ae2ad
Merge claude/codecheck-x64 into claude/parser-codecheck
atiernan Nov 18, 2026
3bb1457
rustfmt: format the codecheck validator tests and clazel-x64's module…
atiernan Nov 20, 2026
71bef5f
clazel-codecheck: run 2 000 random rounds under Miri, not 20 000
atiernan Nov 20, 2026
6f4d521
clazel-js-syntax: keep Miri off the huge-input and file-reading tests
atiernan Nov 20, 2026
3af71a5
Merge claude/lir-spec into claude/parser-codecheck
atiernan Nov 20, 2026
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
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions crates/clazel-codecheck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "clazel-codecheck"
version = "0.0.0"
edition.workspace = true
license.workspace = true
publish.workspace = true
description = "The JIT's code validators (docs/phases/jit.md item J.6), the x86-64 one first: what an accepted code blob is, and the contract of the validator. Only the spec, the contract and examples exist so far; there is no validator yet."

[dependencies]
vstd = "=0.0.0-2026-10-04-0306"
# The instruction subset the validator accepts, and its canonical encoding.
# The decoder of untrusted bytes is this crate's own (CLAUDE.md rule 8); the
# only thing taken from `clazel-x64` is the specification of the subset.
clazel-x64 = { path = "../clazel-x64" }

# Verification tier (docs/VERIFICATION.md). `tier` is what is proven about the
# shipped code today: nothing, because no validator exists yet (the spec, the
# contract and examples are written first, CLAUDE.md rule 3). `target-tier` is
# what jit.md's "Crates" table sets.
[package.metadata.clazel]
tier = 0
target-tier = 2

[package.metadata.verus]
verify = true

[lints]
workspace = true
121 changes: 121 additions & 0 deletions crates/clazel-codecheck/mutations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"mutations": [
{
"id": "index-fact-ignored",
"file": "src/spec.rs",
"find": "(Fact::Base(k), Fact::Idx(k2, n)) => k == k2 && a.size <= n,",
"replace": "(Fact::Base(k), _) => true,",
"expect": "killed",
"reason": "Accepts a region access through any base register, whatever is known of the index (J.6: an index register compared against the region's bound): a load through an index no bounds check touched would be accepted, so lemma_region_access_facts is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_region_access_facts(cx_base2(), cx_load())",
"witness": "access_ok(cx_base2(), cx_load()) && !(fact_of(cx_base2(), 1) is Idx)"
}
},
{
"id": "check-size-order-reversed",
"file": "src/spec.rs",
"find": "k == k2 && a.size <= n,",
"replace": "k == k2 && n <= a.size,",
"expect": "killed",
"reason": "Reverses the comparison of the checked size and the access size, so a check for 4 bytes would license an 8-byte access and the last 4 bytes could lie outside the region: lemma_region_access_facts is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_region_access_facts(cx_idx4(), cx_load())",
"witness": "access_ok(cx_idx4(), cx_load()) && !idx_covers(fact_of(cx_idx4(), 1), 8)"
}
},
{
"id": "check-region-not-compared",
"file": "src/spec.rs",
"find": "k == k2 && a.size <= n,",
"replace": "a.size <= n,",
"expect": "killed",
"reason": "Does not compare the region of the base register with the region the index was checked against, so an index checked against a small region could be used with a large region's base: lemma_region_access_facts is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_region_access_facts(cx_idx_region2(), cx_load())",
"witness": "access_ok(cx_idx_region2(), cx_load()) && !same_region(fact_of(cx_idx_region2(), 2), fact_of(cx_idx_region2(), 1))"
}
},
{
"id": "stack-pointer-not-reserved",
"file": "src/spec.rs",
"find": "r == ctx_reg() || r == sp_reg()",
"replace": "r == ctx_reg()",
"expect": "killed",
"reason": "Lets the code write the stack pointer (J.6: reserved registers and the stack pointer are written only in the fixed prologue and epilogue), which would make the exit sequence's ret return anywhere: lemma_plain_ok_safe is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_plain_ok_safe(no_facts(), cx_mov_rsp())",
"witness": "plain_ok(no_facts(), cx_mov_rsp()) is Some"
}
},
{
"id": "targets-not-boundaries",
"file": "src/spec.rs",
"find": "Some(starts) => subset_of(all_targets(ins, entries), starts),",
"replace": "Some(starts) => true,",
"expect": "killed",
"reason": "Drops the rule that every direct target is the start of a unit (J.6: every direct target is a decoded boundary inside the blob): a jump into the middle of a bounds check, skipping its first instructions, would be accepted, so lemma_policy_targets_are_unit_starts is false. (example_jump_into_check_rejected is false too.)",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_policy_targets_are_unit_starts(super::examples::prog_jump_into_check(), seq![0int])",
"witness": "policy(super::examples::prog_jump_into_check(), seq![0int]) && !subset_of(all_targets(super::examples::prog_jump_into_check(), seq![0int]), unit_starts(super::examples::prog_jump_into_check(), seq![0int]))"
}
},
{
"id": "facts-kept-at-targets",
"file": "src/spec.rs",
"find": "let fs0 = if seq_has(tg, here) {",
"replace": "let fs0 = if false && seq_has(tg, here) {",
"expect": "killed",
"reason": "Keeps what is known about registers at a jump target, though the target can be reached without the instructions that established it (J.6: earlier in the same basic block): a jump past a bounds check to the access would be accepted, so lemma_scan_forgets_at_targets is false. (example_jump_over_check_rejected is false too.)",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_scan_forgets_at_targets(super::examples::prog_jump_over_check(), all_targets(super::examples::prog_jump_over_check(), seq![0int]), 10, cx_checked())",
"witness": "seq_has(all_targets(super::examples::prog_jump_over_check(), seq![0int]), start_of(super::examples::prog_jump_over_check(), 10)) && scan(super::examples::prog_jump_over_check(), all_targets(super::examples::prog_jump_over_check(), seq![0int]), 10, cx_checked()) is Some && scan(super::examples::prog_jump_over_check(), all_targets(super::examples::prog_jump_over_check(), seq![0int]), 10, no_facts()) is None"
}
},
{
"id": "region-table-writable",
"file": "src/spec.rs",
"find": "!a.store || abi::exit_code_off() <= a.mem.disp",
"replace": "true",
"expect": "killed",
"reason": "Lets a store go anywhere in the context, including the region table: the code could rewrite a region's base or bound, then pass its own bounds check against the forged bound. lemma_ctx_store_in_exit_area is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_ctx_store_in_exit_area(no_facts(), cx_table_store())",
"witness": "access_ok(no_facts(), cx_table_store())"
}
},
{
"id": "end-of-blob-not-checked",
"file": "src/spec.rs",
"find": "(ins.last() is Ret || ins.last() is Jmp) && match scan(",
"replace": "true && match scan(",
"expect": "killed",
"reason": "Drops the rule that the last instruction is ret or jmp (J.6: every path ends in the exit sequence or a branch): control could run past the end of the blob into whatever follows. lemma_policy_ends is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_policy_ends(cx_falls_off(), seq![0int])",
"witness": "policy(cx_falls_off(), seq![0int])"
}
},
{
"id": "bare-ret-allowed",
"file": "src/spec.rs",
"find": "if i is Ret {",
"replace": "if i is Ret && false {",
"expect": "killed",
"reason": "Accepts a ret that is not the end of an exit sequence (J.6: no indirect branch except the exit sequence): the blob could return without having stored an exit code. lemma_plain_ok_safe is false.",
"certificate": {
"file": "src/lemmas.rs",
"lemma": "lemma_plain_ok_safe(no_facts(), Instr::Ret)",
"witness": "plain_ok(no_facts(), Instr::Ret) is Some"
}
}
]
}
103 changes: 103 additions & 0 deletions crates/clazel-codecheck/src/acc_lemmas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//! Facts about the spec's scan and policy that the completeness of the
//! validator needs: an accepted blob's targets all lie inside it, and the
//! list `seq_has` and `subset_of` behave as membership and inclusion.

#[allow(unused_imports)]
use super::spec::*;
#[allow(unused_imports)]
use vstd::prelude::*;

verus! {

/// `seq_has` of a concatenation.
pub proof fn lemma_seq_has_concat(a: Seq<int>, b: Seq<int>, x: int)
ensures
seq_has(a + b, x) == (seq_has(a, x) || seq_has(b, x)),
decreases b.len(),
{
if b.len() == 0 {
assert(a + b =~= a);
} else {
let d = b.drop_last();
lemma_seq_has_concat(a, d, x);
assert((a + b).drop_last() =~= a + d);
assert((a + b).last() == b.last());
}
}

/// A one-element list has just that element.
pub proof fn lemma_seq_has_single(y: int, x: int)
ensures
seq_has(seq![y], x) == (y == x),
{
reveal_with_fuel(seq_has, 2);
assert(seq![y].drop_last() =~= Seq::<int>::empty());
}

/// Membership in a subset implies membership in the superset.
pub proof fn lemma_subset_elim(a: Seq<int>, b: Seq<int>, x: int)
requires
subset_of(a, b),
seq_has(a, x),
ensures
seq_has(b, x),
decreases a.len(),
{
if a.len() > 0 {
if a.last() != x {
lemma_subset_elim(a.drop_last(), b, x);
}
}
}

/// Every unit start the scan finds is the start of an instruction at or after
/// `j`.
pub proof fn lemma_scan_starts(ins: Seq<Instr>, tg: Seq<int>, j: int, fs: Facts, x: int)
requires
0 <= j,
scan(ins, tg, j, fs) is Some,
seq_has(scan(ins, tg, j, fs)->Some_0, x),
ensures
exists|k: int| j <= k < ins.len() && x == start_of(ins, k),
decreases ins.len() - j,
{
reveal_with_fuel(scan, 2);
if j < ins.len() {
let here = start_of(ins, j);
let fs0 = if seq_has(tg, here) {
no_facts()
} else {
fs
};
let u = unit_at(ins, j, fs0)->Some_0;
let rest = scan(ins, tg, j + u.len, u.facts)->Some_0;
lemma_seq_has_concat(seq![here], rest, x);
lemma_seq_has_single(here, x);
if x != here {
lemma_scan_starts(ins, tg, j + u.len, u.facts, x);
} else {
assert(j <= j < ins.len() && x == start_of(ins, j));
}
}
}

/// **An accepted blob's targets lie inside it**: every entry and every jump
/// target of an instruction list that passes the policy is the offset of one
/// of its instructions, so in `[0, start_of(ins, len))`.
pub proof fn lemma_policy_in_range(ins: Seq<Instr>, entries: Seq<int>, x: int)
requires
policy(ins, entries),
seq_has(all_targets(ins, entries), x),
ensures
0 <= x < start_of(ins, ins.len() as int),
{
let tg = all_targets(ins, entries);
let starts = scan(ins, tg, 0, no_facts())->Some_0;
lemma_subset_elim(tg, starts, x);
lemma_scan_starts(ins, tg, 0, no_facts(), x);
let k = choose|k: int| 0 <= k < ins.len() && x == start_of(ins, k);
super::scan_exec::lemma_start_of_lt(ins, k, ins.len() as int);
super::validate::lemma_start_of_ge(ins, k);
}

} // verus!
32 changes: 32 additions & 0 deletions crates/clazel-codecheck/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! The contract-only API of the validator: a trait with no implementation,
//! so Verus accepts it with no escape hatch (CLAUDE.md rule 4), the pattern
//! of `clazel-x64`'s `api.rs`. The implementation (a later commit of J.6)
//! implements it, or replaces it with a free function whose `requires` and
//! `ensures` are the same predicates.
//!
//! jit.md J.0(a) has a `Validated` value that only this crate can build and
//! `clazel-sys`'s `enter` takes. Building it from a `true` result is a later
//! step, with the implementation: it is a wrapper around a blob for which
//! this function answered yes.

#[allow(unused_imports)]
use super::spec::*;
#[allow(unused_imports)]
use vstd::prelude::*;

verus! {

/// The x86-64 validator, with its contract.
pub trait Validator {
/// Whether `blob`, entered at the byte offsets `entries`, is accepted
/// (see [`crate::spec::accepted`]). Reads the bytes once, left to right,
/// and never panics, whatever the bytes are.
fn validate(blob: &[u8], entries: &[usize]) -> (ok: bool)
requires
crate::contract::validate_requires(blob@, entries@),
ensures
crate::contract::validate_ensures(blob@, entries@, ok),
;
}

} // verus!
58 changes: 58 additions & 0 deletions crates/clazel-codecheck/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Contract of the validator (CLAUDE.md rule 3, docs/SPEC-STYLE.md): one
//! `requires` and one `ensures` predicate for [`super::api::Validator`], in
//! terms of [`super::spec`]. Reviewing these and the spec is enough to know
//! what an implementation guarantees.
//!
//! What they say (jit.md J.6):
//!
//! - **Soundness.** If the validator says yes, the blob is [`accepted`]:
//! exactly the canonical encodings of subset instructions that pass the
//! policy. This is the direction safety rests on: a `true` the spec does
//! not license would let unchecked code run.
//! - **Completeness, given a prefix code.** If the blob is accepted, the
//! validator says yes, provided `clazel-x64`'s `canonical_prefix_free`
//! holds (a statement about its encoder that is to be proven there). It
//! makes the instruction sequence of a blob unique, so a decoder that reads
//! the first match finds the one the spec quantifies over. Without it only
//! soundness is promised, so a validator proven against this contract is
//! safe whether or not that lemma is ever proven; what it would lack is the
//! guarantee that it refuses nothing the spec accepts.
//! - **Entries** are byte offsets inside the blob; each must be the start of
//! a unit, or the answer is no ([`accepted`] requires it).
//! - **A blob is at most 2^31 - 1 bytes** (`requires`).
//!
//! Not stated here: that an accepted blob is *safe to run*. That is jit.md's
//! theorem (exit criterion 2), over `clazel_x64::spec::step`, and it is not
//! yet written; see [`super::spec`]'s header.

#[allow(unused_imports)]
use super::spec::*;
#[allow(unused_imports)]
use vstd::prelude::*;

verus! {

/// The largest blob the validator takes, in bytes.
pub open spec fn max_blob_len() -> int {
0x7FFF_FFFF
}

/// The entries as the spec's integer offsets.
pub open spec fn entry_offsets(entries: Seq<usize>) -> Seq<int> {
entries.map_values(|e: usize| e as int)
}

/// Precondition of the validator: the blob is within the size limit. Every
/// other input, including random bytes and any entries, is legal.
pub open spec fn validate_requires(blob: Seq<u8>, entries: Seq<usize>) -> bool {
blob.len() <= max_blob_len()
}

/// Postcondition of the validator.
pub open spec fn validate_ensures(blob: Seq<u8>, entries: Seq<usize>, ok: bool) -> bool {
&&& ok ==> accepted(blob, entry_offsets(entries))
&&& clazel_x64::contract::canonical_prefix_free() ==> (accepted(blob, entry_offsets(entries))
==> ok)
}

} // verus!
Loading
Loading