Skip to content

Commit a5d2cd6

Browse files
committed
Plutus V4 and dijkstraPV
1 parent 7e168c0 commit a5d2cd6

33 files changed

Lines changed: 931 additions & 34 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added
2+
3+
- Plutus V4 and `dijkstraPV`.

‎plutus-ledger-api/exe/analyse-script-events/Main.hs‎

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import PlutusLedgerApi.Test.EvaluationEvent
2424
import PlutusLedgerApi.V1 qualified as V1
2525
import PlutusLedgerApi.V2 qualified as V2
2626
import PlutusLedgerApi.V3 qualified as V3
27+
import PlutusLedgerApi.V4 qualified as V4
2728
import PlutusTx.AssocMap qualified as M
2829
import UntypedPlutusCore as UPLC
2930

@@ -73,6 +74,16 @@ stringOfPurposeV3 = \case
7374
V3.VotingScript {} -> "V3 Voting"
7475
V3.ProposingScript {} -> "V3 Proposing"
7576

77+
stringOfPurposeV4 :: V4.ScriptInfo -> String
78+
stringOfPurposeV4 = \case
79+
V4.MintingScript {} -> "V4 Minting"
80+
V4.SpendingScript {} -> "V4 Spending"
81+
V4.WithdrawingScript {} -> "V4 Withdrawing"
82+
V4.CertifyingScript {} -> "V4 Certifying"
83+
V4.VotingScript {} -> "V4 Voting"
84+
V4.ProposingScript {} -> "V4 Proposing"
85+
V4.GuardingScript {} -> "V4 Guarding"
86+
7687
shapeOfValue :: V1.Value -> String
7788
shapeOfValue (V1.Value m) =
7889
let l = M.toList m
@@ -117,6 +128,16 @@ analyseTxInfoV3 i = do
117128
analyseValue $ V3.mintValueBurned (V3.txInfoMint i)
118129
analyseOutputs (V3.txInfoOutputs i) V3.txOutValue
119130

131+
analyseTxInfoV4 :: V4.TxInfo -> IO ()
132+
analyseTxInfoV4 i = do
133+
putStr "Fee: "
134+
print $ V4.txInfoFee i
135+
putStr "Mint: "
136+
analyseValue $ V4.mintValueMinted (V4.txInfoMint i)
137+
putStr "Burn: "
138+
analyseValue $ V4.mintValueBurned (V4.txInfoMint i)
139+
analyseOutputs (V4.txInfoOutputs i) V4.txOutValue
140+
120141
analyseScriptContext :: EventAnalyser
121142
analyseScriptContext _ctx _params ev = case ev of
122143
PlutusEvent PlutusV1 ScriptEvaluationData {..} _expected ->
@@ -134,6 +155,11 @@ analyseScriptContext _ctx _params ev = case ev of
134155
[_, _, c] -> analyseCtxV3 c
135156
[_, c] -> analyseCtxV3 c
136157
l -> error $ printf "Unexpected number of V3 script arguments: %d" (length l)
158+
PlutusEvent PlutusV4 ScriptEvaluationData {..} _expected ->
159+
case dataInputs of
160+
[_, _, c] -> analyseCtxV4 c
161+
[_, c] -> analyseCtxV4 c
162+
l -> error $ printf "Unexpected number of V4 script arguments: %d" (length l)
137163
where
138164
analyseCtxV1 c =
139165
case V1.fromData @V1.ScriptContext c of
@@ -176,6 +202,11 @@ analyseScriptContext _ctx _params ev = case ev of
176202
printV1info p
177203
Nothing -> putStrLn "* Failed to decode V1 ScriptContext for V3 event: giving up\n"
178204

205+
analyseCtxV4 c =
206+
case V4.fromData @V4.ScriptContext c of
207+
Just p -> printV4info p
208+
Nothing -> putStrLn "\n* Failed to decode V4 ScriptContext for V4 event: giving up\n"
209+
179210
printV1info p = do
180211
putStrLn "----------------"
181212
putStrLn $ stringOfPurposeV1 $ V1.scriptContextPurpose p
@@ -191,6 +222,11 @@ analyseScriptContext _ctx _params ev = case ev of
191222
putStrLn $ stringOfPurposeV3 $ V3.scriptContextScriptInfo p
192223
analyseTxInfoV3 $ V3.scriptContextTxInfo p
193224

225+
printV4info p = do
226+
putStrLn "----------------"
227+
putStrLn $ stringOfPurposeV4 $ V4.scriptContextScriptInfo p
228+
analyseTxInfoV4 $ V4.scriptContextTxInfo p
229+
194230
-- Data object analysis
195231

196232
-- Statistics about a Data object
@@ -416,6 +452,25 @@ analyseCosts ctx _ ev =
416452
(_, Left _) -> Failed
417453
(_, Right cost) -> OK cost
418454
printCost result dataBudget
455+
PlutusEvent PlutusV4 ScriptEvaluationData {..} _ -> do
456+
dataInput <-
457+
case dataInputs of
458+
[input] -> pure input
459+
_ -> throwIO $ userError "PlutusV4 script expects exactly one input"
460+
let result =
461+
case deserialiseScript PlutusV4 dataProtocolVersion dataScript of
462+
Left _ -> DeserialisationError
463+
Right script -> do
464+
case V4.evaluateScriptRestricting
465+
dataProtocolVersion
466+
V4.Quiet
467+
ctx
468+
dataBudget
469+
script
470+
dataInput of
471+
(_, Left _) -> Failed
472+
(_, Right cost) -> OK cost
473+
printCost result dataBudget
419474
where
420475
printCost :: EvaluationResult -> ExBudget -> IO ()
421476
printCost result claimedCost =
@@ -463,12 +518,14 @@ analyseOneFile analyse eventFile = do
463518
case ( mkContext V1.mkEvaluationContext (eventsCostParamsV1 events)
464519
, mkContext V2.mkEvaluationContext (eventsCostParamsV2 events)
465520
, mkContext V3.mkEvaluationContext (eventsCostParamsV2 events)
521+
, mkContext V4.mkEvaluationContext (eventsCostParamsV2 events)
466522
) of
467-
(Right ctxV1, Right ctxV2, Right ctxV3) ->
468-
mapM_ (runSingleEvent ctxV1 ctxV2 ctxV3) (eventsOf events)
469-
(Left err, _, _) -> error $ display err
470-
(_, Left err, _) -> error $ display err
471-
(_, _, Left err) -> error $ display err
523+
(Right ctxV1, Right ctxV2, Right ctxV3, Right ctxV4) ->
524+
mapM_ (runSingleEvent ctxV1 ctxV2 ctxV3 ctxV4) (eventsOf events)
525+
(Left err, _, _, _) -> error $ display err
526+
(_, Left err, _, _) -> error $ display err
527+
(_, _, Left err, _) -> error $ display err
528+
(_, _, _, Left err) -> error $ display err
472529
where
473530
mkContext f = \case
474531
Nothing -> Right Nothing
@@ -478,9 +535,10 @@ analyseOneFile analyse eventFile = do
478535
:: Maybe (EvaluationContext, [Int64])
479536
-> Maybe (EvaluationContext, [Int64])
480537
-> Maybe (EvaluationContext, [Int64])
538+
-> Maybe (EvaluationContext, [Int64])
481539
-> ScriptEvaluationEvent
482540
-> IO ()
483-
runSingleEvent ctxV1 ctxV2 ctxV3 event =
541+
runSingleEvent ctxV1 ctxV2 ctxV3 ctxV4 event =
484542
case event of
485543
PlutusEvent PlutusV1 _ _ ->
486544
case ctxV1 of
@@ -494,6 +552,10 @@ analyseOneFile analyse eventFile = do
494552
case ctxV3 of
495553
Just (ctx, params) -> analyse ctx params event
496554
Nothing -> putStrLn "*** ctxV3 missing ***"
555+
PlutusEvent PlutusV4 _ _ ->
556+
case ctxV4 of
557+
Just (ctx, params) -> analyse ctx params event
558+
Nothing -> putStrLn "*** ctxV4 missing ***"
497559

498560
main :: IO ()
499561
main =

‎plutus-ledger-api/exe/dump-cost-model-parameters/Main.hs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import PlutusLedgerApi.Common (IsParamName, PlutusLedgerLanguage (..), showParam
1616
import PlutusLedgerApi.V1 qualified as V1
1717
import PlutusLedgerApi.V2 qualified as V2
1818
import PlutusLedgerApi.V3 qualified as V3
19+
import PlutusLedgerApi.V4 qualified as V4
1920

2021
import Data.Aeson qualified as A (Object, ToJSON, Value (Array, Number))
2122
import Data.Aeson.Encode.Pretty (encodePretty)
@@ -70,6 +71,7 @@ infoFor =
7071
PlutusV1 -> (PLC.DefaultFunSemanticsVariantD, paramNames @V1.ParamName)
7172
PlutusV2 -> (PLC.DefaultFunSemanticsVariantD, paramNames @V2.ParamName)
7273
PlutusV3 -> (PLC.DefaultFunSemanticsVariantE, paramNames @V3.ParamName)
74+
PlutusV4 -> (PLC.DefaultFunSemanticsVariantE, paramNames @V4.ParamName)
7375

7476
-- Return the current cost model parameters for a given LL version in the form
7577
-- of a list of (name, value) pairs ordered by name according to the relevant

‎plutus-ledger-api/exe/dump-cost-model-parameters/Parsers.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parseVersion = eitherReader $ \case
1616
"1" -> Right $ One PlutusV1
1717
"2" -> Right $ One PlutusV2
1818
"3" -> Right $ One PlutusV3
19+
"4" -> Right $ One PlutusV4
1920
s -> Left $ "Unknown ledger language version: " ++ s
2021

2122
whichll :: Parser WhichLL

‎plutus-ledger-api/exe/test-onchain-evaluation/Main.hs‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Control.Monad.Writer.Strict
1818
import Data.List.NonEmpty (nonEmpty)
1919
import Data.Maybe (catMaybes)
2020
import PlutusLedgerApi.V3.EvaluationContext qualified as V3
21+
import PlutusLedgerApi.V4.EvaluationContext qualified as V4
2122
import System.Directory.Extra (listFiles)
2223
import System.Environment (getEnv)
2324
import System.FilePath (isExtensionOf, takeBaseName)
@@ -31,23 +32,25 @@ testOneFile eventFile = testCase (takeBaseName eventFile) $ do
3132
case ( mkContext V1.mkEvaluationContext (eventsCostParamsV1 events)
3233
, mkContext V2.mkEvaluationContext (eventsCostParamsV2 events)
3334
, mkContext V3.mkEvaluationContext (eventsCostParamsV2 events)
35+
, mkContext V4.mkEvaluationContext (eventsCostParamsV2 events)
3436
) of
35-
(Right ctxV1, Right ctxV2, Right ctxV3) -> do
37+
(Right ctxV1, Right ctxV2, Right ctxV3, Right ctxV4) -> do
3638
errs <-
3739
fmap catMaybes $
3840
mapConcurrently
39-
(evaluate . runSingleEvent ctxV1 ctxV2 ctxV3)
41+
(evaluate . runSingleEvent ctxV1 ctxV2 ctxV3 ctxV4)
4042
(eventsOf events)
4143
whenJust (nonEmpty errs) $ assertFailure . renderTestFailures
42-
(Left err, _, _) -> assertFailure $ display err
43-
(_, Left err, _) -> assertFailure $ display err
44-
(_, _, Left err) -> assertFailure $ display err
44+
(Left err, _, _, _) -> assertFailure $ display err
45+
(_, Left err, _, _) -> assertFailure $ display err
46+
(_, _, Left err, _) -> assertFailure $ display err
47+
(_, _, _, Left err) -> assertFailure $ display err
4548
where
4649
mkContext f = \case
4750
Nothing -> Right Nothing
4851
Just costParams -> Just . (,costParams) . fst <$> runWriterT (f costParams)
4952

50-
runSingleEvent ctxV1 ctxV2 ctxV3 event =
53+
runSingleEvent ctxV1 ctxV2 ctxV3 ctxV4 event =
5154
case event of
5255
PlutusEvent PlutusV1 _ _ -> case ctxV1 of
5356
Just (ctx, params) -> InvalidResult <$> checkEvaluationEvent ctx params event
@@ -58,6 +61,9 @@ testOneFile eventFile = testCase (takeBaseName eventFile) $ do
5861
PlutusEvent PlutusV3 _ _ -> case ctxV3 of
5962
Just (ctx, params) -> InvalidResult <$> checkEvaluationEvent ctx params event
6063
Nothing -> Just $ MissingCostParametersFor PlutusV3
64+
PlutusEvent PlutusV4 _ _ -> case ctxV4 of
65+
Just (ctx, params) -> InvalidResult <$> checkEvaluationEvent ctx params event
66+
Nothing -> Just $ MissingCostParametersFor PlutusV4
6167

6268
main :: IO ()
6369
main = do

‎plutus-ledger-api/executables/src/PlutusCore/Executable/Blueprint.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ readPlutusVersion = \case
6464
"v1" -> PlutusV1
6565
"v2" -> PlutusV2
6666
"v3" -> PlutusV3
67+
"v4" -> PlutusV4
6768
other -> error $ "Unknown plutusVersion in blueprint: " <> T.unpack other
6869

6970
getPlutusVersion :: Value -> PlutusLedgerLanguage

‎plutus-ledger-api/plutus-ledger-api.cabal‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ library
104104
PlutusLedgerApi.V4.Data.Address
105105
PlutusLedgerApi.V4.Data.Contexts
106106
PlutusLedgerApi.V4.Data.Tx
107+
PlutusLedgerApi.V4.EvaluationContext
108+
PlutusLedgerApi.V4.ParamName
107109
PlutusLedgerApi.V4.Tx
108110

109111
other-modules:
@@ -190,6 +192,8 @@ library plutus-ledger-api-testlib
190192
PlutusLedgerApi.Test.V3.Data.MintValue
191193
PlutusLedgerApi.Test.V3.EvaluationContext
192194
PlutusLedgerApi.Test.V3.MintValue
195+
PlutusLedgerApi.Test.V4.Data.EvaluationContext
196+
PlutusLedgerApi.Test.V4.EvaluationContext
193197

194198
build-depends:
195199
, barbies

‎plutus-ledger-api/src/PlutusLedgerApi/Common.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module PlutusLedgerApi.Common
4747
, Protocol.changPV
4848
, Protocol.plominPV
4949
, Protocol.vanRossemPV
50+
, Protocol.dijkstraPV
5051
, Protocol.newestPV
5152
, Protocol.knownPVs
5253

‎plutus-ledger-api/src/PlutusLedgerApi/Common/Hash.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ plutusVersionTag = \case
2929
PlutusV1 -> 0x1
3030
PlutusV2 -> 0x2
3131
PlutusV3 -> 0x3
32+
PlutusV4 -> 0x4
3233
{-# INLINEABLE plutusVersionTag #-}

‎plutus-ledger-api/src/PlutusLedgerApi/Common/ProtocolVersions.hs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module PlutusLedgerApi.Common.ProtocolVersions
1212
, changPV
1313
, plominPV
1414
, vanRossemPV
15+
, dijkstraPV
1516
, newestPV
1617
, knownPVs
1718
, futurePV
@@ -85,6 +86,10 @@ plominPV = MajorProtocolVersion 10
8586
vanRossemPV :: MajorProtocolVersion
8687
vanRossemPV = MajorProtocolVersion 11
8788

89+
-- | The Dijkstra HF will introduce the Dijkstra era and Plutus V4.
90+
dijkstraPV :: MajorProtocolVersion
91+
dijkstraPV = MajorProtocolVersion 12
92+
8893
{-| The set of protocol versions that are "known", i.e. that have been released
8994
and have actual differences associated with them. This is currently only
9095
used for testing, so efficiency is not parmount and a list is fine. -}
@@ -99,14 +104,15 @@ knownPVs =
99104
, changPV
100105
, plominPV
101106
, vanRossemPV
107+
, dijkstraPV
102108
]
103109

104110
-- We're sometimes in an intermediate state where we've added new builtins but
105111
-- not yet released them (but intend to). This is used by some of the tests to
106112
-- decide what PVs the test should include. UPDATE THIS when we're expecting to
107113
-- release new builtins in a forthcoming PV.
108114
newestPV :: MajorProtocolVersion
109-
newestPV = vanRossemPV
115+
newestPV = dijkstraPV
110116

111117
{-| This is a placeholder for when we don't yet know what protocol version will
112118
be used for something. It's a very high protocol version that should never
@@ -127,7 +133,8 @@ Here's a table specifying the mapping in full:
127133
ll
128134
1 A B D
129135
2 A B D
130-
3 C C E
136+
3 - C E
137+
4 - - E? (TBD)
131138
132139
I.e. for example
133140

0 commit comments

Comments
 (0)