diff --git a/crates/daphne/src/vdaf/mod.rs b/crates/daphne/src/vdaf/mod.rs index 6ce9ce8c..d3eabf1e 100644 --- a/crates/daphne/src/vdaf/mod.rs +++ b/crates/daphne/src/vdaf/mod.rs @@ -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, @@ -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, @@ -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 @@ -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), @@ -365,7 +363,7 @@ impl ParameterizedDecode 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 { .. } => { diff --git a/crates/daphne/src/vdaf/prio2.rs b/crates/daphne/src/vdaf/prio2.rs index 4eb873aa..c0cca4e2 100644 --- a/crates/daphne/src/vdaf/prio2.rs +++ b/crates/daphne/src/vdaf/prio2.rs @@ -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::{ @@ -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" @@ -71,7 +72,10 @@ pub(crate) fn prio2_prep_init( <()>::get_decoded_with_param(&vdaf, public_share_data)?; let input_share: Share = Share::get_decoded_with_param(&(&vdaf, agg_id), input_share_data)?; - 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))) } @@ -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)", @@ -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)) } @@ -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)", @@ -133,7 +139,7 @@ pub(crate) fn prio2_prep_finish( ))) } }; - let agg_share = VdafAggregateShare::Field32Draft09(vdaf.aggregate(&(), [out_share])?); + let agg_share = VdafAggregateShare::Field32(vdaf.aggregate(&(), [out_share])?); Ok(agg_share) }