Skip to content

Commit c9ee7c7

Browse files
committed
Add data preconditions to UTXOW
1 parent 0b585e4 commit c9ee7c7

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ record UTxOEnv : Type where
4242
pparams : PParams
4343
treasury : Treasury
4444
utxo₀ : UTxO
45-
refInputsScripts : ℙ Script
45+
allRefInputsScripts : ℙ Script
46+
allData : DataHash ⇀ Datum
4647
4748
record UTxOState : Type where
4849
field

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,50 @@ data _⊢_⇀⦇_,UTXOW⦈_ : UTxOEnv → UTxOState → Tx ℓ → UTxOState →
4242
open Tx tx
4343
open TxBody txBody
4444
open TxWitnesses txWitnesses
45+
open UTxOEnv
4546
46-
utxo₀ = Γ .UTxOEnv.utxo₀
47+
utxo₀ = Γ .utxo₀
4748
utxo = s .UTxOState.utxo
49+
50+
witsKeyHashes : ℙ KeyHash
4851
witsKeyHashes = mapˢ hash (dom vKeySigs)
49-
neededScriptHashes = mapPartial (isScriptObj ∘ proj₂) (credsNeeded utxo₀ txBody)
50-
neededVKeyHashes = mapPartial (isKeyHashObj ∘ proj₂) (credsNeeded utxo₀ txBody)
51-
-- txdatsHashes = mapˢ hash txdats
52-
-- inputsDataHashes = mapPartial (λ txout → if txOutToP2Script utxo tx txout
53-
-- then txOutToDataHash txout
54-
-- else nothing) (range (utxo ∣ txIns))
55-
-- refInputsDataHashes = mapPartial txOutToDataHash (range (utxo ∣ refInputs))
56-
-- outputsDataHashes = mapPartial txOutToDataHash (range txOuts)
57-
p1Scripts = mapPartial toP1Script
52+
53+
allScripts : ℙ Script
54+
allScripts =
5855
( scripts -- (1) scripts from witnesses
59-
∪ mapPartial txOutScript
56+
∪ mapPartial txOutToScript
6057
( range (utxo₀ ∣ txIns) -- (2) scripts from transaction inputs
6158
∪ range (utxo ∣ refInputs) -- (3) scripts from reference inputs
6259
)
63-
∪ Γ .UTxOEnv.refInputsScripts -- (4) scripts from all reference inputs
60+
∪ Γ .allRefInputsScripts -- (4) scripts from all reference inputs
6461
)
62+
63+
p1Scripts : ℙ P1Script
64+
p1Scripts = mapPartial toP1Script allScripts
65+
66+
p2Scripts : ℙ P2Script
67+
p2Scripts = mapPartial toP2Script allScripts
68+
69+
neededScriptHashes : ℙ ScriptHash
70+
neededScriptHashes = mapPartial (isScriptObj ∘ proj₂) (credsNeeded utxo₀ txBody)
71+
72+
neededVKeyHashes : ℙ KeyHash
73+
neededVKeyHashes = mapPartial (isKeyHashObj ∘ proj₂) (credsNeeded utxo₀ txBody)
74+
75+
neededDataHashes : ℙ DataHash
76+
neededDataHashes = mapPartial (λ txOut@(a , _ , d , _) → do sh ← isScriptObj (payCred a)
77+
_ ← lookupᵐ? (setToMap (mapˢ < hash , id > p2Scripts)) sh
78+
d >>= isInj₂)
79+
(range (utxo₀ ∣ txIns))
80+
6581
in
6682
∙ ∀[ (vk , σ) ∈ vKeySigs ] isSigned vk (txidBytes txId) σ
6783
∙ ∀[ s ∈ p1Scripts ] (hash s ∈ neededScriptHashes → validP1Script witsKeyHashes txVldt s)
84+
∙ neededScriptHashes ⊆ mapˢ hash allScripts
6885
∙ neededVKeyHashes ⊆ witsKeyHashes
69-
-- ∙ inputsDataHashes ⊆ txdatsHashes
70-
-- ∙ txdatsHashes ⊆ inputsDataHashes ∪ outputsDataHashes ∪ refInputsDataHashes
86+
∙ neededDataHashes ⊆ dom (Γ .allData)
7187
-- ∙ languages tx utxo ⊆ allowedLanguages tx utxo
72-
-- ∙ txADhash ≡ map hash txAD
88+
∙ txADhash ≡ map hash txAuxData
7389
-- ∙ Γ ⊢ s ⇀⦇ tx ,UTXO⦈ s'
7490
────────────────────────────────
7591
Γ ⊢ s ⇀⦇ tx ,UTXOW⦈ s'

0 commit comments

Comments
 (0)