Browse Source

Finish security def?

gas-move-test
Thomas Kerber 6 months ago
parent
commit
5b6bfeee81
Signed by: Thomas Kerber <tk@drwx.org> GPG Key ID: 8489B911F9ED617B
2 changed files with 78 additions and 50 deletions
  1. 71
    47
      Yggdrasil/Security.agda
  2. 7
    3
      Yggdrasil/World.agda

+ 71
- 47
Yggdrasil/Security.agda View File

@@ -1,18 +1,35 @@
1 1
 module Yggdrasil.Security where
2 2
 
3
+open import Agda.Builtin.FromNat using (Number)
4
+import Data.Nat.Literals as ℕLit
5
+import Data.Rational.Literals as ℚLit
6
+import Data.Integer.Literals as ℤLit
3 7
 open import Data.List using (_∷_; []; map)
4 8
 open import Data.Product using (_×_; Σ; Σ-syntax; proj₁; proj₂; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
5
-open import Data.Nat using (ℕ)
9
+open import Data.Nat using (ℕ; zero; suc; _≤_; _^_)
10
+open import Data.Integer using (ℤ)
6 11
 open import Data.Maybe using (Maybe) renaming (map to mmap)
7 12
 open import Data.Unit using (⊤; tt)
13
+open import Data.Rational using (ℚ)
8 14
 open import Function using (_∘_)
9 15
 open import Level using (Level; Lift; lift) renaming (suc to lsuc)
10
-open import Relation.Binary.PropositionalEquality using (_≡_; refl)
16
+open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
17
+open import Relation.Nullary.Decidable using (fromWitnessFalse)
11 18
 open import Yggdrasil.List using (_∈_; here; there; with-proof; map≡-implies-∈≡)
12
-open import Yggdrasil.World using (WorldType; WorldState; World; Oracle; Call; Strategy; Node; Action; weaken; call; call↓; _↑_; stnode; _∷_; []; exec; _⊑_; Query; _∈↑_; abort; dist; _>>=_; call↯; query; path; _↑)
13
-open import Yggdrasil.Probability using (Dist; _>>=_; pure)
19
+open import Yggdrasil.World using (WorldType; WorldState; World; Oracle; Call; Strategy; Node; Action; weaken; call; call↓; _↑_; stnode; _∷_; []; ⌊exec⌋; _⊑_; Query; _∈↑_; abort; dist; _>>=_; call↯; query; path; _↑; strat)
20
+open import Yggdrasil.Probability using (Dist; _>>=_; pure; _≈[_]≈_)
21
+open import Yggdrasil.Rational using (_÷_)
14 22
 open WorldType
15 23
 open Node
24
+open Strategy
25
+
26
+instance
27
+  ℕnumber : Number ℕ
28
+  ℕnumber = ℕLit.number
29
+  ℤnumber : Number ℤ
30
+  ℤnumber = ℤLit.number
31
+  ℚnumber : Number ℚ
32
+  ℚnumber = ℚLit.number
16 33
 
17 34
 data Guess {ℓ : Level} : Set ℓ where
18 35
   real? ideal? : Guess
@@ -40,94 +57,63 @@ record Simulator {ℓ : Level} (Γᵢ Γᵣ : WorldType ℓ) : Set (lsuc ℓ) wh
40 57
 open Simulator
41 58
 
42 59
 Actionᵢ⇒Actionᵣ : ∀ {ℓ : Level} {Γᵢ Γᵣ : WorldType ℓ} {A : Set ℓ} →
43
-  Simulator Γᵢ Γᵣ → Oracle Γᵢ → Action Γᵢ A → Action Γᵣ A
60
+  Simulator Γᵢ Γᵣ → Oracle Γᵢ → ℕ → Action Γᵢ A → Action Γᵣ A
44 61
 Action↯⇒Action : ∀ {ℓ : Level} {Γᵢ Γᵣ : WorldType ℓ} {A : Set ℓ} →
45
-  (S : Simulator Γᵢ Γᵣ) → Oracle Γᵢ → Action↯ Γᵢ Γᵣ {hon-≡ S} A → Action Γᵣ A
62
+  (S : Simulator Γᵢ Γᵣ) → Oracle Γᵢ → ℕ → Action↯ Γᵢ Γᵣ {hon-≡ S} A → Action Γᵣ A
46 63
 
47
-Actionᵢ⇒Actionᵣ S O ((call↓ ∈Γᵢ x) ↑) with map≡-implies-∈≡ (hon-≡ S) ∈Γᵢ
64
+Actionᵢ⇒Actionᵣ _ _ zero _ = abort
65
+Actionᵢ⇒Actionᵣ S O (suc g) ((call↓ ∈Γᵢ x) ↑) with map≡-implies-∈≡ (hon-≡ S) ∈Γᵢ
48 66
 ... | ⟨ _ , ⟨ ∈Γᵣ , refl ⟩ ⟩ = call↓ ∈Γᵣ x ↑
49
-Actionᵢ⇒Actionᵣ _ _ abort = abort
50
-Actionᵢ⇒Actionᵣ _ _ (dist D) = dist D
51
-Actionᵢ⇒Actionᵣ S O (call↯ ∈Γ Γ⊑ x) = Action↯⇒Action S O (call↯-map S ∈Γ Γ⊑ x)
52
-Actionᵢ⇒Actionᵣ S O (α >>= β) = (Actionᵢ⇒Actionᵣ S O α) >>=
53
-  (Actionᵢ⇒Actionᵣ S O ∘ β)
54
-
55
-Action↯⇒Action S O (query ∈Γ Γ⊑ x) = {!Actionᵢ⇒Actionᵣ S O (O (path Γ⊑ ∈Γ) x)!}
56
-Action↯⇒Action _ _ abort = abort
57
-Action↯⇒Action _ _ (dist D) = dist D
58
-Action↯⇒Action _ _ (call↯ ∈Γ Γ⊑ x) = call↯ ∈Γ Γ⊑ x
59
-Action↯⇒Action S O (α >>= β) = (Action↯⇒Action S O α) >>=
60
-  (Action↯⇒Action S O ∘ β)
67
+Actionᵢ⇒Actionᵣ _ _ _ abort = abort
68
+Actionᵢ⇒Actionᵣ _ _ _ (dist D) = dist D
69
+Actionᵢ⇒Actionᵣ S O (suc g) (call↯ ∈Γ Γ⊑ x) = Action↯⇒Action S O g (call↯-map S ∈Γ Γ⊑ x)
70
+Actionᵢ⇒Actionᵣ S O (suc g) (α >>= β) = (Actionᵢ⇒Actionᵣ S O (suc g) α) >>=
71
+  (Actionᵢ⇒Actionᵣ S O g ∘ β)
72
+
73
+Action↯⇒Action _ _ zero _ = abort
74
+Action↯⇒Action S O (suc g) (query ∈Γ Γ⊑ x) = Actionᵢ⇒Actionᵣ S O g (O (path Γ⊑ ∈Γ) x)
75
+Action↯⇒Action _ _ _ abort = abort
76
+Action↯⇒Action _ _ _ (dist D) = dist D
77
+Action↯⇒Action _ _ _ (call↯ ∈Γ Γ⊑ x) = call↯ ∈Γ Γ⊑ x
78
+Action↯⇒Action S O (suc g) (α >>= β) = (Action↯⇒Action S O (suc g) α) >>=
79
+  (Action↯⇒Action S O g ∘ β)
80
+
81
+extract-oracle : ∀ {ℓ Γᵢ Γᵣ} → Simulator {ℓ} Γᵢ Γᵣ → Oracle Γᵢ → ℕ → Oracle Γᵣ
82
+extract-oracle S O g ∈Γ x = Action↯⇒Action S O g (query-map S ∈Γ x)
61 83
 
84
+simulated-strategy : ∀ {ℓ Γᵢ Γᵣ A} → Simulator {ℓ} Γᵢ Γᵣ → Strategy Γᵢ A → ℕ →
85
+  Strategy Γᵣ A
86
+simulated-strategy S str g = strat
87
+  (Actionᵢ⇒Actionᵣ S (oracle str) g (init str))
88
+  (extract-oracle S (oracle str) g)
62 89
 
63 90
 record Challenge {ℓ : Level} : Set (lsuc ℓ) where
64 91
   field
65
-    Γᵣ : WorldType ℓ
66 92
     Γᵢ : WorldType ℓ
67
-    Σᵣ : WorldState Γᵣ
93
+    Γᵣ : WorldType ℓ
68 94
     Σᵢ : WorldState Γᵢ
95
+    Σᵣ : WorldState Γᵣ
69 96
     sim : Simulator Γᵢ Γᵣ
70
-    --sim   : Σ[ σ ∈ Set ℓ ] (σ × (∀ {c} → σ → c ∈ adv (proj₁ ideal) →
71
-    --  σ × (Σ (Call ℓ (node (proj₁ real))) (_∈ adv (proj₁ real)))))
72
- -- strategy : 
73
-
74
---exec-ideal : {ℓ : Level} → (c : Challenge {ℓ}) → (s : Strategy (proj₁ (ideal c)))
75
-
76
---private
77
---
78
---data Outcome : Set where
79
---
80
---record RouterConfig {ℓ : Level} : Set (lsuc ℓ) where
81
---
82
---open RouterConfig
83
---
84
---router-world-type : ∀ {ℓ} → RouterConfig {ℓ} → WorldType ℓ
85
---router-world-type {ℓ} rc = record
86
---
87
---router-world-state : ∀ {ℓ} → (rc : RouterConfig {ℓ}) → Guess {ℓ} →
88
---router-world-state rc real? = stnode ⟨ real? , proj₁ (proj₂ (sim rc)) ⟩
89
---router-world-state rc ideal? = stnode ⟨ ideal? , lift tt ⟩
90
-
91
---router-strategy : ∀ {ℓ A} → (rc : RouterConfig {ℓ}) →
92
---router-strategy = ?
93
---
94
---yggdrasil-game : ∀ {ℓ} → (rc : RouterConfig {ℓ}) →
95
---yggdrasil-game rc str world gas =
97
+
98
+record Adv[_]≤_ {ℓ : Level} (c : Challenge {ℓ}) (ε : ℚ) :
99
+    Set (lsuc (lsuc ℓ)) where
100
+  field
101
+    g-exec-min : ℕ
102
+    g-sim-min : ℕ
103
+    proof : (g-exec g-sim : ℕ) → g-exec-min ≤ g-exec → g-sim-min ≤ g-sim →
104
+      (str : Strategy (Challenge.Γᵢ c) Guess) →
105
+      (⌊exec⌋ str (Challenge.Σᵢ c) g-exec)
106
+        ≈[ ε ]≈
107
+      (⌊exec⌋ (simulated-strategy (Challenge.sim c) str g-sim) (Challenge.Σᵣ c)
108
+        g-exec)
109
+
110
+Perfect : {ℓ : Level} → Challenge {ℓ} → Set (lsuc (lsuc ℓ))
111
+Perfect c = Adv[ c ]≤ 0
112
+
113
+private
114
+  ^≢0 : ∀ {n m} → (suc n) ^ m ≢ 0
115
+  ^≢0 {n} {zero} ()
116
+  ^≢0 {n} {suc m} ()
117
+
118
+Computational : {ℓ : Level} → ℕ → (ℕ → Challenge {ℓ}) → Set (lsuc (lsuc ℓ))
119
+Computational κ f = Adv[ f κ ]≤ (_÷_ 1 (2 ^ κ) {fromWitnessFalse (^≢0 {1} {κ})})

+ 7
- 3
Yggdrasil/World.agda View File

@@ -3,12 +3,13 @@ module Yggdrasil.World where
3 3
 open import Data.Bool using (Bool)
4 4
 open import Data.Empty using (⊥-elim)
5 5
 open import Data.List using (List; _∷_; []; map)
6
-open import Data.Maybe using (Maybe; nothing; just)
6
+open import Data.Maybe using (Maybe; nothing; just) renaming (map to mmap)
7 7
 open import Data.Nat using (ℕ; zero; suc)
8
-open import Data.Product using (_×_; Σ; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
8
+open import Data.Product using (_×_; Σ; ∃; ∃-syntax; proj₁) renaming (_,_ to ⟨_,_⟩)
9 9
 open import Data.Sum using (_⊎_; inj₁; inj₂)
10
+open import Function using (_∘_)
10 11
 open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
11
-open import Level using (Level) renaming (suc to lsuc; lift to llift)
12
+open import Level using (Level; Lift) renaming (suc to lsuc; lift to llift)
12 13
 open import Yggdrasil.Probability using (Dist; pure; _>>=_; lift)
13 14
 open import Yggdrasil.List using (_∈_; here; there)
14 15
 
@@ -133,6 +134,8 @@ set (there Γ′∈ ⊑Γ) (stnode Σ Σs) Σ′ = stnode Σ (set′ Γ′∈ 
133 134
     set′ here ⊑Γ (Σ ∷ Σs) Σ′ = set ⊑Γ Σ Σ′ ∷ Σs
134 135
     set′ (there Γ∈) ⊑Γ (Σ ∷ Σs) Σ′ = Σ ∷ set′ Γ∈ ⊑Γ Σs Σ′
135 136
 
137
+⌊exec⌋ : ∀ {ℓ Γ A} → Strategy {ℓ} Γ A → WorldState {ℓ} Γ → ℕ →
138
+  Dist (Maybe (Lift (lsuc ℓ) A))
136 139
 exec : ∀ {ℓ Γ A} → Strategy {ℓ} Γ A → WorldState {ℓ} Γ → ℕ →
137 140
   Dist (Maybe (A × WorldState {ℓ} Γ))
138 141
 exec′ : ∀ {ℓ Γ A} → Oracle Γ → Action Γ A → WorldState {ℓ} Γ → ℕ →
@@ -145,6 +148,7 @@ exec↑ : ∀ {ℓ Γ₁ Γ₂ N A} → Oracle Γ₁ → Action↑ N A → World
145 148
   Γ₂ ⊑ Γ₁ → N ≡ node Γ₂ → ℕ → Dist (Maybe (A × WorldState {ℓ} Γ₁))
146 149
 
147 150
 -- NOTE: Gas is only used for termination here, it is NOT a computational model.
151
+⌊exec⌋ str Σ g = (exec str Σ g) >>= (pure ∘ mmap (llift ∘ proj₁))
148 152
 exec (strat α O) Σ g = exec′ O α Σ g
149 153
 
150 154
 exec′ _ _ _ zero = pure nothing

Loading…
Cancel
Save