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

LW-11572 V10 protocol fixes #1485

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading