Skip to content

Commit b979081

Browse files
authored
[Dijkstra] UTXOW: Implement languages and allowedLanguages (#1038)
* Move getLanguage to Script * Add allowedLanguages and languages
1 parent ccdf3e8 commit b979081

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

src-lib-exts/stdlib/Data/List.agda

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# OPTIONS --safe --without-K #-}
2+
module stdlib.Data.List where
3+
4+
open import Data.List
5+
open import Data.List.Relation.Unary.All
6+
open import Data.Empty
7+
8+
Is-[] : {A : Set} List A Set
9+
Is-[] = All (λ _ ⊥)

src/Ledger/Conway/Specification/Script/Base.lagda.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ record ScriptStructure : Type₁ where
108108
109109
toP2Script : Script → Maybe P2Script
110110
toP2Script = isInj₂
111+
112+
getLanguage : Script → Maybe Language
113+
getLanguage s = toP2Script s <&> language
111114
```

src/Ledger/Conway/Specification/Utxow.lagda.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ instance
6868
6969
languages : Tx → UTxO → ℙ Language
7070
languages tx utxo = mapPartial getLanguage (txscripts tx utxo)
71-
where
72-
getLanguage : Script → Maybe Language
73-
getLanguage (inj₁ _) = nothing
74-
getLanguage (inj₂ s) = just (language s)
7571
```
7672
-->
7773

src/Ledger/Dijkstra/Specification/Utxow.lagda.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,85 @@ private variable
3030
```
3131
-->
3232

33+
## Witnessing Functions {#sec:witnessing-functions}
34+
3335
```agda
34-
languages : Tx ℓ → UTxO → ℙ Language
35-
languages tx utxo = ∅ -- TODO
36+
module _ (tx : TopLevelTx) where
37+
open Tx tx
38+
open TxBody txBody
39+
40+
module _ (utxo : UTxO) where
41+
UsesBootstrapAddress : Type
42+
UsesBootstrapAddress = ∃[ o ∈ (range txOuts) ∪ range (utxo ∣ (txIns ∪ refInputs)) ] isBootstrapAddr (proj₁ o)
43+
44+
HasInlineDatum : TxOut → Type
45+
HasInlineDatum txout = Is-just (txOutToDatum txout)
46+
47+
UsesV2Features : Type
48+
UsesV2Features = ∃[ o ∈ (range txOuts) ∪ range (utxo ∣ (txIns ∪ refInputs)) ] HasInlineDatum o
49+
50+
data UsesV3Features : Set where
51+
hasVotes : ¬ (Is-[] txGovVotes) → UsesV3Features
52+
hasProposals : ¬ (Is-[] txGovProposals) → UsesV3Features
53+
hasDonation : NonZero txDonation → UsesV3Features
54+
hasTreasure : Is-just currentTreasury → UsesV3Features
55+
56+
data UsesV4Features : Set where
57+
hasSubtransactions : ¬ (Is-[] txSubTransactions) → UsesV4Features
58+
hasGuards : ¬ (Is-∅ txGuards) → UsesV4Features
59+
```
3660

37-
allowedLanguages : Tx ℓ → UTxO → ℙ Language
38-
allowedLanguages tx utxo = ∅ -- TODO
61+
<!--
62+
```agda
63+
module _ {tx : TopLevelTx} where
64+
open Tx tx
65+
open TxBody txBody
66+
67+
instance
68+
Dec-UsesV3Features : UsesV3Features tx ⁇
69+
Dec-UsesV3Features .dec
70+
with ¿ ¬ (Is-[] txGovVotes) ¿ | ¿ ¬ (Is-[] txGovProposals) ¿
71+
| ¿ NonZero txDonation ¿ | ¿ Is-just currentTreasury ¿
72+
... | yes p | _ | _ | _ = yes (hasVotes p)
73+
... | _ | yes p | _ | _ = yes (hasProposals p)
74+
... | _ | _ | yes p | _ = yes (hasDonation p)
75+
... | _ | _ | _ | yes p = yes (hasTreasure p)
76+
... | no p₁ | no p₂ | no p₃ | no p₄
77+
= no λ { (hasVotes x) → p₁ x ; (hasProposals x) → p₂ x ; (hasDonation x) → p₃ x ; (hasTreasure x) → p₄ x}
78+
79+
module _ {tx : TopLevelTx} where
80+
open Tx tx
81+
open TxBody txBody
82+
83+
instance
84+
Dec-UsesV4Features : UsesV4Features tx ⁇
85+
Dec-UsesV4Features .dec
86+
with ¿ ¬ (Is-[] txSubTransactions) ¿ | ¿ ¬ (Is-∅ txGuards) ¿
87+
... | yes p | _ = yes (hasSubtransactions p)
88+
... | _ | yes p = yes (hasGuards p)
89+
... | no p₁ | no p₂
90+
= no λ { (hasSubtransactions x) → p₁ x ; (hasGuards x) → p₂ x}
91+
```
92+
-->
93+
94+
```agda
95+
languages : ℙ P2Script → ℙ Language
96+
languages p2Scripts = mapˢ language p2Scripts
97+
98+
allowedLanguages : TopLevelTx → UTxO → ℙ Language
99+
allowedLanguages tx utxo =
100+
if UsesBootstrapAddress tx utxo
101+
then ∅
102+
else
103+
if UsesV4Features tx
104+
then fromList (PlutusV4 ∷ [])
105+
else
106+
if UsesV3Features tx
107+
then fromList (PlutusV4 ∷ PlutusV3 ∷ [])
108+
else
109+
if UsesV2Features tx utxo
110+
then fromList (PlutusV4 ∷ PlutusV3 ∷ PlutusV2 ∷ [])
111+
else fromList (PlutusV4 ∷ PlutusV3 ∷ PlutusV2 ∷ PlutusV1 ∷ [])
39112
```
40113

41114
```agda
@@ -78,7 +151,6 @@ data _⊢_⇀⦇_,SUBUTXOW⦈_ : UTxOEnv → UTxOState → SubLevelTx → UTxOSt
78151
∙ neededVKeyHashes ⊆ witsKeyHashes
79152
∙ neededScriptHashes ⊆ mapˢ hash p1Scripts ∪ mapˢ hash p2Scripts
80153
∙ neededDataHashes ⊆ dom (Γ .globalData)
81-
∙ languages tx utxo ⊆ allowedLanguages tx utxo
82154
∙ txADhash ≡ map hash txAuxData
83155
∙ Γ ⊢ s ⇀⦇ stx ,SUBUTXO⦈ s'
84156
────────────────────────────────
@@ -123,7 +195,7 @@ data _⊢_⇀⦇_,UTXOW⦈_ : UTxOEnv → UTxOState → TopLevelTx → UTxOState
123195
∙ neededVKeyHashes ⊆ witsKeyHashes
124196
∙ neededScriptHashes ⊆ mapˢ hash p1Scripts ∪ mapˢ hash p2Scripts
125197
∙ neededDataHashes ⊆ dom (Γ .globalData)
126-
∙ languages tx utxo ⊆ allowedLanguages tx utxo
198+
∙ languages p2Scripts ⊆ allowedLanguages tx utxo
127199
∙ txADhash ≡ map hash txAuxData
128200
∙ Γ ⊢ s ⇀⦇ tx ,UTXO⦈ s'
129201
────────────────────────────────

src/Ledger/Prelude.lagda.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ lookupHash : ∀ {T H : Type} ⦃ _ : DecEq H ⦄ ⦃ _ : Hashable T H ⦄ → H
9090
lookupHash h s =
9191
if h ∈ mapˢ proj₁ (m ˢ) then just (lookupᵐ m h) else nothing
9292
where m = setToMap (mapˢ < hash , id > s)
93+
94+
Is-∅ : {A : Type} → ℙ A → Type
95+
Is-∅ X = Is-[] (setToList X)
9396
```

src/Prelude.lagda.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ open import Data.Bool.ListAction public
2121
open import Data.Empty public
2222
open import Data.List public
2323
hiding (all; and; any; align; alignWith; filter; fromMaybe; map; or; product; sum; zip; zipWith)
24+
open import stdlib.Data.List public
25+
using (Is-[])
2426
open import Data.List.Membership.Propositional public
2527
using () renaming (_∈_ to _∈ˡ_; _∉_ to _∉ˡ_)
2628
open import Data.Maybe public
@@ -120,4 +122,9 @@ negPart x with sign x
120122
∸≡posPart⊖ {zero} {ℕ.suc n} = _≡_.refl
121123
∸≡posPart⊖ {ℕ.suc m} {zero} = _≡_.refl
122124
∸≡posPart⊖ {ℕ.suc m} {ℕ.suc n} = trans (∸≡posPart⊖{m}{n}) (sym (cong posPart (([1+m]⊖[1+n]≡m⊖n m n))))
125+
126+
instance
127+
Dec-NonZero : ∀ {n} → NonZero n ⁇
128+
Dec-NonZero {zero} .dec = no λ ()
129+
Dec-NonZero {suc n} .dec = yes (record { nonZero = tt })
123130
```

0 commit comments

Comments
 (0)