Преглед изворни кода

Finish security def?

gas-move-test
Thomas Kerber пре 1 година
родитељ
комит
5b6bfeee81
Signed by: Thomas Kerber <tk@drwx.org> GPG Key ID: 8489B911F9ED617B
2 измењених фајлова са 78 додато и 50 уклоњено
  1. +71
    -47
      Yggdrasil/Security.agda
  2. +7
    -3
      Yggdrasil/World.agda

+ 71
- 47
Yggdrasil/Security.agda Прегледај датотеку

@@ -1,18 +1,35 @@
module Yggdrasil.Security where

open import Agda.Builtin.FromNat using (Number)
import Data.Nat.Literals as ℕLit
import Data.Rational.Literals as ℚLit
import Data.Integer.Literals as ℤLit
open import Data.List using (_∷_; []; map)
open import Data.Product using (_×_; Σ; Σ-syntax; proj₁; proj₂; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Data.Nat using (ℕ)
open import Data.Nat using (ℕ; zero; suc; _≤_; _^_)
open import Data.Integer using (ℤ)
open import Data.Maybe using (Maybe) renaming (map to mmap)
open import Data.Unit using (⊤; tt)
open import Data.Rational using (ℚ)
open import Function using (_∘_)
open import Level using (Level; Lift; lift) renaming (suc to lsuc)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
open import Relation.Nullary.Decidable using (fromWitnessFalse)
open import Yggdrasil.List using (_∈_; here; there; with-proof; map≡-implies-∈≡)
open import Yggdrasil.World using (WorldType; WorldState; World; Oracle; Call; Strategy; Node; Action; weaken; call; call↓; _↑_; stnode; _∷_; []; exec; _⊑_; Query; _∈↑_; abort; dist; _>>=_; call↯; query; path; _↑)
open import Yggdrasil.Probability using (Dist; _>>=_; pure)
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)
open import Yggdrasil.Probability using (Dist; _>>=_; pure; _≈[_]≈_)
open import Yggdrasil.Rational using (_÷_)
open WorldType
open Node
open Strategy

instance
ℕnumber : Number ℕ
ℕnumber = ℕLit.number
ℤnumber : Number ℤ
ℤnumber = ℤLit.number
ℚnumber : Number ℚ
ℚnumber = ℚLit.number

data Guess {ℓ : Level} : Set ℓ where
real? ideal? : Guess
@@ -40,94 +57,63 @@ record Simulator {ℓ : Level} (Γᵢ Γᵣ : WorldType ℓ) : Set (lsuc ℓ) wh
open Simulator

Actionᵢ⇒Actionᵣ : ∀ {ℓ : Level} {Γᵢ Γᵣ : WorldType ℓ} {A : Set ℓ} →
Simulator Γᵢ Γᵣ → Oracle Γᵢ → Action Γᵢ A → Action Γᵣ A
Simulator Γᵢ Γᵣ → Oracle Γᵢ → ℕ → Action Γᵢ A → Action Γᵣ A
Action↯⇒Action : ∀ {ℓ : Level} {Γᵢ Γᵣ : WorldType ℓ} {A : Set ℓ} →
(S : Simulator Γᵢ Γᵣ) → Oracle Γᵢ → Action↯ Γᵢ Γᵣ {hon-≡ S} A → Action Γᵣ A
(S : Simulator Γᵢ Γᵣ) → Oracle Γᵢ → ℕ → Action↯ Γᵢ Γᵣ {hon-≡ S} A → Action Γᵣ A

Actionᵢ⇒Actionᵣ S O ((call↓ ∈Γᵢ x) ↑) with map≡-implies-∈≡ (hon-≡ S) ∈Γᵢ
Actionᵢ⇒Actionᵣ _ _ zero _ = abort
Actionᵢ⇒Actionᵣ S O (suc g) ((call↓ ∈Γᵢ x) ↑) with map≡-implies-∈≡ (hon-≡ S) ∈Γᵢ
... | ⟨ _ , ⟨ ∈Γᵣ , refl ⟩ ⟩ = call↓ ∈Γᵣ x ↑
Actionᵢ⇒Actionᵣ _ _ abort = abort
Actionᵢ⇒Actionᵣ _ _ (dist D) = dist D
Actionᵢ⇒Actionᵣ S O (call↯ ∈Γ Γ⊑ x) = Action↯⇒Action S O (call↯-map S ∈Γ Γ⊑ x)
Actionᵢ⇒Actionᵣ S O (α >>= β) = (Actionᵢ⇒Actionᵣ S O α) >>=
(Actionᵢ⇒Actionᵣ S O ∘ β)

Action↯⇒Action S O (query ∈Γ Γ⊑ x) = {!Actionᵢ⇒Actionᵣ S O (O (path Γ⊑ ∈Γ) x)!}
Action↯⇒Action _ _ abort = abort
Action↯⇒Action _ _ (dist D) = dist D
Action↯⇒Action _ _ (call↯ ∈Γ Γ⊑ x) = call↯ ∈Γ Γ⊑ x
Action↯⇒Action S O (α >>= β) = (Action↯⇒Action S O α) >>=
(Action↯⇒Action S O ∘ β)
Actionᵢ⇒Actionᵣ _ _ _ abort = abort
Actionᵢ⇒Actionᵣ _ _ _ (dist D) = dist D
Actionᵢ⇒Actionᵣ S O (suc g) (call↯ ∈Γ Γ⊑ x) = Action↯⇒Action S O g (call↯-map S ∈Γ Γ⊑ x)
Actionᵢ⇒Actionᵣ S O (suc g) (α >>= β) = (Actionᵢ⇒Actionᵣ S O (suc g) α) >>=
(Actionᵢ⇒Actionᵣ S O g ∘ β)

Action↯⇒Action _ _ zero _ = abort
Action↯⇒Action S O (suc g) (query ∈Γ Γ⊑ x) = Actionᵢ⇒Actionᵣ S O g (O (path Γ⊑ ∈Γ) x)
Action↯⇒Action _ _ _ abort = abort
Action↯⇒Action _ _ _ (dist D) = dist D
Action↯⇒Action _ _ _ (call↯ ∈Γ Γ⊑ x) = call↯ ∈Γ Γ⊑ x
Action↯⇒Action S O (suc g) (α >>= β) = (Action↯⇒Action S O (suc g) α) >>=
(Action↯⇒Action S O g ∘ β)

extract-oracle : ∀ {ℓ Γᵢ Γᵣ} → Simulator {ℓ} Γᵢ Γᵣ → Oracle Γᵢ → ℕ → Oracle Γᵣ
extract-oracle S O g ∈Γ x = Action↯⇒Action S O g (query-map S ∈Γ x)

simulated-strategy : ∀ {ℓ Γᵢ Γᵣ A} → Simulator {ℓ} Γᵢ Γᵣ → Strategy Γᵢ A → ℕ →
Strategy Γᵣ A
simulated-strategy S str g = strat
(Actionᵢ⇒Actionᵣ S (oracle str) g (init str))
(extract-oracle S (oracle str) g)

record Challenge {ℓ : Level} : Set (lsuc ℓ) where
field
Γᵣ : WorldType ℓ
Γᵢ : WorldType ℓ
Σᵣ : WorldState Γᵣ
Γᵣ : WorldType ℓ
Σᵢ : WorldState Γᵢ
Σᵣ : WorldState Γᵣ
sim : Simulator Γᵢ Γᵣ
--sim : Σ[ σ ∈ Set ℓ ] (σ × (∀ {c} → σ → c ∈ adv (proj₁ ideal) →
-- σ × (Σ (Call ℓ (node (proj₁ real))) (_∈ adv (proj₁ real)))))
-- strategy :

--exec-ideal : {ℓ : Level} → (c : Challenge {ℓ}) → (s : Strategy (proj₁ (ideal c)))

--private
--
--data Outcome : Set where
--
--record RouterConfig {ℓ : Level} : Set (lsuc ℓ) where
--
--open RouterConfig
--
--router-world-type : ∀ {ℓ} → RouterConfig {ℓ} → WorldType ℓ
--router-world-type {ℓ} rc = record
--
--router-world-state : ∀ {ℓ} → (rc : RouterConfig {ℓ}) → Guess {ℓ} →
--router-world-state rc real? = stnode ⟨ real? , proj₁ (proj₂ (sim rc)) ⟩
--router-world-state rc ideal? = stnode ⟨ ideal? , lift tt ⟩

--router-strategy : ∀ {ℓ A} → (rc : RouterConfig {ℓ}) →
--router-strategy = ?
--
--yggdrasil-game : ∀ {ℓ} → (rc : RouterConfig {ℓ}) →
--yggdrasil-game rc str world gas =

record Adv[_]≤_ {ℓ : Level} (c : Challenge {ℓ}) (ε : ℚ) :
Set (lsuc (lsuc ℓ)) where
field
g-exec-min : ℕ
g-sim-min : ℕ
proof : (g-exec g-sim : ℕ) → g-exec-min ≤ g-exec → g-sim-min ≤ g-sim →
(str : Strategy (Challenge.Γᵢ c) Guess) →
(⌊exec⌋ str (Challenge.Σᵢ c) g-exec)
≈[ ε ]≈
(⌊exec⌋ (simulated-strategy (Challenge.sim c) str g-sim) (Challenge.Σᵣ c)
g-exec)

Perfect : {ℓ : Level} → Challenge {ℓ} → Set (lsuc (lsuc ℓ))
Perfect c = Adv[ c ]≤ 0

private
^≢0 : ∀ {n m} → (suc n) ^ m ≢ 0
^≢0 {n} {zero} ()
^≢0 {n} {suc m} ()

Computational : {ℓ : Level} → ℕ → (ℕ → Challenge {ℓ}) → Set (lsuc (lsuc ℓ))
Computational κ f = Adv[ f κ ]≤ (_÷_ 1 (2 ^ κ) {fromWitnessFalse (^≢0 {1} {κ})})

+ 7
- 3
Yggdrasil/World.agda Прегледај датотеку

@@ -3,12 +3,13 @@ module Yggdrasil.World where
open import Data.Bool using (Bool)
open import Data.Empty using (⊥-elim)
open import Data.List using (List; _∷_; []; map)
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Maybe using (Maybe; nothing; just) renaming (map to mmap)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_×_; Σ; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Data.Product using (_×_; Σ; ∃; ∃-syntax; proj₁) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
open import Level using (Level) renaming (suc to lsuc; lift to llift)
open import Level using (Level; Lift) renaming (suc to lsuc; lift to llift)
open import Yggdrasil.Probability using (Dist; pure; _>>=_; lift)
open import Yggdrasil.List using (_∈_; here; there)

@@ -133,6 +134,8 @@ set (there Γ′∈ ⊑Γ) (stnode Σ Σs) Σ′ = stnode Σ (set′ Γ′∈
set′ here ⊑Γ (Σ ∷ Σs) Σ′ = set ⊑Γ Σ Σ′ ∷ Σs
set′ (there Γ∈) ⊑Γ (Σ ∷ Σs) Σ′ = Σ ∷ set′ Γ∈ ⊑Γ Σs Σ′

⌊exec⌋ : ∀ {ℓ Γ A} → Strategy {ℓ} Γ A → WorldState {ℓ} Γ → ℕ →
Dist (Maybe (Lift (lsuc ℓ) A))
exec : ∀ {ℓ Γ A} → Strategy {ℓ} Γ A → WorldState {ℓ} Γ → ℕ →
Dist (Maybe (A × WorldState {ℓ} Γ))
exec′ : ∀ {ℓ Γ A} → Oracle Γ → Action Γ A → WorldState {ℓ} Γ → ℕ →
@@ -145,6 +148,7 @@ exec↑ : ∀ {ℓ Γ₁ Γ₂ N A} → Oracle Γ₁ → Action↑ N A → World
Γ₂ ⊑ Γ₁ → N ≡ node Γ₂ → ℕ → Dist (Maybe (A × WorldState {ℓ} Γ₁))

-- NOTE: Gas is only used for termination here, it is NOT a computational model.
⌊exec⌋ str Σ g = (exec str Σ g) >>= (pure ∘ mmap (llift ∘ proj₁))
exec (strat α O) Σ g = exec′ O α Σ g

exec′ _ _ _ zero = pure nothing

Loading…
Откажи
Сачувај