Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Babbage TxOut decoder can't fail due to malformed Ptr #2897

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -662,8 +663,9 @@ decodeTxOut ::
FromCBOR (Annotator (Core.Script era)),
DecodeNonNegative (Core.Value era)
) =>
(forall s'. Decoder s' (Addr (Crypto era), CompactAddr (Crypto era))) ->
Decoder s (TxOut era)
decodeTxOut = do
decodeTxOut decAddr = do
dtxo <- decode $ SparseKeyed "TxOut" initial bodyFields requiredFields
case dtxo of
DecodingTxOut SNothing _ _ _ -> cborError $ DecoderErrorCustom "TxOut" "Impossible: no Addr"
Expand All @@ -676,7 +678,7 @@ decodeTxOut = do
bodyFields 0 =
field
(\x txo -> txo {decodingTxOutAddr = SJust x})
(D fromCborBothAddr)
(D decAddr)
bodyFields 1 =
field
(\x txo -> txo {decodingTxOutVal = x})
Expand Down Expand Up @@ -759,12 +761,12 @@ fromCborTxOutWithAddr ::
FromCBOR (Annotator (Core.Script era)),
DecodeNonNegative (Core.Value era)
) =>
Decoder s (Addr (Crypto era), CompactAddr (Crypto era)) ->
(forall s'. Decoder s' (Addr (Crypto era), CompactAddr (Crypto era))) ->
Decoder s (TxOut era)
fromCborTxOutWithAddr decAddr = do
peekTokenType >>= \case
TypeMapLenIndef -> decodeTxOut
TypeMapLen -> decodeTxOut
TypeMapLenIndef -> decodeTxOut decAddr
TypeMapLen -> decodeTxOut decAddr
_ -> oldTxOut
where
oldTxOut = do
Expand Down