mirror of
https://github.com/luxfi/proofs.git
synced 2026-10-30 15:21:05 +00:00
lean/axioms.py runs `#print axioms` over every theorem in the corpus. A green
build says each proof follows from what it was given; only this says what that
was. Lean's own propext, Classical.choice and Quot.sound are the ambient logic
and are not assumptions about our systems, so a theorem resting on those alone
is proved and anything else it names is load-bearing.
Measured here: 715 theorems queried, 594 proved outright, 121 resting on
axioms. It also ranks the axioms by how many theorems stand on them, which is
where the corpus's weight actually sits — Crypto.NonCustodial.sign carries 15,
and the four Quasar hardness axioms carry 7 each.
Building it surfaced a defect no per-file build could: `Vault.KeyIsolation` and
`Crypto.DEKDerivation` both declared `deriveOrgKEK` at top level, with no
namespace in either, so importing both failed and the corpus could not be
loaded as a whole. They were the only two files in 115 without a namespace, and
nothing imports either. Both now have one.
Modules in no library have no .olean, so importing one aborts the query. Those
are exactly the modules nothing checks; they are named and counted, not
imported.
vacuity.py caught one shape and now catches four, which took it from 55 to 75:
- `... True`, as before
- `∃ x, e = x`, closed by `⟨_, rfl⟩` — the witness is whatever the other side
evaluates to, so the equation says only that it has a value
- a conclusion that is one of its own hypotheses, `P → P`
- `sorry` and `admit`, over comment-stripped source
And the claim of a `def` is its body, not the part before `:=`. Cutting at `:=`
for every kind is what let `TSUFBound : Prop := ∃ _a, True` read as content —
along with `MagnetarTSUFBound`, `corona_eufcma_to_mlwe`, and both
`NoLeakReduction`, all now reported.
Co-authored-by: Hanzo Dev <[email protected]>
136 lines
6.0 KiB
Lean4
136 lines
6.0 KiB
Lean4
/-
|
|
Copyright (C) 2025, Lux Industries Inc. All rights reserved.
|
|
|
|
Vault Key Isolation Proof
|
|
|
|
Proves that the DEK/KEK hierarchy provides:
|
|
1. User isolation: different users get different DEKs
|
|
2. Org isolation: same user in different orgs gets different DEKs
|
|
3. Collection isolation: shared collection DEK ≠ user DEK
|
|
4. Recovery soundness: threshold shares reconstruct the correct DEK
|
|
|
|
Key hierarchy:
|
|
OrgKEK = HMAC(MasterKEK, "vault:org:" ++ orgID)
|
|
UserDEK = HMAC(OrgKEK, "vault:user:" ++ userID)
|
|
ColDEK = HMAC(UserDEK, "collection:" ++ colName)
|
|
DeviceKey = HMAC(UserDEK, "device:" ++ deviceID)
|
|
-/
|
|
|
|
namespace Vault.KeyIsolation
|
|
|
|
-- Model HMAC as a PRF: deterministic, collision-resistant, independent outputs
|
|
-- for independent inputs.
|
|
axiom PRF : List UInt8 → List UInt8 → List UInt8
|
|
axiom prf_deterministic : ∀ k m, PRF k m = PRF k m
|
|
axiom prf_collision_resistant :
|
|
∀ k m₁ m₂, m₁ ≠ m₂ → PRF k m₁ ≠ PRF k m₂
|
|
|
|
-- PRF with different keys produces independent outputs (standard assumption).
|
|
axiom prf_key_independent :
|
|
∀ k₁ k₂ m, k₁ ≠ k₂ → PRF k₁ m ≠ PRF k₂ m
|
|
|
|
-- PRF output never coincides with its own key input. Standard PRF/RO property:
|
|
-- a pseudorandom output is independent of the secret key that produced it, so it
|
|
-- equals that key only with negligible probability. Trusted base assumption.
|
|
axiom prf_output_ne_key : ∀ k m, PRF k m ≠ k
|
|
|
|
-- UTF-8 encoding is injective on the byte-list view: distinct strings encode to
|
|
-- distinct byte sequences. This is a structural property of the UTF-8 encoding
|
|
-- (uniquely decodable / prefix-free), used here only as encoding plumbing to lift
|
|
-- string inequalities to byte-list inequalities for the PRF message arguments.
|
|
axiom toUTF8_toList_inj :
|
|
∀ (s t : String), s.toUTF8.toList = t.toUTF8.toList → s = t
|
|
|
|
-- String append is left-cancellative (proved from String.data_append and String.ext).
|
|
theorem str_append_left_cancel (p s1 s2 : String) (h : p ++ s1 = p ++ s2) : s1 = s2 := by
|
|
apply String.ext
|
|
have hd : (p ++ s1).data = (p ++ s2).data := by rw [h]
|
|
rw [String.data_append, String.data_append] at hd
|
|
exact List.append_cancel_left hd
|
|
|
|
-- Distinct suffixes under a shared domain-separation prefix encode to distinct
|
|
-- byte-lists. This is the message-inequality feeding prf_collision_resistant.
|
|
theorem prefixed_encoding_ne (p s1 s2 : String) (h : s1 ≠ s2) :
|
|
(p ++ s1).toUTF8.toList ≠ (p ++ s2).toUTF8.toList := fun heq =>
|
|
h (str_append_left_cancel p s1 s2 (toUTF8_toList_inj _ _ heq))
|
|
|
|
-- Key derivation functions matching the vault SDK
|
|
noncomputable def deriveOrgKEK (masterKEK : List UInt8) (orgID : String) : List UInt8 :=
|
|
PRF masterKEK ("vault:org:" ++ orgID).toUTF8.toList
|
|
|
|
noncomputable def deriveUserDEK (orgKEK : List UInt8) (userID : String) : List UInt8 :=
|
|
PRF orgKEK ("vault:user:" ++ userID).toUTF8.toList
|
|
|
|
noncomputable def deriveCollectionDEK (userDEK : List UInt8) (colName : String) : List UInt8 :=
|
|
PRF userDEK ("collection:" ++ colName).toUTF8.toList
|
|
|
|
noncomputable def deriveDeviceKey (userDEK : List UInt8) (deviceID : String) : List UInt8 :=
|
|
PRF userDEK ("device:" ++ deviceID).toUTF8.toList
|
|
|
|
-- Theorem 1: User Isolation
|
|
-- Different users in the same org get different DEKs.
|
|
theorem user_isolation
|
|
(masterKEK : List UInt8) (orgID : String)
|
|
(user1 user2 : String) (h : user1 ≠ user2) :
|
|
let orgKEK := deriveOrgKEK masterKEK orgID
|
|
deriveUserDEK orgKEK user1 ≠ deriveUserDEK orgKEK user2 := by
|
|
intro orgKEK
|
|
simp only [deriveUserDEK]
|
|
apply prf_collision_resistant
|
|
exact prefixed_encoding_ne "vault:user:" user1 user2 h
|
|
|
|
-- Theorem 2: Org Isolation
|
|
-- Same user in different orgs gets different DEKs (via different org KEKs).
|
|
theorem org_isolation
|
|
(masterKEK : List UInt8)
|
|
(org1 org2 : String) (h : org1 ≠ org2)
|
|
(_userID : String) :
|
|
let orgKEK1 := deriveOrgKEK masterKEK org1
|
|
let orgKEK2 := deriveOrgKEK masterKEK org2
|
|
orgKEK1 ≠ orgKEK2 := by
|
|
show deriveOrgKEK masterKEK org1 ≠ deriveOrgKEK masterKEK org2
|
|
simp only [deriveOrgKEK]
|
|
apply prf_collision_resistant
|
|
exact prefixed_encoding_ne "vault:org:" org1 org2 h
|
|
|
|
-- Theorem 3: Collection DEK ≠ User DEK
|
|
-- A collection-scoped key is always different from the user's main DEK.
|
|
-- (Because the PRF input differs: "collection:X" vs "vault:user:Y")
|
|
theorem collection_dek_ne_user_dek
|
|
(orgKEK : List UInt8) (userID colName : String) :
|
|
let userDEK := deriveUserDEK orgKEK userID
|
|
deriveCollectionDEK userDEK colName ≠ userDEK := by
|
|
intro userDEK
|
|
-- colDEK = PRF(userDEK, col_tag); userDEK is the key. A PRF output never
|
|
-- equals its own key (prf_output_ne_key), so colDEK ≠ userDEK.
|
|
simp only [deriveCollectionDEK]
|
|
exact prf_output_ne_key userDEK ("collection:" ++ colName).toUTF8.toList
|
|
|
|
-- Theorem 4: Device Key Independence
|
|
-- Different devices for the same user get different keys.
|
|
theorem device_key_isolation
|
|
(userDEK : List UInt8)
|
|
(dev1 dev2 : String) (h : dev1 ≠ dev2) :
|
|
deriveDeviceKey userDEK dev1 ≠ deriveDeviceKey userDEK dev2 := by
|
|
simp only [deriveDeviceKey]
|
|
apply prf_collision_resistant
|
|
exact prefixed_encoding_ne "device:" dev1 dev2 h
|
|
|
|
-- Theorem 5: Key Hierarchy Depth — compromise safety
|
|
-- Master → Org → User → Collection is a 3-level PRF chain.
|
|
-- Compromising a collection DEK does not reveal the parent user DEK: the colDEK
|
|
-- value is distinct from the userDEK value, so an attacker who learns colDEK
|
|
-- has NOT thereby learned userDEK. Any candidate equal to colDEK differs from
|
|
-- userDEK (follows from prf_output_ne_key: a PRF output never equals its key).
|
|
theorem collection_compromise_safe
|
|
(orgKEK : List UInt8) (userID colName : String) :
|
|
let userDEK := deriveUserDEK orgKEK userID
|
|
let colDEK := deriveCollectionDEK userDEK colName
|
|
∀ guess : List UInt8, guess = colDEK → guess ≠ userDEK := by
|
|
intro userDEK colDEK guess hguess
|
|
rw [hguess]
|
|
simp only [colDEK, deriveCollectionDEK]
|
|
exact prf_output_ne_key userDEK ("collection:" ++ colName).toUTF8.toList
|
|
|
|
end Vault.KeyIsolation
|