From 982b8865c346f8938407364dd45de158e656e464 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sat, 11 Jan 2025 19:56:59 -0700 Subject: [PATCH] Get rid of backwards compatibility during TxOut deserialization --- .../impl/src/Cardano/Ledger/Babbage/TxOut.hs | 7 ++---- libs/cardano-ledger-core/CHANGELOG.md | 1 + .../src/Cardano/Ledger/Address.hs | 22 ++++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs b/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs index b7ae7c4c06a..825c2b83a40 100644 --- a/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs +++ b/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs @@ -46,8 +46,8 @@ import Cardano.Ledger.Address ( CompactAddr, compactAddr, decompactAddr, - fromCborBackwardsBothAddr, fromCborBothAddr, + fromCborRigorousBothAddr, ) import Cardano.Ledger.Alonzo.Core import Cardano.Ledger.Alonzo.TxBody ( @@ -463,10 +463,7 @@ instance (EraScript era, Val (Value era)) => DecCBOR (BabbageTxOut era) where instance (EraScript era, Val (Value era)) => DecShareCBOR (BabbageTxOut era) where type Share (BabbageTxOut era) = Interns (Credential 'Staking) decShareCBOR credsInterns = - -- Even in Babbage the ledger state still contains garbage pointers that we need to - -- deal with. This will be taken care of upon entry to Conway era. After which this - -- backwards compatibility shim can be removed. - internBabbageTxOut (interns credsInterns) <$!> decodeBabbageTxOut fromCborBackwardsBothAddr + internBabbageTxOut (interns credsInterns) <$!> decodeBabbageTxOut fromCborRigorousBothAddr {-# INLINEABLE decShareCBOR #-} internBabbageTxOut :: diff --git a/libs/cardano-ledger-core/CHANGELOG.md b/libs/cardano-ledger-core/CHANGELOG.md index 006336377bc..01e76c3ec12 100644 --- a/libs/cardano-ledger-core/CHANGELOG.md +++ b/libs/cardano-ledger-core/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.17.0.0 +* Add `fromCborRigorousBothAddr` * Add `SlotNo32` and use it in `Ptr` definition * Add `mkPtrNormalized` * Deprecate `normalizePtr` and `addrPtrNormalize` diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs index 5b43dd83d65..e0683a03abf 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs @@ -52,6 +52,7 @@ module Cardano.Ledger.Address ( fromCborAddr, fromCborBothAddr, fromCborCompactAddr, + fromCborRigorousBothAddr, fromCborBackwardsBothAddr, decodeRewardAccount, fromCborRewardAccount, @@ -425,20 +426,21 @@ fromCborCompactAddr = snd <$> fromCborBothAddr -- that it was encoded as. fromCborBothAddr :: Decoder s (Addr, CompactAddr) fromCborBothAddr = do - ifDecoderVersionAtLeast (natVersion @7) decodeAddrRigorous fromCborBackwardsBothAddr - where - -- Starting with Babbage we no longer allow addresses with garbage in them. - decodeAddrRigorous = do - sbs <- decCBOR - flip evalStateT 0 $ do - addr <- decodeAddrStateLenientT False False sbs - pure (addr, UnsafeCompactAddr sbs) - {-# INLINE decodeAddrRigorous #-} + ifDecoderVersionAtLeast (natVersion @7) fromCborRigorousBothAddr fromCborBackwardsBothAddr {-# INLINE fromCborBothAddr #-} +-- | Starting with Babbage we no longer allow addresses with garbage in them. +fromCborRigorousBothAddr :: Decoder s (Addr, CompactAddr) +fromCborRigorousBothAddr = do + sbs <- decCBOR + flip evalStateT 0 $ do + addr <- decodeAddrStateLenientT False False sbs + pure (addr, UnsafeCompactAddr sbs) +{-# INLINE fromCborRigorousBothAddr #-} + -- | Prior to Babbage era we did not check if a binary blob representing an address was -- fully consumed, so unfortunately we must preserve this behavior. However, we do not --- need to preserve the unconsumed bytes in memory, therefore we can to drop the +-- need to preserve the unconsumed bytes in memory, therefore we can drop the -- garbage after we successfully decoded the malformed address. We also need to allow -- bogus pointer address to be deserializeable prior to Babbage era. fromCborBackwardsBothAddr :: Decoder s (Addr, CompactAddr)