Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Costing] Provide support for multiple 'CostModel's #5851

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
49db6d5
[Builtins] Store 'BuiltinRuntime' lazily explicitly
effectfully Feb 27, 2024
e1d60b6
An additional variant
effectfully Feb 27, 2024
3c40023
Revert "[Builtins] Store 'BuiltinRuntime' lazily explicitly"
effectfully Feb 27, 2024
1705f9e
Fix validation benchmarks
effectfully Feb 28, 2024
32c08f0
Fix a bunch more stuff
effectfully Feb 29, 2024
3b5bd38
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Mar 15, 2024
3f96021
Cosmetics
effectfully Mar 15, 2024
430d7f9
Remove warnings
effectfully Mar 19, 2024
aef3def
Push 'MajorProtocolVersion' into 'MachineParameters'
effectfully Mar 19, 2024
21bb075
Make 'CostingPart' into a function
effectfully Mar 8, 2024
8fa97cc
Revert "Make 'CostingPart' into a function"
effectfully Mar 22, 2024
a9a71bd
Provide support for multiple 'CostModel's
effectfully Mar 22, 2024
3944b7f
Add 'SubDefaultFunSemanticsVariant'
effectfully Mar 26, 2024
0a1af53
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Mar 26, 2024
1843823
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Mar 27, 2024
3134e88
Fix the arbitrary evaluation nonsense in 'nofib'
effectfully Mar 27, 2024
86a176d
Revert "Add 'SubDefaultFunSemanticsVariant'"
effectfully Apr 1, 2024
53b49c2
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 1, 2024
d2b57a6
Revert "Fix the arbitrary evaluation nonsense in 'nofib'"
effectfully Apr 4, 2024
b6c9c3c
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 4, 2024
69fc298
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 9, 2024
12679c7
Put 'mkMachineParameters' inside the loop
effectfully Apr 9, 2024
6151af8
Make errors explicit
effectfully Apr 11, 2024
20e2677
Add a call to 'lazy' in 'toBuiltinsRuntime' out of paranoia
effectfully Apr 11, 2024
ecc9a85
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 11, 2024
e543b28
Fix 'haskell-conformance'
effectfully Apr 11, 2024
a336d02
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 13, 2024
12bbcc1
Comments
effectfully Apr 15, 2024
4d3ddb0
Use a list instead of a function
effectfully Apr 15, 2024
7a23b0e
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 15, 2024
846ae8e
Remove a bang
effectfully Apr 16, 2024
5bf9d5e
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 16, 2024
ae5718b
Add 'evaluationContextCacheIsComplete'
effectfully Apr 18, 2024
809675d
Refactoring and comments
effectfully Apr 18, 2024
28f46c7
More comments
effectfully Apr 18, 2024
9d8942d
Comments and fixes
effectfully Apr 18, 2024
039dce1
Tweaks
effectfully Apr 23, 2024
60bbf02
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully Apr 25, 2024
1f1bf5e
Add 'Note [Mapping of protocol versions and ledger languages to seman…
effectfully Apr 25, 2024
e507dae
Add a changelog entry
effectfully Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plutus-benchmark/common/PlutusBenchmark/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ mkEvalCtx =
Just p ->
let errOrCtx =
-- The validation benchmarks were all created from PlutusV1 scripts
LedgerApi.mkDynEvaluationContext DefaultFunSemanticsVariant1 p
LedgerApi.mkDynEvaluationContext
"PlutusV1"
[DefaultFunSemanticsVariant1]
(const DefaultFunSemanticsVariant1)
p
in case errOrCtx of
Right ec -> ec
Left err -> error $ show err
Expand Down
4 changes: 2 additions & 2 deletions plutus-conformance/haskell/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import UntypedPlutusCore.Evaluation.Machine.Cek (CountingSt (..), counting, runC
evalUplcProg :: UplcEvaluator
evalUplcProg = UplcEvaluatorWithCosting $ \modelParams (UPLC.Program a v t) ->
do
params <- case mkMachineParametersFor def modelParams of
params <- case mkMachineParametersFor [def] (const def) modelParams of
Left _ -> Nothing
Right p -> Just p
Right p -> p ()
-- runCek-like functions (e.g. evaluateCekNoEmit) are partial on term's with free variables,
-- that is why we manually check first for any free vars
case UPLC.deBruijnTerm t of
Expand Down
5 changes: 4 additions & 1 deletion plutus-core/executables/src/PlutusCore/Executable/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ exampleOpts = ExampleOptions <$> exampleMode
builtinSemanticsVariantReader :: String -> Maybe (BuiltinSemanticsVariant DefaultFun)
builtinSemanticsVariantReader =
\case
"0" -> Just DefaultFunSemanticsVariant0
"1" -> Just DefaultFunSemanticsVariant1
"2" -> Just DefaultFunSemanticsVariant2
_ -> Nothing
Expand All @@ -149,6 +150,7 @@ builtinSemanticsVariantReader =
showBuiltinSemanticsVariant :: BuiltinSemanticsVariant DefaultFun -> String
showBuiltinSemanticsVariant =
\case
DefaultFunSemanticsVariant0 -> "0"
DefaultFunSemanticsVariant1 -> "1"
DefaultFunSemanticsVariant2 -> "2"

Expand All @@ -160,7 +162,8 @@ builtinSemanticsVariant = option (maybeReader builtinSemanticsVariantReader)
<> value DefaultFunSemanticsVariant2
<> showDefaultWith showBuiltinSemanticsVariant
<> help
("Builtin semantics variant: 1 -> DefaultFunSemanticsVariant1, "
("Builtin semantics variant: 0 -> DefaultFunSemanticsVariant0, "
<> "1 -> DefaultFunSemanticsVariant1"
<> "2 -> DefaultFunSemanticsVariant2"
)
)
Expand Down
20 changes: 1 addition & 19 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/Meaning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import PlutusCore.Evaluation.Machine.ExBudgetStream
import PlutusCore.Evaluation.Machine.ExMemoryUsage
import PlutusCore.Name.Unique

import Control.DeepSeq
import Data.Array
import Data.Kind qualified as GHC
import Data.Proxy
Expand Down Expand Up @@ -399,22 +398,5 @@ toBuiltinsRuntime
-> cost
-> BuiltinsRuntime fun val
toBuiltinsRuntime semvar cost =
let runtime = BuiltinsRuntime $ toBuiltinRuntime cost . inline toBuiltinMeaning semvar
-- This pragma is very important, removing it destroys the carefully set up optimizations of
-- of costing functions (see Note [Optimizations of runCostingFun*]). The reason for that is
-- that if @runtime@ doesn't have a pragma, then GHC sees that it's only referenced once and
-- inlines it below, together with this entire function (since we tell GHC to), at which
-- point everything's inlined and we're completely at GHC's mercy to optimize things
-- properly. Unfortunately, GHC doesn't want to cooperate and push 'toBuiltinRuntime' to
-- the inside of the inlined to 'toBuiltinMeaning' call, creating lots of 'BuiltinMeaning's
-- instead of 'BuiltinRuntime's with the former hiding the costing optimizations behind a
-- lambda binding the @cost@ variable, which renders all the optimizations useless. By
-- using a @NOINLINE@ pragma we tell GHC to create a separate thunk, which it can properly
-- optimize, because the other bazillion things don't get in the way.
{-# NOINLINE runtime #-}
in
-- Force each 'BuiltinRuntime' to WHNF, so that the thunk is allocated and forced at
-- initialization time rather than at runtime. Not that we'd lose much by not forcing all
-- 'BuiltinRuntime's here, but why pay even very little if there's an easy way not to pay.
force runtime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have force in mkMachineParametersFor, so we don't need it here.

lazy . BuiltinsRuntime $ toBuiltinRuntime cost . inline toBuiltinMeaning semvar
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said during the GHC Core presentation, lazy is way more reliable here than let + NOINLINE.

{-# INLINE toBuiltinsRuntime #-}
29 changes: 16 additions & 13 deletions plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,10 +1075,11 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
possibly different semantics. Note that DefaultFunSemanticsVariant1,
DefaultFunSemanticsVariant1 etc. do not correspond directly to PlutusV1,
PlutusV2 etc. in plutus-ledger-api: see Note [Builtin semantics variants]. -}
data BuiltinSemanticsVariant DefaultFun =
DefaultFunSemanticsVariant1
| DefaultFunSemanticsVariant2
deriving stock (Enum, Bounded, Show)
data BuiltinSemanticsVariant DefaultFun
= DefaultFunSemanticsVariant0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote that we change these to DefaultSemanticsVariantA/B/C or something similar. It's quite confusing having all these variants and versions in the code, so it might help if they're not all identified by numbers that might lead people to believe that the same number means the same thing in different contexts. That would mean changing the specification too though, so if we do it let's do it later in its own PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine either way. I'm hopeful we'll be able to get rid of the semantics variants entirely and simply rely on the language and protocol versions directly (maybe in the "condensed" form).

| DefaultFunSemanticsVariant1
| DefaultFunSemanticsVariant2
deriving stock (Eq, Enum, Bounded, Show)

-- Integers
toBuiltinMeaning
Expand Down Expand Up @@ -1176,6 +1177,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
appendByteStringDenotation
(runCostingFunTwoArguments . paramAppendByteString)

-- See Note [Builtin semantics variants]
toBuiltinMeaning semvar ConsByteString =
-- The costing function is the same for all variants of this builtin,
-- but since the denotation of the builtin accepts constants of
Expand All @@ -1185,26 +1187,26 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
:: ExMemoryUsage a => BuiltinCostModel -> a -> BS.ByteString -> ExBudgetStream
costingFun = runCostingFunTwoArguments . paramConsByteString
{-# INLINE costingFun #-}
-- See Note [Builtin semantics variants]
in case semvar of
DefaultFunSemanticsVariant1 ->
consByteStringMeaning_V1 =
let consByteStringDenotation :: Integer -> BS.ByteString -> BS.ByteString
consByteStringDenotation n xs = BS.cons (fromIntegral n) xs
{-# INLINE consByteStringDenotation #-}
in makeBuiltinMeaning
consByteStringDenotation
costingFun
-- For builtin semantics variants other (i.e. larger) than
-- DefaultFunSemanticsVariant1, the first input must be in range
-- [0..255]. See Note [How to add a built-in function: simple
-- cases]
DefaultFunSemanticsVariant2 ->
-- For builtin semantics variants larger than 'DefaultFunSemanticsVariant1', the first
-- input must be in range @[0..255]@.
consByteStringMeaning_V2 =
let consByteStringDenotation :: Word8 -> BS.ByteString -> BS.ByteString
consByteStringDenotation = BS.cons
{-# INLINE consByteStringDenotation #-}
in makeBuiltinMeaning
consByteStringDenotation
costingFun
in case semvar of
DefaultFunSemanticsVariant0 -> consByteStringMeaning_V1
DefaultFunSemanticsVariant1 -> consByteStringMeaning_V1
DefaultFunSemanticsVariant2 -> consByteStringMeaning_V2

toBuiltinMeaning _semvar SliceByteString =
let sliceByteStringDenotation :: Int -> Int -> BS.ByteString -> BS.ByteString
Expand Down Expand Up @@ -1287,7 +1289,8 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
:: BS.ByteString -> BS.ByteString -> BS.ByteString -> BuiltinResult Bool
verifyEd25519SignatureDenotation =
case semvar of
DefaultFunSemanticsVariant1 -> verifyEd25519Signature_V1
DefaultFunSemanticsVariant0 -> verifyEd25519Signature_V1
DefaultFunSemanticsVariant1 -> verifyEd25519Signature_V2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mapping is potentially easy to get wrong. Is there any test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're just replacing one implementation with another for maintenance reasons, so doing this matching here is only for the purpose of being paranoid about not breaking anything in the past in case of some unknown unknown. There's nothing additional to test therefore beyond what we already test, which is how we use ed25519_Variant0Prop to test all variants of this builtin.

Note that consByteString is untestable in the same way, but for a different reason: Variant0 and Variant1 versions of that builtin are completely identical (unlike with verifyEd25519Signature, whose variants behave identically but come from different libraries, i.e. are nominally different), so again there's nothing to test.

So for both the builtins we only make sure that whatever their variant is, it behaves as expected, we cannot test that Variant0 behaves differently from Variant1, because it doesn't.

DefaultFunSemanticsVariant2 -> verifyEd25519Signature_V2
{-# INLINE verifyEd25519SignatureDenotation #-}
in makeBuiltinMeaning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module PlutusCore.Evaluation.Machine.ExBudgetingDefaults
( defaultBuiltinsRuntimeForSemanticsVariant
, defaultBuiltinsRuntime
, defaultCekCostModel
, toCekCostModel
, defaultCekMachineCosts
, defaultCekParameters
, defaultCostModelParams
Expand Down Expand Up @@ -85,6 +86,9 @@ defaultCekMachineCosts =
defaultCekCostModel :: CostModel CekMachineCosts BuiltinCostModel
defaultCekCostModel = CostModel defaultCekMachineCosts defaultBuiltinCostModel

toCekCostModel :: BuiltinSemanticsVariant DefaultFun -> CostModel CekMachineCosts BuiltinCostModel
toCekCostModel _ = defaultCekCostModel
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where we get the additional extensibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it therefore have some comment explaining that?


-- | The default cost model data. This is exposed to the ledger, so let's not
-- confuse anybody by mentioning the CEK machine
defaultCostModelParams :: Maybe CostModelParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Control.DeepSeq
import Control.Lens
import GHC.Exts (inline)
import GHC.Generics
import NoThunks.Class

{-| We need to account for the costs of evaluator steps and also built-in function
evaluation. The models for these have different structures and are used in
Expand Down Expand Up @@ -44,11 +43,6 @@ data MachineParameters machinecosts fun val =
deriving stock Generic
deriving anyclass (NFData)

-- For some reason the generic instance gives incorrect nothunk errors,
-- see https://github.com/input-output-hk/nothunks/issues/24
instance (NoThunks machinecosts, Bounded fun, Enum fun) => NoThunks (MachineParameters machinecosts fun val) where
wNoThunks ctx (MachineParameters costs runtime) = allNoThunks [ noThunks ctx costs, noThunks ctx runtime ]

{- Note [The CostingPart constraint in mkMachineParameters]
Discharging the @CostingPart uni fun ~ builtincosts@ constraint in 'mkMachineParameters' causes GHC
to fail to inline the function at its call site regardless of the @INLINE@ pragma and an explicit
Expand Down Expand Up @@ -86,6 +80,6 @@ mkMachineParameters ::
=> BuiltinSemanticsVariant fun
-> CostModel machinecosts builtincosts
-> MachineParameters machinecosts fun val
mkMachineParameters semvar (CostModel mchnCosts builtinCosts) =
MachineParameters mchnCosts (inline toBuiltinsRuntime semvar builtinCosts)
mkMachineParameters semVar (CostModel mchnCosts builtinCosts) =
MachineParameters mchnCosts (inline toBuiltinsRuntime semVar builtinCosts)
{-# INLINE mkMachineParameters #-}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{-# LANGUAGE BangPatterns #-}

-- | Defines the type of default machine parameters and a function for creating a value of the type.
-- We keep them separate, because the function unfolds into multiple thousands of lines of Core that
-- we need to be able to visually inspect, hence we dedicate a separate file to it.
module PlutusCore.Evaluation.Machine.MachineParameters.Default where

import PlutusPrelude

import PlutusCore.Builtin
import PlutusCore.Default
import PlutusCore.Evaluation.Machine.CostModelInterface
Expand Down Expand Up @@ -56,13 +60,16 @@ inlining).
-- This function is expensive, so its result needs to be cached if it's going to be used multiple
-- times.
mkMachineParametersFor
:: MonadError CostModelApplyError m
=> BuiltinSemanticsVariant DefaultFun
:: forall m a. MonadError CostModelApplyError m
=> [BuiltinSemanticsVariant DefaultFun]
-> (a -> BuiltinSemanticsVariant DefaultFun)
-> CostModelParams
-> m DefaultMachineParameters
mkMachineParametersFor semvar newCMP =
inline mkMachineParameters semvar <$>
applyCostModelParams defaultCekCostModel newCMP
-> m (a -> Maybe DefaultMachineParameters)
mkMachineParametersFor semVars toSemVar newCMP = do
semVarAndMachineParametersCache <- for semVars $ \semVar ->
(,) semVar . inline mkMachineParameters semVar <$>
applyCostModelParams (toCekCostModel semVar) newCMP
pure $ \x -> lookup (toSemVar x) semVarAndMachineParametersCache
-- Not marking this function with @INLINE@, since at this point everything we wanted to be inlined
-- is inlined and there's zero reason to duplicate thousands and thousands of lines of Core down
-- the line.
7 changes: 2 additions & 5 deletions plutus-core/testlib/PlutusIR/Pass/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
{-# OPTIONS_GHC -Wno-orphans #-}
module PlutusIR.Pass.Test where

import Control.Exception (throw)
import Control.Monad.Except
import Data.Bifunctor (first)
import Data.Functor (void)
import Data.Typeable
import PlutusCore qualified as PLC
import PlutusCore.Builtin
import PlutusCore.Default (BuiltinSemanticsVariant (..))
import PlutusCore.Generators.QuickCheck (forAllDoc)
import PlutusCore.Pretty qualified as PLC
import PlutusIR.Core.Type
Expand All @@ -20,6 +16,7 @@ import PlutusIR.Generators.QuickCheck
import PlutusIR.Pass
import PlutusIR.TypeCheck
import PlutusIR.TypeCheck qualified as TC
import PlutusPrelude
import Test.QuickCheck

-- Convert Either Error () to Either String () to match with the Testable (Either String ())
Expand All @@ -31,7 +28,7 @@ convertToEitherString = \case
Right () -> Right ()

instance Arbitrary (BuiltinSemanticsVariant PLC.DefaultFun) where
arbitrary = elements [DefaultFunSemanticsVariant1, DefaultFunSemanticsVariant2]
arbitrary = elements enumerate

-- | An appropriate number of tests for a compiler pass property, so that we get some decent
-- exploration of the program space. If you also take other arguments, then consider multiplying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module UntypedPlutusCore.Evaluation.Machine.Cek
, logWithTimeEmitter
, logWithBudgetEmitter
-- * Misc
, CekValue(..)
, BuiltinsRuntime (..)
, CekValue (..)
, readKnownCek
, Hashable
, ThrowableBuiltins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ import PlutusCore.StdLib.Data.Unit
import Evaluation.Builtins.BLS12_381 (test_BLS12_381)
import Evaluation.Builtins.Common
import Evaluation.Builtins.Conversion qualified as Conversion
import Evaluation.Builtins.SignatureVerification (ecdsaSecp256k1Prop, ed25519_Variant1Prop,
ed25519_Variant2Prop, schnorrSecp256k1Prop)
import Evaluation.Builtins.SignatureVerification (ecdsaSecp256k1Prop, ed25519_Variant0Prop,
ed25519_Variant1Prop, ed25519_Variant2Prop,
schnorrSecp256k1Prop)


import Control.Exception
Expand Down Expand Up @@ -770,6 +771,8 @@ test_ConsByteString =
+ 33 -- the index of '!' in ascii table
expr1 = mkIterAppNoAnn (builtin () (Left ConsByteString :: DefaultFunExt))
[cons @Integer asciiBangWrapped, cons @ByteString "hello world"]
Right (EvaluationSuccess $ cons @ByteString "!hello world") @=?
typecheckEvaluateCekNoEmit (PairV DefaultFunSemanticsVariant0 def) defaultBuiltinCostModelExt expr1
Right (EvaluationSuccess $ cons @ByteString "!hello world") @=?
typecheckEvaluateCekNoEmit (PairV DefaultFunSemanticsVariant1 def) defaultBuiltinCostModelExt expr1
Right EvaluationFailure @=? typecheckEvaluateCekNoEmit
Expand Down Expand Up @@ -802,6 +805,12 @@ test_SignatureVerification :: TestTree
test_SignatureVerification =
adjustOption (\x -> max x . HedgehogTestLimit . Just $ 8000) .
testGroup "Signature verification" $ [
testGroup "Ed25519 signatures (Variant0)"
[ testPropertyNamed
"Ed25519_Variant0 verification behaves correctly on all inputs"
"ed25519_Variant0_correct"
. property $ ed25519_Variant0Prop
],
testGroup "Ed25519 signatures (Variant1)"
[ testPropertyNamed
"Ed25519_Variant1 verification behaves correctly on all inputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module Evaluation.Builtins.SignatureVerification (
ecdsaSecp256k1Prop,
ed25519_Variant0Prop,
ed25519_Variant1Prop,
ed25519_Variant2Prop,
schnorrSecp256k1Prop,
Expand Down Expand Up @@ -75,6 +76,9 @@ ed25519Prop semvar = do
cover 18 "happy path" . is (_Shouldn'tError . _AllGood) $ testCase
runTestDataWith semvar testCase id VerifyEd25519Signature

ed25519_Variant0Prop :: PropertyT IO ()
ed25519_Variant0Prop = ed25519Prop DefaultFunSemanticsVariant0

ed25519_Variant1Prop :: PropertyT IO ()
ed25519_Variant1Prop = ed25519Prop DefaultFunSemanticsVariant1

Expand Down
17 changes: 12 additions & 5 deletions plutus-ledger-api/src/PlutusLedgerApi/Common/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ mkTermToEvaluate ll pv script args = do
through (liftEither . first DeBruijnError . UPLC.checkScope) appliedT

toMachineParameters :: MajorProtocolVersion -> EvaluationContext -> DefaultMachineParameters
toMachineParameters _ = machineParameters
toMachineParameters pv ctx = machineParameters ctx pv

{-| An opaque type that contains all the static parameters that the evaluator needs to evaluate a
script. This is so that they can be computed once and cached, rather than being recomputed on every
evaluation.
-}
newtype EvaluationContext = EvaluationContext
{ machineParameters :: DefaultMachineParameters
{ machineParameters :: MajorProtocolVersion -> DefaultMachineParameters
}
deriving stock Generic
deriving anyclass (NFData, NoThunks)
Expand All @@ -128,11 +128,18 @@ with the updated cost model parameters.
-}
mkDynEvaluationContext
:: MonadError CostModelApplyError m
=> BuiltinSemanticsVariant DefaultFun
=> String
-> [BuiltinSemanticsVariant DefaultFun]
-> (MajorProtocolVersion -> BuiltinSemanticsVariant DefaultFun)
-> Plutus.CostModelParams
-> m EvaluationContext
mkDynEvaluationContext semvar newCMP =
EvaluationContext <$> mkMachineParametersFor semvar newCMP
mkDynEvaluationContext lv semVars toSemVar newCMP =
mkMachineParametersFor semVars toSemVar newCMP <&> \getMachPars ->
EvaluationContext $ \pv ->
case getMachPars pv of
Nothing -> error $ Prelude.concat
["Internal error: ", show lv, " does not support ", show pv]
Just machPars -> machPars

-- FIXME: remove this function
assertWellFormedCostModelParams :: MonadError CostModelApplyError m => Plutus.CostModelParams -> m ()
Expand Down
Loading