Skip to content

formal: add Lean proofs for KMS, gateway and guest OS logic - #1597

Merged
kvinwang merged 5 commits into
nextfrom
feat/lean-proofs
Nov 18, 2026
Merged

kvinwang merged 5 commits into
nextfrom
feat/lean-proofs

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

Adds formal/, a Lean 4 project (core Lean, no Mathlib) with hand-written models of security-relevant logic and machine-checked proofs, plus a CI job (lean.yml) that builds it and rejects sorry, axiom and native_decide. See formal/README.md for the module list and trust base; each module header names the Rust/Solidity functions it mirrors and its modeling gaps.

  • KMS: root-epoch contract invariants and agreement with the Rust chain hashes, servable_epoch/handover binding, KDF domain separation, RA-TLS encoding injectivity, and the key-release check set.
  • Gateway: KV import, IP allocation, port policy, cert resolution, ingress parsing, health hysteresis, SNI and msgpack skipping, and the cert-renewal lock.
  • Guest: event-log preimages and replay (the V1 theorem relies on the colon check from fix(cc-eventlog): reject V1 runtime event names containing ':' #1596), the boot measure-before-use trace, MR_CONFIG_ID, instance id, env file, and compose policy checks.

Hashes and KDFs are parameters; injectivity is an explicit hypothesis, never an axiom.

Observations from the proofs, for follow-up (not changed here):

  • The cert-renewal lock is not mutually exclusive across nodes during a replication gap (documented). Its value has second granularity, so after a force release or clock step back a stale holder's release can delete a lock re-acquired in the same second.
  • extract_sni ignores the declared record/extension/server-name lengths.
  • CertStore::exact_certs is never populated, so the exact-match branch of resolve_cert is dead.
  • Cross-node instance agreement relies on node pools not overlapping, which no config check enforces; a CVM can register with node A using node B's gateway key, which A accepts and B rejects.
  • instance_id_seed length is unchecked, so the instance id alone is not globally unique across app ids (it is for a fixed app id).

Hand-written Lean 4 models of security-relevant pure logic, with
machine-checked proofs and a CI job that builds them and rejects sorry,
axioms and native_decide. Cryptographic idealizations are explicit
theorem hypotheses.

Signed-off-by: Kevin Wang <wy721@qq.com>
CertLock follows #1599-#1601 on wavekv 2.2: the lock value carries a
nonce, a lease stamped beyond the drift bound counts as expired, and
release and lease-guarded writes are no-ops once the lease expired by the
local clock. The force-release, clock-step-back and stale-release
counterexamples become positive theorems: ownership on one node under any
clock, and a release or guarded commit losing LWW to any successor whose
clock is within the drift bound. The replication gap, skew beyond the
drift bound, and cross-node force release remain as counterexamples.

Sni follows #1602: the returned name lies within every declared block.
CertStore follows #1603: no exact-match table, empty first label refused.

Signed-off-by: Kevin Wang <wy721@qq.com>
Import follows #1604: a record carrying any replicated gateway key, or
the judging node's own, is rejected as LostConflict on every node. Nodes
with equal KV contents now agree once their own keys have replicated;
the window before that is kept as a counterexample. Key squatting is
added: a counterexample without proof of possession, and stable key
binding under the hypothesis that every record was registered by its
key's holder (#1615, modeled abstractly).

IpAlloc follows #1605: release_ip frees an address only when no other
instance holds it. Registration, rebuild, forget and KV reload are
modeled, and alloc_ip never reissues a live address, including one a
conflict loser shares during its grace period. PoolsClear stays an
assumption; #1606 only warns.

Signed-off-by: Kevin Wang <wy721@qq.com>
Model dstack-vmm's per-VM state machine (start, stop, remove and
finish_remove, guest power-off record, auto-restart, boot and RPC
reloads, update, create) together with the supervisor's two-step deploy,
as one step per stretch of code between awaits, with crashes that keep
disk and supervisor state. Tracks next with #1609-#1614.

An inductive invariant proves: no deploy once a removal holds the launch
lock; at most one running process per id; remove_all only with nothing
running and netd released; removals (including crash recovery) only
target workdirs with .removing or none; the reload RPC never tears down
a VM whose create is in flight; a guest power-off never cancels a later
start; a deleted workdir never comes back.

Concrete traces mirror the Rust tests and show that a deploy can land
while the id is in the removing set, that a start future dropped during
deploy lets two QEMUs run, and that the reload RPC's start, which does
not recheck started under the lock, overrides an acknowledged stop.

Signed-off-by: Kevin Wang <wy721@qq.com>
Model #1616 (load_vm and load_or_update_vm auto-starts recheck started
under the launch lock) and #1617 (a start runs in its own task, so a
dropped caller no longer releases the lock mid-launch) as Config
switches that the fixed code has on. stop_sticks and at_most_one_running
now hold for the fixed code without extra assumptions; the old traces
replay the bugs with the switches off.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang merged commit d0002f7 into next Nov 18, 2026
12 checks passed
@kvinwang
kvinwang deleted the feat/lean-proofs branch November 18, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant