Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoyla committed Jan 14, 2025
1 parent 5078b99 commit 28ff330
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 118 deletions.
1 change: 1 addition & 0 deletions crates/dapf/src/acceptance/load_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ pub async fn execute_single_combination_from_env(
&measurment,
VERSION,
system_now.0,
Some(vec![]),
vec![messages::Extension::Taskprov],
t.replay_reports,
)
Expand Down
4 changes: 4 additions & 0 deletions crates/dapf/src/acceptance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,10 @@ impl Test {
measurement.as_ref(),
version,
now.0,
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![messages::Extension::Taskprov],
self.replay_reports,
)
Expand Down
20 changes: 18 additions & 2 deletions crates/daphne-server/tests/e2e/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ async fn leader_upload_taskprov() {
t.now,
&task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![Extension::Taskprov],
version,
)
Expand Down Expand Up @@ -447,6 +451,10 @@ async fn leader_upload_taskprov() {
t.now,
&task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![Extension::Taskprov],
version,
)
Expand Down Expand Up @@ -512,6 +520,10 @@ async fn leader_upload_taskprov_wrong_version(version: DapVersion) {
t.now,
&task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![Extension::Taskprov],
version,
)
Expand Down Expand Up @@ -1542,18 +1554,18 @@ async fn leader_collect_taskprov_repeated_abort() {
.unwrap(),
),
{
let mut report = task_config
let report = task_config
.vdaf
.produce_report_with_extensions(
&hpke_config_list,
now,
&task_id,
DapMeasurement::U32Vec(vec![1; 10]),
Some(vec![Extension::Taskprov]),
extensions,
version,
)
.unwrap();
report.report_metadata.public_extensions = Some(vec![Extension::Taskprov]);
report.get_encoded_with_param(&version).unwrap()
},
)
Expand Down Expand Up @@ -1660,6 +1672,10 @@ async fn leader_collect_taskprov_ok(version: DapVersion) {
now,
&task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
extensions,
version,
)
Expand Down
12 changes: 4 additions & 8 deletions crates/daphne/src/error/aborts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,10 @@ impl DapAbort {
task_id: &TaskId,
unknown_extensions: &[u16],
) -> Result<Self, DapError> {
let detail = serde_json::to_string(&unknown_extensions);
match detail {
Ok(s) => Ok(Self::UnsupportedExtension {
detail: s,
task_id: *task_id,
}),
Err(x) => Err(fatal_error!(err = %x,)),
}
Ok(Self::UnsupportedExtension {
detail: format!("{unknown_extensions:?}"),
task_id: *task_id,
})
}

fn title_and_type(&self) -> (&'static str, Option<String>) {
Expand Down
24 changes: 21 additions & 3 deletions crates/daphne/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ impl Decode for HpkeCiphertext {
/// A plaintext input share.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PlaintextInputShare {
pub extensions: Vec<Extension>,
pub private_extensions: Vec<Extension>,
pub payload: Vec<u8>,
}

Expand All @@ -1428,7 +1428,7 @@ impl ParameterizedEncode<DapVersion> for PlaintextInputShare {
version: &DapVersion,
bytes: &mut Vec<u8>,
) -> Result<(), CodecError> {
encode_u16_items(bytes, version, &self.extensions)?;
encode_u16_items(bytes, version, &self.private_extensions)?;
encode_u32_bytes(bytes, &self.payload)?;
Ok(())
}
Expand All @@ -1440,7 +1440,7 @@ impl ParameterizedDecode<DapVersion> for PlaintextInputShare {
bytes: &mut Cursor<&[u8]>,
) -> Result<Self, CodecError> {
Ok(Self {
extensions: decode_u16_items(version, bytes)?,
private_extensions: decode_u16_items(version, bytes)?,
payload: decode_u32_bytes(bytes)?,
})
}
Expand Down Expand Up @@ -1648,6 +1648,24 @@ mod test {

test_versions! {report_metadata_encode_decode}

#[test]
fn report_metadata_encode_latest_decode_draft09() {
let ext_rm = ReportMetadata {
id: ReportId([15; 16]),
time: 123_456,
public_extensions: Some(vec![Extension::NotImplemented {
typ: 0x10,
payload: vec![0x11, 0x12],
}]),
};
let bytes = ext_rm.get_encoded_with_param(&DapVersion::Latest).unwrap();
assert!(matches!(
ReportMetadata::get_decoded_with_param(&DapVersion::Draft09, bytes.as_slice())
.unwrap_err(),
CodecError::BytesLeftOver(..)
));
}

fn partial_batch_selector_encode_decode(version: DapVersion) {
const TEST_DATA_DRAFT09: &[u8] = &[1];
const TEST_DATA_LATEST: &[u8] = &[1, 0, 0];
Expand Down
4 changes: 2 additions & 2 deletions crates/daphne/src/protocol/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause

use super::{
no_duplicates,
check_no_duplicates,
report_init::{InitializedReport, WithPeerPrepShare},
};
use crate::{
Expand Down Expand Up @@ -241,7 +241,7 @@ impl DapTaskConfig {
DapAggregationParam::get_decoded_with_param(&self.vdaf, &agg_job_init_req.agg_param)
.map_err(|e| DapAbort::from_codec_error(e, *task_id))?;
if replay_protection.enabled() {
no_duplicates(
check_no_duplicates(
agg_job_init_req
.prep_inits
.iter()
Expand Down
30 changes: 22 additions & 8 deletions crates/daphne/src/protocol/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ impl VdafConfig {
/// * `extensions` are the extensions.
///
/// * `version` is the `DapVersion` to use.
#[allow(clippy::too_many_arguments)]
pub fn produce_report_with_extensions(
&self,
hpke_config_list: &[HpkeConfig; 2],
time: Time,
task_id: &TaskId,
measurement: DapMeasurement,
extensions: Vec<Extension>,
public_extensions: Option<Vec<Extension>>,
private_extensions: Vec<Extension>,
version: DapVersion,
) -> Result<Report, DapError> {
let mut rng = thread_rng();
Expand All @@ -51,7 +53,8 @@ impl VdafConfig {
time,
task_id,
&report_id,
extensions,
public_extensions,
private_extensions,
version,
)
}
Expand All @@ -65,21 +68,28 @@ impl VdafConfig {
time: Time,
task_id: &TaskId,
report_id: &ReportId,
extensions: Vec<Extension>,
public_extensions: Option<Vec<Extension>>,
private_extensions: Vec<Extension>,
version: DapVersion,
) -> Result<Report, DapError> {
match (&public_extensions, version) {
(Some(_), DapVersion::Draft09) | (None, DapVersion::Latest) => {
return Err(DapError::ReportError(
crate::messages::ReportError::InvalidMessage,
))
}
_ => (),
}

let mut plaintext_input_share = PlaintextInputShare {
extensions,
private_extensions,
payload: Vec::default(),
};

let metadata = ReportMetadata {
id: *report_id,
time,
public_extensions: match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(Vec::new()),
},
public_extensions,
};

let encoded_input_shares = input_shares.into_iter().map(|input_share| {
Expand Down Expand Up @@ -147,6 +157,10 @@ impl VdafConfig {
time,
task_id,
measurement,
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(Vec::new()),
},
Vec::new(),
version,
)
Expand Down
52 changes: 37 additions & 15 deletions crates/daphne/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) mod report_init;

/// checks if an iterator has no duplicate items, returns the ok if there are no dups or an error
/// with the first offending item.
pub(crate) fn no_duplicates<I>(iterator: I) -> Result<(), I::Item>
pub(crate) fn check_no_duplicates<I>(iterator: I) -> Result<(), I::Item>
where
I: Iterator,
I::Item: Eq + std::hash::Hash,
Expand Down Expand Up @@ -752,6 +752,10 @@ mod test {
t.now,
&t.task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![Extension::NotImplemented {
typ: 0xffff,
payload: b"some extension data".to_vec(),
Expand Down Expand Up @@ -784,29 +788,32 @@ mod test {

test_versions! { handle_unrecognized_report_extensions }

fn handle_unknown_public_extensions_in_report(version: DapVersion) {
#[test]
fn handle_unknown_public_extensions_in_report() {
let version = DapVersion::Latest;
let t = AggregationJobTest::new(TEST_VDAF, HpkeKemId::X25519HkdfSha256, version);
let mut report = t
let report = t
.task_config
.vdaf
.produce_report(
.produce_report_with_extensions(
&t.client_hpke_config_list,
t.now,
&t.task_id,
DapMeasurement::U32Vec(vec![1; 10]),
Some(vec![
Extension::NotImplemented {
typ: 0x01,
payload: b"This is ignored".to_vec(),
},
Extension::NotImplemented {
typ: 0x02,
payload: b"This is ignored too".to_vec(),
},
]),
vec![],
version,
)
.unwrap();
report.report_metadata.public_extensions = Some(vec![
Extension::NotImplemented {
typ: 0x01,
payload: b"This is ignored".to_vec(),
},
Extension::NotImplemented {
typ: 0x02,
payload: b"This is ignored too".to_vec(),
},
]);
let report_metadata = report.report_metadata.clone();
let [leader_share, _] = report.encrypted_input_shares;
let initialized_report = InitializedReport::from_client(
Expand All @@ -832,7 +839,6 @@ mod test {
}
);
}
test_versions! {handle_unknown_public_extensions_in_report}

fn handle_repeated_report_extensions(version: DapVersion) {
let t = AggregationJobTest::new(TEST_VDAF, HpkeKemId::X25519HkdfSha256, version);
Expand All @@ -844,6 +850,10 @@ mod test {
t.now,
&t.task_id,
DapMeasurement::U32Vec(vec![1; 10]),
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
vec![
Extension::NotImplemented {
typ: 23,
Expand Down Expand Up @@ -906,6 +916,10 @@ mod test {
self.now,
&self.task_id,
&report_id,
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
Vec::new(), // extensions
version,
)
Expand Down Expand Up @@ -937,6 +951,10 @@ mod test {
self.now,
&self.task_id,
&report_id,
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
Vec::new(), // extensions
version,
)
Expand Down Expand Up @@ -969,6 +987,10 @@ mod test {
self.now,
&self.task_id,
&report_id,
match version {
DapVersion::Draft09 => None,
DapVersion::Latest => Some(vec![]),
},
Vec::new(), // extensions
version,
)
Expand Down
Loading

0 comments on commit 28ff330

Please sign in to comment.