-
Notifications
You must be signed in to change notification settings - Fork 0
Linear Leios trace verifier #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
112eb5f
Add Linear Leios spec
WhatisRT 19af3ad
Initial linear leios trace verifier
yveshauser aebf9b8
Minor update
yveshauser 6fadc35
No need for Stage-Upkeep in Linear Leios
yveshauser ca66b96
WIP: Linear Leios trace verifier
yveshauser 1864f70
Unused
yveshauser 32a96a7
Proofs
yveshauser 90f099f
Comment
yveshauser b74fb8c
Example trace
yveshauser 3c44544
Upkeep as list (#23)
yveshauser 22036bf
Renaming
yveshauser 0f1384c
Merge branch 'main' into yveshauser/linear-leios-trace-verifier
yveshauser 65c34f4
Commented
yveshauser 6183e56
Merge branch 'main' into yveshauser/linear-leios-trace-verifier
yveshauser c8a871e
Trace verifier for updated rules
yveshauser e1aa9e4
Cleanup
yveshauser 5af81b7
Merge branch 'main' into yveshauser/linear-leios-trace-verifier
yveshauser c15a694
Re-introducing negative rules
yveshauser f6baeb7
Added PubKeys
yveshauser 2e659ef
Corrected hash
yveshauser 6cf577b
Missing module
yveshauser 7c47b97
Add linear Leios trace verifier
yveshauser e43d75d
Corrected EndorserBlock hash
yveshauser 2de6423
isValid
yveshauser 7801769
Cleanup
yveshauser 6888bac
Dropped negative rules again
yveshauser 2e471db
Decidability proof
yveshauser 08958b0
cleanup
yveshauser 16c6ee4
Need injectivity for addUpkeep
yveshauser 77d9b7e
Voting in test trace
yveshauser 72fb55f
Cleanup
yveshauser 7ca3b56
Cleanup
yveshauser a108eca
More readable
yveshauser 45c8105
More cleanup
yveshauser 914610b
Unused import
yveshauser 253f50b
Cert in RB in example trace
yveshauser 38023dc
Uncommented Short Leios (#30)
yveshauser 1f2ff7a
Simplify
WhatisRT e49f61e
Bringing `isValid?` into scope
yveshauser d46c3ed
Simplify
WhatisRT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| open import Leios.Prelude hiding (id; _>>=_; return) | ||
| open import Leios.Config | ||
| open import Leios.SpecStructure using (SpecStructure) | ||
|
|
||
| open import Prelude.Result | ||
| open import CategoricalCrypto hiding (id; _∘_) | ||
|
|
||
| module Leios.Linear.Trace.Verifier (params : Params) where | ||
|
|
||
| -- SpecStructure is not a module parameter, as the type for VrfPf needs to be known | ||
| open import Leios.Defaults params using (d-SpecStructure; isb; hpe) public | ||
| open SpecStructure d-SpecStructure hiding (Hashable-IBHeader; Hashable-EndorserBlock; isVoteCertified) public | ||
|
|
||
| module Defaults | ||
| (Lhdr Lvote Ldiff : ℕ) | ||
| (splitTxs : List Tx → List Tx × List Tx) | ||
| (validityCheckTime : EndorserBlock → ℕ) | ||
| where | ||
|
|
||
| open import Leios.Linear d-SpecStructure params Lhdr Lvote Ldiff splitTxs validityCheckTime public | ||
| open GenFFD | ||
| open Types params | ||
|
|
||
| data Action : Type where | ||
| EB-Role-Action : ℕ → EndorserBlock → Action | ||
| VT-Role-Action : ℕ → EndorserBlock → ℕ → Action | ||
| Ftch-Action : ℕ → Action | ||
| Slot₁-Action : ℕ → Action | ||
| Slot₂-Action : ℕ → Action | ||
| Base₁-Action : ℕ → Action | ||
| Base₂-Action : ℕ → Action | ||
| No-EB-Role-Action : ℕ → Action | ||
| No-VT-Role-Action : ℕ → Action | ||
|
|
||
| TestTrace = List (Action × (FFDT Out ⊎ BaseT Out ⊎ IOT In)) | ||
|
|
||
| private variable | ||
| s s′ : LeiosState | ||
| σ : Action | ||
| σs : TestTrace | ||
| ib : InputBlock | ||
| eb : EndorserBlock | ||
| ebs : List EndorserBlock | ||
| vt : List Vote | ||
| i : FFDT Out ⊎ BaseT Out ⊎ IOT In | ||
| o : FFDT In | ||
|
|
||
| open LeiosState | ||
|
|
||
| getAction : ∀ {i o} → s -⟦ i / o ⟧⇀ s′ → Action | ||
| getAction (Slot₁ {s} _) = Slot₁-Action (slot s) | ||
| getAction (Slot₂ {s}) = Slot₂-Action (slot s) | ||
| getAction (Ftch {s}) = Ftch-Action (slot s) | ||
| getAction (Base₁ {s}) = Base₁-Action (slot s) | ||
| getAction (Base₂ {s} _) = Base₂-Action (slot s) | ||
| getAction (Roles₁ (VT-Role {s} {eb = eb} {slot' = slot'} _)) = VT-Role-Action (slot s) eb slot' | ||
| getAction (Roles₁ (EB-Role {s} {eb = eb} _)) = EB-Role-Action (slot s) eb | ||
| getAction (Roles₂ {u = Base} (_ , x)) = ⊥-elim (x refl) | ||
| getAction (Roles₂ {s} {u = EB-Role} _) = No-EB-Role-Action (slot s) | ||
| getAction (Roles₂ {s} {u = VT-Role} _) = No-VT-Role-Action (slot s) | ||
|
|
||
| getSlot : Action → ℕ | ||
| getSlot (EB-Role-Action x _) = x | ||
| getSlot (VT-Role-Action x _ _) = x | ||
| getSlot (No-EB-Role-Action x) = x | ||
| getSlot (No-VT-Role-Action x) = x | ||
| getSlot (Ftch-Action x) = x | ||
| getSlot (Slot₁-Action x) = x | ||
| getSlot (Slot₂-Action x) = x | ||
| getSlot (Base₁-Action x) = x | ||
| getSlot (Base₂-Action x) = x | ||
|
|
||
|
|
||
| data Err-verifyAction (σ : Action) (i : FFDT Out ⊎ BaseT Out ⊎ IOT In) (s : LeiosState) : Type where | ||
| E-Err-Slot : getSlot σ ≢ slot s → Err-verifyAction σ i s | ||
| E-Err-CanProduceIB : (∀ π → ¬ canProduceIB (slot s) sk-IB (stake s) π) → Err-verifyAction σ i s | ||
| dummyErr : Err-verifyAction σ i s | ||
|
|
||
| -- NOTE: this goes backwards, from the current state to the initial state | ||
| data _—→_ : LeiosState → LeiosState → Type where | ||
|
|
||
| ActionStep : ∀ {s i o s′} → | ||
| ∙ s -⟦ i / o ⟧⇀ s′ | ||
| ─────────────────── | ||
| s′ —→ s | ||
|
|
||
| open import Prelude.Closures _—→_ | ||
|
|
||
| infix 0 _≈_ _≈¹_ | ||
|
|
||
| data _≈¹_ : Action × (FFDT Out ⊎ BaseT Out ⊎ IOT In) → s′ —→ s → Type where | ||
|
|
||
| FromAction¹ : | ||
| ∀ i {s′ o} | ||
| → (σ : s -⟦ honestOutputI (rcvˡ (-, i)) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₁ i) ≈¹ ActionStep σ | ||
|
|
||
| FromAction² : | ||
| ∀ i {s′ o} | ||
| → (σ : s -⟦ honestOutputI (rcvʳ (-, i)) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₂ (inj₁ i)) ≈¹ ActionStep σ | ||
|
|
||
| FromAction³ : | ||
| ∀ i {s′ o} | ||
| → (σ : s -⟦ honestInputI (-, i) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₂ (inj₂ i)) ≈¹ ActionStep σ | ||
|
|
||
| data ValidStep (es : Action × (FFDT Out ⊎ BaseT Out ⊎ IOT In)) (s : LeiosState) : Type where | ||
| Valid : (tr : s′ —→ s) → es ≈¹ tr → ValidStep es s | ||
|
|
||
| data _≈_ : TestTrace → s′ —↠ s → Type where | ||
|
|
||
| FromAction-FFD : | ||
| ∀ i {σs s′ s₀ o} {tr : s —↠ s₀} | ||
| → σs ≈ tr | ||
| → (σ : s -⟦ honestOutputI (rcvˡ (-, i)) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₁ i) ∷ σs ≈ s′ —→⟨ ActionStep σ ⟩ tr | ||
|
|
||
| FromAction-Base : | ||
| ∀ i {σs s′ s₀ o} {tr : s —↠ s₀} | ||
| → σs ≈ tr | ||
| → (σ : s -⟦ honestOutputI (rcvʳ (-, i)) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₂ (inj₁ i)) ∷ σs ≈ s′ —→⟨ ActionStep σ ⟩ tr | ||
|
|
||
| FromAction-IO : | ||
| ∀ i {σs s′ s₀ o} {tr : s —↠ s₀} | ||
| → σs ≈ tr | ||
| → (σ : s -⟦ honestInputI (-, i) / o ⟧⇀ s′) | ||
| → (getAction σ , inj₂ (inj₂ i)) ∷ σs ≈ s′ —→⟨ ActionStep σ ⟩ tr | ||
|
|
||
| Done : [] ≈ s ∎ | ||
|
|
||
| data ValidTrace (es : TestTrace) (s : LeiosState) : Type where | ||
| Valid : (tr : s′ —↠ s) → es ≈ tr → ValidTrace es s | ||
|
|
||
| getNewState : ∀ {es s} → ValidTrace es s → LeiosState | ||
| getNewState (Valid {s′ = s} _ _) = s | ||
|
|
||
| data Err-verifyTrace : TestTrace → LeiosState → Type where | ||
| Err-StepOk : Err-verifyTrace σs s → Err-verifyTrace ((σ , i) ∷ σs) s | ||
| Err-Action : Err-verifyAction σ i s′ → Err-verifyTrace ((σ , i) ∷ σs) s | ||
|
|
||
| Ok' : ∀ {s i o s′} → (σ : s -⟦ honestOutputI (rcvˡ (-, i)) / o ⟧⇀ s′) | ||
| → Result (Err-verifyAction (getAction σ) (inj₁ i) s) (ValidStep (getAction σ , inj₁ i) s) | ||
| Ok' a = Ok (Valid _ (FromAction¹ _ a)) | ||
|
|
||
| Ok'' : ∀ {s i o s′} → (σ : s -⟦ honestOutputI (rcvʳ (-, i)) / o ⟧⇀ s′) | ||
| → Result (Err-verifyAction (getAction σ) (inj₂ (inj₁ i)) s) (ValidStep (getAction σ , inj₂ (inj₁ i)) s) | ||
| Ok'' a = Ok (Valid _ (FromAction² _ a)) | ||
|
|
||
| Ok''' : ∀ {s i o s′} → (σ : s -⟦ honestInputI (-, i) / o ⟧⇀ s′) | ||
| → Result (Err-verifyAction (getAction σ) (inj₂ (inj₂ i)) s) (ValidStep (getAction σ , inj₂ (inj₂ i)) s) | ||
| Ok''' a = Ok (Valid _ (FromAction³ _ a)) | ||
|
|
||
| open import Relation.Nullary.Negation | ||
|
|
||
| verifyStep' : (a : Action) → (i : FFDT Out ⊎ BaseT Out ⊎ IOT In) → (s : LeiosState) → getSlot a ≡ slot s | ||
| → Result (Err-verifyAction a i s) (ValidStep (a , i) s) | ||
| verifyStep' (EB-Role-Action n ebs) (inj₁ SLOT) s refl with ¿ EB-Role-premises {s = s} .proj₁ ¿ | ||
| ... | yes h = Ok' (Roles₁ (EB-Role h)) | ||
| ... | _ = Err dummyErr | ||
| verifyStep' (EB-Role-Action _ _) (inj₁ FTCH) _ _ = Err dummyErr | ||
| verifyStep' (EB-Role-Action _ _) (inj₁ (FFD-OUT _)) _ _ = Err dummyErr | ||
| verifyStep' (VT-Role-Action .(slot s) eb slot') (inj₁ SLOT) s refl | ||
| with ¿ VT-Role-premises {s = s} {eb = eb} {ebHash = hash eb} {slot' = slot'} .proj₁ ¿ | ||
| | isValid? s (inj₁ (ebHeader eb)) -- TODO: why not covered above? | ||
| ... | yes (x , x₁ , x₂ , x₃ , x₄ , x₅ , x₆ , x₇ , x₈ , x₉ , x₁₀) | yes h = Ok' (Roles₁ (VT-Role {ebHash = hash eb} {slot' = slot'} ((x , x₁ , x₂ , x₃ , h , x₄ , x₅ , x₆ , x₇ , x₈ , x₉ , x₁₀)))) | ||
| ... | yes (x , x₁ , x₂ , x₃ , x₄ , x₅ , x₆ , x₇ , x₈ , x₉ , x₁₀) | no _ = Err dummyErr | ||
| ... | no ¬h | _ = Err dummyErr | ||
| verifyStep' (VT-Role-Action _ _ _) (inj₁ FTCH) _ _ = Err dummyErr | ||
| verifyStep' (VT-Role-Action _ _ _) (inj₁ (FFD-OUT _)) _ _ = Err dummyErr | ||
| verifyStep' (VT-Role-Action _ _ _) (inj₂ _) _ refl = Err dummyErr | ||
|
|
||
| -- This has a different IO pattern, not sure if we want to model that here | ||
| -- For now we'll just fail | ||
| verifyStep' (Ftch-Action n) _ _ _ = Err dummyErr | ||
|
|
||
| verifyStep' (Slot₁-Action n) (inj₁ SLOT) _ _ = Err dummyErr | ||
| verifyStep' (Slot₁-Action n) (inj₁ FTCH) _ _ = Err dummyErr | ||
| verifyStep' (Slot₁-Action n) (inj₁ (FFD-OUT msgs)) s refl with ¿ Slot₁-premises {s = s} .proj₁ ¿ | ||
| ... | yes p = Ok' (Slot₁ {s = s} {msgs = msgs} p) | ||
| ... | no _ = Err dummyErr | ||
| verifyStep' (Slot₂-Action n) (inj₁ _) _ _ = Err dummyErr | ||
| verifyStep' (Slot₂-Action n) (inj₂ (inj₁ (BASE-LDG rbs))) s refl = Ok'' (Slot₂ {s = s} {rbs = rbs}) | ||
| verifyStep' (Slot₂-Action n) (inj₂ (inj₂ y)) s refl = Err dummyErr | ||
|
|
||
| -- Different IO pattern again | ||
| verifyStep' (Base₁-Action n) (inj₂ (inj₂ (SubmitTxs txs))) s refl = Ok''' Base₁ | ||
| verifyStep' (Base₂-Action n) (inj₁ SLOT) s refl with ¿ Base₂-premises {s = s} .proj₁ ¿ | ||
| ... | yes p = Ok' (Base₂ p) | ||
| ... | no _ = Err dummyErr | ||
| verifyStep' (Base₂-Action n) _ s refl = Err dummyErr | ||
| verifyStep' (No-EB-Role-Action n) (inj₁ SLOT) s refl | ||
| with ¿ needsUpkeep s EB-Role × (∀ π → ¬ canProduceEB (slot s) (EB , tt) (stake s) π) ¿ | ||
| ... | yes p = Ok' (Roles₂ {s' = addUpkeep s EB-Role} {u = EB-Role} ((No-EB-Role p , λ () ))) | ||
| ... | no ¬p = Err dummyErr | ||
| verifyStep' (No-EB-Role-Action n) _ s refl = Err dummyErr | ||
| verifyStep' (No-VT-Role-Action n) (inj₁ SLOT) s refl | ||
| with ¿ No-VT-Role-premises {s = s} .proj₁ ¿ | ||
| ... | yes p = Ok' (Roles₂ {s' = addUpkeep s VT-Role} {u = VT-Role} (No-VT-Role p , λ ())) | ||
| ... | no ¬p = Err dummyErr | ||
| verifyStep' (No-VT-Role-Action n) _ s refl = Err dummyErr | ||
| verifyStep' (EB-Role-Action .(slot s) x) (inj₂ y) s refl = Err dummyErr | ||
| verifyStep' (Slot₁-Action x₁) (inj₂ y) s x = Err dummyErr | ||
| verifyStep' (Base₁-Action .(slot s)) (inj₁ x) s refl = Err dummyErr | ||
| verifyStep' (Base₁-Action .(slot s)) (inj₂ y) s refl = Err dummyErr | ||
|
|
||
| verifyStep : (a : Action) → (i : FFDT Out ⊎ BaseT Out ⊎ IOT In) → (s : LeiosState) → Result (Err-verifyAction a i s) (ValidStep (a , i) s) | ||
| verifyStep a i s = case getSlot a ≟ slot s of λ where | ||
| (yes p) → verifyStep' a i s p | ||
| (no ¬p) → Err (E-Err-Slot λ p → ⊥-elim (¬p p)) | ||
|
|
||
| verifyTrace : ∀ (σs : TestTrace) → (s : LeiosState) → Result (Err-verifyTrace σs s) (ValidTrace σs s) | ||
| verifyTrace [] s = Ok (Valid (s ∎) Done) | ||
| verifyTrace ((a , i) ∷ σs) s = do | ||
| σs ← mapErr Err-StepOk (verifyTrace σs s) | ||
| x ← mapErr Err-Action (verifyStep a i (getNewState σs)) | ||
| return (σs Valid∷ʳ x) | ||
| where | ||
| open Monad-Result | ||
| _Valid∷ʳ_ : ∀ {e es s} → (σs : ValidTrace es s) → ValidStep e (getNewState σs) → ValidTrace (e ∷ es) s | ||
| Valid tr x Valid∷ʳ Valid (ActionStep as) (FromAction¹ a _) = Valid (_ —→⟨ ActionStep as ⟩ tr) (FromAction-FFD a x as) | ||
| Valid tr x Valid∷ʳ Valid (ActionStep as) (FromAction² a _) = Valid (_ —→⟨ ActionStep as ⟩ tr) (FromAction-Base a x as) | ||
| Valid tr x Valid∷ʳ Valid (ActionStep as) (FromAction³ a _) = Valid (_ —→⟨ ActionStep as ⟩ tr) (FromAction-IO a x as) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.