Dealing with accidental "always true" minting policies #817
Replies: 6 comments 7 replies
-
|
Beta Was this translation helpful? Give feedback.
-
This is an unfortunate issue resulting from how we don't have explicit accept values for Plutus scripts. This will be solved by the following CIP: |
Beta Was this translation helpful? Give feedback.
-
To elaborate a bit on bullet 2, right now the generated code is something along the lines of:
And the reason this doesn't fail, is because we apply two parameters, and are left with a lambda, type checking code un-run. If we instead did:
Then we would fail as soon as the node tried to apply the script context as the redeemer parameter (or the redeemer as the datum, if it was something other than Data). Admittedly, this doesn't catch you if you write either of the following:
but it seems at least better than the status quo... |
Beta Was this translation helpful? Give feedback.
-
here is an example tx that proves this on preview testnet: https://preview.cardanoscan.io/transaction/be078384dcce92068c1d7fc0311ed2ae5b6e68c21f5039632274d223b749cbab and the validator offchain code |
Beta Was this translation helpful? Give feedback.
-
We might want to enforce that we have either:
So said differently, you can't ever specify a spend validator alone. If you do, you must also provide an equivalent mint validator. Might it be just |
Beta Was this translation helpful? Give feedback.
-
Status quo improved on main as of #819 |
Beta Was this translation helpful? Give feedback.
-
I recently discovered a fun quirk of UPLC. If you have the following Aiken code:
This effectively creates an "always succeed" minting policy.
The reason for this is because the node will apply the minting redeemer to the
_datum
parameter, and the script context to theredeemer
parameter, and the result will be a lambda waiting for the script context parameter. Since the node executed this UPLC and didn't receive an error, it considers the transaction to have passed.In particular, the type checking code injected for the parameters doesn't run until the body of the method, and so the fact that the redeemer wasn't
Void
or the script context wasn't anXYZ
never got a chance to fail the transaction.This is super non-intuitive and indeed dangerous; A newish Aiken developer unaware of this quirk, who wants to include the datum parameter because it looks more uniform with other scripts (or out of habit, etc.), will run their end to end tests (even going so far as to submit it to the chain and see that it succeeds!) with no problems, and introduce a devastating vulnerability into their protocol.
I figured I'd start a discussion to brainstorm ways we can catch / surface this for the user. Some ideas I came up with:
I'm not a UPLC expert, so there may be something preventing 2, but that would be my strong preference.
At the very least, perhaps some heuristic based warnings: if the function name has
mint
, but takes 3 arguments, surface a warning, etc.Beta Was this translation helpful? Give feedback.
All reactions