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

CIP-???? | Augment Spend Purpose #754

Closed
wants to merge 3 commits into from

Conversation

micahkendall
Copy link

@micahkendall micahkendall commented Jan 27, 2024

We should change the purpose Spend(OutputReference) to instead be Spend(x, ScriptHash)

EDIT: I have changed the proposal from Spend(OutputReference, ScriptHash) to Spend(x, ScriptHash), to indicate that this proposal is compatible with any changes to the first argument.

This would introduce asymptotic time savings for smart contracts using the pattern found in the Fortuna hard fork, or described in my blogpost. The cost to search the inputs list for an output reference, and then to find its address is fairly high in my personal benchmarking. Every other purpose exposes the script hash in some form, this unifies the ability of a script to know its own address (cheaply).

As an unverified, allegorical benchmark, we cut down from about 40k memunits per UTxO spent down to 14k memunits per UTxO spent by optimising around this limitation. We expect we could lift this limitation more with the acceptance of this CIP, and accomplish these numbers in an ergonomic, developer-friendly way.

Some different ways we currently optimise around this:

  • parameterise a script with an NFT, putting the script hash into a utxo that owns that NFT, which we use to know the hash of the spending script, from reference inputs.
  • put the script hash into the datum, in the case of validators locked by tokens

Rendered proposal on a author's fork

@micahkendall micahkendall marked this pull request as ready for review January 27, 2024 11:05
@colll78
Copy link
Contributor

colll78 commented Jan 28, 2024

This CIP synergizes well with the multi-validator trick and CIP-112. It would provide a large benefit to DApp throughput using current design patterns (withdraw-zero trick), that would transfer over directly to the equivalent pattern with observation scripts. I think this is a great idea.

Personally, I would like to see this extended to:
Spending Integer ScriptHash

Where integer is the index of the input that is being spent in the txInfoInputs list. I haven't really ever seen TxOutRef be used in a way other than to search for the input being unlocked.

@micahkendall
Copy link
Author

Personally, I would like to see this extended to: Spending Integer ScriptHash

I'm very happy with any use case which supersets the functionality I propose superseding this CIP! If we get the full input (as @MicroProofs wants), or we have minor adjustments on the first argument as you say, I'm happy.

Frankly I'm moving away from any pattern which uses the spend validation directly in all my code so anything goes as long as the ScriptHash is somewhere in the constructor.

@longngn
Copy link

longngn commented Jan 29, 2024

+1
It's very useful for a validator to know its own scriptHash and reduce the cost of un-packing and searching the inputs. This is especially prominent in the batching pattern where in 1 tx, we have dozens of script inputs that are doing this exact same thing. By reducing the cost of each script, we can marginally increase the total number of script inputs in the transaction (hence the throughput of Dapp).

@Ryun1 Ryun1 changed the title CIP-???? Augment Spend Purpose CIP-???? | Augment Spend Purpose Jan 29, 2024
@Ryun1 Ryun1 added the Category: Plutus Proposals belonging to the 'Plutus' category. label Jan 29, 2024
@Ryun1 Ryun1 marked this pull request as draft January 29, 2024 11:22
@Ryun1
Copy link
Collaborator

Ryun1 commented Jan 29, 2024

Hey @micahkendall,

Since this proposal is currently very brief on all sections, I have converted it to a draft.

@micahkendall
Copy link
Author

Hey @micahkendall,

Since this proposal is currently very brief on all sections, I have converted it to a draft.

What needs elaboration?

@rphair
Copy link
Collaborator

rphair commented Jan 30, 2024

@micahkendall: What needs elaboration?

  • The single-sentence Motivation
    • e.g. what problems have you run into without this? How often do these problems occur in general practice?
  • The single-sentence Specification
    • what does the proposed code look like? what do examples of its usage look like?
  • The single-sentence Rationale: maybe OK; depends on how much is covered in Motivation about why we are doing this & the alternatives.
  • The cursory Path to Active: please see CIP-0035 to see what needs to be added for Plutus changes.
    • The requirements are strict for non-Core changes and even stricter for Core changes.
    • Please make them into checkboxes so implementors can mark these as resolved if & when it moves from Proposed to Active.
  • Copyright requires open-source licensing for a reason you may not have considered: a disclaimer of liability. The community needs this as well as you. Please choose CC or Apache as required here for all CIPs: https://github.com/cardano-foundation/CIPs/blob/master/CIP-0001/README.md#licensing

cc @Ryun1

@rphair
Copy link
Collaborator

rphair commented Jan 30, 2024

p.s. @micahkendall a good start would be to put all the things from this PR's OP into the proposal itself. My last answer was just to address the editing question directly. But you have some good detail in your original posting that answers a lot of these "elaboration" questions & would at least provide a starting point for proper review in the document itself.

@michaelpj
Copy link
Contributor

I think we should instead go for consistent integer indexes and fix #638 to get O(1) lookup in the inputs list.

@michaelpj
Copy link
Contributor

The point of the ScriptPurpose is to be the information you need to identify the particular script invocation. Caching random additional information in it dilutes that purpose and it's not clear when you should include things or not.

@colll78
Copy link
Contributor

colll78 commented Feb 2, 2024

I think we should instead go for consistent integer indexes and fix #638 to get O(1) lookup in the inputs list.

100% onboard with this. Would be an incredible improvement.

@micahkendall
Copy link
Author

@michaelpj

If we're going to be getting O(1) lookup on inputs in time for Plutus V3 then I'm happy to withdraw this CIP. I think from a developer experience standpoint it's still sane to bring the information together, as it can hardly be considered random additional information when it is the exact information that every other script purpose variant contains. However to me that doesn't make it a meaningful improvement because I primarily care about performance.

@michaelpj
Copy link
Contributor

I think it's pretty unlikely that any further significant changes to the script context are going to hit PlutusV3, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Plutus Proposals belonging to the 'Plutus' category.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants