Skip to content

Commit

Permalink
Refactor Prio3 dispatch logic, remove unneeded variants
Browse files Browse the repository at this point in the history
Move sharding, preparation, and unsharding dispatchers to `Prio3Config`.
Not all variants are supported by all DAP versions, so pass the version
to each dispatcher in order to resolve DAP and Prio3 version
compatibility. (Note Prio3 is not API-compatible across versions.)

The following variants are supported in DAP-13:

* Prio3Count
* Prio3Sum
* Prio3SumVec
* Prio3Histogram

The following variants are supported in DAP-09:

* Prio3SumVecField64MultiproofHmacSha256Aes128

Modify the taskprov provisioning logic accordingly, by removing support
for the following VDAFs in DAP-13:

* Prio3SumVecField64MultiproofHmacSha256Aes128
* Pine32HmacSha256Aes128
* Pine64HmacSha256Aes128

These VDAFs need to be upgraded for VDAF-13 compatibility.
  • Loading branch information
cjpatton committed Dec 20, 2024
1 parent 11c1754 commit 4d3dd54
Show file tree
Hide file tree
Showing 21 changed files with 862 additions and 1,375 deletions.
8 changes: 4 additions & 4 deletions crates/dapf/src/acceptance/load_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ fn jobs_per_batch() -> impl Iterator<Item = usize> {
fn vdaf_config_params() -> impl Iterator<Item = VdafConfig> {
[
VdafConfig::Prio2 { dimension: 99_992 },
VdafConfig::Prio3Draft09(
daphne::vdaf::Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
VdafConfig::Prio3(
daphne::vdaf::Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits: 1,
length: 100_000,
chunk_length: 320,
num_proofs: 2,
},
),
VdafConfig::Prio3Draft09(
daphne::vdaf::Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
VdafConfig::Prio3(
daphne::vdaf::Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits: 1,
length: 100_000,
chunk_length: 320,
Expand Down
1 change: 1 addition & 0 deletions crates/dapf/src/acceptance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ impl Test {
agg_job_state,
agg_job_resp,
self.metrics(),
task_config.version,
)?;

let aggregated_report_count = agg_share_span
Expand Down
16 changes: 8 additions & 8 deletions crates/dapf/src/cli_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ impl DefaultVdafConfigs {
fn into_vdaf_config(self) -> VdafConfig {
match self {
Self::Prio2Dimension99k => VdafConfig::Prio2 { dimension: 99_992 },
Self::Prio3Draft09NumProofs2 => {
VdafConfig::Prio3Draft09(Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
Self::Prio3Draft09NumProofs2 => VdafConfig::Prio3(
Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits: 1,
length: 100_000,
chunk_length: 320,
num_proofs: 2,
})
}
Self::Prio3Draft09NumProofs3 => {
VdafConfig::Prio3Draft09(Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
},
),
Self::Prio3Draft09NumProofs3 => VdafConfig::Prio3(
Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits: 1,
length: 100_000,
chunk_length: 320,
num_proofs: 3,
})
}
},
),
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions crates/daphne-server/src/roles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,32 +186,36 @@ mod test_utils {
cmd.vdaf.bits,
cmd.vdaf.length,
cmd.vdaf.chunk_length,
cmd.vdaf.dimension,
) {
("Prio3Count", None, None, None) => VdafConfig::Prio3Draft09(Prio3Config::Count),
("Prio3Sum", Some(bits), None, None) => VdafConfig::Prio3Draft09(Prio3Config::Sum {
bits: bits.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse bits for Prio3Config::Sum"))?,
("Prio3Count", None, None, None, None) => VdafConfig::Prio3(Prio3Config::Count),
("Prio3Sum", Some(max_measurement), None, None, None) => VdafConfig::Prio3(Prio3Config::Sum {
max_measurement: max_measurement.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse bits for Prio3Config::Sum"))?,
}),
("Prio3SumVec", Some(bits), Some(length), Some(chunk_length)) => {
VdafConfig::Prio3Draft09(Prio3Config::SumVec {
("Prio3SumVec", Some(bits), Some(length), Some(chunk_length), None) => {
VdafConfig::Prio3(Prio3Config::SumVec {
bits: bits.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse bits for Prio3Config::SumVec"))?,
length: length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse length for Prio3Config::SumVec"))?,
chunk_length: chunk_length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse chunk_length for Prio3Config::SumVec"))?,
})
}
("Prio3Histogram", None, Some(length), Some(chunk_length)) => {
VdafConfig::Prio3Draft09(Prio3Config::Histogram {
("Prio3Histogram", None, Some(length), Some(chunk_length), None) => {
VdafConfig::Prio3(Prio3Config::Histogram {
length: length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse length for Prio3Config::Histogram"))?,
chunk_length: chunk_length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse chunk_length for Prio3Config::Histogram"))?,
})
}
("Prio3SumVecField64MultiproofHmacSha256Aes128", Some(bits), Some(length), Some(chunk_length)) => {
VdafConfig::Prio3Draft09(Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
("Prio3SumVecField64MultiproofHmacSha256Aes128", Some(bits), Some(length), Some(chunk_length), None) => {
VdafConfig::Prio3(Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits: bits.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse bits for Prio3Config::SumVecField64MultiproofHmacSha256Aes128"))?,
length: length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse length for Prio3Config::SumVecField64MultiproofHmacSha256Aes128"))?,
chunk_length: chunk_length.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse chunk_length for Prio3Config::SumVecField64MultiproofHmacSha256Aes128"))?,
num_proofs: 2,
})
}
("Prio2", None, None, None, Some(dimension)) => VdafConfig::Prio2 {
dimension: dimension.parse().map_err(|e| fatal_error!(err = ?e, "failed to parse dimension for Prio2"))?,
},
_ => return Err(fatal_error!(err = "command failed: unrecognized VDAF")),
};

Expand Down
39 changes: 22 additions & 17 deletions crates/daphne-server/tests/e2e/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ async fn hpke_configs_are_cached(version: DapVersion) {

async_test_versions! { hpke_configs_are_cached }

// TODO draft02 cleanup: In draft09, the client is meant to PUT its report, not POST it.
async fn leader_upload(version: DapVersion) {
let t = TestRunner::default_with_version(version).await;
let mut rng = thread_rng();
Expand All @@ -171,7 +170,7 @@ async fn leader_upload(version: DapVersion) {
&hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U64(23),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap();
Expand Down Expand Up @@ -202,7 +201,7 @@ async fn leader_upload(version: DapVersion) {
&hpke_config_list,
t.now,
&bad_id,
DapMeasurement::U64(999),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand All @@ -222,7 +221,7 @@ async fn leader_upload(version: DapVersion) {
&hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U64(999),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap();
Expand Down Expand Up @@ -264,7 +263,7 @@ async fn leader_upload(version: DapVersion) {
&hpke_config_list,
t.task_config.not_after, // past the expiration date
&t.task_id,
DapMeasurement::U64(23),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap();
Expand Down Expand Up @@ -352,7 +351,7 @@ async fn leader_back_compat_upload(version: DapVersion) {
&hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U64(23),
DapMeasurement::U32Vec(vec![0; 10]),
version,
)
.unwrap();
Expand Down Expand Up @@ -561,7 +560,7 @@ async fn internal_leader_process(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -641,7 +640,7 @@ async fn leader_collect_ok(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -707,7 +706,10 @@ async fn leader_collect_ok(version: DapVersion) {
.unwrap();
assert_eq!(
agg_res,
DapAggregateResult::U128(u128::from(t.task_config.min_batch_size))
DapAggregateResult::U32Vec(vec![
u32::try_from(t.task_config.min_batch_size).unwrap();
10
])
);

// Check that the time interval for the reports is correct.
Expand Down Expand Up @@ -739,7 +741,7 @@ async fn leader_collect_ok(version: DapVersion) {
// "upload",
// DapMediaType::Report,
// t.task_config.vdaf
// .produce_report(&hpke_config_list, now, &t.task_id, DapMeasurement::U64(1))
// .produce_report(&hpke_config_list, now, &t.task_id, DapMeasurement::U32Vec(vec![1; 10]))
// .unwrap()
// .get_encoded(),
// 400,
Expand Down Expand Up @@ -779,7 +781,7 @@ async fn leader_collect_ok_interleaved(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -843,7 +845,7 @@ async fn leader_collect_not_ready_min_batch_size(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -936,7 +938,7 @@ async fn leader_collect_back_compat(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -1091,7 +1093,7 @@ async fn leader_collect_abort_overlapping_batch_interval(version: DapVersion) {
&hpke_config_list,
now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -1187,7 +1189,7 @@ async fn leader_selected() {
&hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down Expand Up @@ -1256,7 +1258,10 @@ async fn leader_selected() {
.unwrap();
assert_eq!(
agg_res,
DapAggregateResult::U128(u128::from(t.task_config.min_batch_size))
DapAggregateResult::U32Vec(vec![
u32::try_from(t.task_config.min_batch_size).unwrap();
10
])
);

// Collector: Poll the collect URI once more. Expect the response to be the same as the first,
Expand All @@ -1282,7 +1287,7 @@ async fn leader_selected() {
&hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U64(1),
DapMeasurement::U32Vec(vec![1; 10]),
version,
)
.unwrap()
Expand Down
11 changes: 6 additions & 5 deletions crates/daphne-server/tests/e2e/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use daphne::{
encode_base64url, taskprov::TaskprovAdvertisement, Base64Encode, BatchId, CollectionJobId,
Duration, HpkeConfigList, Interval, TaskId,
},
vdaf::{Prio3Config, VdafConfig},
vdaf::VdafConfig,
DapBatchMode, DapGlobalConfig, DapLeaderProcessTelemetry, DapTaskConfig, DapVersion,
};
use daphne_service_utils::http_headers;
Expand All @@ -29,7 +29,8 @@ use std::{
use tokio::time::timeout;
use url::Url;

const VDAF_CONFIG: &VdafConfig = &VdafConfig::Prio3Draft09(Prio3Config::Sum { bits: 10 });
// Use a VDAF that is supported in all versions of DAP.
const VDAF_CONFIG: &VdafConfig = &VdafConfig::Prio2 { dimension: 10 };
pub(crate) const MIN_BATCH_SIZE: u64 = 10;
pub(crate) const MAX_BATCH_SIZE: u32 = 12;
pub(crate) const TIME_PRECISION: Duration = 3600; // seconds
Expand Down Expand Up @@ -167,10 +168,10 @@ impl TestRunner {
encode_base64url(t.collector_hpke_receiver.config.get_encoded().unwrap());

let vdaf = json!({
"type": "Prio3Sum",
"bits": assert_matches!(
"type": "Prio2",
"dimension": assert_matches!(
t.task_config.vdaf,
VdafConfig::Prio3Draft09(Prio3Config::Sum{ bits }) => format!("{bits}")
VdafConfig::Prio2{ dimension } => format!("{dimension}")
),
});

Expand Down
54 changes: 21 additions & 33 deletions crates/daphne-service-utils/src/test_route_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,44 @@ pub struct InternalTestVdaf {
pub length: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub chunk_length: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dimension: Option<String>,
}

impl From<VdafConfig> for InternalTestVdaf {
fn from(vdaf: VdafConfig) -> Self {
let (typ, bits, length, chunk_length) = match vdaf {
VdafConfig::Prio3Draft09(prio3) => match prio3 {
Prio3Config::Count => ("Prio3Draft09Count", None, None, None),
Prio3Config::Sum { bits } => ("Prio3Draft09Sum", Some(bits), None, None),
let (typ, bits, length, chunk_length, dimension) = match vdaf {
VdafConfig::Prio3(prio3) => match prio3 {
Prio3Config::Count => ("Prio3Count", None, None, None, None),
Prio3Config::Sum { max_measurement } => (
"Prio3Sum",
Some(usize::try_from(max_measurement).unwrap()),
None,
None,
None,
),
Prio3Config::Histogram {
length,
chunk_length,
} => (
"Prio3Draft09Histogram",
"Prio3Histogram",
None,
Some(length),
Some(chunk_length),
None,
),
Prio3Config::SumVec {
bits,
length,
chunk_length,
} => (
"Prio3Draft09SumVec",
"Prio3SumVec",
Some(bits),
Some(length),
Some(chunk_length),
None,
),
Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
Prio3Config::Draft09SumVecField64MultiproofHmacSha256Aes128 {
bits,
length,
chunk_length,
Expand All @@ -67,34 +77,11 @@ impl From<VdafConfig> for InternalTestVdaf {
Some(bits),
Some(length),
Some(chunk_length),
None,
),
},
VdafConfig::Prio3(prio3) => match prio3 {
Prio3Config::Count => ("Prio3Count", None, None, None),
Prio3Config::Sum { bits } => ("Prio3Sum", Some(bits), None, None),
Prio3Config::Histogram {
length,
chunk_length,
} => ("Prio3Histogram", None, Some(length), Some(chunk_length)),
Prio3Config::SumVec {
bits,
length,
chunk_length,
} => ("Prio3SumVec", Some(bits), Some(length), Some(chunk_length)),
Prio3Config::SumVecField64MultiproofHmacSha256Aes128 {
bits,
length,
chunk_length,
num_proofs: _unimplemented,
} => (
"Prio3SumVecField64MultiproofHmacSha256Aes128",
Some(bits),
Some(length),
Some(chunk_length),
),
},
VdafConfig::Prio2 { .. } => ("Prio2", None, None, None),
VdafConfig::Pine(_) => ("Pine", None, None, None),
VdafConfig::Prio2 { dimension } => ("Prio2", None, None, None, Some(dimension)),
VdafConfig::Pine(_) => ("Pine", None, None, None, None),
#[cfg(feature = "experimental")]
VdafConfig::Mastic { .. } => todo!(),
};
Expand All @@ -103,6 +90,7 @@ impl From<VdafConfig> for InternalTestVdaf {
bits: bits.map(|a| a.to_string()),
length: length.map(|a| a.to_string()),
chunk_length: chunk_length.map(|a| a.to_string()),
dimension: dimension.map(|a| a.to_string()),
}
}
}
Expand Down
Loading

0 comments on commit 4d3dd54

Please sign in to comment.