@@ -47,9 +47,10 @@ import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..))
4747import Cardano.Ledger.Alonzo.TxWits (nullRedeemers )
4848import Cardano.Ledger.Babbage.Collateral (collAdaBalance )
4949import Cardano.Ledger.Babbage.Core
50- import Cardano.Ledger.Babbage.Era (BabbageUTXO )
50+ import Cardano.Ledger.Babbage.Era (BabbageEra , BabbageUTXO )
5151import Cardano.Ledger.Babbage.Rules.Utxos (BabbageUTXOS )
5252import Cardano.Ledger.BaseTypes (
53+ ProtVer (.. ),
5354 ShelleyBase ,
5455 epochInfo ,
5556 networkId ,
@@ -71,7 +72,7 @@ import Cardano.Ledger.TxIn (TxIn)
7172import Cardano.Ledger.UTxO (EraUTxO (.. ), UTxO (.. ), areAllAdaOnly , balance )
7273import Cardano.Ledger.Val ((<->) )
7374import qualified Cardano.Ledger.Val as Val (inject , isAdaOnly , pointwise )
74- import Control.Monad (unless )
75+ import Control.Monad (unless , when )
7576import Control.Monad.Trans.Reader (asks )
7677import Control.SetAlgebra (eval , (◁) )
7778import Control.State.Transition.Extended (
@@ -89,6 +90,8 @@ import Data.Foldable (sequenceA_, toList)
8990import Data.List.NonEmpty (NonEmpty )
9091import qualified Data.Map.Strict as Map
9192import Data.Maybe.Strict (StrictMaybe (.. ))
93+ import Data.Set (Set )
94+ import qualified Data.Set as Set
9295import Data.Typeable (Typeable )
9396import GHC.Generics (Generic )
9497import Lens.Micro
@@ -110,6 +113,9 @@ data BabbageUtxoPredFailure era
110113 -- together with the minimum value for the given output.
111114 BabbageOutputTooSmallUTxO
112115 ! [(TxOut era , Coin )]
116+ | -- | TxIns that appear in both inputs and reference inputs
117+ BabbageNonDisjointRefInputs
118+ ! (Set (TxIn (EraCrypto era )))
113119 deriving (Generic )
114120
115121deriving instance
@@ -118,6 +124,7 @@ deriving instance
118124 , Show (PredicateFailure (EraRule " UTXO" era ))
119125 , Show (TxOut era )
120126 , Show (Script era )
127+ , Show (TxIn (EraCrypto era ))
121128 ) =>
122129 Show (BabbageUtxoPredFailure era )
123130
@@ -127,6 +134,7 @@ deriving instance
127134 , Eq (PredicateFailure (EraRule " UTXO" era ))
128135 , Eq (TxOut era )
129136 , Eq (Script era )
137+ , Eq (TxIn (EraCrypto era ))
130138 ) =>
131139 Eq (BabbageUtxoPredFailure era )
132140
@@ -194,6 +202,20 @@ feesOK pp tx (UTxO utxo) =
194202 validateTotalCollateral pp txBody utxoCollateral
195203 ]
196204
205+ disjointRefInputs ::
206+ forall era .
207+ EraPParams era =>
208+ PParams era ->
209+ Set (TxIn (EraCrypto era )) ->
210+ Set (TxIn (EraCrypto era )) ->
211+ Test (BabbageUtxoPredFailure era )
212+ disjointRefInputs pp inputs refInputs =
213+ when
214+ (pvMajor (pp ^. ppProtocolVersionL) > eraProtVerHigh @ (BabbageEra (EraCrypto era )))
215+ (failureIf (null common) (BabbageNonDisjointRefInputs common))
216+ where
217+ common = inputs `Set.intersection` refInputs
218+
197219validateTotalCollateral ::
198220 forall era .
199221 BabbageEraTxBody era =>
@@ -320,6 +342,13 @@ utxoTransition = do
320342 {- txb := txbody tx -}
321343 let txBody = body tx
322344 allInputs = txBody ^. allInputsTxBodyF
345+ refInputs :: Set (TxIn (EraCrypto era ))
346+ refInputs = txBody ^. referenceInputsTxBodyL
347+ inputs :: Set (TxIn (EraCrypto era ))
348+ inputs = txBody ^. inputsTxBodyL
349+
350+ {- inputs ∩ refInputs = ∅ -}
351+ runTest $ disjointRefInputs @ era pp inputs refInputs
323352
324353 {- ininterval slot (txvld txb) -}
325354 runTest $ Allegra. validateOutsideValidityIntervalUTxO slot txBody
@@ -431,6 +460,7 @@ instance
431460 , EncCBOR (PredicateFailure (EraRule " UTXOS" era ))
432461 , EncCBOR (PredicateFailure (EraRule " UTXO" era ))
433462 , EncCBOR (Script era )
463+ , EncCBOR (TxIn (EraCrypto era ))
434464 , Typeable (TxAuxData era )
435465 ) =>
436466 EncCBOR (BabbageUtxoPredFailure era )
@@ -440,6 +470,7 @@ instance
440470 AlonzoInBabbageUtxoPredFailure x -> Sum AlonzoInBabbageUtxoPredFailure 1 !> To x
441471 IncorrectTotalCollateralField c1 c2 -> Sum IncorrectTotalCollateralField 2 !> To c1 !> To c2
442472 BabbageOutputTooSmallUTxO x -> Sum BabbageOutputTooSmallUTxO 3 !> To x
473+ BabbageNonDisjointRefInputs x -> Sum BabbageNonDisjointRefInputs 4 !> To x
443474
444475instance
445476 ( Era era
@@ -456,6 +487,7 @@ instance
456487 1 -> SumD AlonzoInBabbageUtxoPredFailure <! From
457488 2 -> SumD IncorrectTotalCollateralField <! From <! From
458489 3 -> SumD BabbageOutputTooSmallUTxO <! From
490+ 4 -> SumD BabbageNonDisjointRefInputs <! From
459491 n -> Invalid n
460492
461493deriving via
0 commit comments