Skip to content

Commit

Permalink
Use u32 for TaskProv's histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
tholop authored and cjpatton committed Jul 14, 2023
1 parent dbd506d commit bce9e8a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions daphne/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ pub enum Prio3Config {
/// equal to `0` or `1`.
Count,

/// A histogram for estimating the distribution of 64-bit, unsigned integers using pre-defined
/// bucket boundaries.
/// A histogram for estimating the distribution of 64-bit, unsigned integers where each
/// measurement is a bucket index in range `[0, len)`.
Histogram { len: usize },

/// The sum of 64-bit, unsigned integers. Each measurement is an integer in range `[0,
Expand Down
2 changes: 1 addition & 1 deletion daphne/src/messages/mod_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn read_unsupported_hpke_config() {
);
}

// NOTE: these test vectors are no longer valid, TaskProv doesn't match the VDAF-06
// NOTE: these test vectors are no longer valid, TaskProv doesn't match the VDAF-06 spec.
// Tracking the issue here: https://github.com/wangshan/draft-wang-ppm-dap-taskprov/issues/33.
// #[test]
// fn read_vdaf_config() {
Expand Down
10 changes: 6 additions & 4 deletions daphne/src/messages/taskprov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl KeyType for VdafType {
pub enum VdafTypeVar {
Prio3Aes128Count,
Prio3Aes128Sum { bit_length: u8 },
Prio3Aes128Histogram { len_length: u8 },
// NOTE: this doesn't comply with the TaskProv spec, which doesn't match the VDAF-06 spec.
// Tracking the issue here: https://github.com/wangshan/draft-wang-ppm-dap-taskprov/issues/33.
Prio3Aes128Histogram { len: u32 },
Poplar1Aes128 { bit_length: u16 },
NotImplemented(u32),
}
Expand All @@ -67,9 +69,9 @@ impl Encode for VdafTypeVar {
VDAF_TYPE_PRIO3_AES128_SUM.encode(bytes);
bit_length.encode(bytes);
}
VdafTypeVar::Prio3Aes128Histogram { len_length } => {
VdafTypeVar::Prio3Aes128Histogram { len } => {
VDAF_TYPE_PRIO3_AES128_HISTOGRAM.encode(bytes);
len_length.encode(bytes);
len.encode(bytes);
}
VdafTypeVar::Poplar1Aes128 { bit_length } => {
VDAF_TYPE_POPLAR1_AES128.encode(bytes);
Expand All @@ -91,7 +93,7 @@ impl Decode for VdafTypeVar {
bit_length: u8::decode(bytes)?,
}),
VDAF_TYPE_PRIO3_AES128_HISTOGRAM => Ok(Self::Prio3Aes128Histogram {
len_length: u8::decode(bytes)?,
len: u32::decode(bytes)?,
}),
VDAF_TYPE_POPLAR1_AES128 => Ok(Self::Poplar1Aes128 {
bit_length: u16::decode(bytes)?,
Expand Down
4 changes: 2 additions & 2 deletions daphne/src/taskprov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ impl From<VdafTypeVar> for VdafConfig {
fn from(var: VdafTypeVar) -> Self {
match var {
VdafTypeVar::Prio3Aes128Count => VdafConfig::Prio3(Prio3Config::Count),
VdafTypeVar::Prio3Aes128Histogram { len_length } => {
VdafTypeVar::Prio3Aes128Histogram { len } => {
VdafConfig::Prio3(Prio3Config::Histogram {
len: len_length.into(),
len: len.try_into().unwrap(),
})
}
VdafTypeVar::Prio3Aes128Sum { bit_length } => VdafConfig::Prio3(Prio3Config::Sum {
Expand Down
2 changes: 1 addition & 1 deletion daphne/src/taskprov_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_resolve_advertised_task_config() {
task_expiration: 0x6352f9a5,
vdaf_config: VdafConfig {
dp_config: DpConfig::None,
var: VdafTypeVar::Prio3Aes128Histogram { len_length: 1 },
var: VdafTypeVar::Prio3Aes128Histogram { len: 3 },
},
};

Expand Down
3 changes: 2 additions & 1 deletion daphne/src/vdaf/prio3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pub(crate) fn prio3_shard(
}
(Prio3Config::Histogram { len }, DapMeasurement::U64(measurement)) => {
let vdaf = Prio3::new_histogram(2, *len)?;
Ok(shard!(vdaf, &(measurement as usize), nonce))
let m: usize = measurement.try_into().unwrap();
Ok(shard!(vdaf, &m, nonce))
}
(Prio3Config::Sum { bits }, DapMeasurement::U64(measurement)) => {
let vdaf = Prio3::new_sum(2, *bits)?;
Expand Down
1 change: 1 addition & 0 deletions daphne_worker/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ impl<'srv> DaphneWorker<'srv> {
}
// NOTE: the VDAF-06 format is not supported yet
// https://datatracker.ietf.org/doc/html/draft-dcook-ppm-dap-interop-test-design-04#name-internal-test-add_task
// Issue tracked here: https://github.com/divergentdave/draft-dcook-ppm-dap-interop-test-design/issues/40
("Prio3Histogram", Some(len), None) => {
let len = len.parse().map_err(int_err)?;
VdafConfig::Prio3(Prio3Config::Histogram { len })
Expand Down

0 comments on commit bce9e8a

Please sign in to comment.