From f468f920e65d4d2d6a786c58fa3f82bd75912174 Mon Sep 17 00:00:00 2001 From: Michele Nuzzi Date: Wed, 6 Aug 2025 20:59:33 +0200 Subject: [PATCH 1/2] init --- CIP-????/README.md | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 CIP-????/README.md diff --git a/CIP-????/README.md b/CIP-????/README.md new file mode 100644 index 0000000000..0538a1e937 --- /dev/null +++ b/CIP-????/README.md @@ -0,0 +1,155 @@ +--- +CIP: ? +Title: Better script purposes +Category: Plutus +Status: Proposed +Authors: + - Michele Nuzzi +Implementors: [] +Discussions: + - https://github.com/cardano-foundation/CIPs/pull/? +Created: 2025-08-06 +License: CC-BY-4.0 +--- + +## Abstract + +This CIP proposes better script purposes to optimize for common operations for each purpose + +## Motivation: why is this CIP necessary? + + +Common operations such as deriving the hash of the script being executed, or finding the relevant data for validation could be optimized if the trusted data provided to the script was more complete. + +The same result could be achieved by including this data in the redeemer, however these alternative solutions ofter imply greater complexity in the offchain code, and do not come without overhead on-chian, since the redeemer cannot be trusted. + +This CIP would solve those problems, with great improvements on the development experience as well as the resulting onchain scripts complexity and efficiency. + + +## Specification + + +this CIP proposes to modify the definition of `ScriptInfo` and `ScriptPurpose` in [`plutus-ledger-api`](https://github.com/IntersectMBO/plutus/blob/618480658ec1750179c2832c6b619bc2d872b225/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs#L428-L461) as follows + +```hs +data ScriptInfo + = MintingScript + -- hash of the script being executed (same as polciy) + V2.CurrencySymbol + -- | 0-based index of the given `CurrencySymbol` in `txInfoMint` + Haskell.Integer + | SpendingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the input being spent in `txInfoInputs` + Haskell.Integer + (Haskell.Maybe V2.Datum) + -- resolved input being spent + V3.TxOut + V3.TxOutRef + | RewardingScript + -- V2.Credential -- removed, since implictily it must be a script credential + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the withdrawal being verified in `txInfoWdrl` + Haskell.Integer + | CertifyingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given `TxCert` in `txInfoTxCerts` + Haskell.Integer + TxCert + | VotingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given vote in `txInfoVotes` + Haskell.Integer + Voter + | ProposingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given `ProposalProcedure` in `txInfoProposalProcedures` + Haskell.Integer + ProposalProcedure + deriving stock (Generic, Haskell.Show, Haskell.Eq) + deriving anyclass (HasBlueprintDefinition) + deriving (Pretty) via (PrettyShow ScriptInfo) +``` + +```hs +data ScriptPurpose + = MintingScript + -- hash of the script being executed (same as polciy) + V2.CurrencySymbol + -- | 0-based index of the given `CurrencySymbol` in `txInfoMint` + Haskell.Integer + | SpendingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the input being spent in `txInfoInputs` + Haskell.Integer + V3.TxOutRef + | RewardingScript + -- V2.Credential -- removed, since implictily it must be a script credential + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the withdrawal being verified in `txInfoWdrl` + Haskell.Integer + | CertifyingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given `TxCert` in `txInfoTxCerts` + Haskell.Integer + TxCert + | VotingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given vote in `txInfoVotes` + Haskell.Integer + Voter + | ProposingScript + -- hash of the script being executed + V2.ScriptHash + -- | 0-based index of the given `ProposalProcedure` in `txInfoProposalProcedures` + Haskell.Integer + ProposalProcedure + deriving stock (Generic, Haskell.Show, Haskell.Eq) + deriving anyclass (HasBlueprintDefinition) + deriving (Pretty) via (PrettyShow ScriptInfo) +``` + +## Rationale: how does this CIP achieve its goals? + + +This modification would be reflected in the underlying data representation as always having the script hash of the given script as the first field of the purpose, and the index relevant to the purpose as second element. + +This allows to optimize for the very common operation of deriving the hash of the script itself onchain, greatly reducing onchain complexity and cost of execution. + +The change also propses to add the resovled input in the case of the very common spending purpose, where the majority of the relevant informations is present. + +## Path to Active + +Changes are reflected on the plutus-ledger-api + +### Acceptance Criteria + + +The change is included in an hardfork + +### Implementation Plan + +N/A + + + +## Copyright + + +This CIP is licensed under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/legalcode) + From 6d1fcf0c95d97501794884d7b09bc7d9fe3b3954 Mon Sep 17 00:00:00 2001 From: Michele Nuzzi Date: Wed, 6 Aug 2025 21:18:34 +0200 Subject: [PATCH 2/2] remove Maybe Datum, add discussions link --- CIP-????/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CIP-????/README.md b/CIP-????/README.md index 0538a1e937..898d384cf8 100644 --- a/CIP-????/README.md +++ b/CIP-????/README.md @@ -7,7 +7,7 @@ Authors: - Michele Nuzzi Implementors: [] Discussions: - - https://github.com/cardano-foundation/CIPs/pull/? + - https://github.com/cardano-foundation/CIPs/pull/1072 Created: 2025-08-06 License: CC-BY-4.0 --- @@ -43,7 +43,8 @@ data ScriptInfo V2.ScriptHash -- | 0-based index of the input being spent in `txInfoInputs` Haskell.Integer - (Haskell.Maybe V2.Datum) + -- removed optional datum, since its presence (or not) is determined by the resolved input + -- (Haskell.Maybe V2.Datum) -- resolved input being spent V3.TxOut V3.TxOutRef