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

Serde is now a non-optional dependency #996

Merged
merged 6 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 4 additions & 6 deletions ipa-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ default = [
"ipa-prf",
]
cli = ["comfy-table", "clap"]
enable-serde = ["serde", "serde_json"]
disable-metrics = []
# TODO move web-app to a separate crate. It adds a lot of build time to people who mostly write protocols
# TODO Consider moving out benches as well
Expand All @@ -28,7 +27,6 @@ web-app = [
"base64",
"clap",
"comfy-table",
"enable-serde",
"hyper",
"hyper-rustls",
"rcgen",
Expand All @@ -40,7 +38,7 @@ web-app = [
"tower",
"tower-http",
]
test-fixture = ["enable-serde", "weak-field"]
test-fixture = ["weak-field"]
# Include observability instruments that detect lack of progress inside MPC. If there is a bug that leads to helper
# miscommunication, this feature helps to detect it. Turning it on has some cost.
# If "shuttle" feature is enabled, turning this on has no effect.
Expand Down Expand Up @@ -134,8 +132,8 @@ rustls-pemfile = { version = "1", optional = true }
# we can remove pinning
rustls-webpki = "^0.101.4"
# TODO consider using zerocopy or serde_bytes or in-house serialization
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
sha2 = "0.10"
shuttle-crate = { package = "shuttle", version = "0.6.1", optional = true }
thiserror = "1.0"
Expand Down Expand Up @@ -179,7 +177,7 @@ bench = false
[[bin]]
name = "ipa_bench"
path = "src/bin/ipa_bench/ipa_bench.rs"
required-features = ["cli", "enable-serde"]
required-features = ["cli"]
bench = false

[[bin]]
Expand Down
2 changes: 0 additions & 2 deletions ipa-core/src/bin/ipa_bench/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use std::ops::Range;

use serde::{Deserialize, Serialize};

#[cfg(feature = "enable-serde")]
#[derive(Serialize, Deserialize, Debug)]
pub struct WeightedIndex<T> {
pub index: T,
pub weight: f64,
}

#[cfg(feature = "enable-serde")]
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub devices_per_user: Vec<WeightedIndex<u8>>,
Expand Down
24 changes: 9 additions & 15 deletions ipa-core/src/bin/ipa_bench/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
/// An offset in seconds into a given epoch. Using an 32-bit value > 20-bit > 604,800 seconds.
pub type Offset = u32;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Serialize, Deserialize)]

Check warning on line 23 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L23

Added line #L23 was not covered by tests
pub struct SecretShare {
ss: [CipherText; 3],
}
Expand Down Expand Up @@ -119,8 +118,7 @@
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]

Check warning on line 121 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L121

Added line #L121 was not covered by tests
/// A timestamp of a source/trigger report represented by epoch and offset.
///
/// Internally, the time is stored in `u32`, but the value is capped at `(Epoch::MAX + 1) * SECONDS_IN_EPOCH - 1`.
Expand Down Expand Up @@ -206,8 +204,7 @@
}
}

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]

Check warning on line 207 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L207

Added line #L207 was not covered by tests
pub struct Event {
// An identifier, set in the user agent, which identifies an individual person. This must never be released (beyond
/// the match key provider) to any party in unencrypted form. For the purpose of this tool, however, the value is in
Expand All @@ -222,8 +219,7 @@
pub timestamp: EventTimestamp,
}

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]

Check warning on line 222 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L222

Added line #L222 was not covered by tests
pub enum GenericReport {
/// An event produced on websites/apps when a user interacts with an ad (i.e. impression, click).
Source {
Expand All @@ -242,22 +238,20 @@
},
}

// TODO(taiki): Implement Serialize/Deserialize

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Serialize, Deserialize)]

Check warning on line 241 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L241

Added line #L241 was not covered by tests
enum QueryType {
SourceFanout,
TriggerFanout,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Serialize, Deserialize)]

Check warning on line 247 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L247

Added line #L247 was not covered by tests
enum Node {
Helper1,
Helper2,
Helper3,
}

#[cfg_attr(feature = "enable-serde", derive(Serialize))]
#[derive(Serialize)]
struct IPAQuery {
/// Caller authentication token.
auth_token: PlainText,
Expand All @@ -278,7 +272,7 @@
reports: Vec<GenericReport>,
}

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

Expand All @@ -299,7 +293,7 @@
}
}

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

Expand Down
5 changes: 3 additions & 2 deletions ipa-core/src/cli/ipa_output.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::time::Duration;

use serde::{Deserialize, Serialize};

use crate::helpers::query::{IpaQueryConfig, QuerySize};

#[derive(Debug)]
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryResult {
pub input_size: QuerySize,
pub config: IpaQueryConfig,
Expand Down
1 change: 0 additions & 1 deletion ipa-core/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod playbook;
#[cfg(feature = "web-app")]
mod test_setup;
mod verbosity;

#[cfg(feature = "web-app")]
pub use clientconf::{setup as client_config_setup, ConfGenArgs};
pub use csv::Serializer as CsvSerializer;
Expand Down
9 changes: 4 additions & 5 deletions ipa-core/src/cli/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use clap::Args;
use rand::rngs::StdRng;
use rand_core::SeedableRng;
use serde::{Deserialize, Serialize, Serializer};

use crate::protocol::dp::InsecureDiscreteDp;

Expand All @@ -30,8 +31,7 @@
cap: u32,
}

#[derive(Debug)]
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Serialize, Deserialize)]

Check warning on line 34 in ipa-core/src/cli/noise.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/cli/noise.rs#L34

Added line #L34 was not covered by tests
pub struct NoisyOutput {
/// Aggregated breakdowns with noise applied. It is important to use unsigned values here
/// to avoid bias/mean skew
Expand All @@ -45,11 +45,10 @@
#[derive(Debug, Copy, Clone)]
pub struct EpsilonBits(f64);

#[cfg(feature = "enable-serde")]
impl serde::Serialize for EpsilonBits {
impl Serialize for EpsilonBits {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
S: Serializer,

Check warning on line 51 in ipa-core/src/cli/noise.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/cli/noise.rs#L51

Added line #L51 was not covered by tests
{
serializer.serialize_str(&self.0.to_string())
}
Expand Down
1 change: 0 additions & 1 deletion ipa-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub enum Error {
#[error("runtime error")]
RuntimeError(JoinError),
#[error("failed to parse json: {0}")]
#[cfg(feature = "enable-serde")]
Serde(#[from] serde_json::Error),
#[error("MPC Infrastructure error: {0}")]
MpcInfraError(#[from] crate::helpers::Error<Role>),
Expand Down
4 changes: 2 additions & 2 deletions ipa-core/src/ff/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
ops::{Mul, MulAssign},
};

use serde::{Deserialize, Serialize};
use typenum::{U1, U4};

use crate::{
Expand Down Expand Up @@ -37,8 +38,7 @@ pub trait Field:
const ONE: Self;
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum FieldType {
#[cfg(any(test, feature = "weak-field"))]
Expand Down
30 changes: 9 additions & 21 deletions ipa-core/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
pub(crate) mod prss_protocol;
pub mod stream;
mod transport;

use std::ops::{Index, IndexMut};

/// to validate that transport can actually send streams of this type
#[cfg(test)]
pub use buffers::OrderingSender;
pub use error::Error;
pub use futures::MaybeFuture;
use serde::{Deserialize, Serialize, Serializer};

#[cfg(feature = "stall-detection")]
mod gateway_exports {
Expand Down Expand Up @@ -81,22 +81,18 @@
/// represents a helper's role within an MPC protocol, which may be different per protocol.
/// `HelperIdentity` will be established at startup and then never change. Components that want to
/// resolve this identifier into something (Uri, encryption keys, etc) must consult configuration
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(
feature = "enable-serde",
derive(serde::Deserialize),
serde(try_from = "usize")
)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Deserialize)]
#[serde(try_from = "usize")]
pub struct HelperIdentity {
id: u8,
}

// Serialize as `serde(transparent)` would. Don't see how to enable that
// for only one of (de)serialization.
impl serde::Serialize for HelperIdentity {
impl Serialize for HelperIdentity {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
S: Serializer,
{
self.id.serialize(serializer)
}
Expand Down Expand Up @@ -219,26 +215,18 @@
/// may be `H2` or `H3`.
/// Each helper instance must be able to take any role, but once the role is assigned, it cannot
/// be changed for the remainder of the query.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]

Check warning on line 218 in ipa-core/src/helpers/mod.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/helpers/mod.rs#L218

Added line #L218 was not covered by tests
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
#[cfg_attr(
feature = "enable-serde",
derive(serde::Serialize, serde::Deserialize),
serde(into = "&'static str", try_from = "&str")
)]
#[serde(into = "&'static str", try_from = "&str")]
pub enum Role {
H1 = 0,
H2 = 1,
H3 = 2,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cfg_attr(
feature = "enable-serde",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
#[serde(transparent)]
pub struct RoleAssignment {
helper_roles: [HelperIdentity; 3],
}
Expand Down
31 changes: 6 additions & 25 deletions ipa-core/src/helpers/transport/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
protocol::{step::Step, QueryId},
};

#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
#[cfg_attr(feature = "enable-serde", derive(Serialize))]
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Serialize)]
pub struct QuerySize(u32);

impl QuerySize {
pub const MAX: u32 = 1_000_000_000;
}

#[cfg(feature = "enable-serde")]
impl<'de> Deserialize<'de> for QuerySize {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -84,9 +82,8 @@
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct QueryConfig {
pub size: QuerySize,
pub field_type: FieldType,
Expand All @@ -99,9 +96,8 @@
BadQuerySize(#[from] BadQuerySizeError),
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct PrepareQuery {
pub query_id: QueryId,
pub config: QueryConfig,
Expand All @@ -123,15 +119,9 @@
NoStep
}

#[cfg(feature = "enable-serde")]
fn extra(&self) -> Self::Params {
serde_json::to_string(self).unwrap()
}

#[cfg(not(feature = "enable-serde"))]
fn extra(&self) -> Self::Params {
unimplemented!()
}
}

impl From<&QueryConfig> for GatewayConfig {
Expand Down Expand Up @@ -177,15 +167,9 @@
NoStep
}

#[cfg(feature = "enable-serde")]
fn extra(&self) -> Self::Params {
serde_json::to_string(self).unwrap()
}

#[cfg(not(feature = "enable-serde"))]
fn extra(&self) -> Self::Params {
unimplemented!()
}
}

pub struct QueryInput {
Expand All @@ -199,8 +183,7 @@
}
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum QueryType {
#[cfg(any(test, feature = "test-fixture", feature = "cli"))]
TestMultiply,
Expand All @@ -225,8 +208,7 @@

impl Step for QueryType {}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "clap", derive(clap::Args))]
pub struct IpaQueryConfig {
#[cfg_attr(feature = "clap", arg(long, default_value = "8"))]
Expand Down Expand Up @@ -331,8 +313,7 @@
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]

Check warning on line 316 in ipa-core/src/helpers/transport/query/mod.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/helpers/transport/query/mod.rs#L316

Added line #L316 was not covered by tests
pub struct SparseAggregateQueryConfig {
pub contribution_bits: ContributionBits,
pub num_contributions: u32,
Expand Down
Loading
Loading