Skip to content

Commit

Permalink
Guard sizes for output conversion
Browse files Browse the repository at this point in the history
We also disambiguate between VerKey and SignKey conversion errors.

Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
  • Loading branch information
iquerejeta and lehins committed Feb 1, 2023
1 parent 696b301 commit 9ad1983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cardano-crypto-praos/src/Cardano/Crypto/VRF/Praos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,21 @@ vkToBatchCompat :: VerKeyVRF PraosVRF -> VerKeyVRF BC.PraosBatchCompatVRF
vkToBatchCompat praosVk =
case rawDeserialiseVerKeyVRF (rawSerialiseVerKeyVRF praosVk) of
Just vk -> vk
Nothing -> error "Unable to convert PraosVK to BatchCompatVK."
Nothing -> error "VerKeyVRF: Unable to convert PraosVK to BatchCompatVK."

-- | Construct a BatchCompat skey from praos, non-batchcompat
skToBatchCompat :: SignKeyVRF PraosVRF -> SignKeyVRF BC.PraosBatchCompatVRF
skToBatchCompat praosSk =
case rawDeserialiseSignKeyVRF (rawSerialiseSignKeyVRF praosSk) of
Just sk -> sk
Nothing -> error "Unable to convert PraosSK to BatchCompatSK."
Nothing -> error "SignKeyVRF: Unable to convert PraosSK to BatchCompatSK."

-- | Construct a BatchCompat output from praos, non-batchcompat
outputToBatchCompat :: OutputVRF PraosVRF -> OutputVRF BC.PraosBatchCompatVRF
outputToBatchCompat praosOutput =
if vrfKeySizeVRF /= BC.vrfKeySizeVRF
then error "OutputVRF: Unable to convert PraosSK to BatchCompatSK."
else
OutputVRF (getOutputVRFBytes praosOutput)


Expand Down
3 changes: 1 addition & 2 deletions cardano-crypto-tests/src/Test/Crypto/VRF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ instance (VRFAlgorithm v,
instance VRFAlgorithm v => Arbitrary (OutputVRF v) where
arbitrary = do
bytes <- BS.pack <$> vectorOf (fromIntegral (sizeOutputVRF (Proxy :: Proxy v))) arbitrary
return $ OutputVRF( bytes )
shrink = const []
return $ OutputVRF bytes

instance Arbitrary BS32 where
arbitrary = BS32 . BS.pack <$> vectorOf 32 arbitrary

0 comments on commit 9ad1983

Please sign in to comment.