Skip to content

Commit 75365e1

Browse files
committed
Add UTXOW preconditions
1 parent 9686678 commit 75365e1

File tree

6 files changed

+154
-21
lines changed

6 files changed

+154
-21
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
--
22
source_branch: master
33
source_path: src/Ledger/Dijkstra/Specification/Ledger.lagda
44
---
@@ -197,15 +197,15 @@ data _⊢_⇀⦇_,SUBLEDGER⦈_ : SubLedgerEnv → LState → SubLevelTx → LSt
197197
```agda
198198
in
199199
∙ isTopLevelValid ≡ true
200-
∙ ⟦ slot , pp , treasury ⟧ ⊢ utxoState ⇀⦇ stx ,SUBUTXOW⦈ utxoState'
200+
∙ ⟦ slot , pp , treasury , {!!} ⟧ ⊢ utxoState ⇀⦇ stx ,SUBUTXOW⦈ utxoState'
201201
∙ ⟦ epoch slot , pp , txGovVotes , txWithdrawals , allColdCreds govState enactState ⟧ ⊢ certState ⇀⦇ txCerts ,CERTS⦈ certState'
202202
∙ ⟦ txId , epoch slot , pp , ppolicy , enactState , certState' , dom (RewardsOf certState) ⟧ ⊢ {- rmOrphanDRepVotes certState' -} govState ⇀⦇ txgov txb ,GOVS⦈ govState'
203203
────────────────────────────────
204204
⟦ slot , ppolicy , pp , enactState , treasury , isTopLevelValid ⟧ ⊢ ⟦ utxoState , govState , certState ⟧ ⇀⦇ stx ,SUBLEDGER⦈ ⟦ utxoState' , govState' , certState' ⟧
205205
206206
SUBLEDGER-I :
207207
∙ isTopLevelValid ≡ false
208-
∙ ⟦ slot , pp , treasury ⟧ ⊢ utxoState ⇀⦇ stx ,SUBUTXOW⦈ utxoState
208+
∙ ⟦ slot , pp , treasury , {!!} ⟧ ⊢ utxoState ⇀⦇ stx ,SUBUTXOW⦈ utxoState
209209
────────────────────────────────
210210
⟦ slot , ppolicy , pp , enactState , treasury , isTopLevelValid ⟧ ⊢ ⟦ utxoState , govState , certState ⟧ ⇀⦇ stx ,SUBLEDGER⦈ ⟦ utxoState , govState , certState ⟧
211211
@@ -237,7 +237,7 @@ data _⊢_⇀⦇_,LEDGER⦈_ : LedgerEnv → LState → TopLevelTx → LState
237237
in
238238
∙ isValid tx ≡ true
239239
∙ ⟦ slot , ppolicy , pp , enactState , treasury , isValid tx ⟧ ⊢ ⟦ utxoState , govState , certState ⟧ ⇀⦇ txSubTransactions ,SUBLEDGERS⦈ ⟦ utxoState' , govState' , certState' ⟧
240-
∙ ⟦ slot , pp , treasury ⟧ ⊢ utxoState' ⇀⦇ tx ,UTXOW⦈ utxoState''
240+
∙ ⟦ slot , pp , treasury , {!!} ⟧ ⊢ utxoState' ⇀⦇ tx ,UTXOW⦈ utxoState''
241241
∙ ⟦ epoch slot , pp , txGovVotes , txWithdrawals , allColdCreds govState enactState ⟧ ⊢ certState' ⇀⦇ txCerts ,CERTS⦈ certState''
242242
∙ ⟦ txId , epoch slot , pp , ppolicy , enactState , certState' , dom (RewardsOf certState) ⟧ ⊢ {- rmOrphanDRepVotes certState' -} govState ⇀⦇ txgov txb ,GOVS⦈ govState'
243243
────────────────────────────────
@@ -255,7 +255,7 @@ data _⊢_⇀⦇_,LEDGER⦈_ : LedgerEnv → LState → TopLevelTx → LState
255255
in
256256
∙ isValid tx ≡ false
257257
∙ ⟦ slot , ppolicy , pp , enactState , treasury , isValid tx ⟧ ⊢ ⟦ utxoState , govState , certState ⟧ ⇀⦇ txSubTransactions ,SUBLEDGERS⦈ ⟦ utxoState , govState , certState ⟧
258-
∙ ⟦ slot , pp , treasury ⟧ ⊢ utxoState ⇀⦇ tx ,UTXOW⦈ utxoState'
258+
∙ ⟦ slot , pp , treasury , {!!} ⟧ ⊢ utxoState ⇀⦇ tx ,UTXOW⦈ utxoState'
259259
────────────────────────────────
260260
⟦ slot , ppolicy , pp , enactState , treasury ⟧ ⊢ ⟦ utxoState , govState , certState ⟧ ⇀⦇ tx ,LEDGER⦈ ⟦ utxoState' , govState , certState ⟧
261261
```

src/Ledger/Dijkstra/Specification/Script/Validation.lagda.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ credsNeededMinusCollateral txb = a ∪ b ∪ c ∪ d ∪ e
129129
e = mapPartial (λ p → if PolicyOf p then (λ {sh} → just (Propose p , ScriptObj sh)) else nothing)
130130
(fromList (GovProposalsOf txb))
131131
132-
credsNeeded : (ℓ : TxLevel) → UTxO → (TxBody ℓ) → ℙ (ScriptPurpose × Credential)
133-
credsNeeded TxLevelTop utxo txb = credsNeededMinusCollateral txb
132+
credsNeeded : {ℓ : TxLevel} → UTxO → (TxBody ℓ) → ℙ (ScriptPurpose × Credential)
133+
credsNeeded {TxLevelTop} utxo txb = credsNeededMinusCollateral txb
134134
∪ mapˢ (λ (i , o) → (Spend i , payCred (proj₁ o))) ((utxo ∣ (txIns ∪ collateralInputs)) ˢ)
135135
where open TxBody txb
136136
137-
credsNeeded TxLevelSub utxo txb = credsNeededMinusCollateral txb
137+
credsNeeded {TxLevelSub} utxo txb = credsNeededMinusCollateral txb
138138
∪ mapˢ (λ (i , o) → (Spend i , payCred (proj₁ o))) ((utxo ∣ txIns) ˢ)
139139
where open TxBody txb
140140

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ This section collects some unimportant but useful helper and accessor functions.
397397
txinsScript : ℙ TxIn → UTxO → ℙ TxIn
398398
txinsScript txins utxo = txins ∩ dom (proj₁ (scriptOuts utxo))
399399
400+
txOutToScript : TxOut → Maybe Script
401+
txOutToScript (_ , _ , _ , s) = s
402+
403+
```
404+
400405
refScripts : Tx txLevel → UTxO → List Script
401406
refScripts tx utxo =
402407
mapMaybe (proj₂ ∘ proj₂ ∘ proj₂) $ setToList (range (utxo ∣ (txIns ∪ refInputs)))
@@ -406,6 +411,7 @@ This section collects some unimportant but useful helper and accessor functions.
406411
txscripts tx utxo = scripts (tx .txWitnesses) ∪ fromList (refScripts tx utxo)
407412
where open Tx; open TxWitnesses
408413

414+
<<<<<<< HEAD
409415
lookupScriptHash : ScriptHash → Tx txLevel → UTxO → Maybe Script
410416
lookupScriptHash sh tx utxo =
411417
if sh ∈ mapˢ proj₁ (m ˢ) then
@@ -414,6 +420,17 @@ This section collects some unimportant but useful helper and accessor functions.
414420
nothing
415421
where m = setToMap (mapˢ < hash , id > (txscripts tx utxo))
416422

423+
=======
424+
lookupScriptHash : ScriptHash → Tx txLevel → UTxO → UTxO → Maybe Script
425+
lookupScriptHash sh tx utxoSpend₀ utxoRefView = lookupHash sh (txscripts tx utxoSpend₀ utxoRefView)
426+
427+
-- TODO: implement the actual evolving `utxoRefView` (issue #1006)
428+
429+
```
430+
431+
<!--
432+
```agda
433+
>>>>>>> fc70f5e8 (Add UTXOW preconditions)
417434
getSubTxScripts : SubLevelTx → ℙ (TxId × ScriptHash)
418435
getSubTxScripts subtx = mapˢ (λ hash → (TxIdOf subtx , hash)) (ScriptHashes subtx)
419436
where
@@ -428,6 +445,10 @@ This section collects some unimportant but useful helper and accessor functions.
428445
getTxScripts {TxLevelTop} =
429446
concatMapˢ getSubTxScripts ∘ fromList ∘ TxBody.txSubTransactions ∘ TxBodyOf
430447
```
448+
<<<<<<< HEAD
449+
=======
450+
-->
451+
>>>>>>> fc70f5e8 (Add UTXOW preconditions)
431452
432453
CIP-0118 models "required top-level guards" as a list of requirements coming
433454
from subtransaction bodies. The list can contain duplicates, and later logic

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ open import Ledger.Dijkstra.Specification.Script.Validation txs abs
3838
```agda
3939
record UTxOEnv : Type where
4040
field
41-
slot : Slot
42-
pparams : PParams
43-
treasury : Treasury
41+
slot : Slot
42+
pparams : PParams
43+
treasury : Treasury
44+
utxo₀ : UTxO
45+
globalRefInputsScripts : ℙ Script
46+
globalData : DataHash ⇀ Datum
4447
4548
record UTxOState : Type where
4649
field
@@ -102,10 +105,17 @@ data _⊢_⇀⦇_,SUBUTXO⦈_ : UTxOEnv → UTxOState → SubLevelTx → UTxOSta
102105
data _⊢_⇀⦇_,UTXO⦈_ : UTxOEnv → UTxOState → TopLevelTx → UTxOState → Type where
103106
104107
UTXO :
108+
<<<<<<< HEAD
105109
let txb = Tx.txBody tx
106110
subTxs = TxBody.txSubTransactions txb
107111
in
108112
∙ requiredTopLevelGuardsSatisfied tx subTxs
113+
=======
114+
∙ SpendInputsOf tx ≢ ∅
115+
∙ SpendInputsOf tx ⊆ dom (UTxOOf Γ) -- (1)
116+
∙ ReferenceInputsOf tx ⊆ dom (UTxOOf s)
117+
∙ requiredTopLevelGuardsSatisfied tx (SubTransactionsOf tx) -- (2)
118+
>>>>>>> fc70f5e8 (Add UTXOW preconditions)
109119
∙ Γ ⊢ s ⇀⦇ tx ,UTXOS⦈ s'
110120
────────────────────────────────
111121
Γ ⊢ s ⇀⦇ tx ,UTXO⦈ s'

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

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ source_branch: master
33
source_path: src/Ledger/Dijkstra/Specification/Utxow.lagda.md
44
---
55

6-
# UTxOW (Dijkstra skeleton)
7-
8-
This is a **minimal skeleton** of the Dijkstra-era witnessing layer.
9-
10-
It currently acts as a wrapper around `UTXO`, mirroring Conway's shape, but without
11-
committing to full witnessing checks yet.
6+
# UTxOW
127

138
<!--
149
```agda
@@ -24,30 +19,133 @@ module Ledger.Dijkstra.Specification.Utxow
2419
where
2520
2621
open import Ledger.Dijkstra.Specification.Utxo txs abs
22+
open import Ledger.Dijkstra.Specification.Script.Validation txs abs
2723
2824
private variable
25+
ℓ : TxLevel
2926
Γ : UTxOEnv
3027
s s' : UTxOState
3128
tx : TopLevelTx
3229
stx : SubLevelTx
3330
```
3431
-->
3532

33+
```agda
34+
languages : Tx ℓ → UTxO → ℙ Language
35+
languages tx utxo = ∅ -- TODO
36+
37+
allowedLanguages : Tx ℓ → UTxO → ℙ Language
38+
allowedLanguages tx utxo = ∅ -- TODO
39+
```
40+
3641
```agda
3742
data _⊢_⇀⦇_,SUBUTXOW⦈_ : UTxOEnv → UTxOState → SubLevelTx → UTxOState → Type where
3843
3944
SUBUTXOW :
45+
let
46+
open Tx tx
47+
open TxBody txBody
48+
open TxWitnesses txWitnesses
49+
open UTxOEnv
50+
51+
utxo₀ = Γ .utxo₀
52+
utxo = s .UTxOState.utxo
53+
54+
witsKeyHashes : ℙ KeyHash
55+
witsKeyHashes = mapˢ hash (dom vKeySigs)
56+
57+
allScripts : ℙ Script
58+
allScripts =
59+
( scripts -- (1) scripts from witnesses
60+
∪ mapPartial txOutToScript
61+
( range (utxo₀ ∣ txIns) -- (2) scripts from transaction inputs
62+
∪ range (utxo ∣ refInputs) -- (3) scripts from reference inputs
63+
)
64+
∪ Γ .globalRefInputsScripts -- (4) scripts from global reference inputs
65+
)
66+
67+
p1Scripts : ℙ P1Script
68+
p1Scripts = mapPartial toP1Script allScripts
69+
70+
p2Scripts : ℙ P2Script
71+
p2Scripts = mapPartial toP2Script allScripts
72+
73+
neededScriptHashes : ℙ ScriptHash
74+
neededScriptHashes = mapPartial (isScriptObj ∘ proj₂) (credsNeeded utxo₀ txBody)
75+
76+
neededVKeyHashes : ℙ KeyHash
77+
neededVKeyHashes = mapPartial (isKeyHashObj ∘ proj₂) (credsNeeded utxo₀ txBody)
78+
79+
neededDataHashes : ℙ DataHash
80+
neededDataHashes = mapPartial (λ txOut@(a , _ , d , _) → do sh ← isScriptObj (payCred a)
81+
_ ← lookupHash sh p2Scripts
82+
d >>= isInj₂)
83+
(range (utxo₀ ∣ txIns))
84+
85+
in
86+
∙ ∀[ (vk , σ) ∈ vKeySigs ] isSigned vk (txidBytes txId) σ
87+
∙ ∀[ s ∈ p1Scripts ] (hash s ∈ neededScriptHashes → validP1Script witsKeyHashes txVldt s)
88+
∙ neededVKeyHashes ⊆ witsKeyHashes
89+
∙ neededScriptHashes ⊆ mapˢ hash allScripts
90+
∙ neededDataHashes ⊆ dom (Γ .globalData)
91+
∙ languages tx utxo ⊆ allowedLanguages tx utxo
92+
∙ txADhash ≡ map hash txAuxData
4093
∙ Γ ⊢ s ⇀⦇ stx ,SUBUTXO⦈ s'
4194
────────────────────────────────
4295
Γ ⊢ s ⇀⦇ stx ,SUBUTXOW⦈ s'
4396
4497
data _⊢_⇀⦇_,UTXOW⦈_ : UTxOEnv → UTxOState → TopLevelTx → UTxOState → Type where
4598
4699
UTXOW :
47-
∙ Γ ⊢ s ⇀⦇ tx ,UTXO⦈ s'
100+
let
101+
open Tx tx
102+
open TxBody txBody
103+
open TxWitnesses txWitnesses
104+
open UTxOEnv
105+
106+
utxo₀ = Γ .utxo₀
107+
utxo = s .UTxOState.utxo
108+
109+
witsKeyHashes : ℙ KeyHash
110+
witsKeyHashes = mapˢ hash (dom vKeySigs)
111+
112+
allScripts : ℙ Script
113+
allScripts =
114+
( scripts -- (1) scripts from witnesses
115+
∪ mapPartial txOutToScript
116+
( range (utxo₀ ∣ txIns) -- (2) scripts from transaction inputs
117+
∪ range (utxo ∣ refInputs) -- (3) scripts from reference inputs
118+
)
119+
∪ Γ .globalRefInputsScripts -- (4) scripts from global reference inputs
120+
)
121+
122+
p1Scripts : ℙ P1Script
123+
p1Scripts = mapPartial toP1Script allScripts
124+
125+
p2Scripts : ℙ P2Script
126+
p2Scripts = mapPartial toP2Script allScripts
127+
128+
neededScriptHashes : ℙ ScriptHash
129+
neededScriptHashes = mapPartial (isScriptObj ∘ proj₂) (credsNeeded utxo₀ txBody)
130+
131+
neededVKeyHashes : ℙ KeyHash
132+
neededVKeyHashes = mapPartial (isKeyHashObj ∘ proj₂) (credsNeeded utxo₀ txBody)
133+
134+
neededDataHashes : ℙ DataHash
135+
neededDataHashes = mapPartial (λ txOut@(a , _ , d , _) → do sh ← isScriptObj (payCred a)
136+
_ ← lookupHash sh p2Scripts
137+
d >>= isInj₂)
138+
(range (utxo₀ ∣ txIns))
139+
140+
in
141+
∙ ∀[ (vk , σ) ∈ vKeySigs ] isSigned vk (txidBytes txId) σ
142+
∙ ∀[ s ∈ p1Scripts ] (hash s ∈ neededScriptHashes → validP1Script witsKeyHashes txVldt s)
143+
∙ neededVKeyHashes ⊆ witsKeyHashes
144+
∙ neededScriptHashes ⊆ mapˢ hash allScripts
145+
∙ neededDataHashes ⊆ dom (Γ .globalData)
146+
∙ languages tx utxo ⊆ allowedLanguages tx utxo
147+
∙ txADhash ≡ map hash txAuxData
148+
∙ Γ ⊢ s ⇀⦇ tx ,UTXO⦈ s'
48149
────────────────────────────────
49150
Γ ⊢ s ⇀⦇ tx ,UTXOW⦈ s'
50151
```
51-
52-
This file intentionally contains **no** additional premises yet. As Dijkstra witnessing
53-
evolves, this is where signature / script / datum / language constraints can be added.

src/Ledger/Prelude.lagda.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ module Filter where
8686
filter : ∀ {a} {p} {A : Type a} → (P : Pred A p) → ⦃ P ⁇¹ ⦄ → List A → List A
8787
filter P = Data.List.filter ¿ P ¿¹
8888
89+
lookupHash : ∀ {T H : Type} ⦃ _ : DecEq H ⦄ ⦃ _ : Hashable T H ⦄ → H → ℙ T → Maybe T
90+
lookupHash h s =
91+
if h ∈ mapˢ proj₁ (m ˢ) then just (lookupᵐ m h) else nothing
92+
where m = setToMap (mapˢ < hash , id > s)
8993
```

0 commit comments

Comments
 (0)