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

Bump Prio2 to VDAF-13 Take #2 #745

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
12 changes: 5 additions & 7 deletions crates/daphne/src/vdaf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ use prio::{
codec::{CodecError, Encode, ParameterizedDecode},
field::{Field128, Field64, FieldPrio2},
vdaf::{
prio2::{Prio2PrepareShare, Prio2PrepareState},
prio3::{Prio3PrepareShare, Prio3PrepareState},
AggregateShare, Aggregator, Client, Collector, PrepareTransition, Vdaf,
},
};

#[cfg(feature = "experimental")]
#[cfg(any(test, feature = "test-utils", feature = "experimental"))]
use prio::field::FieldElement;
#[cfg(any(test, feature = "test-utils"))]
use prio_draft09::field::FieldElement as FieldElementDraft09;
use prio_draft09::{
codec::{
CodecError as CodecErrorDraft09, Encode as EncodeDraft09,
Expand All @@ -36,7 +35,6 @@ use prio_draft09::{
Field128 as Field128Draft09, Field64 as Field64Draft09, FieldPrio2 as FieldPrio2Draft09,
},
vdaf::{
prio2::{Prio2PrepareShare, Prio2PrepareState},
prio3::{
Prio3PrepareShare as Prio3Draft09PrepareShare,
Prio3PrepareState as Prio3Draft09PrepareState,
Expand Down Expand Up @@ -293,7 +291,7 @@ impl deepsize::DeepSizeOf for VdafPrepShare {
fn deep_size_of_children(&self, _context: &mut deepsize::Context) -> usize {
match self {
// The Prio2 prep share consists of three field elements.
Self::Prio2(_msg) => 3 * FieldPrio2Draft09::ENCODED_SIZE,
Self::Prio2(_msg) => 3 * FieldPrio2::ENCODED_SIZE,
// The Prio3 prep share consists of an optional XOF seed for the Aggregator's joint
// randomness part and a sequence of field elements for the Aggregator's verifier
// share. The length of the verifier share depends on the Prio3 type, which we don't
Expand Down Expand Up @@ -324,7 +322,7 @@ impl Encode for VdafPrepShare {
Self::Prio3Field64(share) => share.encode(bytes),
Self::Prio3Field64HmacSha256Aes128(share) => share.encode(bytes),
Self::Prio3Field128(share) => share.encode(bytes),
Self::Prio2(share) => share.encode(bytes).map_err(from_codec_error),
Self::Prio2(share) => share.encode(bytes),
#[cfg(feature = "experimental")]
Self::Mastic(share) => share.encode(bytes),
Self::Pine64HmacSha256Aes128(share) => share.encode(bytes).map_err(from_codec_error),
Expand Down Expand Up @@ -365,7 +363,7 @@ impl ParameterizedDecode<VdafPrepState> for VdafPrepShare {
Prio3PrepareShare::decode_with_param(state, bytes)?,
)),
VdafPrepState::Prio2(state) => Ok(VdafPrepShare::Prio2(
Prio2PrepareShare::decode_with_param(state, bytes).map_err(from_codec_error)?,
Prio2PrepareShare::decode_with_param(state, bytes)?,
)),
#[cfg(feature = "experimental")]
VdafPrepState::Mastic { .. } => {
Expand Down
22 changes: 14 additions & 8 deletions crates/daphne/src/vdaf/prio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
fatal_error, vdaf::VdafError, DapAggregateResult, DapMeasurement, VdafAggregateShare,
VdafPrepShare, VdafPrepState, VdafVerifyKey,
};
use prio_draft09::{
use prio::{
codec::{Decode, Encode, ParameterizedDecode},
field::FieldPrio2,
vdaf::{
Expand All @@ -27,7 +27,8 @@ pub(crate) fn prio2_shard(
VdafError::Dap(fatal_error!(err = ?e, "failed to create prio2 from {dimension}"))
})?;
let (public_share, input_shares) = match measurement {
DapMeasurement::U32Vec(ref data) => vdaf.shard(data, nonce)?,
// Prio2 ignores the ctx string, so we don't construct it.
DapMeasurement::U32Vec(ref data) => vdaf.shard(&[], data, nonce)?,
_ => {
return Err(VdafError::Dap(fatal_error!(
err = "prio2_shard: unexpected measurement type"
Expand Down Expand Up @@ -71,7 +72,10 @@ pub(crate) fn prio2_prep_init(
<()>::get_decoded_with_param(&vdaf, public_share_data)?;
let input_share: Share<FieldPrio2, 32> =
Share::get_decoded_with_param(&(&vdaf, agg_id), input_share_data)?;
cjpatton marked this conversation as resolved.
Show resolved Hide resolved
let (state, share) = vdaf.prepare_init(verify_key, agg_id, &(), nonce, &(), &input_share)?;

// Prio2 ignores the ctx string, so we don't construct it.
let (state, share) =
vdaf.prepare_init(verify_key, &[], agg_id, &(), nonce, &(), &input_share)?;
Ok((VdafPrepState::Prio2(state), VdafPrepShare::Prio2(share)))
}

Expand All @@ -88,8 +92,9 @@ pub(crate) fn prio2_prep_finish_from_shares(
let (out_share, outbound) = match (host_state, host_share) {
(VdafPrepState::Prio2(state), VdafPrepShare::Prio2(share)) => {
let peer_share = Prio2PrepareShare::get_decoded_with_param(&state, peer_share_data)?;
vdaf.prepare_shares_to_prepare_message(&(), [share, peer_share])?;
match vdaf.prepare_next(state, ())? {
// Prio2 ignores the ctx string, so we don't construct it.
vdaf.prepare_shares_to_prepare_message(&[], &(), [share, peer_share])?;
match vdaf.prepare_next(&[], state, ())? {
PrepareTransition::Continue(..) => {
return Err(VdafError::Dap(fatal_error!(
err = "prio2_prep_finish_from_shares: unexpected transition (continued)",
Expand All @@ -104,7 +109,7 @@ pub(crate) fn prio2_prep_finish_from_shares(
)))
}
};
let agg_share = VdafAggregateShare::Field32Draft09(vdaf.aggregate(&(), [out_share])?);
let agg_share = VdafAggregateShare::Field32(vdaf.aggregate(&(), [out_share])?);
Ok((agg_share, outbound))
}

Expand All @@ -118,8 +123,9 @@ pub(crate) fn prio2_prep_finish(
VdafError::Dap(fatal_error!(err = ?e, "failed to create prio2 from {dimension}"))
})?;
<()>::get_decoded(peer_message_data)?;
// Prio2 ignores the ctx string, so we don't construct it.
let out_share = match host_state {
VdafPrepState::Prio2(state) => match vdaf.prepare_next(state, ())? {
VdafPrepState::Prio2(state) => match vdaf.prepare_next(&[], state, ())? {
PrepareTransition::Continue(..) => {
return Err(VdafError::Dap(fatal_error!(
err = "prio2_prep_finish: unexpected transition (continued)",
Expand All @@ -133,7 +139,7 @@ pub(crate) fn prio2_prep_finish(
)))
}
};
let agg_share = VdafAggregateShare::Field32Draft09(vdaf.aggregate(&(), [out_share])?);
jhoyla marked this conversation as resolved.
Show resolved Hide resolved
let agg_share = VdafAggregateShare::Field32(vdaf.aggregate(&(), [out_share])?);
Ok(agg_share)
}

Expand Down
Loading