Skip to content

Commit 424ab29

Browse files
committed
Added HSPlutusScript
1 parent 1e62760 commit 424ab29

File tree

10 files changed

+42
-24
lines changed

10 files changed

+42
-24
lines changed

src/Ledger/Conway/Conformance/Script.agda

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,29 @@ module Ledger.Conway.Conformance.Script
2424

2525
open Ledger.Script crypto es
2626

27-
record HashedTimelock : Type where
27+
record HSTimelock : Type where
2828
field
29-
timelock : Timelock
30-
storedHash : ScriptHash
29+
timelock : Timelock
30+
tlScriptHash : ScriptHash
31+
tlScriptSize :
3132

3233
instance
33-
Hashable-HashedTimelock : Hashable HashedTimelock ScriptHash
34-
Hashable-HashedTimelock .hash = HashedTimelock.storedHash
34+
Hashable-HSTimelock : Hashable HSTimelock ScriptHash
35+
Hashable-HSTimelock .hash = HSTimelock.tlScriptHash
3536

36-
unquoteDecl DecEq-HashedTimelock = derive-DecEq ((quote HashedTimelock , DecEq-HashedTimelock) ∷ [])
37+
unquoteDecl DecEq-HSTimelock = derive-DecEq ((quote HSTimelock , DecEq-HSTimelock) ∷ [])
38+
39+
record HSPlutusScript : Type where
40+
constructor MkHSPlutusScript
41+
field psScriptHash : ScriptHash
42+
psScriptSize :
43+
44+
instance
45+
Hashable-HSPlutusScript : Hashable HSPlutusScript ScriptHash
46+
Hashable-HSPlutusScript .hash = HSPlutusScript.psScriptHash
3747

3848
P1ScriptStructure-HTL : P1ScriptStructure
3949
P1ScriptStructure-HTL = record
40-
{ P1Script = HashedTimelock
41-
; validP1Script = λ x y evalTimelock x y ∘ HashedTimelock.timelock }
50+
{ P1Script = HSTimelock
51+
; validP1Script = λ x y evalTimelock x y ∘ HSTimelock.timelock }
52+

src/Ledger/Conway/Conformance/Utxow.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data _⊢_⇀⦇_,UTXOW⦈_ where
3535
witsKeyHashes = mapˢ hash (dom vkSigs)
3636
witsScriptHashes = mapˢ hash scripts
3737
inputHashes = L.getInputHashes tx utxo
38-
refScriptHashes = mapˢ hash (refScripts tx utxo)
38+
refScriptHashes = fromList $ map hash (refScripts tx utxo)
3939
neededHashes = L.scriptsNeeded utxo txb
4040
txdatsHashes = dom txdats
4141
allOutHashes = L.getDataHashes (range txouts)

src/Ledger/Conway/Foreign/HSLedger/Core.agda

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ module Implementation where
7979
toData : {A : Type} A Data
8080
toData _ = 0
8181

82-
PlutusScript = ℕ × ⊤
8382
ExUnits = ℕ × ℕ
8483
ExUnit-CommutativeMonoid = CommutativeMonoid 0ℓ 0ℓ ExUnits ∋ (Conversion.fromBundle record
8584
{ Carrier = ExUnits
@@ -94,9 +93,6 @@ module Implementation where
9493
instance
9594
Show-ExUnits : Show ExUnits
9695
Show-ExUnits = Show-×
97-
98-
Hashable-PlutusScript : Hashable PlutusScript ℕ
99-
Hashable-PlutusScript .hash (h , _) = h
10096

10197
CostModel =
10298
Language =

src/Ledger/Conway/Foreign/HSLedger/ExternalStructures.agda

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ instance
5050
HSP2ScriptStructure = record
5151
{ Implementation
5252
; validPlutusScript = λ _ _ _ _
53+
; PlutusScript = HSPlutusScript
5354
}
5455

5556
open import Ledger.PParams it it it hiding (Acnt; DrepThresholds; PoolThresholds)
@@ -120,7 +121,9 @@ instance
120121
; indexOfProposal = λ _ _ nothing
121122
}
122123
; runPLCScript = λ _ _ _ _ false
123-
; scriptSize = λ _ 0
124+
; scriptSize = λ where
125+
(inj₁ x) HSTimelock.tlScriptSize x
126+
(inj₂ x) HSPlutusScript.psScriptSize x
124127
}
125128

126129
open import Ledger.Address Network KeyHash ScriptHash using () public

src/Ledger/Conway/Foreign/HSLedger/Transaction.agda

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ instance
1818
{-# TERMINATING #-}
1919
Conv-Timelock = autoConvert Timelock
2020

21-
HsTy-HashedTimelock = autoHsType HashedTimelock
22-
Conv-HashedTimelock = autoConvert HashedTimelock
21+
HsTy-HSTimelock = autoHsType HSTimelock
22+
Conv-HSTimelock = autoConvert HSTimelock
23+
24+
HsTy-HSPlutusScript = autoHsType HSPlutusScript
25+
Conv-HSPlutusScript = autoConvert HSPlutusScript
2326

2427
HsTy-TxWitnessess = autoHsType TxWitnesses ⊣ withConstructor "MkTxWitnesses"
2528
Conv-TxWitnessess = autoConvert TxWitnesses

src/Ledger/Conway/Foreign/HSLedger/Utxo.agda

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
module Ledger.Conway.Foreign.HSLedger.Utxo where
44

5+
open import Ledger.Prelude
6+
57
open import Ledger.Conway.Foreign.ExternalFunctions
68

7-
open import Data.String.Base renaming (_++_ to _+ˢ_) hiding (show; length)
9+
open import Data.String.Base renaming (_++_ to _+ˢ_) hiding (show; length; map; fromList)
810

911
open import Ledger.Conway.Foreign.HSLedger.Core
1012
open import Ledger.Conway.Foreign.HSLedger.Address
@@ -65,6 +67,9 @@ module _ (ext : ExternalFunctions) where
6567
("\tDeposits: \t" +ˢ show (inject (L.newDeposits pparams (from st) body))) ∷
6668
("\tFees: \t" +ˢ show (inject txfee)) ∷
6769
("\tTotal: \t" +ˢ show (L.produced pparams (from st) body)) ∷
70+
""
71+
"Reference Scripts Info:"
72+
("\tTotal size: \t" +ˢ show (L.refScriptsSize utxo (from tx))) ∷
6873
[]
6974

7075
{-# COMPILE GHC utxo-debug as utxoDebug #-}
@@ -77,7 +82,7 @@ module _ (ext : ExternalFunctions) where
7782
open UTxOEnv (from env)
7883
open TxWitnesses (coerce ⦃ TrustMe ⦄ wits)
7984
neededHashes = LW.scriptsNeeded utxo body
80-
refScriptHashes = mapˢ
85+
refScriptHashes = fromList $ map
8186
hash
8287
(refScripts (coerce ⦃ TrustMe ⦄ (from tx)) (coerce ⦃ TrustMe ⦄ utxo))
8388
witsScriptHashes = mapˢ hash scripts

src/Ledger/Transaction.lagda

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ Ingredients of the transaction body introduced in the Conway era are the followi
211211
txinsScript : ℙ TxIn → UTxO → ℙ TxIn
212212
txinsScript txins utxo = txins ∩ dom (proj₁ (scriptOuts utxo))
213213

214-
refScripts : Tx → UTxO → Script
214+
refScripts : Tx → UTxO → List Script
215215
refScripts tx utxo =
216-
mapPartial (proj₂ ∘ proj₂ ∘ proj₂) (range (utxo ∣ (txins ∪ refInputs)))
216+
mapMaybe (proj₂ ∘ proj₂ ∘ proj₂) $ setToList (range (utxo ∣ (txins ∪ refInputs)))
217217
where open Tx; open TxBody (tx .body)
218218

219219
txscripts : Tx → UTxO → ℙ Script
220-
txscripts tx utxo = scripts (tx .wits) ∪ refScripts tx utxo
220+
txscripts tx utxo = scripts (tx .wits) ∪ fromList (refScripts tx utxo)
221221
where open Tx; open TxWitnesses
222222

223223
lookupScriptHash : ScriptHash → Tx → UTxO → Maybe Script

src/Ledger/Utxo.lagda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ module _ (let open Tx; open TxBody; open TxWitnesses) where opaque
206206
\end{NoConway}
207207
\begin{code}
208208
refScriptsSize : UTxO → Tx → ℕ
209-
refScriptsSize utxo tx = ∑[ x ← mapValues scriptSize (setToHashMap (refScripts tx utxo)) ] x
209+
refScriptsSize utxo tx = sum $ map scriptSize (refScripts tx utxo)
210210

211211
minfee : PParams → UTxO → Tx → Coin
212212
minfee pp utxo tx = pp .a * tx .body .txsize + pp .b

src/Ledger/Utxow.lagda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ data _⊢_⇀⦇_,UTXOW⦈_ where
157157
witsKeyHashes = mapˢ hash (dom vkSigs)
158158
witsScriptHashes = mapˢ hash scripts
159159
inputHashes = getInputHashes tx utxo
160-
refScriptHashes = mapˢ hash (refScripts tx utxo)
160+
refScriptHashes = fromList $ map hash (refScripts tx utxo)
161161
neededHashes = scriptsNeeded utxo txb
162162
txdatsHashes = dom txdats
163163
allOutHashes = getDataHashes (range txouts)

src/Ledger/hs-src/Lib.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.PParams as X
1212
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Transaction as X
1313
( Tag(..), Timelock(..), TxWitnesses(..), TxBody(..), Tx(..), TxId, Ix, TxIn, P1Script, P2Script
1414
, Script, Datum, DataHash, Value, TxOut, RdmrPtr, ScriptHash, AuxiliaryData, Wdrl
15-
, HashedTimelock(..))
15+
, HSTimelock (..), HSPlutusScript (..))
1616
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Cert as X
1717
(certStep, certsStep, CertState(..))
1818
import MAlonzo.Code.Ledger.Conway.Foreign.HSLedger.Chain as X

0 commit comments

Comments
 (0)