Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions iris-mpc-common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub struct Config {
#[serde(default = "default_match_distances_2d_buffer_size")]
pub match_distances_2d_buffer_size: usize,

/// Minimum number of reauth match distances required before publishing 1D anonymized stats
#[serde(default = "default_reauth_match_distances_min_count")]
pub reauth_match_distances_min_count: usize,

#[serde(default = "default_n_buckets")]
pub n_buckets: usize,

Expand Down Expand Up @@ -394,6 +398,10 @@ fn default_match_distances_2d_buffer_size() -> usize {
1 << 13 // 8192
}

fn default_reauth_match_distances_min_count() -> usize {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if we need this, was just a consideration on how to limit the amount of reauth bucket stats to send

10_000
}

fn default_n_buckets() -> usize {
375
}
Expand Down Expand Up @@ -712,6 +720,7 @@ pub struct CommonConfig {
match_distances_buffer_size: usize,
match_distances_buffer_size_extra_percent: usize,
match_distances_2d_buffer_size: usize,
reauth_match_distances_min_count: usize,
n_buckets: usize,
enable_sending_anonymized_stats_message: bool,
enable_sending_mirror_anonymized_stats_message: bool,
Expand Down Expand Up @@ -801,6 +810,7 @@ impl From<Config> for CommonConfig {
match_distances_buffer_size,
match_distances_buffer_size_extra_percent,
match_distances_2d_buffer_size,
reauth_match_distances_min_count,
n_buckets,
enable_sending_anonymized_stats_message,
enable_sending_mirror_anonymized_stats_message,
Expand Down Expand Up @@ -872,6 +882,7 @@ impl From<Config> for CommonConfig {
match_distances_buffer_size,
match_distances_buffer_size_extra_percent,
match_distances_2d_buffer_size,
reauth_match_distances_min_count,
n_buckets,
enable_sending_anonymized_stats_message,
enable_sending_mirror_anonymized_stats_message,
Expand Down
40 changes: 40 additions & 0 deletions iris-mpc-common/src/helpers/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use chrono::{
use serde::{Deserialize, Serialize};
use std::fmt;

// Operation of the anonymized statistics producer
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
pub enum Operation {
#[default]
Uniqueness,
Reauth,
}

// 1D anonymized statistics types
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BucketResult {
Expand All @@ -30,6 +38,8 @@ pub struct BucketStatistics {
pub match_distances_buffer_size: usize,
pub party_id: usize,
pub eye: Eye,
// Operation type this histogram belongs to
pub operation: Operation,
#[serde(with = "ts_seconds")]
// Start timestamp at which we start recording the statistics
pub start_time_utc_timestamp: DateTime<Utc>,
Expand All @@ -54,6 +64,7 @@ impl fmt::Display for BucketStatistics {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, " party_id: {}", self.party_id)?;
writeln!(f, " eye: {:?}", self.eye)?;
writeln!(f, " operation: {:?}", self.operation)?;
writeln!(f, " start_time_utc: {}", self.start_time_utc_timestamp)?;
match &self.end_time_utc_timestamp {
Some(end) => writeln!(f, " end_time_utc: {}", end)?,
Expand Down Expand Up @@ -84,13 +95,27 @@ impl BucketStatistics {
eye,
match_distances_buffer_size,
party_id,
operation: Operation::Uniqueness,
start_time_utc_timestamp: Utc::now(),
end_time_utc_timestamp: None,
next_start_time_utc_timestamp: None,
is_mirror_orientation: false,
}
}

/// Create a new `BucketStatistics` with explicit operation type.
pub fn new_with_operation(
match_distances_buffer_size: usize,
n_buckets: usize,
party_id: usize,
eye: Eye,
operation: Operation,
) -> Self {
let mut bs = Self::new(match_distances_buffer_size, n_buckets, party_id, eye);
bs.operation = operation;
bs
}

/// `buckets_array` array of buckets
/// `buckets`, which for i=0..n_buckets might be a cumulative count (or
/// partial sum).
Expand Down Expand Up @@ -181,6 +206,8 @@ pub struct BucketStatistics2D {
// The number of two-sided matches gathered before sending the statistics
pub match_distances_buffer_size: usize,
pub party_id: usize,
// Operation type this histogram belongs to
pub operation: Operation,
#[serde(with = "ts_seconds")]
pub start_time_utc_timestamp: DateTime<Utc>,
#[serde(with = "ts_seconds_option")]
Expand All @@ -200,6 +227,7 @@ impl BucketStatistics2D {
impl fmt::Display for BucketStatistics2D {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, " party_id: {}", self.party_id)?;
writeln!(f, " operation: {:?}", self.operation)?;
writeln!(f, " start_time_utc: {}", self.start_time_utc_timestamp)?;
match &self.end_time_utc_timestamp {
Some(end) => writeln!(f, " end_time_utc: {}", end)?,
Expand Down Expand Up @@ -231,12 +259,24 @@ impl BucketStatistics2D {
n_buckets_per_side,
match_distances_buffer_size,
party_id,
operation: Operation::Uniqueness,
start_time_utc_timestamp: Utc::now(),
end_time_utc_timestamp: None,
next_start_time_utc_timestamp: None,
}
}

pub fn new_with_operation(
match_distances_buffer_size: usize,
n_buckets_per_side: usize,
party_id: usize,
operation: Operation,
) -> Self {
let mut bs = Self::new(match_distances_buffer_size, n_buckets_per_side, party_id);
bs.operation = operation;
bs
}

// Fill bucket counts for the 2D histogram.
// buckets_2d is expected in row-major order (left index major):
// buckets_2d[left_idx * n_buckets_per_side + right_idx]
Expand Down
4 changes: 4 additions & 0 deletions iris-mpc-common/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ pub struct ServerJobResult<A = ()> {
// 2D anonymized statistics across both eyes (only for matches on both sides)
// Only for Normal orientation
pub anonymized_bucket_statistics_2d: BucketStatistics2D,
// Reauth-only anonymized stats (Normal orientation only)
pub anonymized_bucket_statistics_left_reauth: BucketStatistics,
pub anonymized_bucket_statistics_right_reauth: BucketStatistics,
pub anonymized_bucket_statistics_2d_reauth: BucketStatistics2D,
// Mirror orientation bucket statistics
pub anonymized_bucket_statistics_left_mirror: BucketStatistics,
pub anonymized_bucket_statistics_right_mirror: BucketStatistics,
Expand Down
Loading
Loading