-
Notifications
You must be signed in to change notification settings - Fork 322
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-0069 | add Datum to ScriptContext #784
Conversation
@zliu41 we're reviewing some related & alternative proposals at the next CIP meeting (https://hackmd.io/@cip-editors/84) and expect good Plutus representation there, so I've added this to the agenda. Would be nice if you could make it to that meeting. 🤓 |
I am in support of this alternative over my own PR. |
CIP-0069/README.md
Outdated
```hs | ||
data ScriptPurpose | ||
= ... | ||
| Spending TxOutRef Datum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Maybe Datum instead of Datum? Or is this a Datum field containing
Datum Hash, InlineDatum, No Datum?
I was thinking of a different variant, something like this:
("Evaluation" info since it contains information about the specific evaluation of a script that is occurring, since a given script can be evaluated multiple times in multiple ways. Could have a better name) |
The problem with this naming is that
Could be true, but I thought it'd be just as easy for the ledger if we add Datum to ScriptPurpose. I believe when constructing ScriptPurpose, the ledger does have access to the Datum, so it can simply stuff it in. But I could be wrong. @lehins @WhatisRT let me know whether you prefer ScriptContext/ScriptIdentifier, or ScriptInfo/ScriptContext (in both cases, the former contains the additional datum). |
What would the case be for no datum btw? |
I thought allowing datum to be optional is the subject of another CIP, but |
Updated; datum is now optional |
@zygomeb this was reviewed at the CIP editor's meeting today & the response was favourable, indicating that the IOG Plutus team would prefer to do it this way (cc @michaelpj) ... i.e. they would prefer to implement your original proposal with this change. I'm marking it |
I think I don't mind adding the |
Is it possible to make this or a simplified version of just Maybe Datum instead of Datum make it into the Chang hardfork? I believe the feature is worth delaying the Chang hard fork if we can get even a more simplified version of this CIP. |
re: #784 (comment) @MicroProofs I've added this question to tonight's CIP meeting agenda in the hope you can make it. If not done already in the PR thread in the meantime, we can clarify your request and maybe get feedback from other developers about how much their experience might be affected with & without it. |
Ok I'll make it to the meeting today. |
I have said it many time at every opportunity I get basically, but this functionality is game-changing for smart-wallets and will enable an entire new class of users for the ecosystem. for my work the lack of this functionality has been a blocking issue for a very long time. |
If the ledger team is not feature frozen, I am wondering if it's possible to change the ledger to pass in a Maybe Datum instead of Datum. Here is the code that would change in master I think I got the right area, but my LSP for Haskell isn't working at the moment so I might be off the location by a little bit. Apologies.
I believe here you would change how spendingDatum returns to differentiate between NoDatum vs other script purposes. This would enable a wide variety of features here Use cases include Smart wallets, wallets that can do 2fa, vault features Datumless utxos accidentally sent to a Dapp could be recovered for the user. Easier subscription services that don't require you to send funds to a contract |
Sorry guys, I was on PTO for a while and was catching up with all of the other important Conway related issues. Unfortunately proposed solution requires quite a bit of work on the ledger side and we just don't have enough time to get it done, considering how close we are to the Chang hardfork deadline.
Such decision is definitely above my pay grade. 🥲 So if we were to postpone the deadline this would have to come from the upper management, not from the developers. With respect to the CIP. To be honest with you I am not very fond of the proposed solution and I think we can do better if we are not gonna rush it. That being said we might be able to do an interim solution for PlutusV3 that resembles the original suggestion quite easily, if there is interest in it. Solution I am talking about is what @MicroProofs suggested:
In my opinion this is a safer solution, albeit less type safe, than the one proposed in this CIP. In particular my worry is that plutus evaluator is essentially a variadic function that will always succeed if it is not fully saturated. Which means that if we reduce number of arguments to 2 for spending scripts then older scripts blindly ported to PlutusV3 would always succeed, because they would not have enough arguments. What I personally would suggest instead, since everyone is in favor of having the same number of arguments for all type of scripts, is to stop accepting a list of data ScriptContext
= Minting TxInfo Redeemer CurrencySymbol
| Spending TxInfo Redeemer Datum TxOutRef
| Rewarding TxInfo Redeemer Credential
| Certifying TxInfo Redeemer Integer TxCert
| Voting TxInfo Redeemer Voter
| Proposing TxInfo Redeemer Integer ProposalProcedure In other words changing the type signature of this function to: evaluateScriptRestricting ::
-- | Which protocol version to run the operation in
MajorProtocolVersion ->
-- | Whether to produce log output
VerboseMode ->
-- | Includes the cost model to use for tallying up the execution costs
EvaluationContext ->
-- | The resource budget which must not be exceeded during evaluation
ExBudget ->
-- | The script to evaluate
ScriptForEvaluation ->
-- | The arguments to the script
PLC.Data -> -- <-------- This is the change we should aim for.
(LogOutput, Either EvaluationError ExBudget) I honestly don't understand what was the reason for evaluator to accept a list of Of course, this is just my opinion and maybe it either needs to be polished a bit more or maybe it has some serious downsides that I am not aware. In either case neither this solution nor the one proposed in the CIP can make it into Conway due to the time constraints. Back to the potential interim solution for PlutusV3 proposed in #784 (comment). Please, let me know if it would be a sufficient interim solution for Plutus script writers and if it would at least unblock all those use cases mentioned in this discussion. If there would be no objections from all the parties interested in this we could potentially squeeze it in for Conway, because it is simple and requires no changes on the Plutus side and very minimal changes on the Ledger side. Here is a proof of concept implemented in ledger: IntersectMBO/cardano-ledger#4271 Couple of notes about the interim solution:
|
My apologies on suggesting the delayed hard fork. The better option is to rally community support to put it at the forefront of the next HF or possibly an early mini one (depending on community feedback and testing and scope of changes of course) |
The interim solution with both enforcing that Spend still takes in 3 arguments as well as it being a List [Data] is a fine solution for PlutusV3. This would work for the use cases mentioned and unblocks a lot for wallet maker to move forward with smart contract wallets. Since this change requires buy in from the active Language developers, I will tag them here. If you need a new CIP as well I can create one. This is in my opinion a good improvement over status quo. I'll tag the other language creators. @nielstron @nau @michele-nuzzi @christianschmitz @michaelpj |
An alternative solution is constr 0 {[Datum]} to represent Some(Datum) and constr 1 {[]} to represent None in Plutus Data |
I would prefer the constr0/constr1 distinction (which is essentially PlutusData maybe). A list gives the illusion of the possibility of multiple parameters to the script. That said my opinion on this is not very strong except for "it would be really nice to have any solution ASAP" :) |
Please thumbs up 👍 who is in favor of or thumbs down 👎 who is against this representation for Going for the best correspondence for the Haskell's
|
Same as above, but constructors swapped as in proposed solution by @MicroProofs:
|
Just for completeness sake. Same as above 👍 and 👎, for the less popular solution of using
|
It seems to me that this is the most (and only?) viable choice given that it's already the encoding used for I believe @MicroProofs just mixed up the constructor indices in his comment 😅, but the essence of the suggestion was about suggesting to "use Constr instead of a List". @nau @nielstron any reason for preferring |
the "Haskell Maybe" (Just contsr 0 and Nothing constr 1) representation is already used anyway in V1 TxOuts for datum hashes and V2 TxOuts for ref scripts; I don't see why we should go for something else |
To my knowledge the PR linked should allow utxos without datums to be spent by scripts since there will always be 3 arguments. Could you let me know what else is blocking the spending of datumless utxos? |
Yes it does so inderectly. It prevents you from spending it, if it is locked by a Plutus script and datum is not supplied |
@MicroProofs See the very last thing in my comment:
|
Doesn't your proposed solution allow no datums to resolve to Nothing based on the lookup function I copied over. Is there some other error in the ledger that prevents no datum utxo spends? |
The interim solution was an attempt to bypass where the check for the Datum happens by replacing it with a Data instead. But I see it is in a separate file where the utxo itself is checked. Is there a solution we can do for this before Conway. This is the main blocker in this thread for various solutions. |
Yes, that is exactly what I am saying. There is a predicate check that fails validation when the TxOut is locked by a Plutus script and does not have a datum associated with it. |
Sorry to be a bearer of bad news, but not without moving the Conway deadline. Note that the goal of this CIP was to change the number of arguments that all scripts get. At least that was my understanding of the CIP. Making Datum optional was just a minor addition to the CIP. That is why I suggested to go with the interim solution that would solve the main problem. Looks like we all got too happy too soon. 😞 |
Is this code in libs/cardano-ledger-api/src/Cardano/Ledger/Api/Scripts/ExUnits.hs |
Yes, but it is a minor issue. This is just a helper function for the cardano-api/cli It is not used by the ledger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Couple suggestions from me
|
||
The ScriptPurpose type used in the Redeemers Map is left the same. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we also specify somewhere here maybe that we need enforce a single argumet to plutus evaluating function, which at the very least means changing type signatures for these two functions for PlutusV3
in a way that they will accept a single PLC.Data
agument, instead of [PLC.Data]
:
Co-authored-by: Alexey Kuleshevich <[email protected]>
Co-authored-by: Alexey Kuleshevich <[email protected]>
@lehins @zliu41 @MicroProofs @michaelpj @KtorZ @colll78 should #769 be updated with any of these deliberations? Does what's being agreed upon here settle that issue? |
Because this has been technically at |
After some discussion here's the current proposal: All scripts have the signature of data ScriptContext = ScriptContext
{ scriptContextTxInfo :: TxInfo
, scriptContextScriptInfo :: ScriptInfo
-- ^ Previously this was `ScriptPurpose`
}
data ScrintInfo
= MintingScript V2.CurrencySymbol Redeemer
| SpendingScript V3.TxOutRef (Maybe Datum) Redeemer
| RewardingScript V2.Credential Redeemer
| CertifyingScript
Haskell.Integer
-- ^ 0-based index of the given `TxCert` in `txInfoTxCerts`
TxCert
Redeemer
| VotingScript Voter Redeemer
| ProposingScript
Haskell.Integer
-- ^ 0-based index of the given `ProposalProcedure` in `txInfoProposalProcedures`
ProposalProcedure
Redeemer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my understanding this is good to go
and planned to be included within Plutus V3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also my understanding but would be happy to hear, before merging, one final confirmation from @zliu41 and/or @MicroProofs that the recently modified changes accurately describe the planned changes for the next hard fork.
I need to make another update before merging |
I made an update to the |
Closes #769
cc @michaelpj @lehins @MicroProofs @rphair @KtorZ @zygomeb @L-as