Skip to content

Commit 4f05c43

Browse files
authored
Merge pull request #5099 from IntersectMBO/ldan/complete-patterns
Fix `COMPLETE` pragmas for `TxCert` and `NativeScript` Resolves #4613
2 parents e4234a1 + b9d50a0 commit 4f05c43

File tree

13 files changed

+125
-7
lines changed

13 files changed

+125
-7
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.8.0.0
44

5+
* Added `COMPLETE` pragma for `TxCert AllegraEra`
6+
* Added `COMPLETE` pragma for `NativeScript AllegraEra`
57
* Move to `testlib` `DecCBOR` instances for: `TxBody AllegraEra`, `AllegraTxAuxDataRaw`, `AllegraTxAuxData`, `TimelockRaw`, `Timelock`
68
* Remove `AllegraTxBody`
79
* Removed `era` parameter from `AllegraTxBodyRaw`

eras/allegra/impl/src/Cardano/Ledger/Allegra/Scripts.hs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE DeriveAnyClass #-}
34
{-# LANGUAGE DeriveGeneric #-}
@@ -14,10 +15,14 @@
1415
{-# LANGUAGE StandaloneDeriving #-}
1516
{-# LANGUAGE TypeApplications #-}
1617
{-# LANGUAGE TypeFamilies #-}
18+
{-# LANGUAGE TypeOperators #-}
1719
{-# LANGUAGE UndecidableInstances #-}
1820
{-# LANGUAGE UndecidableSuperClasses #-}
1921
{-# LANGUAGE ViewPatterns #-}
2022
{-# OPTIONS_GHC -Wno-orphans #-}
23+
#if __GLASGOW_HASKELL__ >= 908
24+
{-# OPTIONS_GHC -Wno-x-unsafe-ledger-internal #-}
25+
#endif
2126

2227
module Cardano.Ledger.Allegra.Scripts (
2328
AllegraEraScript (..),
@@ -68,6 +73,7 @@ import Cardano.Ledger.Binary.Coders (
6873
(<*!),
6974
)
7075
import Cardano.Ledger.Core
76+
import Cardano.Ledger.Internal.Era (AlonzoEra, BabbageEra, ConwayEra, MaryEra)
7177
import Cardano.Ledger.MemoBytes (
7278
EqRaw (..),
7379
MemoBytes (Memo),
@@ -294,7 +300,48 @@ pattern RequireTimeStart mslot <- (getTimeStart -> Just mslot)
294300
, RequireAnyOf
295301
, RequireMOf
296302
, RequireTimeExpire
297-
, RequireTimeStart
303+
, RequireTimeStart ::
304+
AllegraEra
305+
#-}
306+
307+
{-# COMPLETE
308+
RequireSignature
309+
, RequireAllOf
310+
, RequireAnyOf
311+
, RequireMOf
312+
, RequireTimeExpire
313+
, RequireTimeStart ::
314+
MaryEra
315+
#-}
316+
317+
{-# COMPLETE
318+
RequireSignature
319+
, RequireAllOf
320+
, RequireAnyOf
321+
, RequireMOf
322+
, RequireTimeExpire
323+
, RequireTimeStart ::
324+
AlonzoEra
325+
#-}
326+
327+
{-# COMPLETE
328+
RequireSignature
329+
, RequireAllOf
330+
, RequireAnyOf
331+
, RequireMOf
332+
, RequireTimeExpire
333+
, RequireTimeStart ::
334+
BabbageEra
335+
#-}
336+
337+
{-# COMPLETE
338+
RequireSignature
339+
, RequireAllOf
340+
, RequireAnyOf
341+
, RequireMOf
342+
, RequireTimeExpire
343+
, RequireTimeStart ::
344+
ConwayEra
298345
#-}
299346

300347
mkRequireSignatureTimelock :: forall era. Era era => KeyHash 'Witness -> Timelock era
@@ -353,7 +400,7 @@ ltePosInfty SNothing _ = False -- ∞ > j
353400
ltePosInfty (SJust i) j = i <= j
354401

355402
evalTimelock ::
356-
AllegraEraScript era =>
403+
(AllegraEraScript era, NativeScript era ~ Timelock era) =>
357404
Set.Set (KeyHash 'Witness) ->
358405
ValidityInterval ->
359406
NativeScript era ->
@@ -372,6 +419,7 @@ evalTimelock vhks (ValidityInterval txStart txExp) = go
372419
RequireAllOf xs -> all go xs
373420
RequireAnyOf xs -> any go xs
374421
RequireMOf m xs -> isValidMOf m xs
422+
_ -> error "Impossible: All NativeScripts should have been accounted for"
375423

376424
-- =========================================================
377425
-- Operations on Timelock scripts
@@ -398,6 +446,7 @@ showTimelock (RequireMOf m xs) = "(MOf " ++ show m ++ " " ++ F.foldl' accum ")"
398446
where
399447
accum ans x = showTimelock x ++ " " ++ ans
400448
showTimelock (RequireSignature hash) = "(Signature " ++ show hash ++ ")"
449+
showTimelock _ = error "Impossible: All NativeScripts should have been accounted for"
401450

402451
-- | Check the equality of two underlying types, while ignoring their binary
403452
-- representation, which `Eq` instance normally does. This is used for testing.

eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE ScopedTypeVariables #-}
44
{-# LANGUAGE TypeApplications #-}
55
{-# LANGUAGE TypeFamilies #-}
6+
{-# LANGUAGE TypeOperators #-}
67
{-# LANGUAGE UndecidableInstances #-}
78
{-# OPTIONS_GHC -Wno-orphans #-}
89

@@ -12,7 +13,7 @@ module Cardano.Ledger.Allegra.Tx (
1213

1314
import Cardano.Ledger.Allegra.Era (AllegraEra)
1415
import Cardano.Ledger.Allegra.PParams ()
15-
import Cardano.Ledger.Allegra.Scripts (AllegraEraScript (..), evalTimelock)
16+
import Cardano.Ledger.Allegra.Scripts (AllegraEraScript (..), Timelock, evalTimelock)
1617
import Cardano.Ledger.Allegra.TxAuxData ()
1718
import Cardano.Ledger.Allegra.TxBody (AllegraEraTxBody (..))
1819
import Cardano.Ledger.Allegra.TxWits ()
@@ -72,7 +73,8 @@ instance EraTx AllegraEra where
7273
-- We still need to correctly compute the witness set for TxBody as well.
7374

7475
validateTimelock ::
75-
(EraTx era, AllegraEraTxBody era, AllegraEraScript era) => Tx era -> NativeScript era -> Bool
76+
(EraTx era, AllegraEraTxBody era, AllegraEraScript era, NativeScript era ~ Timelock era) =>
77+
Tx era -> NativeScript era -> Bool
7678
validateTimelock tx timelock = evalTimelock vhks (tx ^. bodyTxL . vldtTxBodyL) timelock
7779
where
7880
vhks = Set.map witVKeyHash (tx ^. witsTxL . addrTxWitsL)

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/ImpTest.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Cardano.Ledger.Allegra (AllegraEra)
1616
import Cardano.Ledger.Allegra.Core
1717
import Cardano.Ledger.Allegra.Scripts (
1818
AllegraEraScript,
19+
Timelock,
1920
evalTimelock,
2021
pattern RequireTimeExpire,
2122
pattern RequireTimeStart,
@@ -45,6 +46,7 @@ instance ShelleyEraImp AllegraEra where
4546
impAllegraSatisfyNativeScript ::
4647
( AllegraEraScript era
4748
, AllegraEraTxBody era
49+
, NativeScript era ~ Timelock era
4850
) =>
4951
Set.Set (KeyHash 'Witness) ->
5052
TxBody era ->
@@ -79,4 +81,5 @@ impAllegraSatisfyNativeScript providedVKeyHashes txBody script = do
7981
lock@(RequireTimeExpire _)
8082
| evalTimelock mempty vi lock -> Just mempty
8183
| otherwise -> Nothing
84+
_ -> error "Impossible: All NativeScripts should have been accounted for"
8285
pure $ satisfyScript script

eras/alonzo/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.14.0.0
44

5+
* Added `COMPLETE` pragma for `TxCert AlonzoEra`
6+
* Added `COMPLETE` pragma for `NativeScript AlonzoEra`
57
* Deprecated `toAlonzoGenesisPairs`
68
* Removed `MissingRequiredSigners` from `AlonzoUtxowPredFailure`
79
* Renamed fields of `AlonzoTx`

eras/babbage/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.12.0.0
44

5+
* Added `COMPLETE` pragma for `TxCert BabbageEra`
6+
* Added `COMPLETE` pragma for `NativeScript BabbageEra`
57
* Move to `testlib` the `DecCBOR` instance for `TxBody BabbageEra`
68
* Remove `BabbageNonDisjointRefInputs` for protocol versions >10
79
* Added `ppCoinsPerUTxOByte` to `PParams`

eras/conway/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.20.0.0
44

5+
* Added `COMPLETE` pragma for `NativeScript ConwayEra`
56
* Add default implementation for `tcConwayGenesisL`
67
* Remove `tcDelegsL` and `tcInitialDRepsL`
78
* Export `registerDRepsThenDelegs`

eras/conway/impl/src/Cardano/Ledger/Conway/TxCert.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ pattern UpdateDRepTxCert cred mAnchor <- (getUpdateDRepTxCert -> Just (cred, mAn
342342
, ResignCommitteeColdTxCert
343343
, RegDRepTxCert
344344
, UnRegDRepTxCert
345-
, UpdateDRepTxCert
345+
, UpdateDRepTxCert ::
346+
ConwayEra
346347
#-}
347348

348349
getDelegateeTxCert :: ConwayEraTxCert era => TxCert era -> Maybe Delegatee

eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ transTxBodyWithdrawals txBody =
539539
-- omitting the deposit in these cases. It has been confirmed that this buggy behavior for protocol
540540
-- version 9 has been exercised on Mainnet, therefore this conditional translation can never be
541541
-- removed for Conway era (#4863)
542-
transTxCert :: ConwayEraTxCert era => ProtVer -> TxCert era -> PV3.TxCert
542+
transTxCert ::
543+
(ConwayEraTxCert era, TxCert era ~ ConwayTxCert era) => ProtVer -> TxCert era -> PV3.TxCert
543544
transTxCert pv = \case
544545
RegPoolTxCert PoolParams {ppId, ppVrf} ->
545546
PV3.TxCertPoolRegister
@@ -575,6 +576,7 @@ transTxCert pv = \case
575576
PV3.TxCertUnRegDRep (transDRepCred drepCred) (transCoinToLovelace refund)
576577
UpdateDRepTxCert drepCred _anchor ->
577578
PV3.TxCertUpdateDRep (transDRepCred drepCred)
579+
_ -> error "Impossible: All TxCerts should have been accounted for"
578580

579581
transDRepCred :: Credential 'DRepRole -> PV3.DRepCredential
580582
transDRepCred = PV3.DRepCredential . transCred

eras/mary/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.9.0.0
44

5+
* Added `COMPLETE` pragma for `TxCert MaryEra`
6+
* Added `COMPLETE` pragma for `NativeScript MaryEra`
57
* Move to `testlib` the `DecCBOR` instance for `TxBody MaryEra`
68
* Remove `MaryTxBody`
79
* Converted `MaryTxBodyRaw` into a type synonym

eras/shelley/impl/src/Cardano/Ledger/Shelley/TxCert.hs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE CPP #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE DeriveAnyClass #-}
45
{-# LANGUAGE DeriveGeneric #-}
@@ -19,6 +20,9 @@
1920
{-# LANGUAGE UndecidableSuperClasses #-}
2021
{-# LANGUAGE ViewPatterns #-}
2122
{-# OPTIONS_GHC -Wno-orphans #-}
23+
#if __GLASGOW_HASKELL__ >= 908
24+
{-# OPTIONS_GHC -Wno-x-unsafe-ledger-internal #-}
25+
#endif
2226

2327
module Cardano.Ledger.Shelley.TxCert (
2428
ShelleyEraTxCert (..),
@@ -97,6 +101,7 @@ import Cardano.Ledger.Credential (
97101
credKeyHashWitness,
98102
credScriptHash,
99103
)
104+
import Cardano.Ledger.Internal.Era (AllegraEra, AlonzoEra, BabbageEra, MaryEra)
100105
import Cardano.Ledger.Keys (asWitness)
101106
import Cardano.Ledger.PoolParams (PoolParams (..))
102107
import Cardano.Ledger.Shelley.Era (ShelleyEra)
@@ -231,7 +236,52 @@ pattern GenesisDelegTxCert genKey genDelegKey vrfKeyHash <-
231236
, UnRegTxCert
232237
, DelegStakeTxCert
233238
, MirTxCert
234-
, GenesisDelegTxCert
239+
, GenesisDelegTxCert ::
240+
ShelleyEra
241+
#-}
242+
243+
{-# COMPLETE
244+
RegPoolTxCert
245+
, RetirePoolTxCert
246+
, RegTxCert
247+
, UnRegTxCert
248+
, DelegStakeTxCert
249+
, MirTxCert
250+
, GenesisDelegTxCert ::
251+
AllegraEra
252+
#-}
253+
254+
{-# COMPLETE
255+
RegPoolTxCert
256+
, RetirePoolTxCert
257+
, RegTxCert
258+
, UnRegTxCert
259+
, DelegStakeTxCert
260+
, MirTxCert
261+
, GenesisDelegTxCert ::
262+
MaryEra
263+
#-}
264+
265+
{-# COMPLETE
266+
RegPoolTxCert
267+
, RetirePoolTxCert
268+
, RegTxCert
269+
, UnRegTxCert
270+
, DelegStakeTxCert
271+
, MirTxCert
272+
, GenesisDelegTxCert ::
273+
AlonzoEra
274+
#-}
275+
276+
{-# COMPLETE
277+
RegPoolTxCert
278+
, RetirePoolTxCert
279+
, RegTxCert
280+
, UnRegTxCert
281+
, DelegStakeTxCert
282+
, MirTxCert
283+
, GenesisDelegTxCert ::
284+
BabbageEra
235285
#-}
236286

237287
-- | Genesis key delegation certificate

libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/SpecTranslate/Conway/Base.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ instance
225225
pure . Agda.RequireMOf (toInteger m) $ toList tls
226226
RequireTimeExpire slot -> Agda.RequireTimeExpire <$> toSpecRep slot
227227
RequireTimeStart slot -> Agda.RequireTimeStart <$> toSpecRep slot
228+
_ -> error "Impossible: All NativeScripts should have been accounted for"
228229

229230
instance
230231
( AlonzoEraScript era

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/TxGen.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ mkTimelockWit era mTag =
302302
F.fold <$> mapM (mkTimelockWit era mTag) ts
303303
RequireTimeStart _ -> pure (const [])
304304
RequireTimeExpire _ -> pure (const [])
305+
_ -> error "Impossible: All NativeScripts should have been accounted for"
305306

306307
-- | Same as `genCredKeyWit`, but for `TxOuts`
307308
genTxOutKeyWitness ::

0 commit comments

Comments
 (0)