1 {-# LANGUAGE OverloadedStrings #-}
4 import qualified Data.List as List
5 import qualified Data.Text as Text
6 import qualified Text.Printf as Printf
11 makeElection :: forall c. Reifies c FFC => Int -> Int -> Election c
12 makeElection nQuests nChoices = elec
14 election_uuid = UUID "xLcs7ev6Jy6FHH"
16 { election_name = Text.pack $ "elec"<>show nQuests<>show nChoices
17 , election_description = "benchmarkable election"
19 , election_crypto = ElectionCrypto_FFC (reflect (Proxy::Proxy c)) $
20 let secKey = credentialSecretKey election_uuid (Credential "xLcs7ev6Jy6FHHE") in
22 , election_hash = hashElection elec
23 , election_questions =
24 (<$> [1..nQuests]) $ \quest -> Question
25 { question_text = Text.pack $ "quest"<>show quest
26 , question_choices = (<$> [1..nChoices]) $ \choice -> Text.pack $ "choice"<>show choice
28 , question_maxi = one -- sum $ List.replicate nChoices one
32 makeVotes :: Election c -> [[Bool]]
33 makeVotes Election{..} =
34 [ True : List.tail [ False | _choice <- question_choices quest ]
35 | quest <- election_questions
38 makeBallot :: Reifies c FFC => Election c -> Ballot c
40 case runExcept $ (`evalStateT` mkStdGen seed) $ do
41 ballotSecKey <- randomSecretKey
42 encryptBallot elec (Just ballotSecKey) $
44 Right ballot -> ballot
45 Left err -> error ("encryptBallot: "<>show err)
49 titleElection :: Election c -> String
50 titleElection Election{..} =
51 Printf.printf "(questions=%i)×(choices=%i)==%i"
52 nQuests nChoices (nQuests * nChoices)
54 nQuests = List.length election_questions
55 nChoices = List.foldr max 0 $ List.length . question_choices <$> election_questions
57 benchEncryptBallot :: FFC -> Int -> Int -> Benchmark
58 benchEncryptBallot ffc nQuests nChoices =
59 reify ffc $ \(Proxy::Proxy c) ->
61 let elec :: Election c = makeElection nQuests nChoices
63 env setupEnv $ \ ~(elec) ->
64 bench (titleElection elec) $
67 benchVerifyBallot :: FFC -> Int -> Int -> Benchmark
68 benchVerifyBallot ffc nQuests nChoices =
69 reify ffc $ \(Proxy::Proxy c) ->
71 let elec :: Election c = makeElection nQuests nChoices
72 let ballot = makeBallot elec
73 return (elec,ballot) in
74 env setupEnv $ \ ~(elec, ballot) ->
75 bench (titleElection elec) $
76 nf (verifyBallot elec) ballot
78 benchmarks :: [Benchmark]
82 | nQ <- [1,5,10,15,20,25]
86 [ bgroup "encryptBallot"
87 [ benchEncryptBallot weakFFC nQuests nChoices
88 | (nQuests,nChoices) <- inputs
90 , bgroup "verifyBallot"
91 [ benchVerifyBallot weakFFC nQuests nChoices
92 | (nQuests,nChoices) <- inputs
95 , bgroup "beleniosFFC"
96 [ bgroup "encryptBallot"
97 [ benchEncryptBallot beleniosFFC nQuests nChoices
98 | (nQuests,nChoices) <- inputs
100 , bgroup "verifyBallot"
101 [ benchVerifyBallot beleniosFFC nQuests nChoices
102 | (nQuests,nChoices) <- inputs