File tree Expand file tree Collapse file tree
cardano-crypto-leios/src/Cardano/Crypto Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -194,10 +194,24 @@ resolveLeiosVoter committee voterId =
194194-- If the committee carries duplicate verification keys, returns the smallest
195195-- index matching @vk@ (committee selection is expected to deduplicate, but
196196-- this module does not enforce it).
197+ --
198+ -- Errors if the matching index does not fit in 'Word16'. The wire format of
199+ -- 'LeiosCert' indexes voters by a 16-bit field, so a committee with more than
200+ -- @2^16@ seats is already malformed. NOTE: this partiality could later be
201+ -- avoided by introducing a smart constructor for 'LeiosCommittee' (or for the
202+ -- committee-selection step in consensus) that rejects oversized committees
203+ -- up front.
197204getLeiosVoterId :: LeiosVerificationKey -> LeiosCommittee -> Maybe LeiosVoterId
198205getLeiosVoterId vk committee =
199- LeiosVoterId . fromIntegral @ Int @ Word16
200- <$> V. findIndex ((== vk) . voterVKey) committee. committeeVoters
206+ toVoterId <$> V. findIndex ((== vk) . voterVKey) committee. committeeVoters
207+ where
208+ toVoterId i
209+ | i > fromIntegral @ Word16 @ Int maxBound =
210+ error $
211+ " Cardano.Crypto.Leios.getVoterId: committee index "
212+ <> show i
213+ <> " does not fit in Word16"
214+ | otherwise = LeiosVoterId (fromIntegral @ Int @ Word16 i)
201215
202216-- | A Leios certificate over an endorser block, as specified in CIP-164:
203217--
You can’t perform that action at this time.
0 commit comments