Skip to content

Commit 0b86722

Browse files
committed
fix(core): don't check for cost model array length
1 parent b5be7a4 commit 0b86722

File tree

1 file changed

+2
-47
lines changed

1 file changed

+2
-47
lines changed

packages/core/src/Serialization/Update/Costmdls/CostModel.ts

+2-47
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { InvalidArgumentError, InvalidStateError } from '@cardano-sdk/util';
1+
import { InvalidArgumentError } from '@cardano-sdk/util';
22
import { PlutusLanguageVersion } from '../../../Cardano/types/Script';
33

4-
const PLUTUS_V1_COST_MODEL_OP_COUNT = 166;
5-
const PLUTUS_V2_COST_MODEL_OP_COUNT = 175;
6-
const PLUTUS_V3_COST_MODEL_OP_COUNT = 179;
7-
84
/**
95
* The execution of plutus scripts consumes resources. To make sure that these
106
* scripts don't run indefinitely or consume excessive resources (which would be
@@ -28,32 +24,6 @@ export class CostModel {
2824
constructor(language: PlutusLanguageVersion, costs: Array<number>) {
2925
this.#language = language;
3026
this.#costs = costs;
31-
32-
switch (this.#language) {
33-
case PlutusLanguageVersion.V1:
34-
if (costs.length !== PLUTUS_V1_COST_MODEL_OP_COUNT)
35-
throw new InvalidArgumentError(
36-
'costs',
37-
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
38-
);
39-
break;
40-
case PlutusLanguageVersion.V2:
41-
if (costs.length !== PLUTUS_V2_COST_MODEL_OP_COUNT)
42-
throw new InvalidArgumentError(
43-
'costs',
44-
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
45-
);
46-
break;
47-
case PlutusLanguageVersion.V3:
48-
if (costs.length !== PLUTUS_V3_COST_MODEL_OP_COUNT)
49-
throw new InvalidArgumentError(
50-
'costs',
51-
`Cost model for PlutusV3 language should have ${PLUTUS_V3_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
52-
);
53-
break;
54-
default:
55-
throw new InvalidStateError('Invalid plutus language version.');
56-
}
5727
}
5828

5929
/**
@@ -141,21 +111,6 @@ export class CostModel {
141111
* @returns true if is a valid operation; otherwise; false.
142112
*/
143113
#isOperationValid(operation: number): boolean {
144-
let isValid = false;
145-
switch (this.#language) {
146-
case PlutusLanguageVersion.V1:
147-
isValid = operation >= 0 && operation < PLUTUS_V1_COST_MODEL_OP_COUNT;
148-
break;
149-
case PlutusLanguageVersion.V2:
150-
isValid = operation >= 0 && operation < PLUTUS_V2_COST_MODEL_OP_COUNT;
151-
break;
152-
case PlutusLanguageVersion.V3:
153-
isValid = operation >= 0 && operation < PLUTUS_V3_COST_MODEL_OP_COUNT;
154-
break;
155-
default:
156-
throw new InvalidStateError('Invalid plutus language version.');
157-
}
158-
159-
return isValid;
114+
return operation >= 0;
160115
}
161116
}

0 commit comments

Comments
 (0)