Skip to content

Suggestion for ScriptContext changes in PlutusV4 #6408

@KtorZ

Description

@KtorZ

Describe the feature you'd like

Hello, after playing around with Plutus V3 script context, I bumped into a few non-optimal things which I believe could be improved to avoid confusing situations and silly mistakes. Some of those points (e.g. 2) likely belong to intersectMBO/cardano-ledger but I am documenting them here since they are part of the same discussion, I reckon.

1 - Uniform Rational representations

We find rational numbers in two places in Plutus v3. The first one is inside the UpdateCommittee variant of GovernanceAction; which represents the new quorum for the next committee. Other places are inside the following protocol parameters: stake pool pledge influence, monetary expansion, treasury expansion, the new tier fee base for reference scripts and all the voting thresholds for dreps and spos (indices 9, 10, 11, 25, 26 and 33 respectively).

In the GovernanceAction, it is encoded as a Constr data, with index 0 and two data-integer fields. In other protocol parameters, they are encoded as a List data with 2 data-integer elements.

2 - Voter ordering in txInfoVotes

Votes are ordered by ascending voters, and then ascending governance action id. For multi-variant constructors (e.g. Voter), the ordering follows the order of the constructors ... except for Credential! For Credential, scripts are treated as lower values than pub key credentials. Or more specifically, the data received from the ledger will be ordered following this rule. The discrepancy here is seemingly due to the way the ledger encodes Credential (with the two variants swapped compared to the Plutus api):

https://github.com/IntersectMBO/cardano-ledger/blob/adb63e0c899109d89b5e99cc0d5b6a2e97fa3d2d/libs/cardano-ledger-core/src/Cardano/Ledger/Credential.hs#L81-L84

vs

data Credential
=
-- | The transaction that spends this output must be signed by the private key.
-- See `Crypto.PubKeyHash`.
PubKeyCredential PubKeyHash
-- | The transaction that spends this output must include the validator script and
-- be accepted by the validator. See `ScriptHash`.
| ScriptCredential ScriptHash
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (NFData)

Caution

This last point might lead to a bug in Plutus-Tx, which relies on the derived Ord instance for certificates in order to maintain a Map. I don't think this is currently a problem as I imagine the Map to be fully re-constructed when Scott-encoded; but that's perhaps something you may want to double-check?

3 - Segregate pointer stake credentials

This one isn't properly introduced in by Plutus v3, but I was somewhat hoping to see Pointer addresses gone from V3 contexts. Truth is, no one uses pointer addresses, and yet, they always get in the way when dealing with addresses. They keep confusing new developers, and they increase the costs of having to deal with stake credentials for everyone. My suggestion would be to introduce a second variant on Address into which move any pointer address:

data Address = 
    | Address
        { addressCredential        :: Credential -- ^ the payment credential
        , addressStakingCredential :: Maybe Credential -- ^ the staking credential
        }
    | PointerAddress 
        { addressCredential        :: Credential -- ^ the payment credential
        , addressStakingCredential :: (Int, Int, Int) -- ^ the staking credential
        }

Those not willing to deal with Pointer addresses can simply always ignore the second variant. And it makes working with standard addresses a bit more friendly (and efficient -- although I don't have precise numbers).

Describe alternatives you've considered

Not really applicable here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions