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
[Costing] Provide support for multiple 'CostModel's #5851
Conversation
c8abb84
to
a9a71bd
Compare
/benchmark validation |
Click here to check the status of your benchmark. |
18f2db1
to
9758d10
Compare
9758d10
to
b97e9f1
Compare
/benchmark validation |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on '381172295' (base) and 'b97e9f11e' (PR) Results table
|
/benchmark nofib |
Click here to check the status of your benchmark. |
…to effectfully/builtins/both-MajorProtocolVersion-and-multiple-CostModels
b97e9f1
to
0a1af53
Compare
Click here to check the status of your benchmark. |
/benchmark lists |
1 similar comment
/benchmark lists |
Comparing benchmark results of 'validation' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'validation' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'nofib' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
Click here to check the status of your benchmark. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks totally legit
@@ -1287,7 +1291,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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Comparing benchmark results of 'nofib' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'lists' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
Click here to check the status of your benchmark. |
Comparing benchmark results of 'lists' on '16a986fd8' (base) and '9d8942da1' (PR) Results table
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@@ -85,6 +86,9 @@ defaultCekMachineCosts = | |||
defaultCekCostModel :: CostModel CekMachineCosts BuiltinCostModel | |||
defaultCekCostModel = CostModel defaultCekMachineCosts defaultBuiltinCostModel | |||
|
|||
toCekCostModel :: BuiltinSemanticsVariant DefaultFun -> CostModel CekMachineCosts BuiltinCostModel | |||
toCekCostModel _ = defaultCekCostModel |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Inevitably once I started thinking about this stuff again I became confused by the versions and how they depend on each other. I'm pretty convinced that this does what we want though.
| DefaultFunSemanticsVariant2 | ||
deriving stock (Enum, Bounded, Show) | ||
data BuiltinSemanticsVariant DefaultFun | ||
= DefaultFunSemanticsVariant0 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
>=> mkDynEvaluationContext | ||
PlutusV3 | ||
[DefaultFunSemanticsVariant2] | ||
(const Plutus.DefaultFunSemanticsVariant2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again we could probably do without the Plutus
here and in the import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check: V1 and V2 have if pv < conwayPV then ... else ...
here, but it's safe to have const
for V3 because we know that PlutusV3
is going to be introduced at the same time as conwayPV
, so a PlutusV3 script can never be executed with a lower PV, so there's no possiblity that pv < conwayPV
here (but conceivably we might need if pv < einsteinPV
or something in the future). Is that right? Maybe we should try to explain that somewhere, since there's a LL/PV dependency that I don't think is captured in the code anywhere. Maybe we should have note containing a table like we do in the PLC specification (or a big table that contains all of the relevant information, since there are multiple tables in the spec).
[Later] Actually, maybe the dependencies are specified in PlutusLedgerApi.Common.Versions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check: V1 and V2 have
if pv < conwayPV then ... else ...
here, but it's safe to haveconst
for V3 because we know thatPlutusV3
is going to be introduced at the same time asconwayPV
, so a PlutusV3 script can never be executed with a lower PV, so there's no possiblity thatpv < conwayPV
here (but conceivably we might needif pv < einsteinPV
or something in the future). Is that right?
I believe so, yes.
Maybe we should try to explain that somewhere, since there's a LL/PV dependency that I don't think is captured in the code anywhere. Maybe we should have note containing a table like we do in the PLC specification (or a big table that contains all of the relevant information, since there are multiple tables in the spec).
Good point, I'll add a small table somewhere, but I'm not totally sure where given that the logic is spread across multiple files. I guess PlutusLedgerApi.Common.Versions
indeed.
evaluation. | ||
|
||
Different protocol versions may require different bundles of machine parameters, which allows us for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this into a Note? It seems quite important. It would seem to have some bearing on this, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this into a Note?
I kinda want this to be the Haddock for extra transparency. I do reference the Haddock of a function instead of a Note sometimes.
/benchmark validation |
Click here to check the status of your benchmark. |
e6afc0b
to
039dce1
Compare
…to effectfully/builtins/both-MajorProtocolVersion-and-multiple-CostModels
This makes cost models configurable, so that the cost model can depend on the protocol version. All commentary is in the diff.