Skip to content

Commit

Permalink
add plumbing for starting a hybrid query
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck committed Dec 5, 2024
1 parent 5015b71 commit 4bff1d6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
19 changes: 17 additions & 2 deletions ipa-core/src/query/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::{
Gate,
},
query::{
runner::{OprfIpaQuery, QueryResult},
runner::{execute_hybrid_protocol, OprfIpaQuery, QueryResult},
state::RunningQuery,
},
sync::Arc,
Expand Down Expand Up @@ -165,7 +165,22 @@ pub fn execute<R: PrivateKeyRegistry>(
)
},
),
(QueryType::MaliciousHybrid(_), _) => todo!(),
(QueryType::MaliciousHybrid(ipa_config), _) => do_query(
runtime,
config,
gateway,
input,
move |prss, gateway, config, input| {
Box::pin(execute_hybrid_protocol(
prss,
gateway,
input,
ipa_config,
config,
key_registry,
))
},
),

Check warning on line 183 in ipa-core/src/query/executor.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/query/executor.rs#L168-L183

Added lines #L168 - L183 were not covered by tests
}
}

Expand Down
41 changes: 36 additions & 5 deletions ipa-core/src/query/runner/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ use std::{
use futures::{stream::iter, StreamExt, TryStreamExt};
use generic_array::ArrayLength;

use super::QueryResult;
use crate::{
error::{Error, LengthError},
ff::{
boolean::Boolean,
boolean_array::{BooleanArray, BA3, BA8},
boolean_array::{BooleanArray, BA16, BA3, BA8},
curve_points::RP25519,
ec_prime_field::Fp25519,
Serializable, U128Conversions,
},
helpers::{
query::{DpMechanism, HybridQueryParams, QuerySize},
BodyStream, LengthDelimitedStream,
query::{DpMechanism, HybridQueryParams, QueryConfig, QuerySize},
setup_cross_shard_prss, BodyStream, Gateway, LengthDelimitedStream,
},
hpke::PrivateKeyRegistry,
protocol::{
basics::{shard_fin::FinalizerContext, BooleanArrayMul, BooleanProtocols, Reveal},
context::{DZKPUpgraded, MacUpgraded, ShardedContext, UpgradableContext},
context::{
DZKPUpgraded, MacUpgraded, ShardedContext, ShardedMaliciousContext, UpgradableContext,
},
hybrid::{
hybrid_protocol,
oprf::{CONV_CHUNK, PRF_CHUNK},
step::HybridStep,
},
ipa_prf::{oprf_padding::PaddingParameters, prf_eval::PrfSharing, shuffle::Shuffle},
prss::FromPrss,
prss::{Endpoint, FromPrss},
step::ProtocolStep::Hybrid,
Gate,
},
query::runner::reshard_tag::reshard_aad,
report::hybrid::{
Expand All @@ -42,6 +46,7 @@ use crate::{
replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, TransposeFrom,
Vectorizable,
},
sharding::{ShardConfiguration, Sharded},
};

#[allow(dead_code)]
Expand Down Expand Up @@ -165,6 +170,32 @@ where
}
}

pub async fn execute_hybrid_protocol<'a, R: PrivateKeyRegistry>(
prss: &'a Endpoint,
gateway: &'a Gateway,
input: BodyStream,
ipa_config: HybridQueryParams,
config: &QueryConfig,
key_registry: Arc<R>,
) -> QueryResult {
let gate = Gate::default();
let cross_shard_prss =
setup_cross_shard_prss(gateway, &gate, prss.indexed(&gate), gateway).await?;
let sharded = Sharded {
shard_id: gateway.shard_id(),
shard_count: gateway.shard_count(),
prss: Arc::new(cross_shard_prss),
};

let ctx = ShardedMaliciousContext::new_with_gate(prss, gateway, gate, sharded);

Ok(Box::new(
Query::<_, BA16, R>::new(ipa_config, key_registry)
.execute(ctx, config.size, input)
.await?,

Check warning on line 195 in ipa-core/src/query/runner/hybrid.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/query/runner/hybrid.rs#L173-L195

Added lines #L173 - L195 were not covered by tests
))
}

Check warning on line 197 in ipa-core/src/query/runner/hybrid.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/query/runner/hybrid.rs#L197

Added line #L197 was not covered by tests

#[cfg(all(test, unit_test, feature = "in-memory-infra"))]
mod tests {
use std::{
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/query/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(super) use sharded_shuffle::execute_sharded_shuffle;
#[cfg(any(test, feature = "cli", feature = "test-fixture"))]
pub(super) use test_multiply::execute_test_multiply;

pub use self::oprf_ipa::OprfIpaQuery;
pub use self::{hybrid::execute_hybrid_protocol, oprf_ipa::OprfIpaQuery};
use crate::{error::Error, query::ProtocolResult};

pub(super) type QueryResult = Result<Box<dyn ProtocolResult>, Error>;

0 comments on commit 4bff1d6

Please sign in to comment.