Skip to content

Commit

Permalink
Get rid of backwards compatibility during TxOut deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Jan 12, 2025
1 parent 00297c9 commit 982b886
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
7 changes: 2 additions & 5 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import Cardano.Ledger.Address (
CompactAddr,
compactAddr,
decompactAddr,
fromCborBackwardsBothAddr,
fromCborBothAddr,
fromCborRigorousBothAddr,
)
import Cardano.Ledger.Alonzo.Core
import Cardano.Ledger.Alonzo.TxBody (
Expand Down Expand Up @@ -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 ::
Expand Down
1 change: 1 addition & 0 deletions libs/cardano-ledger-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.17.0.0

* Add `fromCborRigorousBothAddr`
* Add `SlotNo32` and use it in `Ptr` definition
* Add `mkPtrNormalized`
* Deprecate `normalizePtr` and `addrPtrNormalize`
Expand Down
22 changes: 12 additions & 10 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Cardano.Ledger.Address (
fromCborAddr,
fromCborBothAddr,
fromCborCompactAddr,
fromCborRigorousBothAddr,
fromCborBackwardsBothAddr,
decodeRewardAccount,
fromCborRewardAccount,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 982b886

Please sign in to comment.