Fix PlutusV4 script handling and scrambled ToPlutusScriptPurpose type family#1237
Conversation
1992c85 to
9d97ebb
Compare
There was a problem hiding this comment.
Pull request overview
This PR corrects Plutus V4 handling across the API by properly mapping ledger PlutusV4 to PlutusScriptV4, implementing V4 script conversion for the Dijkstra era, and fixing a scrambled ToPlutusScriptPurpose type family used by the experimental legacy-script shim.
Changes:
- Fix
fromAlonzoLanguageto mapPlutusV4→PlutusScriptV4and implementtoShelleyScript/fromShelleyBasedScriptsupport for Plutus V4 in Dijkstra. - Remove an unconditional runtime error for V4 datums in experimental witness handling (
getPlutusDatum). - Correct the purpose mapping in
ToPlutusScriptPurpose(Cert/Mint and Voter/Proposal were swapped).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
cardano-api/src/Cardano/Api/Plutus/Internal/Script.hs |
Fixes Plutus V4 version mapping and adds Dijkstra-era V4 script conversion. |
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/AnyWitness.hs |
Enables datum extraction for Plutus V4 instead of erroring. |
cardano-api/src/Cardano/Api/Experimental/Plutus/Internal/Shim/LegacyScripts.hs |
Fixes the ToPlutusScriptPurpose type family mapping for legacy witness conversion. |
929bbfd to
eab94e1
Compare
| ToPlutusScriptPurpose VoterItem = ProposingScript | ||
| ToPlutusScriptPurpose ProposalItem = VotingScript | ||
| ToPlutusScriptPurpose VoterItem = VotingScript | ||
| ToPlutusScriptPurpose ProposalItem = ProposingScript |
There was a problem hiding this comment.
I'm 99% sure that this was not right.
eab94e1 to
771184b
Compare
Jimbo4350
left a comment
There was a problem hiding this comment.
One comment everything else LGTM
|
|
||
| toPlutusScriptDatum | ||
| :: Witnessable TxInItem era | ||
| :: thing ~ TxInItem |
There was a problem hiding this comment.
This is a cosmetic change. Please revert it.
There was a problem hiding this comment.
I don't have a strong opinion about it, but it made me stop here for a moment and think why thing was set to TxInItem. I can revert it.
771184b to
0d9272a
Compare
| prop_roundtrip_GovernancePollAnswer_CBOR | ||
| ] | ||
| <> [ testProperty | ||
| ("decode only wrapped plutus script " <> show (pretty version) <> " CBOR") |
Context
Several PlutusV4/Dijkstra-era bugs in script conversion functions:
fromShelleyBasedScriptmislabelledDijkstraPlutusV4as V3, causing script hash mismatches andMissingScripterrors for V4 reference scriptstoShelleyScriptcrashed witherrorfor V4 scriptsfromAlonzoLanguagemappedPlutusV4toPlutusScriptV3getPlutusDatumcrashed witherrorfor V4 spending scriptsToPlutusScriptPurposetype family hadCertItem/MintItemandVoterItem/ProposalItemswapped (introduced scrambled in Introduce new witness api #763, never caught because only theTxInItembranch is currently evaluated)How to trust this PR
Each fix is mechanical - correcting a wrong constructor or removing an
errorstub.The
ToPlutusScriptPurposefix can be verified by comparing toPlutusScriptForin the same file (always had the correct mapping).All cardano-api tests pass (
nix build .#checks.x86_64-linux.cardano-api:test:cardano-api-test).Checklist
.changes/