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

Fix compilation of CryptoSpec #976

Merged
merged 2 commits into from
Jul 12, 2023
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
40 changes: 20 additions & 20 deletions hydra-node/test/Hydra/CryptoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ import Cardano.Crypto.PinnedSizedBytes (psbFromByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as Char8
import qualified Data.Map as Map
import Hydra.Party (Party (vkey), deriveParty)
import Test.Aeson.GenericSpecs (roundtripAndGoldenSpecs)
import Test.QuickCheck (
conjoin,
classify,
counterexample,
elements,
forAll,
shuffle,
sublistOf,
(=/=),
(==>), chooseInt,
(===),
(==>),
)
import Test.QuickCheck.Instances.UnorderedContainers ()
import Test.Util (propCollisionResistant)
import Data.List ((!!))

spec :: Spec
spec = do
Expand Down Expand Up @@ -92,24 +95,21 @@ specMultiSignature =
not (null shuffled)
==> verifyMultiSignature (map vkey shuffled) (aggregateInOrder sigs shuffled) msg
=== Verified
in verifyMultiSignature vks msig msg

prop "verifyMultiSignature fails when signature is missing" $ \sks (msg :: ByteString) dummySig ->
(length sks > 2) ==>
forAll (elements sks) $ \missingKeySig ->
sigs = (\sk -> if sk /= missingKeySig then sign sk msg else dummySig) <$> sks
in not (verifyMultiSignature (map getVerificationKey sks) (aggregate sigs) msg)
(length sks > 2)
==> forAll (elements sks)
$ \missingKeySig ->
let sigs = (\sk -> if sk /= missingKeySig then sign sk msg else dummySig) <$> sks
in verifyMultiSignature (map getVerificationKey sks) (aggregate sigs) msg
=/= Verified

prop "does not validate multisig if less keys given" $ \sks (msg :: ByteString) -> do
(length sks > 1)
properPrefixes <- sublistOf sks
==> let sigs = aggregate $ map (`sign` msg) (toList sks)
conjoin
( map
( \prefix ->
not (verifyMultiSignature (map getVerificationKey prefix) sigs msg)
& counterexample ("Prefix: " <> show prefix)
& counterexample ("Signature: " <> show sigs)
)
properPrefixes
)
forAll (sublistOf sks) $ \prefix ->
(length prefix < length sks)
==> let sigs = aggregate $ map (`sign` msg) (toList sks)
in verifyMultiSignature (map getVerificationKey prefix) sigs msg
=/= Verified
& classify (null prefix) "empty"
& counterexample ("Keys: " <> show prefix)
& counterexample ("Signature: " <> show sigs)