Source code on Github
open import Prelude.Init; open SetAsType
open L.Mem
open import Prelude.Lists.Core
open import Prelude.Lists.Dec
open import Prelude.Lists.Indexed
open import Prelude.Nary
open import Prelude.Setoid
open import Prelude.Ord
open import Prelude.InferenceRules
open import Prelude.Null
open import BitML.BasicTypes
open import BitML.Predicate
module BitML.Semantics.InferenceRules (⋯ : ⋯) (let open ⋯ ⋯) where
open import BitML.Contracts ⋯ hiding (d; C; G)
open import BitML.Semantics.Action ⋯
open import BitML.Semantics.Configurations.Types ⋯
open import BitML.Semantics.Configurations.Helpers ⋯
open import BitML.Semantics.Label ⋯
open import BitML.Semantics.Predicate ⋯
infix -1 _—[_]→_ _—[_]↛_
data _—[_]→_ : Cfg → Label → Cfg → Type where
[DEP-AuthJoin] :
────────────────────────────────────────────────────────────────────────
⟨ A has v ⟩at x ∣ ⟨ A has v′ ⟩at y ∣ Γ
—[ auth-join⦅ A , x ↔ y ⦆ ]→
⟨ A has v ⟩at x ∣ ⟨ A has v′ ⟩at y ∣ A auth[ x ↔ y ▷⟨ A , v + v′ ⟩ ] ∣ Γ
[DEP-Join] :
z ∉ x ∷ y ∷ ids Γ
────────────────────────────────────────────────────────────────────────
⟨ A has v ⟩at x ∣ ⟨ A has v′ ⟩at y ∣ A auth[ x ↔ y ▷⟨ A , v + v′ ⟩ ] ∣ Γ
—[ join⦅ x ↔ y ⦆ ]→
⟨ A has (v + v′) ⟩at z ∣ Γ
[DEP-AuthDivide] :
────────────────────────────────────────────────────────
⟨ A has (v + v′) ⟩at x ∣ Γ
—[ auth-divide⦅ A , x ▷ v , v′ ⦆ ]→
⟨ A has (v + v′) ⟩at x ∣ A auth[ x ▷⟨ A , v , v′ ⟩ ] ∣ Γ
[DEP-Divide] :
All (_∉ x ∷ ids Γ) [ y ⨾ y′ ]
────────────────────────────────────────────────────────
⟨ A has (v + v′) ⟩at x ∣ A auth[ x ▷⟨ A , v , v′ ⟩ ] ∣ Γ
—[ divide⦅ x ▷ v , v′ ⦆ ]→
⟨ A has v ⟩at y ∣ ⟨ A has v′ ⟩at y′ ∣ Γ
[DEP-AuthDonate] :
──────────────────────────────────────
⟨ A has v ⟩at x ∣ Γ
—[ auth-donate⦅ A , x ▷ᵈ B ⦆ ]→
⟨ A has v ⟩at x ∣ A auth[ x ▷ᵈ B ] ∣ Γ
[DEP-Donate] :
y ∉ x ∷ ids Γ
──────────────────────────────────────
⟨ A has v ⟩at x ∣ A auth[ x ▷ᵈ B ] ∣ Γ
—[ donate⦅ x ▷ᵈ B ⦆ ]→
⟨ B has v ⟩at y ∣ Γ
[DEP-AuthDestroy] :
∀ {ds : DepositRefs} {j : Index ds} →
let xs = map select₃ ds
Aⱼ = (ds ‼ j) .proj₁
j′ = ‼-map {xs = ds} j
Δ = || map (uncurry₃ ⟨_has_⟩at_) ds
in
y ∉ ids Γ
──────────────────────────────────────────────────────────────
Δ ∣ Γ
—[ auth-destroy⦅ Aⱼ , xs , j′ ⦆ ]→
Δ ∣ Aⱼ auth[ xs , j′ ▷ᵈˢ y ] ∣ Γ
[DEP-Destroy] :
∀ {ds : DepositRefs} →
let
xs = map select₃ ds
Δ = || map (λ (i , Aᵢ , vᵢ , xᵢ) →
⟨ Aᵢ has vᵢ ⟩at xᵢ ∣ Aᵢ auth[ xs , ‼-map {xs = ds} i ▷ᵈˢ y ]
) (enumerate ds)
in
─────────────────────────────────────────────────────────────────────────────
Δ ∣ Γ
—[ destroy⦅ xs ⦆ ]→
Γ
[C-Advertise] : let open ∣AD ad in
∙ ValidAd ad
∙ Any (_∈ Hon) partG
∙ deposits ad ⊆ deposits Γ
────────────────────────────────────────────────────────────
Γ —[ advertise⦅ ad ⦆ ]→ ` ad ∣ Γ
[C-AuthCommit] : let open ∣AD ad in
∀ {secrets : List (Secret × Maybe ℕ)} →
let (as , ms) = unzip secrets
Δ = || map (uncurry ⟨ A ∶_♯_⟩) secrets
in
∙ as ≡ secretsOfᵖ A G
∙ All (_∉ secretsOfᶜᶠ A Γ) as
∙ (A ∈ Hon → All Is-just ms)
──────────────────────────────────────────────────────────────────────────
` ad ∣ Γ
—[ auth-commit⦅ A , ad , secrets ⦆ ]→
` ad ∣ Γ ∣ Δ ∣ A auth[ ♯▷ ad ]
[C-AuthInit] : let open ∣AD ad in
∙ partG ⊆ committedParticipants ad Γ
∙ (A , v , x) ∈ persistentDeposits G
───────────────────────────────────────────────────────────────────────────────────
` ad ∣ Γ
—[ auth-init⦅ A , ad , x ⦆ ]→
` ad ∣ Γ ∣ A auth[ x ▷ˢ ad ]
[C-Init] : let open ∣AD ad in
let toSpend = persistentDeposits G
vs = map select₂ toSpend
xs = map select₃ toSpend
in
x ∉ xs ++ ids Γ
──────────────────────────────────────────────────────────────────────────────
` ad
∣ Γ
∣ || map (λ (Aᵢ , vᵢ , xᵢ) → ⟨ Aᵢ has vᵢ ⟩at xᵢ ∣ Aᵢ auth[ xᵢ ▷ˢ ad ]) toSpend
∣ || map _auth[ ♯▷ ad ] partG
—[ init⦅ G , C ⦆ ]→
⟨ C , sum vs ⟩at x ∣ Γ
[C-Split] :
∀ {vcis : VIContracts} →
let (vs , cs , ys) = unzip₃ vcis in
All (_∉ y ∷ ids Γ) ys
──────────────────────────────────────────
⟨ [ split (zip vs cs) ] , sum vs ⟩at y ∣ Γ
—[ split⦅ y ⦆ ]→
|| map (uncurry₃ $ flip ⟨_,_⟩at_) vcis ∣ Γ
[C-AuthRev] :
─────────────────────────
⟨ A ∶ a ♯ just n ⟩ ∣ Γ
—[ auth-rev⦅ A , a ⦆ ]→
A ∶ a ♯ n ∣ Γ
[C-PutRev] :
∀ {ds : DepositRefs}
{ss : List (Participant × Secret × ℕ)} →
let (_ , vs , xs) = unzip₃ ds
(_ , as , _) = unzip₃ ss
Γ = || map (uncurry₃ ⟨_has_⟩at_) ds
Δ = || map (uncurry₃ _∶_♯_) ss
ΔΓ′ = Δ ∣ Γ′
in
∙ z ∉ y ∷ ids (Γ ∣ ΔΓ′)
∙ ⟦ p ⟧ᵖ Δ ≡ just true
──────────────────────────────────────────────────────
⟨ [ put xs &reveal as if p ⇒ c ] , v ⟩at y ∣ (Γ ∣ ΔΓ′)
—[ put⦅ xs , as , y ⦆ ]→
⟨ c , v + sum vs ⟩at z ∣ ΔΓ′
[C-Withdraw] :
x ∉ y ∷ ids Γ
──────────────────────────────
⟨ [ withdraw A ] , v ⟩at y ∣ Γ
—[ withdraw⦅ A , v , y ⦆ ]→
⟨ A has v ⟩at x ∣ Γ
[C-AuthControl] :
∀ {i : Index c} → let d = c ‼ i in
A ∈ authDecorations d
───────────────────────────────────
⟨ c , v ⟩at x ∣ Γ
—[ auth-control⦅ A , x ▷ d ⦆ ]→
⟨ c , v ⟩at x ∣ A auth[ x ▷ d ] ∣ Γ
[C-Control] :
∀ {i : Index c} → let open ∣SELECT c i in
∙ ¬Null (authDecorations d) ⊎ (length c > 1)
∙ Γ ≈ L
∙ ⟨ [ d∗ ] , v ⟩at x ∣ L —[ α ]→ Γ′
∙ cv α ≡ just x
───────────────────────────────────────────────────────────────────
⟨ c , v ⟩at x ∣ || map _auth[ x ▷ d ] (nub $ authDecorations d) ∣ Γ
—[ α ]→
Γ′
infix 3 _≈ₜ_
_≈ₜ_ : Cfgᵗ → Cfgᵗ → Type
c ≈ₜ c′ = (time c ≡ time c′) × (cfg c ≈ cfg c′)
infix -1 _—[_]→ₜ_
data _—[_]→ₜ_ : Cfgᵗ → Label → Cfgᵗ → Type where
[Action] :
∙ Γ —[ α ]→ Γ′
∙ cv α ≡ nothing
───────────────────────
Γ at t —[ α ]→ₜ Γ′ at t
[Delay] :
δ > 0
─────────────────────────────────────
Γ at t —[ delay⦅ δ ⦆ ]→ₜ Γ at (t + δ)
[Timeout] :
∀ {i : Index c} → let open ∣SELECT c i; As , ts = decorations d in
∙ Null As
∙ All (_≤ t) ts
∙ ⟨ [ d∗ ] , v ⟩at x ∣ Γ —[ α ]→ Γ′
∙ cv α ≡ just x
──────────────────────────────────────────────────────────────────────────────
(⟨ c , v ⟩at x ∣ Γ) at t —[ α ]→ₜ Γ′ at t
_—[_]↛_ : Cfg → Label → Cfg → Type
Γ —[ α ]↛ Γ′ = ¬ (Γ —[ α ]→ Γ′)
_—[_]↛ₜ_ : Cfgᵗ → Label → Cfgᵗ → Type
Γₜ —[ α ]↛ₜ Γₜ′ = ¬ (Γₜ —[ α ]→ₜ Γₜ′)
open import Prelude.Closures
open UpToLabelledReflexiveTransitiveClosure _—[_]→_ public
open UpToLabelledReflexiveTransitiveClosure _—[_]→ₜ_ public
renaming ( begin_ to beginₜ_; _∎ to _∎ₜ
; _—→⟨_⟩_⊢_ to _—→ₜ⟨_⟩_⊢_; _—→⟨_⟩_ to _—→ₜ⟨_⟩_; _`—→⟨_⟩_⊢_ to _`—→ₜ⟨_⟩_⊢_
; _—→_ to _—→ₜ_
; _—[_]↠_ to _—[_]↠ₜ_; _—↠_ to _—↠ₜ_
; _—[_]↠⁺_ to _—[_]↠⁺ₜ_; _—↠⁺_ to _—↠⁺ₜ_
; _⟨_⟩←—_⊢_ to _⟨_⟩←—ₜ_⊢_; _⟨_⟩←—_ to _⟨_⟩←—ₜ_; _`⟨_⟩←—_⊢_ to _`⟨_⟩←—ₜ_⊢_
; _←[_]—_ to _←[_]—ₜ_; _←—_ to _←—ₜ_
; _↞[_]—_ to _↞[_]—ₜ_; _↞—_ to _↞—ₜ_
; _⁺↞[_]—_ to _⁺↞[_]—ₜ_; _⁺↞—_ to _⁺↞—ₜ_
; viewLeft to viewLeftₜ; viewRight to viewRightₜ; view↔ to view↔ₜ
)