Fix PlutusV4 script handling and scrambled ToPlutusScriptPurpose type family#1237
Open
carbolymer wants to merge 1 commit into
Open
Fix PlutusV4 script handling and scrambled ToPlutusScriptPurpose type family#1237carbolymer wants to merge 1 commit into
ToPlutusScriptPurpose type family#1237carbolymer wants to merge 1 commit into
Conversation
1992c85 to
9d97ebb
Compare
Contributor
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
carbolymer
commented
Jun 19, 2026
| ToPlutusScriptPurpose VoterItem = ProposingScript | ||
| ToPlutusScriptPurpose ProposalItem = VotingScript | ||
| ToPlutusScriptPurpose VoterItem = VotingScript | ||
| ToPlutusScriptPurpose ProposalItem = ProposingScript |
Contributor
Author
There was a problem hiding this comment.
I'm 99% sure that this was not right.
eab94e1 to
771184b
Compare
Comment on lines
+136
to
+140
| :: thing ~ TxInItem | ||
| => Witnessable thing era | ||
| -> Old.PlutusScriptVersion lang | ||
| -> Old.ScriptDatum Old.WitCtxTxIn | ||
| -> PlutusScriptDatum (Old.ToLedgerPlutusLanguage lang) (ToPlutusScriptPurpose TxInItem) | ||
| -> PlutusScriptDatum (Old.ToLedgerPlutusLanguage lang) (ToPlutusScriptPurpose thing) |
Comment on lines
1298
to
+1309
| toShelleyScript | ||
| ( ScriptInEra | ||
| _langInEra | ||
| langInEra | ||
| ( PlutusScript | ||
| PlutusScriptV4 | ||
| (PlutusScriptSerialised _script) | ||
| (PlutusScriptSerialised script) | ||
| ) | ||
| ) = error "toShelleyScript: PlutusV4 not implemented yet." | ||
|
|
||
| -- TODO: Ledger needs to introduce a plutusV4 constructor | ||
| -- case langInEra of | ||
| -- PlutusScriptV4InConway -> | ||
| -- Alonzo.PlutusScript . Conway.ConwayPlutusV3 . Plutus.Plutus $ Plutus.PlutusBinary script | ||
| -- PlutusScriptV4InDijkstra -> | ||
| -- Alonzo.PlutusScript . Dijkstra.MkDijkstraPlutusScript . Conway.ConwayPlutusV3 . Plutus.Plutus $ | ||
| -- Plutus.PlutusBinary script | ||
| ) = | ||
| case langInEra of | ||
| PlutusScriptV4InDijkstra -> | ||
| Alonzo.PlutusScript . Dijkstra.DijkstraPlutusV4 . Plutus.Plutus $ | ||
| Plutus.PlutusBinary script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/