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

Prio3Count: Don't branch when converting to bool #743

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 2 additions & 12 deletions crates/daphne/src/vdaf/prio3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@ pub(crate) fn prio3_shard(
task_id: TaskId,
) -> Result<(Vec<u8>, [Vec<u8>; 2]), VdafError> {
match (config, measurement) {
(Prio3Config::Count, DapMeasurement::U64(measurement)) => {
(Prio3Config::Count, DapMeasurement::U64(measurement)) if measurement < 2 => {
let vdaf = Prio3::new_count(2).map_err(|e| {
VdafError::Dap(
fatal_error!(err = ?e, "failed to create prio3 count from num_aggregators(2)"),
)
})?;
// TODO(cjpatton) Make this constant time.
let measurement = match measurement {
0 => false,
1 => true,
_ => {
return Err(VdafError::Dap(fatal_error!(
err = "cannot represent measurement as a 0 or 1"
)))
}
};
shard_then_encode(&vdaf, task_id, &measurement, nonce)
shard_then_encode(&vdaf, task_id, &(measurement != 0), nonce)
}
(
Prio3Config::Histogram {
Expand Down
14 changes: 2 additions & 12 deletions crates/daphne/src/vdaf/prio3_draft09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,13 @@ pub(crate) fn prio3_draft09_shard(
nonce: &[u8; 16],
) -> Result<(Vec<u8>, [Vec<u8>; 2]), VdafError> {
match (config, measurement) {
(Prio3Config::Count, DapMeasurement::U64(measurement)) => {
(Prio3Config::Count, DapMeasurement::U64(measurement)) if measurement < 2 => {
let vdaf = Prio3::new_count(2).map_err(|e| {
VdafError::Dap(
fatal_error!(err = ?e, "failed to create prio3 count from num_aggregators(2)"),
)
})?;
// TODO(cjpatton) Make this constant time.
let measurement = match measurement {
0 => false,
1 => true,
_ => {
return Err(VdafError::Dap(fatal_error!(
err = "cannot represent measurement as a 0 or 1"
)))
}
};
shard_then_encode_draft09(&vdaf, &measurement, nonce)
shard_then_encode_draft09(&vdaf, &(measurement != 0), nonce)
}
(
Prio3Config::Histogram {
Expand Down
Loading