diff --git a/cabal.project b/cabal.project index 00d1d29eb29..6e84fdf5163 100644 --- a/cabal.project +++ b/cabal.project @@ -20,7 +20,7 @@ index-state: -- Bump this if you need newer packages from Hackage , hackage.haskell.org 2024-01-04T21:59:02Z -- Bump this if you need newer packages from CHaP - , cardano-haskell-packages 2024-02-15T21:00:00Z + , cardano-haskell-packages 2024-02-26T13:00:00Z packages: eras/allegra/impl diff --git a/eras/alonzo/impl/cardano-ledger-alonzo.cabal b/eras/alonzo/impl/cardano-ledger-alonzo.cabal index 4d3a2f1c312..468ff03a7e4 100644 --- a/eras/alonzo/impl/cardano-ledger-alonzo.cabal +++ b/eras/alonzo/impl/cardano-ledger-alonzo.cabal @@ -90,7 +90,7 @@ library mtl, microlens, nothunks, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, set-algebra >=1.0, small-steps >=1.0, text, diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs index 880e483b6f1..9f368a04543 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs @@ -220,7 +220,6 @@ transTxOut txOut = do address <- transAddr (txOut ^. addrTxOutL) pure $ PV1.TxOut address (transValue val) (transDataHash <$> strictMaybeToMaybe dataHash) --- | Translate all `Withdrawal`s from within a `TxBody` transTxBodyId :: EraTxBody era => TxBody era -> PV1.TxId transTxBodyId txBody = PV1.TxId (transSafeHash (hashAnnotated txBody)) diff --git a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal index 34c935591f9..c3f876d5a12 100644 --- a/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal +++ b/eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal @@ -59,7 +59,7 @@ library containers, data-default-class, microlens, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, QuickCheck, random, serialise, diff --git a/eras/alonzo/test-suite/golden/translations.cbor b/eras/alonzo/test-suite/golden/translations.cbor index 66768711295..26b75fd4f24 100644 Binary files a/eras/alonzo/test-suite/golden/translations.cbor and b/eras/alonzo/test-suite/golden/translations.cbor differ diff --git a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Translation/TranslationInstance.hs b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Translation/TranslationInstance.hs index e42f0068060..f6408f050f7 100644 --- a/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Translation/TranslationInstance.hs +++ b/eras/alonzo/test-suite/src/Test/Cardano/Ledger/Alonzo/Translation/TranslationInstance.hs @@ -73,6 +73,9 @@ instance Cborg.Serialise PV1.TxInInfo instance Cborg.Serialise PV1.TxInfo instance Cborg.Serialise PV1.TxOut instance Cborg.Serialise PV2.ScriptPurpose +instance Cborg.Serialise PV2.TxId +instance Cborg.Serialise PV2.TxOutRef +instance Cborg.Serialise PV2.TxInInfo instance Cborg.Serialise PV2.TxInfo instance Cborg.Serialise PV3.Address instance Cborg.Serialise PV3.BuiltinData diff --git a/eras/babbage/impl/cardano-ledger-babbage.cabal b/eras/babbage/impl/cardano-ledger-babbage.cabal index 45fa0617c58..55962ef922b 100644 --- a/eras/babbage/impl/cardano-ledger-babbage.cabal +++ b/eras/babbage/impl/cardano-ledger-babbage.cabal @@ -83,7 +83,7 @@ library deepseq, microlens, nothunks, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, set-algebra, small-steps, text, diff --git a/eras/babbage/test-suite/golden/translations.cbor b/eras/babbage/test-suite/golden/translations.cbor index 80479c75ff9..7d436463411 100644 Binary files a/eras/babbage/test-suite/golden/translations.cbor and b/eras/babbage/test-suite/golden/translations.cbor differ diff --git a/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/TxInfo.hs b/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/TxInfo.hs index f27ec4b179f..9ac3f87db4a 100644 --- a/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/TxInfo.hs +++ b/eras/babbage/test-suite/src/Test/Cardano/Ledger/Babbage/TxInfo.hs @@ -155,7 +155,7 @@ expectOneInput i slang txInfo = case slang of SPlutusV1 -> False SPlutusV2 -> PV2.txInfoInputs txInfo == [i] - SPlutusV3 -> PV3.txInfoInputs txInfo == [i] + SPlutusV3 -> False expectOneOutput :: PV2.TxOut -> SLanguage l -> PlutusTxInfo l -> Bool expectOneOutput o slang txInfo = diff --git a/eras/conway/impl/cardano-ledger-conway.cabal b/eras/conway/impl/cardano-ledger-conway.cabal index cacdd714fea..ad4aae043d9 100644 --- a/eras/conway/impl/cardano-ledger-conway.cabal +++ b/eras/conway/impl/cardano-ledger-conway.cabal @@ -96,7 +96,7 @@ library deepseq, microlens, nothunks, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, set-algebra, small-steps, text, diff --git a/eras/conway/impl/cddl-files/conway.cddl b/eras/conway/impl/cddl-files/conway.cddl index 836725371d4..29bdb662bbf 100644 --- a/eras/conway/impl/cddl-files/conway.cddl +++ b/eras/conway/impl/cddl-files/conway.cddl @@ -504,7 +504,7 @@ potential_languages = 0 .. 255 costmdls = { ? 0 : [ 166* int ] ; Plutus v1, only 166 integers are used, but more are accepted (and ignored) , ? 1 : [ 175* int ] ; Plutus v2, only 175 integers are used, but more are accepted (and ignored) - , ? 2 : [ 223* int ] ; Plutus v3, only 223 integers are used, but more are accepted (and ignored) + , ? 2 : [ 233* int ] ; Plutus v3, only 233 integers are used, but more are accepted (and ignored) , ? 3 : [ int ] ; Any 8-bit unsigned number can be used as a key. } diff --git a/eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs b/eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs index 589795da2d0..43aad3391b5 100644 --- a/eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs +++ b/eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs @@ -39,7 +39,7 @@ import Cardano.Ledger.Alonzo.Plutus.Context ( import Cardano.Ledger.Alonzo.Plutus.TxInfo (AlonzoContextError (..), TxOutSource (..)) import qualified Cardano.Ledger.Alonzo.Plutus.TxInfo as Alonzo import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose (..), toAsItem) -import Cardano.Ledger.Babbage.TxInfo (BabbageContextError (..)) +import Cardano.Ledger.Babbage.TxInfo (BabbageContextError (..), transTxOutV2) import qualified Cardano.Ledger.Babbage.TxInfo as Babbage import Cardano.Ledger.BaseTypes ( Inject (..), @@ -49,6 +49,7 @@ import Cardano.Ledger.BaseTypes ( isSJust, kindObject, strictMaybe, + txIxToInt, ) import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..)) import Cardano.Ledger.Binary.Coders ( @@ -98,12 +99,13 @@ import Cardano.Ledger.Plutus.TxInfo ( transEpochNo, transKeyHash, transRewardAccount, + transSafeHash, transScriptHash, - transTxId, - transTxIn, ) +import qualified Cardano.Ledger.Plutus.TxInfo as TxInfo import Cardano.Ledger.PoolParams -import Cardano.Ledger.TxIn (TxIn) +import Cardano.Ledger.SafeHash (hashAnnotated) +import Cardano.Ledger.TxIn (TxId (..), TxIn (..)) import Cardano.Ledger.UTxO (UTxO) import Control.Arrow (ArrowChoice (..)) import Control.DeepSeq (NFData) @@ -237,7 +239,22 @@ transTxInInfoV1 :: transTxInInfoV1 utxo txIn = do txOut <- left (inject . AlonzoContextError @era) $ Alonzo.transLookupTxOut utxo txIn plutusTxOut <- transTxOutV1 (TxOutFromInput txIn) txOut - Right (PV1.TxInInfo (transTxIn txIn) plutusTxOut) + Right (PV1.TxInInfo (TxInfo.transTxIn txIn) plutusTxOut) + +-- | Given a TxIn, look it up in the UTxO. If it exists, translate it to the V3 context +transTxInInfoV3 :: + forall era. + ( Inject (BabbageContextError era) (ContextError era) + , Value era ~ MaryValue (EraCrypto era) + , BabbageEraTxOut era + ) => + UTxO era -> + TxIn (EraCrypto era) -> + Either (ContextError era) PV3.TxInInfo +transTxInInfoV3 utxo txIn = do + txOut <- left (inject . AlonzoContextError @era) $ Alonzo.transLookupTxOut utxo txIn + plutusTxOut <- transTxOutV2 (TxOutFromInput txIn) txOut + Right (PV3.TxInInfo (transTxIn txIn) plutusTxOut) instance Crypto c => EraPlutusTxInfo 'PlutusV1 (ConwayEra c) where toPlutusTxCert _ = transTxCertV1V2 @@ -317,8 +334,8 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV3 (ConwayEra c) where toPlutusTxInfo proxy pp epochInfo systemStart utxo tx = do timeRange <- Alonzo.transValidityInterval pp epochInfo systemStart (txBody ^. vldtTxBodyL) - inputs <- mapM (Babbage.transTxInInfoV2 utxo) (Set.toList (txBody ^. inputsTxBodyL)) - refInputs <- mapM (Babbage.transTxInInfoV2 utxo) (Set.toList (txBody ^. referenceInputsTxBodyL)) + inputs <- mapM (transTxInInfoV3 utxo) (Set.toList (txBody ^. inputsTxBodyL)) + refInputs <- mapM (transTxInInfoV3 utxo) (Set.toList (txBody ^. referenceInputsTxBodyL)) outputs <- zipWithM (Babbage.transTxOutV2 . TxOutFromOutput) @@ -339,7 +356,7 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV3 (ConwayEra c) where , PV3.txInfoSignatories = Alonzo.transTxBodyReqSignerHashes txBody , PV3.txInfoRedeemers = plutusRedeemers , PV3.txInfoData = PV3.fromList $ Alonzo.transTxWitsDatums (tx ^. witsTxL) - , PV3.txInfoId = Alonzo.transTxBodyId txBody + , PV3.txInfoId = transTxBodyId txBody , PV3.txInfoVotes = transVotingProcedures (txBody ^. votingProceduresTxBodyL) , PV3.txInfoProposalProcedures = map (transProposal proxy) $ toList (txBody ^. proposalProceduresTxBodyL) @@ -356,6 +373,15 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV3 (ConwayEra c) where toPlutusScriptContext proxy txInfo scriptPurpose = PV3.ScriptContext txInfo <$> toPlutusScriptPurpose proxy scriptPurpose +transTxId :: TxId c -> PV3.TxId +transTxId txId = PV3.TxId (transSafeHash (unTxId txId)) + +transTxBodyId :: EraTxBody era => TxBody era -> PV3.TxId +transTxBodyId txBody = PV3.TxId (transSafeHash (hashAnnotated txBody)) + +transTxIn :: TxIn c -> PV3.TxOutRef +transTxIn (TxIn txid txIx) = PV3.TxOutRef (transTxId txid) (toInteger (txIxToInt txIx)) + -- | Translate all `Withdrawal`s from within a `TxBody` transTxBodyWithdrawals :: EraTxBody era => TxBody era -> PV3.Map PV3.Credential PV3.Lovelace transTxBodyWithdrawals txBody = diff --git a/flake.lock b/flake.lock index e3367e0969b..8f199cb60a0 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1708015143, - "narHash": "sha256-KkKYA6TP2T+lt74+m3lzeA6I5zzk2JNjw3TClg0ynDM=", + "lastModified": 1708951020, + "narHash": "sha256-TzumeP4pJbWIXy2X149ma/aVmWvDy9Lp4Fo8pZNivMk=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "1d3af4a597179eedf818575254782f0767eb00bd", + "rev": "ac7e615664486e5a6e9f8c4623ae7c8b9364c22f", "type": "github" }, "original": { diff --git a/libs/cardano-ledger-binary/cardano-ledger-binary.cabal b/libs/cardano-ledger-binary/cardano-ledger-binary.cabal index 52def83c028..4b9bac630b2 100644 --- a/libs/cardano-ledger-binary/cardano-ledger-binary.cabal +++ b/libs/cardano-ledger-binary/cardano-ledger-binary.cabal @@ -67,7 +67,7 @@ library network, nothunks, primitive, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, recursion-schemes, serialise, tagged, diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/CostModels.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/CostModels.hs index 04c13d40867..f2e564533c2 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/CostModels.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/CostModels.hs @@ -274,7 +274,7 @@ decodeCostModels = costModelParamsCount :: Language -> Int costModelParamsCount PlutusV1 = 166 costModelParamsCount PlutusV2 = 175 -costModelParamsCount PlutusV3 = 223 +costModelParamsCount PlutusV3 = 233 -- | Prior to version 9, each 'CostModel' was expected to be serialized as -- an array of integers of a specific length (depending on the version of Plutus). diff --git a/libs/cardano-ledger-test/cardano-ledger-test.cabal b/libs/cardano-ledger-test/cardano-ledger-test.cabal index bd861d49598..2c631def4c9 100644 --- a/libs/cardano-ledger-test/cardano-ledger-test.cabal +++ b/libs/cardano-ledger-test/cardano-ledger-test.cabal @@ -139,7 +139,7 @@ library mtl, nothunks, hspec, - plutus-ledger-api ^>=1.21, + plutus-ledger-api ^>=1.22.1, prettyprinter, QuickCheck, small-steps,