Skip to content

Commit

Permalink
Merge pull request #990 from andyleiserson/remove-reshare-record-binding
Browse files Browse the repository at this point in the history
Remove RecordBinding type parameter from Reshare
  • Loading branch information
andyleiserson authored Mar 22, 2024
2 parents 4949f06 + 0466821 commit 29d1f19
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 45 deletions.
6 changes: 2 additions & 4 deletions ipa-core/src/bin/report_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,14 @@ impl KeyRegistries {
network: &NetworkConfig,
) -> Option<(KeyIdentifier, [&KeyRegistry<PublicKeyOnly>; 3])> {
// Get the configs, if all three peers have one
let Some(configs) = network.peers().iter().try_fold(Vec::new(), |acc, peer| {
let configs = network.peers().iter().try_fold(Vec::new(), |acc, peer| {
if let (mut vec, Some(hpke_config)) = (acc, peer.hpke_config.as_ref()) {
vec.push(hpke_config);
Some(vec)
} else {
None
}
}) else {
return None;
};
})?;

// Create key registries
self.0 = configs
Expand Down
4 changes: 1 addition & 3 deletions ipa-core/src/net/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ impl ClientCertRecognizingAcceptor {
network_config: &NetworkConfig,
cert_option: Option<&Certificate>,
) -> Option<ClientIdentity> {
let Some(cert) = cert_option else {
return None;
};
let cert = cert_option?;
// We currently require an exact match with the peer cert (i.e. we don't support verifying
// the certificate against a truststore and identifying the peer by the certificate
// subject). This could be changed if the need arises.
Expand Down
4 changes: 2 additions & 2 deletions ipa-core/src/protocol/basics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use sum_of_product::SumOfProducts;

use crate::{
ff::Field,
protocol::{context::Context, RecordId},
protocol::context::Context,
secret_sharing::{
replicated::semi_honest::AdditiveShare, SecretSharing, SharedValue, Vectorizable,
},
Expand All @@ -34,7 +34,7 @@ use crate::{

pub trait BasicProtocols<C: Context, V: SharedValue + Vectorizable<N>, const N: usize = 1>:
SecretSharing<V>
+ Reshare<C, RecordId>
+ Reshare<C>
+ Reveal<C, N, Output = <V as Vectorizable<N>>::Array>
+ SecureMul<C>
+ ShareKnownValue<C, V>
Expand Down
38 changes: 5 additions & 33 deletions ipa-core/src/protocol/basics/reshare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::iter::{repeat, zip};

use async_trait::async_trait;
use embed_doc_image::embed_doc_image;

use crate::{
error::Error,
ff::Field,
helpers::{Direction, Role},
protocol::{context::Context, prss::SharedRandomness, NoRecord, RecordBinding, RecordId},
protocol::{context::Context, prss::SharedRandomness, RecordId},
secret_sharing::replicated::{
semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing,
},
Expand Down Expand Up @@ -39,11 +37,11 @@ use crate::{
/// `to_helper` = (`rand_left`, `rand_right`) = (r0, r1)
/// `to_helper.right` = (`rand_right`, part1 + part2) = (r0, part1 + part2)
#[async_trait]
pub trait Reshare<C: Context, B: RecordBinding>: Sized + 'static {
pub trait Reshare<C: Context>: Sized + 'static {
async fn reshare<'fut>(
&self,
ctx: C,
record_binding: B,
record_id: RecordId,
to_helper: Role,
) -> Result<Self, Error>
where
Expand All @@ -55,7 +53,7 @@ pub trait Reshare<C: Context, B: RecordBinding>: Sized + 'static {
/// This implements semi-honest reshare algorithm of "Efficient Secure Three-Party Sorting Protocol with an Honest Majority" at communication cost of 2R.
/// Input: Pi-1 and Pi+1 know their secret shares
/// Output: At the end of the protocol, all 3 helpers receive their shares of a new, random secret sharing of the secret value
impl<C: Context, F: Field> Reshare<C, RecordId> for Replicated<F> {
impl<C: Context, F: Field> Reshare<C> for Replicated<F> {
async fn reshare<'fut>(
&self,
ctx: C,
Expand Down Expand Up @@ -108,9 +106,7 @@ impl<C: Context, F: Field> Reshare<C, RecordId> for Replicated<F> {
/// For malicious reshare, we run semi honest reshare protocol twice, once for x and another for rx and return the results
/// # Errors
/// If either of reshares fails
impl<'a, F: ExtendableField> Reshare<UpgradedMaliciousContext<'a, F>, RecordId>
for MaliciousReplicated<F>
{
impl<'a, F: ExtendableField> Reshare<UpgradedMaliciousContext<'a, F>> for MaliciousReplicated<F> {
async fn reshare<'fut>(
&self,
ctx: UpgradedMaliciousContext<'a, F>,
Expand All @@ -137,30 +133,6 @@ impl<'a, F: ExtendableField> Reshare<UpgradedMaliciousContext<'a, F>, RecordId>
}
}

#[async_trait]
impl<S, C: Context> Reshare<C, NoRecord> for Vec<S>
where
S: Reshare<C, RecordId> + Send + Sync,
{
#[tracing::instrument(name = "reshare", skip_all, fields(to = ?to_helper))]
async fn reshare<'fut>(
&self,
ctx: C,
_record_binding: NoRecord,
to_helper: Role,
) -> Result<Vec<S>, Error>
where
C: 'fut,
{
ctx.try_join(
zip(repeat(ctx.set_total_records(self.len())), self.iter())
.enumerate()
.map(|(i, (c, x))| async move { x.reshare(c, RecordId::from(i), to_helper).await }),
)
.await
}
}

#[cfg(all(test, unit_test))]
mod tests {
mod semi_honest {
Expand Down
4 changes: 1 addition & 3 deletions ipa-core/src/protocol/modulus_conversion/convert_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ where
let stream = unfold(
(ctx, locally_converted, first_record),
|(ctx, mut locally_converted, record_id)| async move {
let Some((triple, residual)) = locally_converted.next().await else {
return None;
};
let (triple, residual) = locally_converted.next().await?;
let bit_contexts = (0..).map(|i| ctx.narrow(&ConvertSharesStep::ConvertBit(i)));
let converted =
ctx.parallel_join(zip(bit_contexts, triple).map(|(ctx, triple)| async move {
Expand Down

0 comments on commit 29d1f19

Please sign in to comment.