Download lean/proofs/Sovereign/Serialization.lean from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 10.1 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/proofs/Sovereign/Serialization.lean
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/lean/proofs/Sovereign/Serialization.lean
-
curl -L -o Serialization.lean https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/proofs/Sovereign/Serialization.lean
10.1 kB
Lean 4 Β· 23
declarations statementsfull
def CBOREncoding : Type := Vector UInt8 256 -- max size for a SEB record
def CBOR_MAJOR_BYTES : UInt8 := 0x40
def cbor_encode_seb_record (record : Vector UInt8 96) : CBOREncoding :=
body Β· 10 lines
-- Byte string major type = 2, length 96 = 0x58 (1-byte length follows)
-- 0x5858: major=2, additional=24, then 0x60 (= 96)
let prefix := Vector.replicate 256 (0x00 : UInt8)
let prefix := prefix.set 0 0x58 -- major type 2, additional length 24
let prefix := prefix.set 1 0x60 -- 96 in decimal
Vector.zipWith (fun i a =>
if i < 2 then a
else if i - 2 < 96 then record.get β¨i - 2, by omegaβ©
else 0x00
) prefix (Vector.replicate 256 (0x00 : UInt8))
theorem cbor_encoding_is_canonical :
β (record : Vector UInt8 96),
β enc1 enc2 : CBOREncoding,
cbor_encode_seb_record record = enc1 β
cbor_encode_seb_record record = enc2 β
enc1 = enc2 := by
proof Β· 2 lines
intro record enc1 enc2 h1 h2 rw [h1, h2]
theorem cbor_encoding_unique :
β (record : Vector UInt8 96),
β! enc : CBOREncoding, enc = cbor_encode_seb_record record := by
proof Β· 3 lines
intro record use cbor_encode_seb_record record simp
def Blake3Hash : Type := Vector UInt8 32
opaque blake3_hash : Vector UInt8 β Blake3Hash
axiom blake3_deterministic :
β (x y : Vector UInt8),
x = y β blake3_hash x = blake3_hash y
axiom blake3_collision_resistant :
β (x y : Vector UInt8),
blake3_hash x = blake3_hash y β x = y β¨ computationally_infeasible_to_find_collision
axiom computationally_infeasible_to_find_collision : Prop
theorem blake3_hash_is_deterministic :
β (record : Vector UInt8 96),
blake3_hash (record.map (Fin.cast) : Vector UInt8 96) =
blake3_hash (record.map (Fin.cast) : Vector UInt8 96) := by
proof Β· 2 lines
intro record rfl
theorem blake3_hash_reproducible :
β (record : Vector UInt8 96),
let hash1 := blake3_hash (record.map (Fin.cast) : Vector UInt8 96)
proof Β· 5 lines
let hash2 := blake3_hash (record.map (Fin.cast) : Vector UInt8 96)
hash1 = hash2 := by
intro record
simp
rfl
def Ed25519PublicKey : Type := Vector UInt8 32
def Ed25519SecretKey : Type := Vector UInt8 32
def Ed25519Signature : Type := Vector UInt8 64
opaque ed25519_sign : Ed25519SecretKey β Vector UInt8 β Ed25519Signature
opaque ed25519_verify : Ed25519PublicKey β Vector UInt8 β Ed25519Signature β Bool
axiom ed25519_signature_deterministic :
β (sk : Ed25519SecretKey) (msg : Vector UInt8),
let sig1 := ed25519_sign sk msg
body Β· 2 lines
let sig2 := ed25519_sign sk msg
sig1 = sig2
axiom ed25519_unforgeability :
β (pk : Ed25519PublicKey) (msg : Vector UInt8) (sig : Ed25519Signature),
ed25519_verify pk msg sig = true β
(β sk : Ed25519SecretKey,
ed25519_sign sk msg = sig) β¨
discrete_log_broken
axiom discrete_log_broken : Prop -- This is the hard computational assumption
theorem ed25519_signature_is_unforgeable :
β (pk : Ed25519PublicKey) (msg : Vector UInt8) (sig : Ed25519Signature),
ed25519_verify pk msg sig = true β
(β sk : Ed25519SecretKey,
ed25519_sign sk msg = sig β§
-- This sk correctly produced sig
ed25519_verify pk msg (ed25519_sign sk msg) = true) β¨
-- Or an attacker solved ECDLP
discrete_log_broken := by
proof Β· 3 lines
intro pk msg sig hverify
-- Apply unforgeability axiom
apply ed25519_unforgeability pk msg sig hverify
theorem ed25519_seb_record_signature_is_deterministic :
β (sk : Ed25519SecretKey) (record : Vector UInt8 96),
let sig1 := ed25519_sign sk record
proof Β· 4 lines
let sig2 := ed25519_sign sk record
sig1 = sig2 := by
intro sk record
apply ed25519_signature_deterministic
theorem canonical_serialization_chain :
β (record : Vector UInt8 96) (sk : Ed25519SecretKey),
let encoding := cbor_encode_seb_record record
proof Β· 14 lines
let hash := blake3_hash (encoding.map (Fin.cast) : Vector UInt8 256)
let sig := ed25519_sign sk (encoding.map (Fin.cast) : Vector UInt8 256)
-- The encoding, hash, and signature are all canonical/unique
(β! enc : CBOREncoding, enc = encoding) β§
(β! h : Blake3Hash, h = hash) β§
(β! s : Ed25519Signature, s = sig) := by
intro record sk
constructor
Β· apply cbor_encoding_unique
constructor
Β· use blake3_hash _
simp
Β· use ed25519_sign sk _
simp
Outline
- def
CBOREncoding39 - def
CBOR_MAJOR_BYTES42 - def
cbor_encode_seb_record45 - theorem
cbor_encoding_is_canonical62 - theorem
cbor_encoding_unique72 - def
Blake3Hash89 - opaque
blake3_hash92 - axiom
blake3_deterministic96 - axiom
blake3_collision_resistant101 - axiom
computationally_infeasible_to_find_collision105 - theorem
blake3_hash_is_deterministic111 - theorem
blake3_hash_reproducible119 - def
Ed25519PublicKey142 - def
Ed25519SecretKey143 - def
Ed25519Signature144 - opaque
ed25519_sign147 - opaque
ed25519_verify148 - axiom
ed25519_signature_deterministic152 - axiom
ed25519_unforgeability160 - axiom
discrete_log_broken167 - theorem
ed25519_signature_is_unforgeable178 - theorem
ed25519_seb_record_signature_is_deterministic192 - theorem
canonical_serialization_chain211