Skip to content

Commit

Permalink
Reduce Serialized Size of HybridInfo (#1485)
Browse files Browse the repository at this point in the history
This PR does a few things
1) Changes the codebase to assume helper_origin is a static string and does not need to be stored anywhere. It is removed from structs and outputs and simply grabbed from the place where it's defined if needed.
2) Additionally removes DOMAIN from serialized HybridInfo bytes.
3) Adds a second "to_bytes" method for HybridInfo structs. While we don't need hybrid_info and DOMAIN to deserialize HybridInfo, they are needed when we're actually encrypting/decrypting. For those purposes, a new to_enc_bytes() function is added.
  • Loading branch information
tyurek authored Dec 8, 2024
1 parent d30f67e commit e7a234a
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 256 deletions.
9 changes: 2 additions & 7 deletions ipa-core/src/cli/crypto/hybrid_decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ impl HybridDecryptArgs {
.reconstruct()
.as_u128();
let key_id = impression_report1.info.key_id;
let helper_origin = impression_report1.info.helper_origin;

writeln!(
writer,
"i,{match_key},{breakdown_key},{key_id},{helper_origin}"
)?;
writeln!(writer, "i,{match_key},{breakdown_key},{key_id}")?;
}
(
HybridReport::Conversion(conversion_report1),
Expand All @@ -154,12 +150,11 @@ impl HybridDecryptArgs {
.reconstruct()
.as_u128();
let key_id = conversion_report1.info.key_id;
let helper_origin = conversion_report1.info.helper_origin;
let conversion_site_domain = conversion_report1.info.conversion_site_domain;
let timestamp = conversion_report1.info.timestamp;
let epsilon = conversion_report1.info.epsilon;
let sensitivity = conversion_report1.info.sensitivity;
writeln!(writer, "c,{match_key},{value},{key_id},{helper_origin},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?;
writeln!(writer, "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?;
}
_ => {
panic!("Reports are not all the same type");
Expand Down
4 changes: 0 additions & 4 deletions ipa-core/src/cli/crypto/hybrid_encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,12 @@ mod tests {

#[tokio::test]
async fn try_encrypting_something() {
let helper_origin = "HELPER_ORIGIN".to_string();
let conversion_site_domain = "meta.com".to_string();
let records = vec![
TestHybridRecord::TestConversion {
match_key: 12345,
value: 2,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 100,
epsilon: 0.0,
Expand All @@ -317,7 +315,6 @@ mod tests {
match_key: 12345,
value: 5,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 101,
epsilon: 0.0,
Expand All @@ -327,7 +324,6 @@ mod tests {
match_key: 23456,
breakdown_key: 4,
key_id: 0,
helper_origin: helper_origin.clone(),
},
];
let mut input_file = NamedTempFile::new().unwrap();
Expand Down
9 changes: 2 additions & 7 deletions ipa-core/src/cli/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ impl Serializer for crate::test_fixture::hybrid::TestHybridRecord {
match_key,
breakdown_key,
key_id,
helper_origin,
} => {
write!(
buf,
"i,{match_key},{breakdown_key},{key_id},{helper_origin}"
)?;
write!(buf, "i,{match_key},{breakdown_key},{key_id}")?;
}
crate::test_fixture::hybrid::TestHybridRecord::TestConversion {
match_key,
value,
key_id,
helper_origin,
conversion_site_domain,
timestamp,
epsilon,
sensitivity,
} => {
write!(buf, "c,{match_key},{value},{key_id},{helper_origin},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?;
write!(buf, "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?;
}
}

Expand Down
10 changes: 3 additions & 7 deletions ipa-core/src/cli/playbook/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl InputItem for TestHybridRecord {
let event_type = s.chars().nth(0).unwrap();
match event_type {
'i' => {
if let [_, match_key, number, key_id, helper_origin] =
s.splitn(5, ',').collect::<Vec<_>>()[..]
{
if let [_, match_key, number, key_id] = s.splitn(4, ',').collect::<Vec<_>>()[..] {
let match_key: u64 = match_key
.parse()
.unwrap_or_else(|e| panic!("Expected a u64, got {match_key}: {e}"));
Expand All @@ -80,16 +78,15 @@ impl InputItem for TestHybridRecord {
match_key,
breakdown_key: number,
key_id,
helper_origin: helper_origin.to_string(),
}
} else {
panic!("{s} is not a valid {}", type_name::<Self>())
}
}

'c' => {
if let [_, match_key, number, key_id, helper_origin, conversion_site_domain, timestamp, epsilon, sensitivity] =
s.splitn(9, ',').collect::<Vec<_>>()[..]
if let [_, match_key, number, key_id, conversion_site_domain, timestamp, epsilon, sensitivity] =
s.splitn(8, ',').collect::<Vec<_>>()[..]
{
let match_key: u64 = match_key
.parse()
Expand Down Expand Up @@ -118,7 +115,6 @@ impl InputItem for TestHybridRecord {
match_key,
value: number,
key_id,
helper_origin: helper_origin.to_string(),
conversion_site_domain: conversion_site_domain.to_string(),
timestamp,
epsilon,
Expand Down
15 changes: 0 additions & 15 deletions ipa-core/src/protocol/hybrid/agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,17 @@ pub mod test {

#[allow(clippy::too_many_lines)]
fn get_records() -> Vec<TestHybridRecord> {
let helper_origin = "HELPER_ORIGIN".to_string();
let conversion_site_domain = "meta.com".to_string();
let shard1_records = [
TestHybridRecord::TestImpression {
match_key: SHARD1_MKS[0],
breakdown_key: 45,
key_id: 0,
helper_origin: helper_origin.clone(),
},
TestHybridRecord::TestConversion {
match_key: SHARD1_MKS[1],
value: 1,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 102,
epsilon: 0.0,
Expand All @@ -219,7 +216,6 @@ pub mod test {
match_key: SHARD1_MKS[2],
value: 3,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 103,
epsilon: 0.0,
Expand All @@ -229,7 +225,6 @@ pub mod test {
match_key: SHARD1_MKS[3],
value: 4,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 104,
epsilon: 0.0,
Expand All @@ -239,19 +234,16 @@ pub mod test {
match_key: SHARD1_MKS[4],
breakdown_key: 1,
key_id: 0,
helper_origin: helper_origin.clone(),
}, // duplicated impression with same match_key
TestHybridRecord::TestImpression {
match_key: SHARD1_MKS[4],
breakdown_key: 2,
key_id: 0,
helper_origin: helper_origin.clone(),
}, // duplicated impression with same match_key
TestHybridRecord::TestConversion {
match_key: SHARD1_MKS[5],
value: 7,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 105,
epsilon: 0.0,
Expand All @@ -263,13 +255,11 @@ pub mod test {
match_key: SHARD2_MKS[0],
breakdown_key: 56,
key_id: 0,
helper_origin: helper_origin.clone(),
},
TestHybridRecord::TestConversion {
match_key: SHARD2_MKS[1],
value: 2,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 100,
epsilon: 0.0,
Expand All @@ -279,13 +269,11 @@ pub mod test {
match_key: SHARD2_MKS[2],
breakdown_key: 78,
key_id: 0,
helper_origin: helper_origin.clone(),
}, // NOT attributed
TestHybridRecord::TestConversion {
match_key: SHARD2_MKS[3],
value: 5,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 101,
epsilon: 0.0,
Expand All @@ -295,13 +283,11 @@ pub mod test {
match_key: SHARD2_MKS[4],
breakdown_key: 90,
key_id: 0,
helper_origin: helper_origin.clone(),
}, // attributed twice, removed
TestHybridRecord::TestConversion {
match_key: SHARD2_MKS[5],
value: 6,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 102,
epsilon: 0.0,
Expand All @@ -311,7 +297,6 @@ pub mod test {
match_key: SHARD2_MKS[6],
value: 7,
key_id: 0,
helper_origin: helper_origin.clone(),
conversion_site_domain: conversion_site_domain.clone(),
timestamp: 103,
epsilon: 0.0,
Expand Down
6 changes: 0 additions & 6 deletions ipa-core/src/protocol/hybrid/oprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,16 @@ mod test {
match_key: 12345,
breakdown_key: 2,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
},
TestHybridRecord::TestImpression {
match_key: 68362,
breakdown_key: 1,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
},
TestHybridRecord::TestConversion {
match_key: 12345,
value: 5,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
conversion_site_domain: "meta.com".to_string(),
timestamp: 100,
epsilon: 0.0,
Expand All @@ -253,7 +250,6 @@ mod test {
match_key: 68362,
value: 2,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
conversion_site_domain: "meta.com".to_string(),
timestamp: 102,
epsilon: 0.0,
Expand All @@ -263,13 +259,11 @@ mod test {
match_key: 68362,
breakdown_key: 1,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
},
TestHybridRecord::TestConversion {
match_key: 68362,
value: 7,
key_id: 0,
helper_origin: "HELPER_ORIGIN".to_string(),
conversion_site_domain: "meta.com".to_string(),
timestamp: 104,
epsilon: 0.0,
Expand Down
Loading

0 comments on commit e7a234a

Please sign in to comment.