-
Notifications
You must be signed in to change notification settings - Fork 334
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-0117? | Explicit script return values #747
CIP-0117? | Explicit script return values #747
Conversation
CIP-????/README.md
Outdated
Since the return value of a script will now be significant, a script will only succeed if the whole thing evaluates to 'true'. | ||
This is very unlikely to happen by accident: mistakes in the number of arguments or in what to return will result in failure. | ||
|
||
### Alternatives |
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.
How about unit (or either unit or true)? Most scripts written in Plutus Tx return unit, so they won't need to change anything.
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.
Yeah, breaking backwards compatibility in such a horrible implicit way sounds like an even worse footgun than the status quo. I do understand that people will need to explicitly pick a new language version, but we can't be sure that they will adapt their code properly.
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.
Most scripts written in Plutus Tx return the Plutus Tx datatype unit, i.e. some scott-encoded or SOP type. What that looks like is up to the compiler, so I don't think we can easily state a good recognition procedure for it here. We could recognize builtin unit, though.
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 don't like it. I don't like the status quo either, though. But less so.
CIP-????/README.md
Outdated
### Alternatives | ||
|
||
- The status quo is not terrible, and we could simply accept it. | ||
- We could specifically detect when a script returns a lambda, and say that that is a failure. |
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.
Having such a corner case would be extremely weird in my opinion and I'm opposed to it.
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.
Yeah, I just put it in here for completeness.
CIP-????/README.md
Outdated
|
||
The specification for checking whether a Plutus Core script accepts a transaction changes as follows (the new part is in brackets): | ||
|
||
> A Plutus Core script S with arguments A1...An accepts a transaction if 'eval(S A1 ... An)' succeeds [and evaluates to the builtin boolean constant 'true']. |
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.
This sounds really annoying because of built-in vs native data types. If you return True
in Plutus Tx, will it even evaluate to the built-in True
in the end?
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.
No, it won't. But you can return (and construct) a BuiltinBool
easily enough, or we can provide an adapter.
CIP-????/README.md
Outdated
Since the return value of a script will now be significant, a script will only succeed if the whole thing evaluates to 'true'. | ||
This is very unlikely to happen by accident: mistakes in the number of arguments or in what to return will result in failure. | ||
|
||
### Alternatives |
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.
Yeah, breaking backwards compatibility in such a horrible implicit way sounds like an even worse footgun than the status quo. I do understand that people will need to explicitly pick a new language version, but we can't be sure that they will adapt their code properly.
Please add |
I don't think we should have multiple different kinds of accepted return value. I will add an alternative for the return type being |
That makes sense, I see the value in having a single accepted return value. I see a case for both Either is fine though. I have seen a lot of contract developers especially early on struggle with debugging because they didn't apply enough arguments to their validator, and they couldn't figure out why it was succeeding no matter what they changed so I see a lot of value in this CIP. |
I updated the PR to suggest using unit. That does seem more parsimonious since we only need a single distinguished value for success. |
@rphair I think this is ready for review |
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.
@michaelpj it's already on Review for meeting # 81 in 1 week's time as agreed in last meeting. I'll plan to give this a number after that meeting (you are invited of course). If no dissent we might keep pushing it forward to Last Check
. https://hackmd.io/@cip-editors/81
It seems like the unit
question is settled as of #747 (comment) but of course that can also be triple checked with the other devs at the meeting.
Document itself looks good to me & I would approve it after we assign a number: still keeping an eye on the reservations with @effectfully #747 (review). I would rather see harmony about this before assigning Last Check
if possible: it would be nice if both if you could be at the meeting & we could hear some debate about it.
To be clear, we might not do this, but I think it's helpful to have it merged as Proposed. |
Just seeing this, I think it's a good idea. The |
Somehow |
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.
thanks @michaelpj - confirmed as candidate at CIP editors' meeting today, though still not certain to be implemented: clearly beneficial but uncertain how much. In any case we agree it should stand as a reference among other valid ideas.
Please update directory name to CIP-0117
and change the link to the rendered proposal in the OP accordingly 🎉
CIP-69, which makes all Plutus script take a single argument, makes the problem described in this CIP more likely to happen, and thus more desirable to requiring scripts to return builtin unit to succeed. I don't know how this impacts other languages and compilers. @rvcas @MicroProofs @KtorZ @nielstron @michele-nuzzi @nau any opinions? Do you think this is worth doing? Any concerns? |
OpShin already forces smart contracts to only return builtin unit. |
Aiken also enforces unit is returned on a successful execution. |
Ok, this has been implemented in plutus-ledger-api: @rphair I think we can merge this CIP. |
Yo that's pretty awesome didn't expect this to make into PlutusV3 |
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.
thanks @zliu41 - marked Last Check
so we should merge this no later than the coming Tuesday's meeting (https://hackmd.io/@cip-editors/90) cc @Ryun1 @Crypto2099
Co-authored-by: Ryan <[email protected]>
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.
Good to go ✅
Co-authored-by: Ryan <[email protected]>
Co-authored-by: Ryan <[email protected]>
There is a papercut in how we check whether scripts accept transactions. There are a few ways that people can make mistakes, not notice, and have their scripts fail open. This proposal suggests that we instead be prescriptive about what scripts must return in order to succeed, which would make such mistakes quickly obvious.
This is not a particularly important change, but it would be relatively cheap to do and would fix a minor problem.
Rendered Proposal on Fork < edit: changed to latest version in branch