Skip to content

Commit

Permalink
Merge pull request #1485 from input-output-hk/fix/LW-11572-V10-protoc…
Browse files Browse the repository at this point in the history
…ol-fixes

LW-11572 V10 protocol fixes
  • Loading branch information
iccicci committed Sep 23, 2024
2 parents bf1c222 + 0b86722 commit e8f3f0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
12 changes: 12 additions & 0 deletions packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ const parseReferenceScript = (model: UtxoModel): Cardano.Script => {
version: Cardano.PlutusLanguageVersion.V2
};
break;
case ReferenceScriptType.PlutusV3:
if (!isNotNil(model.reference_script_bytes))
throw new SerializationError(
SerializationFailure.InvalidScript,
'Unexpected error deserializing PlutusV2 script. Data is null'
);
script = {
__type: Cardano.ScriptType.Plutus,
bytes: model.reference_script_bytes as unknown as HexBlob,
version: Cardano.PlutusLanguageVersion.V3
};
break;
default:
throw new SerializationError(
SerializationFailure.InvalidScriptType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export enum ReferenceScriptType {
Multisig = 'multisig',
Timelock = 'timelock',
PlutusV1 = 'plutusV1',
PlutusV2 = 'plutusV2'
PlutusV2 = 'plutusV2',
PlutusV3 = 'plutusV3'
}
49 changes: 2 additions & 47 deletions packages/core/src/Serialization/Update/Costmdls/CostModel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { InvalidArgumentError, InvalidStateError } from '@cardano-sdk/util';
import { InvalidArgumentError } from '@cardano-sdk/util';
import { PlutusLanguageVersion } from '../../../Cardano/types/Script';

const PLUTUS_V1_COST_MODEL_OP_COUNT = 166;
const PLUTUS_V2_COST_MODEL_OP_COUNT = 175;
const PLUTUS_V3_COST_MODEL_OP_COUNT = 179;

/**
* The execution of plutus scripts consumes resources. To make sure that these
* scripts don't run indefinitely or consume excessive resources (which would be
Expand All @@ -28,32 +24,6 @@ export class CostModel {
constructor(language: PlutusLanguageVersion, costs: Array<number>) {
this.#language = language;
this.#costs = costs;

switch (this.#language) {
case PlutusLanguageVersion.V1:
if (costs.length !== PLUTUS_V1_COST_MODEL_OP_COUNT)
throw new InvalidArgumentError(
'costs',
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
);
break;
case PlutusLanguageVersion.V2:
if (costs.length !== PLUTUS_V2_COST_MODEL_OP_COUNT)
throw new InvalidArgumentError(
'costs',
`Cost model for PlutusV2 language should have ${PLUTUS_V2_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
);
break;
case PlutusLanguageVersion.V3:
if (costs.length !== PLUTUS_V3_COST_MODEL_OP_COUNT)
throw new InvalidArgumentError(
'costs',
`Cost model for PlutusV3 language should have ${PLUTUS_V3_COST_MODEL_OP_COUNT} operations, but got ${costs.length}.`
);
break;
default:
throw new InvalidStateError('Invalid plutus language version.');
}
}

/**
Expand Down Expand Up @@ -141,21 +111,6 @@ export class CostModel {
* @returns true if is a valid operation; otherwise; false.
*/
#isOperationValid(operation: number): boolean {
let isValid = false;
switch (this.#language) {
case PlutusLanguageVersion.V1:
isValid = operation >= 0 && operation < PLUTUS_V1_COST_MODEL_OP_COUNT;
break;
case PlutusLanguageVersion.V2:
isValid = operation >= 0 && operation < PLUTUS_V2_COST_MODEL_OP_COUNT;
break;
case PlutusLanguageVersion.V3:
isValid = operation >= 0 && operation < PLUTUS_V3_COST_MODEL_OP_COUNT;
break;
default:
throw new InvalidStateError('Invalid plutus language version.');
}

return isValid;
return operation >= 0;
}
}

0 comments on commit e8f3f0b

Please sign in to comment.