You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update CostModel Validation to Allow Dynamic Cost Model Sizes Based on CDDL Definition
GitHub Issue Description:
Description:
The current implementation of the CostModel class in the Plutus language enforces a strict operation count for each language version. Specifically, the code checks that the costs array length exactly matches a predefined static length, such as:
However, according to the official CDDL definition, the format for cost models is flexible enough to allow additional integers in the costs array beyond the predefined count. These extra integers are accepted and ignored, thus making the model future-proof for potential expansions, such as adding new Plutus built-ins or language versions.
The relevant portion of the CDDL definition is as follows:
costmdls =
{ ? 0 : [ 166* int ] ; Plutus v1, only 166 integers are used, but more are accepted (and ignored)
, ? 1 : [ 175* int ] ; Plutus v2, only 175 integers are used, but more are accepted (and ignored)
, ? 2 : [ 223* int ] ; Plutus v3, only 223 integers are used, but more are accepted (and ignored)
, ? 3 : [ int ] ; Any 8-bit unsigned number can be used as a key.
}
Proposed Change:
The validation logic should be updated to check that the costs array length is at least as long as the required count but allows for longer arrays:
if(costs.length<PLUTUS_V2_COST_MODEL_OP_COUNT)thrownewInvalidArgumentError('costs',`Cost model for PlutusV2 language should have at least ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`);
This change will ensure compliance with the CDDL specification and allow for more flexible and future-proof cost models.
GitHub Issue Title:
Update CostModel Validation to Allow Dynamic Cost Model Sizes Based on CDDL Definition
GitHub Issue Description:
Description:
The current implementation of the
CostModel
class in the Plutus language enforces a strict operation count for each language version. Specifically, the code checks that thecosts
array length exactly matches a predefined static length, such as:cardano-js-sdk/packages/core/src/Serialization/Update/Costmdls/CostModel.ts
Line 34 in 54e2014
However, according to the official CDDL definition, the format for cost models is flexible enough to allow additional integers in the costs array beyond the predefined count. These extra integers are accepted and ignored, thus making the model future-proof for potential expansions, such as adding new Plutus built-ins or language versions.
The relevant portion of the CDDL definition is as follows:
Proposed Change:
The validation logic should be updated to check that the costs array length is at least as long as the required count but allows for longer arrays:
This change will ensure compliance with the CDDL specification and allow for more flexible and future-proof cost models.
References:
CDDL definition of cost models
The text was updated successfully, but these errors were encountered: