plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Use newtype deriving for more parts of `ScriptContext`

Open L-as opened this issue 3 years ago • 2 comments

Describe the feature you'd like

Some newtypes, e.g. TxId, are serialised to Data using Constr unnecessarily, when they could just use deriving newtype. https://github.com/input-output-hk/plutus/blob/master/plutus-ledger-api/src/PlutusLedgerApi/V1/Tx.hs#L219

This would reduce evaluation costs a bit.

Describe alternatives you've considered

No response

L-as avatar Jul 29 '22 11:07 L-as

Same as issue #4705

I fear that too many existing libraries and scripts now depend on TxId being serialized as ConstrData.

So probably best to use data TxId instead of newtype TxId

christianschmitz avatar Aug 09 '22 00:08 christianschmitz

At the moment we have a consistent policy of having a Constr for every type node. It's not that important, but it is consistent. I can't think of anything that would go wrong if we used newtype deriving, but it also seems like a fairly marginal improvement. And it would need a new language version, and we'd have to support both ways, etc.

michaelpj avatar Aug 09 '22 11:08 michaelpj

PubKeyHash uses newtype deriving. IMO, it makes sense to use newtype deriving for this in all cases where possible.

L-as avatar Sep 28 '22 14:09 L-as

Given the huge costs

And it would need a new language version, and we'd have to support both ways, etc.

and the modest benefits

I can't think of anything that would go wrong if we used newtype deriving, but it also seems like a fairly marginal improvement.

I'm going to take responsibility and close this issue.

effectfully avatar Jan 31 '23 22:01 effectfully