mlabs-haskell / ply

A helper library for working with compiled, parameterized Plutus Scripts
MIT License
18 stars 12 forks source link

Why no "type" field in envelope? #46

Closed zmrocze closed 5 months ago

zmrocze commented 1 year ago

Script .plutus files are expected to have this structure:

{  "type": "PlutusScriptV1",
    "description": "password_validator",
    "cborHex": "5843584101000022223232323"
}

and ply yields:

{
    "cborHex": "5901a",
    "description": "nft_hash_applied",
    "params": [
        "PlutusLedgerApi.V1.Tx:TxOutRef",
        "PlutusLedgerApi.V1.Value:TokenName"
    ],
    "rawHex": "5901a501000032323232323",
    "role": "MintingPolicyRole",
    "version": "ScriptV1"
}

so ply expands on this providing more type information with additional fields. But the field "type" is missing, in the end making the envelope incompatible with .plutus still. Wouldn't it be good for the ply format to be a clean extension of .plutus format, integrating with ctl/cardano-api etc?

SeungheonOh commented 1 year ago

I don't think there's a formally declared definition of .plutus file that being said, type field can easily added if needed.

Besides, Ply scripts will almost never be used with Cardano cli because it needs to be applied with paratmeters. For CTL, I encourage using ply-ctl instead of applying parameters manually

zmrocze commented 1 year ago

yes, i know, but it seems like a low hanging fruit. For example it'd allow importing both with ply and with cardano-api.

SeungheonOh commented 1 year ago

IMO, I need to add function that writes .plutus while ensuring there's no more parameters left to apply. I'm mainly concerned with people mistakenly use scripts that needs to be applied with parameters as regular policy or validator.

ply export, in a sense, is not really meant to be .plutus, and they weren't meant to be used as ScriptEnevelope directly.

the function I mentioned on top would look like:

writePlutusEnvelope :: FilePath -> TypedScript _ '[] -> IO ()

It makes explicit that only ready-to-go policies and validators can be exported to .plutus

SeungheonOh commented 1 year ago

I'll update the example export's filename as it can be misleading a bit

zmrocze commented 1 year ago

But what is the problem with saving partially-applied scripts?

SeungheonOh commented 1 year ago

It can be confusing. Possibly dangerous if cardano-cli doesn't check given scripts(<- I'm not sure it it does or not)

zmrocze commented 1 year ago

I think this is crucial though, to be able to save partially-applied scripts? also the added type safety wouldn't add much, as - alright on the ply-based exporter side you're sure that a script is fully applied before saving it - but on the non-ply importer side it doesn't tell you anything

zmrocze commented 1 year ago

For me - this compatibility with cardano-api and the rest would make things much easier. I can also imagine that working out of the box with plenty of other tools is an advantage. Many like

The counter argument is that the "type" field is redundant as it follows from the "version" field.

If you guys agree to implement it, we could on scaffold budget (I can implement or you guys can).

SeungheonOh commented 1 year ago

https://github.com/mlabs-haskell/ply/pull/47

It's very simple. I guess it can be helpful, so why not.