Skip to content

Commit

Permalink
plutus-scripts-bench: Add PlutusV3
Browse files Browse the repository at this point in the history
PlutusV3 support for the tx-generator is exercised via a testcase.

The fallback script in LoopV3.plutus is for ghc versions before 9.x; more recent ones
generate it via TH from LoopV3.hs.

This commit is a fair amount of the way there. Invoking it via
        cabal run tx-generator-apitest --                             \
                --nix-json ./bench/tx-generator/data/run-script.json  \
                --run ./run/current/generator/                        \
                --param data/protocol-parameters-conway.json

gets far enough for Plutus to error with PlutusV3 not being supported:

* Did I manage to extract a genesis fund?
--> Conway: fund check failed
* Can I pre-execute a plutus script?
--> Read plutus script: LoopV3
--> read redeemer: /home/nyc/src/cardano-node/bench/tx-generator/./data/loop.redeemer.json
--> execution failed: ProtocolError (LedgerLanguageNotAvailableError {sdeAffectedLang = PlutusV3, sdeIntroPv = 9, sdeThisPv = 8})
* What does the redeemer look like when the loop counter is maxed out?
--> Left ProtocolError (LedgerLanguageNotAvailableError {sdeAffectedLang = PlutusV3, sdeIntroPv = 9, sdeThisPv = 8})
--> summaries for block budget fits:
ProtocolError (LedgerLanguageNotAvailableError {sdeAffectedLang = PlutusV3, sdeIntroPv = 9, sdeThisPv = 8})
ProtocolError (LedgerLanguageNotAvailableError {sdeAffectedLang = PlutusV3, sdeIntroPv = 9, sdeThisPv = 8})
ProtocolError (LedgerLanguageNotAvailableError {sdeAffectedLang = PlutusV3, sdeIntroPv = 9, sdeThisPv = 8})

It seems that I had been fooled earlier by execution as PlutusV2.
Hopefully it's not too much to advance this the last mile.
  • Loading branch information
NadiaYvette committed Nov 23, 2023
1 parent 34d89af commit f511fdf
Show file tree
Hide file tree
Showing 9 changed files with 846 additions and 28 deletions.
3 changes: 2 additions & 1 deletion bench/plutus-scripts-bench/plutus-scripts-bench.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: plutus-scripts-bench
version: 1.0.0.6
version: 1.0.1.0
synopsis: Plutus scripts used for benchmarking
description: Plutus scripts used for benchmarking.
category: Cardano,
Expand Down Expand Up @@ -66,6 +66,7 @@ library
Cardano.Benchmarking.PlutusScripts.CustomCall
Cardano.Benchmarking.PlutusScripts.EcdsaSecp256k1Loop
Cardano.Benchmarking.PlutusScripts.Loop
Cardano.Benchmarking.PlutusScripts.LoopV3
Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop

--------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ module Cardano.Benchmarking.PlutusScripts
import Prelude

import Data.ByteString.Lazy as LBS (ByteString)
import Data.Text(split, pack)
import Data.List(find)
import System.FilePath(takeBaseName)
import Data.List (find)
import Data.Text (pack, split)
import System.FilePath (takeBaseName)

import Cardano.Api

import qualified Cardano.Benchmarking.PlutusScripts.CustomCall as CustomCall
import qualified Cardano.Benchmarking.PlutusScripts.EcdsaSecp256k1Loop as ECDSA
import qualified Cardano.Benchmarking.PlutusScripts.Loop as Loop
import qualified Cardano.Benchmarking.PlutusScripts.LoopV3 as LoopV3
import qualified Cardano.Benchmarking.PlutusScripts.SchnorrSecp256k1Loop as Schnorr
import Cardano.Benchmarking.ScriptAPI

Expand All @@ -35,6 +36,7 @@ getAllScripts =
[ CustomCall.script
, ECDSA.script
, Loop.script
, LoopV3.script
, Schnorr.script
]

Expand All @@ -59,6 +61,7 @@ encodePlutusScript
= \case
ScriptInAnyLang (PlutusScriptLanguage PlutusScriptV1) s -> textEnvelopeToJSON Nothing s
ScriptInAnyLang (PlutusScriptLanguage PlutusScriptV2) s -> textEnvelopeToJSON Nothing s
ScriptInAnyLang (PlutusScriptLanguage PlutusScriptV3) s -> textEnvelopeToJSON Nothing s
_ -> "{}"


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.Benchmarking.PlutusScripts.LoopV3 (script) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Prelude hiding (pred, ($), (&&), (<), (==))

import Cardano.Api.Shelley (PlutusScript (..), PlutusScriptV3, PlutusScriptVersion (..),
Script (..), toScriptInAnyLang)
import Cardano.Benchmarking.ScriptAPI
import qualified Data.ByteString.Short as SBS

import qualified PlutusLedgerApi.V3 as PlutusV3
import PlutusTx
import PlutusTx.Builtins (unsafeDataAsI)
import PlutusTx.Prelude hiding (Semigroup (..), unless, (.), (<$>))


scriptName :: String
scriptName
= prepareScriptName $(LitE . StringL . loc_module <$> qLocation)

script :: PlutusBenchScript
script = mkPlutusBenchScript scriptName (toScriptInAnyLang (PlutusScript PlutusScriptV3 scriptSerialized))


{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -> BuiltinData -> BuiltinData -> ()
mkValidator _datum redeemer _txContext
= if n < 1000000
then traceError "redeemer is < 1000000"
else loop n
where
n = unsafeDataAsI redeemer
loop i = if i == 1000000 then () else loop $ pred i

loopScriptShortBs :: SBS.ShortByteString
loopScriptShortBs = PlutusV3.serialiseCompiledCode $$(PlutusTx.compile [|| mkValidator ||])

scriptSerialized :: PlutusScript PlutusScriptV3
scriptSerialized = PlutusScriptSerialised loopScriptShortBs
Loading

0 comments on commit f511fdf

Please sign in to comment.