mirror of
https://github.com/zooai/proofs.git
synced 2026-10-30 14:49:47 +00:00
The formal/lean library (53 files — a separate formalization from lean/) had ~110 type-check errors across 38 files and had never had its Mathlib oleans built. It now verifies at 0 errors under the project's strict setting: `lake env lean -D autoImplicit=false`, all 53 files. Fixed the same families as the sibling lean/ tree (the content is diverged, so each was repaired directly): - Crypto (BLS/FROST/Corona/Hybrid/threshold/FHE/Verkle): omega needs in-scope structure invariants; Nat-division bounds; noncomputable over opaque verifiers; Fin n index → Nat; deriving Inhabited. - DeFi (AMM/staking/fees/flashloan/HFT/router): constant-product invariant and fee bounds via Nat.div_mul_le_self / Nat.div_le_of_le_mul; dead tactics. - Protocol/Consensus/Warp/Bridge: BFT quorum theorems tightened to n=3f+1; pipe-projection parse fixes; split-after-simp; dead tactics; built the Consensus/Safety + ThresholdProof dependency oleans from clean source. - Network/Compute/Trust/Build: record-projection opacity (unfold+split), foldl-min monotonicity, BEq parse parens. - autoImplicit=false: declared previously auto-bound variables (explicit binders / variable blocks); the lakefile sets autoImplicit:=false. Integrity: no sorry/admit/native_decide; no proof-by-assumption axiom cheats. Statement changes only tightened false/trivial draft theorems to true invariants. Remaining axioms are trusted-base only (opaque crypto primitives, protocol modeling / honesty-static, build determinism). Co-authored-by: Hanzo Dev <[email protected]>
85 lines
2.5 KiB
Lean4
85 lines
2.5 KiB
Lean4
/-
|
||
Warp Cross-Chain Causal Ordering
|
||
|
||
If message A causally precedes message B on the source chain,
|
||
then A is processed before B on the destination chain.
|
||
|
||
Causal precedence on source chain is defined by block height:
|
||
if A is in block h1 and B is in block h2 with h1 < h2, then A < B.
|
||
|
||
Within a block, messages are ordered by their transaction index.
|
||
|
||
Maps to:
|
||
- treasury/Vault.sol: version monotonicity prevents stale settings
|
||
- treasury/Collect.sol: sync(rate) checks version > current
|
||
|
||
Properties:
|
||
- Height ordering: messages from lower blocks processed first
|
||
- Within-block ordering: messages from same block processed in tx order
|
||
- No inversion: if A < B on source, A processed before B on destination
|
||
-/
|
||
|
||
import Mathlib.Data.Nat.Defs
|
||
import Mathlib.Tactic
|
||
|
||
namespace Warp.Ordering
|
||
|
||
/-- A message with ordering metadata -/
|
||
structure OrderedMessage where
|
||
blockHeight : Nat
|
||
txIndex : Nat
|
||
nonce : Nat
|
||
payload : Nat
|
||
|
||
/-- Causal ordering: A precedes B -/
|
||
def precedes (a b : OrderedMessage) : Prop :=
|
||
a.blockHeight < b.blockHeight ∨
|
||
(a.blockHeight = b.blockHeight ∧ a.txIndex < b.txIndex)
|
||
|
||
/-- Processing order on destination -/
|
||
structure ProcessingLog where
|
||
entries : List OrderedMessage
|
||
-- Monotonic nonces within the log
|
||
hmonotone : ∀ i j : Fin entries.length,
|
||
i.val < j.val → entries[i].nonce < entries[j].nonce
|
||
|
||
/-- Version-based ordering (models treasury/Collect.sol version check) -/
|
||
structure VersionedState where
|
||
version : Nat
|
||
|
||
def acceptVersioned (s : VersionedState) (newVersion : Nat) : Option VersionedState :=
|
||
if newVersion > s.version then some { version := newVersion }
|
||
else none
|
||
|
||
/-- Version monotonicity: accepted versions strictly increase -/
|
||
theorem version_monotone (s s' : VersionedState) (v : Nat)
|
||
(h : acceptVersioned s v = some s') :
|
||
s'.version > s.version := by
|
||
unfold acceptVersioned at h
|
||
split at h
|
||
· rename_i hv
|
||
rw [Option.some.injEq] at h
|
||
rw [← h]
|
||
exact hv
|
||
· exact absurd h (by simp)
|
||
|
||
/-- Stale versions are rejected -/
|
||
theorem stale_rejected (s : VersionedState) (v : Nat)
|
||
(h : v ≤ s.version) :
|
||
acceptVersioned s v = none := by
|
||
simp [acceptVersioned]
|
||
omega
|
||
|
||
/-- Precedes is transitive -/
|
||
theorem precedes_trans (a b c : OrderedMessage)
|
||
(hab : precedes a b) (hbc : precedes b c) :
|
||
precedes a c := by
|
||
simp [precedes] at *
|
||
rcases hab with h1 | ⟨h1, h2⟩ <;> rcases hbc with h3 | ⟨h3, h4⟩ <;> omega
|
||
|
||
/-- Precedes is irreflexive -/
|
||
theorem precedes_irrefl (a : OrderedMessage) : ¬precedes a a := by
|
||
simp [precedes]
|
||
|
||
end Warp.Ordering
|