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

Update CostModel Validation to Allow Dynamic Cost Model Sizes Based on CDDL Definition #1453

Closed
ilap opened this issue Aug 29, 2024 · 1 comment
Assignees

Comments

@ilap
Copy link

ilap commented Aug 29, 2024

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 the costs array length exactly matches a predefined static length, such as:

if (costs.length !== PLUTUS_V1_COST_MODEL_OP_COUNT)

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)
  throw new InvalidArgumentError(
    '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.

References:

CDDL definition of cost models

@AngelCastilloB
Copy link
Member

AngelCastilloB commented Sep 25, 2024

This issue should be solved in version 0.40.0

@rhyslbw rhyslbw closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants