Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events and query structure definitions #27

Merged
merged 4 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
default = ["debug", "cli"]
cli = ["enable-serde", "stderrlog", "structopt"]
debug = ["hex"]
enable-serde = ["serde", "serde_json", "rust-elgamal/enable-serde"]
enable-serde = ["serde", "serde_json", "rust-elgamal/enable-serde", "num-bigint/serde"]

[dependencies]
# rust-elgamal (via curve25519-dalek-ng) only works with digest 0.9, not 0.10
Expand All @@ -27,6 +27,7 @@ serde_json = {version = "1.0", optional = true}
sha2 = "0.9"
stderrlog = {version = "0.5", optional = true}
structopt = {version = "0.3", optional = true}
num-bigint = {version = "0.4.3", optional = true}

[dev-dependencies]
hex = "0.4"
Expand Down
1 change: 1 addition & 0 deletions src/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod aggregation;
pub mod event;
pub mod models;
pub mod privacy_budget;

pub use aggregation::{
Expand Down
140 changes: 140 additions & 0 deletions src/helpers/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use num_bigint::BigInt;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use std::ops::Range;

// Type aliases to indicate whether the parameter should be encrypted, secret shared, etc.
// Underlying types are temporalily assigned for PoC.
type CipherText = BigInt;
taikiy marked this conversation as resolved.
Show resolved Hide resolved
type PlainText = String;
type SecretShare = [CipherText; 3];
type PBRange = Range<u8>;
taikiy marked this conversation as resolved.
Show resolved Hide resolved

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct Event {
/// Secret shared and then encrypted match keys.
matchkeys: Vec<SecretShare>,

/// Date and time of the event occurence. Secret shared and encrypted.
taikiy marked this conversation as resolved.
Show resolved Hide resolved
timestamp: SecretShare,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct SourceEvent {
event: Event,

/// A key to group sets of the events into.
breakdown_key: PlainText,
}

#[cfg(feature = "debug")]
impl Debug for SourceEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"SourceEvent:\n matchkeys={:?}\n breakdown_key={}",
&self.event.matchkeys, &self.breakdown_key
)
}
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct TriggerEvent {
event: Event,

/// Conversion value.
value: SecretShare,

/// Zero knowledge proof that the trigger value lies within a specific range
/// of values. The range is specified in [TriggerFanoutQuery].
zkp: PlainText,
}

#[cfg(feature = "debug")]
impl Debug for TriggerEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"TriggerEvent:\n matchkeys={:?}\n value={:?}",
&self.event.matchkeys, &self.value
)
}
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
enum QueryType {
SourceFanout,
TriggerFanout,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
enum Node {
Helper1,
Helper2,
Helper3,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct IPAQuery {
/// Caller authentication token.
auth_token: PlainText,

/// Initial MPC helper node to send the data to.
leader_node: Node,

/// List of match key providers to be used by the source and trigger events during an epoch.
mk_providers: Vec<String>,

/// Source-fanout or Trigger-fanout.
query_type: QueryType,

/// Percentage of epoch-level privacy budget this query should consume. Likely 1-100.
privacy_budget: PBRange,
taikiy marked this conversation as resolved.
Show resolved Hide resolved

/// A collection of source events. At least 100 (TBD) unique source events must be provided.
source_events: Vec<SourceEvent>,

/// A collection of trigger events. At least 10 (TBD) unique trigger events must be provided.
trigger_events: Vec<TriggerEvent>,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct SourceFanoutQuery {
query: IPAQuery,

/// The maximum number of attributed conversion events that a single person can contribute
taikiy marked this conversation as resolved.
Show resolved Hide resolved
/// towards the final output.
cap: u8,
}

#[cfg(feature = "debug")]
impl Debug for SourceFanoutQuery {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"SourceFanoutQuery:\n {} source events\n {} trigger events",
&self.query.source_events.len(),
&self.query.trigger_events.len()
)
}
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
struct TriggerFanoutQuery {
query: IPAQuery,

/// The range which all trigger event's conversion values must lie within.
taikiy marked this conversation as resolved.
Show resolved Hide resolved
value_range: Range<u32>,
}

#[cfg(feature = "debug")]
impl Debug for TriggerFanoutQuery {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"TriggerFanoutQuery:\n {} source events\n {} trigger events",
&self.query.source_events.len(),
&self.query.trigger_events.len()
)
}
}