Skip to content

Commit 9fe71f4

Browse files
authored
Add Imp test to check that SPO votes are validated against tx witnesses (#5521)
* Enable Utxow tests in conformance * Add Imp test to check SPO vote against tx witnesses * Update formal spec
1 parent c7e028f commit 9fe71f4

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ source-repository-package
1616
subdir: hs
1717
-- !WARNING!:
1818
-- MAKE SURE THIS POINTS TO A COMMIT IN `*-artifacts` BEFORE MERGE!
19-
tag: 9291fe30190180631e79589c506a062e95123961
19+
tag: 3da1ceec493ade9bc6347e342ca51054cc166e78
2020

2121
source-repository-package
2222
type: git

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/UtxowSpec.hs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ import Cardano.Ledger.Conway.Core (
3434
ppCoinsPerUTxOByteL,
3535
txIdTx,
3636
)
37+
import Cardano.Ledger.Conway.Governance
3738
import Cardano.Ledger.Conway.Rules (ConwayUtxowPredFailure (..))
39+
import Cardano.Ledger.Conway.TxBody
3840
import Cardano.Ledger.Credential (Credential (..), StakeReference)
41+
import Cardano.Ledger.Keys (asWitness, witVKeyHash)
3942
import Cardano.Ledger.Plutus (Language (..), SLanguage (..), hashPlutusScript)
4043
import Cardano.Ledger.TxIn (TxIn (..))
41-
import Lens.Micro ((&), (.~), (^.))
44+
import qualified Data.Map as Map
45+
import qualified Data.Set as Set
46+
import qualified Data.Set.NonEmpty as NES
47+
import Lens.Micro ((%~), (&), (.~), (^.))
4248
import Test.Cardano.Ledger.Conway.ImpTest
4349
import Test.Cardano.Ledger.Imp.Common
4450
import Test.Cardano.Ledger.Plutus.Examples (alwaysSucceedsWithDatum)
@@ -48,7 +54,9 @@ spec ::
4854
ConwayEraImp era =>
4955
SpecWith (ImpInit (LedgerSpec era))
5056
spec = do
51-
it "Fails with PPViewHashesDontMatch before PV 11" . whenMajorVersionAtMost @10 $ do
57+
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/1029
58+
-- TODO: Re-enable after issue is resolved, by removing this override
59+
disableInConformanceIt "Fails with PPViewHashesDontMatch before PV 11" . whenMajorVersionAtMost @10 $ do
5260
fixedTx <- fixupTx =<< setupBadPPViewHashTx
5361
badScriptIntegrityHash <- arbitrary
5462
tx <- substituteIntegrityHashAndFixWits badScriptIntegrityHash fixedTx
@@ -86,6 +94,35 @@ spec = do
8694
tx
8795
[ injectFailure $ ScriptIntegrityHashMismatch mismatch (SJust $ originalBytes scriptIntegrity)
8896
]
97+
it "Transaction containing SPO vote but no witness for it fails" $ do
98+
spoKh <- freshKeyHash
99+
registerPool spoKh
100+
gaId <- mkProposal InfoAction >>= submitProposal
101+
submitVote_ @era VoteYes (StakePoolVoter spoKh) gaId
102+
let tx =
103+
mkBasicTx mkBasicTxBody
104+
& bodyTxL . votingProceduresTxBodyL
105+
.~ VotingProcedures
106+
( Map.singleton
107+
(StakePoolVoter spoKh)
108+
( Map.singleton
109+
gaId
110+
( VotingProcedure
111+
{ vProcVote = VoteYes
112+
, vProcAnchor = SNothing
113+
}
114+
)
115+
)
116+
)
117+
let isSPOWitness wit = witVKeyHash wit == asWitness spoKh
118+
withPostFixup (pure . (witsTxL . addrTxWitsL %~ Set.filter (not . isSPOWitness))) $
119+
submitFailingTx
120+
tx
121+
[ injectFailure $
122+
MissingVKeyWitnessesUTXOW $
123+
NES.singleton $
124+
asWitness spoKh
125+
]
89126

90127
setupBadPPViewHashTx ::
91128
forall era.

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/cardano-ledger-conformance/test/Test/Cardano/Ledger/Conformance/Imp/Conway.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Test.Cardano.Ledger.Conway.Imp.LedgerSpec qualified as Ledger
1919
import Test.Cardano.Ledger.Conway.Imp.RatifySpec qualified as Ratify
2020
import Test.Cardano.Ledger.Conway.Imp.UtxoSpec qualified as Utxo
2121
import Test.Cardano.Ledger.Conway.Imp.UtxosSpec qualified as Utxos
22+
import Test.Cardano.Ledger.Conway.Imp.UtxowSpec qualified as Utxow
2223
import Test.Cardano.Ledger.Conway.ImpTest
2324
import Test.Cardano.Ledger.Imp.Common hiding (Args)
2425
import UnliftIO (evaluateDeep)
@@ -46,6 +47,7 @@ spec = do
4647
describe "LEDGER" Ledger.spec
4748
describe "RATIFY" Ratify.spec
4849
describe "UTXO" Utxo.spec
50+
describe "UTXOW" Utxow.spec
4951
xdescribe "UTXOS" Utxos.spec
5052
describe "Imp (only spec)" $ do
5153
RatifySpec.spec

0 commit comments

Comments
 (0)