Skip to content

Commit

Permalink
Use u32 sizes in serialization of vote payloads
Browse files Browse the repository at this point in the history
u64 is overkill, the computations will become impractical
before the number of voters or votes approaches 1^32.
  • Loading branch information
Mikhail Zabaluev committed Oct 20, 2020
1 parent d9edffd commit a865b7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions chain-impl-mockchain/src/vote/payload.rs
Expand Up @@ -72,12 +72,10 @@ impl Payload {
encrypted_vote,
proof,
} => {
let size = encrypted_vote.len();
let mut bb = bb.u64(size as u64);
for ct in encrypted_vote.iter() {
let bb = bb.iter32(encrypted_vote, |bb, ct| {
let buffer = ct.to_bytes();
bb = bb.bytes(&buffer);
}
bb.bytes(&buffer)
});
proof.serialize_in(bb)
}
}
Expand All @@ -92,7 +90,7 @@ impl Payload {
match t {
PayloadType::Public => buf.get_u8().map(Choice::new).map(Self::public),
PayloadType::Private => {
let len: usize = buf.get_u64()? as usize;
let len: usize = buf.get_u32()? as usize;
let mut cypher_texts: Vec<Ciphertext> = Vec::new();
for _ in 0..len {
let ct_buf = buf.get_slice(CIPHERTEXT_BYTES_LEN)?;
Expand Down
6 changes: 1 addition & 5 deletions chain-vote/src/lib.rs
Expand Up @@ -103,11 +103,7 @@ pub struct TallyResult {

impl TallyDecryptShare {
pub fn serialize_in(&self, bb: ByteBuilder<Self>) -> ByteBuilder<Self> {
let mut bb = bb.u64(self.r1s.len() as u64);
for e in &self.r1s {
bb = bb.bytes(&e.to_bytes())
}
bb
bb.iter32(&self.r1s, |bb, e| bb.bytes(&e.to_bytes()))
}

pub fn serialize(&self) -> ByteArray<Self> {
Expand Down

0 comments on commit a865b7b

Please sign in to comment.