Skip to content

Commit 71e8150

Browse files
author
Swapnadeep Som
authored
Fix Issue #347: Remove wording that implies ballot chaining (#348)
* refactor code * changed the description and other previous_ballot_code to code_seed * changed a few more descriptions
1 parent 355b587 commit 71e8150

4 files changed

Lines changed: 24 additions & 32 deletions

File tree

src/electionguard/ballot.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from enum import Enum
44
from typing import Any, List, Iterable, Optional, Protocol, runtime_checkable, Sequence
55

6-
from .ballot_code import get_rotating_ballot_code
6+
from .ballot_code import get_ballot_code
77
from .chaum_pedersen import (
88
ConstantChaumPedersenProof,
99
DisjunctiveChaumPedersenProof,
@@ -666,8 +666,8 @@ class CiphertextBallot(ElectionObjectBase, CryptoHashCheckable):
666666
manifest_hash: ElementModQ
667667
"""Hash of the election manifest"""
668668

669-
previous_code: ElementModQ
670-
"""Previous ballot code or seed"""
669+
code_seed: ElementModQ
670+
"""Seed for ballot code"""
671671

672672
contests: List[CiphertextBallotContest]
673673
"""List of contests for this ballot"""
@@ -690,7 +690,7 @@ def __eq__(self, other: Any) -> bool:
690690
and self.object_id == other.object_id
691691
and self.style_id == other.style_id
692692
and self.manifest_hash == other.manifest_hash
693-
and self.previous_code == other.previous_code
693+
and self.code_seed == other.code_seed
694694
and _list_eq(self.contests, other.contests)
695695
and self.code == other.code
696696
and self.timestamp == other.timestamp
@@ -849,7 +849,7 @@ def make_ciphertext_ballot(
849849
object_id: str,
850850
style_id: str,
851851
manifest_hash: ElementModQ,
852-
previous_ballot_code: Optional[ElementModQ],
852+
code_seed: Optional[ElementModQ],
853853
contests: List[CiphertextBallotContest],
854854
nonce: Optional[ElementModQ] = None,
855855
timestamp: Optional[int] = None,
@@ -864,7 +864,7 @@ def make_ciphertext_ballot(
864864
:param crypto_base_hash: Hash of the cryptographic election context
865865
:param contests: List of contests for this ballot
866866
:param timestamp: Timestamp at which the ballot encryption is generated in tick
867-
:param previous_code: Previous ballot code or seed
867+
:param code_seed: Seed for ballot code
868868
:param nonce: optional nonce used as part of the encryption process
869869
"""
870870

@@ -874,18 +874,16 @@ def make_ciphertext_ballot(
874874
contest_hash = create_ballot_hash(object_id, manifest_hash, contests)
875875

876876
timestamp = to_ticks(datetime.now()) if timestamp is None else timestamp
877-
if previous_ballot_code is None:
878-
previous_ballot_code = manifest_hash
877+
if code_seed is None:
878+
code_seed = manifest_hash
879879
if ballot_code is None:
880-
ballot_code = get_rotating_ballot_code(
881-
previous_ballot_code, timestamp, contest_hash
882-
)
880+
ballot_code = get_ballot_code(code_seed, timestamp, contest_hash)
883881

884882
return CiphertextBallot(
885883
object_id,
886884
style_id,
887885
manifest_hash,
888-
previous_ballot_code,
886+
code_seed,
889887
contests,
890888
ballot_code,
891889
timestamp,
@@ -909,7 +907,7 @@ def make_ciphertext_submitted_ballot(
909907
object_id: str,
910908
style_id: str,
911909
manifest_hash: ElementModQ,
912-
previous_ballot_code: Optional[ElementModQ],
910+
code_seed: Optional[ElementModQ],
913911
contests: List[CiphertextBallotContest],
914912
ballot_code: Optional[ElementModQ],
915913
timestamp: Optional[int] = None,
@@ -921,7 +919,7 @@ def make_ciphertext_submitted_ballot(
921919
:param object_id: the object_id of this specific ballot
922920
:param style_id: The `object_id` of the `BallotStyle` in the `Election` Manifest
923921
:param manifest_hash: Hash of the election manifest
924-
:param previous_code: Previous ballot code or seed
922+
:param code_seed: Seed for ballot code
925923
:param contests: List of contests for this ballot
926924
:param timestamp: Timestamp at which the ballot encryption is generated in tick
927925
:param state: ballot box state
@@ -934,12 +932,10 @@ def make_ciphertext_submitted_ballot(
934932
contest_hash = hash_elems(object_id, manifest_hash, *contest_hashes)
935933

936934
timestamp = to_ticks(datetime.utcnow()) if timestamp is None else timestamp
937-
if previous_ballot_code is None:
938-
previous_ballot_code = manifest_hash
935+
if code_seed is None:
936+
code_seed = manifest_hash
939937
if ballot_code is None:
940-
ballot_code = get_rotating_ballot_code(
941-
previous_ballot_code, timestamp, contest_hash
942-
)
938+
ballot_code = get_ballot_code(code_seed, timestamp, contest_hash)
943939

944940
# copy the contests and selections, removing all nonces
945941
new_contests: List[CiphertextBallotContest] = []
@@ -954,7 +950,7 @@ def make_ciphertext_submitted_ballot(
954950
object_id,
955951
style_id,
956952
manifest_hash,
957-
previous_ballot_code,
953+
code_seed,
958954
new_contests,
959955
ballot_code,
960956
timestamp,
@@ -974,7 +970,7 @@ def from_ciphertext_ballot(
974970
ballot.object_id,
975971
ballot.style_id,
976972
ballot.manifest_hash,
977-
ballot.previous_code,
973+
ballot.code_seed,
978974
ballot.contests,
979975
ballot.code,
980976
ballot.timestamp,

src/electionguard/ballot_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_hash_for_device(
1414
return hash_elems(uuid, session_id, launch_code, location)
1515

1616

17-
def get_rotating_ballot_code(
17+
def get_ballot_code(
1818
prev_code: ElementModQ, timestamp: int, ballot_hash: ElementModQ
1919
) -> ElementModQ:
2020
"""

src/electionguard/ballot_compact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CompactSubmittedBallot:
4141
compact_plaintext_ballot: CompactPlaintextBallot
4242
timestamp: int
4343
ballot_nonce: ElementModQ
44-
previous_code: ElementModQ
44+
code_seed: ElementModQ
4545
code: ElementModQ
4646
ballot_box_state: BallotBoxState
4747

@@ -66,7 +66,7 @@ def compress_submitted_ballot(
6666
compress_plaintext_ballot(plaintext_ballot),
6767
ballot.timestamp,
6868
ballot_nonce,
69-
ballot.previous_code,
69+
ballot.code_seed,
7070
get_optional(ballot.code),
7171
ballot.state,
7272
)
@@ -98,7 +98,7 @@ def expand_compact_submitted_ballot(
9898
plaintext_ballot.object_id,
9999
plaintext_ballot.style_id,
100100
internal_manifest.manifest_hash,
101-
compact_ballot.previous_code,
101+
compact_ballot.code_seed,
102102
contests,
103103
compact_ballot.code,
104104
compact_ballot.timestamp,

tests/unit/test_ballot_code.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from electionguard.group import ZERO_MOD_Q, ONE_MOD_Q, TWO_MOD_Q
44
from electionguard.ballot_code import (
5-
get_rotating_ballot_code,
5+
get_ballot_code,
66
get_hash_for_device,
77
)
88

@@ -24,12 +24,8 @@ def test_rotate_ballot_code(self):
2424
device_hash = get_hash_for_device(
2525
device.uuid, device.session_id, device.launch_code, device.location
2626
)
27-
ballot_code_1 = get_rotating_ballot_code(
28-
device_hash, timestamp_1, ballot_hash_1
29-
)
30-
ballot_code_2 = get_rotating_ballot_code(
31-
device_hash, timestamp_2, ballot_hash_2
32-
)
27+
ballot_code_1 = get_ballot_code(device_hash, timestamp_1, ballot_hash_1)
28+
ballot_code_2 = get_ballot_code(device_hash, timestamp_2, ballot_hash_2)
3329

3430
# Assert
3531
self.assertIsNotNone(device_hash)

0 commit comments

Comments
 (0)