def check_opened_output_commitment_tallies(sbb_dict, db):
    """ Check that for each k, the opened output commitments lagranage
        and tally to values given in tally.
    """
    opened_coms = \
        sbb_dict['proof:outcome_check']\
                ['opened_output_commitments']
    for k in db['opl']:
        # verify tally for this pass/copy k
        tally_k = dict()
        for race_id in db['race_ids']:
            tally_k[race_id] = dict()  # choices to counts
            for choice in sbb_dict['setup:races']\
                ['ballot_style_race_dict'][race_id]['choices']:
                if choice[0] != '*':
                    tally_k[race_id][choice] = 0
            for p in db['p_list']:
                share_list = []
                for i_int, i in enumerate(db['row_list']):
                    y = opened_coms[race_id][k][p][i]['y']
                    share_list.append((i_int+1, y))
                w = sv.lagrange(share_list,
                                db['rows'],
                                db['threshold'],
                                db['races'][race_id]['race_modulus'])
                # convert w back to string version of choice
                # see sv_race.choice_int2str
                choice_bytes = sv.int2bytes(w)
                choice_str = choice_bytes.decode()
                # assert self.is_valid_choice(choice_str)
                # print(race_id, k, iy, choice_str)
                cnt = tally_k[race_id].get(choice_str, 0)
                tally_k[race_id][choice_str] = cnt + 1
        assert tally_k == db['tally']
    print('check_opened_output_commitment_tallies: passed.')
Esempio n. 2
0
def check_opened_output_commitment_tallies(sbb_dict, db):
    """ Check that for each k, the opened output commitments lagranage
        and tally to values given in tally.
    """
    opened_coms = \
        sbb_dict['proof:outcome_check']\
                ['opened_output_commitments']
    for k in db['opl']:
        # verify tally for this pass/copy k
        tally_k = dict()
        for race_id in db['race_ids']:
            tally_k[race_id] = dict()  # choices to counts
            for choice in sbb_dict['setup:races']\
                ['ballot_style_race_dict'][race_id]['choices']:
                if choice[0] != '*':
                    tally_k[race_id][choice] = 0
            for p in db['p_list']:
                share_list = []
                for i_int, i in enumerate(db['row_list']):
                    y = opened_coms[race_id][k][p][i]['y']
                    share_list.append((i_int + 1, y))
                w = sv.lagrange(share_list, db['rows'], db['threshold'],
                                db['races'][race_id]['race_modulus'])
                # convert w back to string version of choice
                # see sv_race.choice_int2str
                choice_bytes = sv.int2bytes(w)
                choice_str = choice_bytes.decode()
                # assert self.is_valid_choice(choice_str)
                # print(race_id, k, iy, choice_str)
                cnt = tally_k[race_id].get(choice_str, 0)
                tally_k[race_id][choice_str] = cnt + 1
        assert tally_k == db['tally']
    print('check_opened_output_commitment_tallies: passed.')
Esempio n. 3
0
 def choice_int2str(self, choice_int):
     """ Inverse of choice_str2int; convert integer to choice string. """
     assert isinstance(choice_int, int) and \
         0 <= choice_int < self.race_modulus
     choice_bytes = sv.int2bytes(choice_int)
     choice_str = choice_bytes.decode()
     assert self.is_valid_choice(choice_str)
     return choice_str