Skip to content

Commit

Permalink
Merge pull request #1394 from andyleiserson/malicious-sharded-shuffle
Browse files Browse the repository at this point in the history
Malicious sharded shuffle
  • Loading branch information
andyleiserson authored Nov 4, 2024
2 parents 91aa71d + 7731424 commit d5cc8f8
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 185 deletions.
29 changes: 26 additions & 3 deletions ipa-core/src/protocol/context/malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use ipa_step::{Step, StepNarrow};

use crate::{
error::Error,
helpers::{Gateway, MpcMessage, MpcReceivingEnd, Role, SendingEnd, TotalRecords},
helpers::{
Gateway, Message, MpcMessage, MpcReceivingEnd, Role, SendingEnd, ShardReceivingEnd,
TotalRecords,
},
protocol::{
basics::mul::{semi_honest_multiply, step::MaliciousMultiplyStep::RandomnessForValidation},
context::{
Expand All @@ -19,7 +22,7 @@ use crate::{
step::UpgradeStep,
upgrade::Upgradable,
validator::{self, BatchValidator},
Base, Context as ContextTrait, InstrumentedSequentialSharedRandomness,
Base, Context as ContextTrait, InstrumentedSequentialSharedRandomness, ShardedContext,
SpecialAccessToUpgradedContext, UpgradableContext, UpgradedContext,
},
prss::{Endpoint as PrssEndpoint, FromPrss},
Expand All @@ -30,7 +33,7 @@ use crate::{
semi_honest::AdditiveShare as Replicated,
},
seq_join::SeqJoin,
sharding::{NotSharded, ShardBinding},
sharding::{NotSharded, ShardBinding, ShardConfiguration, ShardIndex, Sharded},
sync::Arc,
};

Expand All @@ -53,6 +56,26 @@ pub struct Context<'a, B: ShardBinding> {
inner: Base<'a, B>,
}

impl ShardConfiguration for Context<'_, Sharded> {
fn shard_id(&self) -> ShardIndex {
self.inner.shard_id()
}

fn shard_count(&self) -> ShardIndex {
self.inner.shard_count()
}
}

impl ShardedContext for Context<'_, Sharded> {
fn shard_send_channel<M: Message>(&self, dest_shard: ShardIndex) -> SendingEnd<ShardIndex, M> {
self.inner.shard_send_channel(dest_shard)
}

fn shard_recv_channel<M: Message>(&self, origin: ShardIndex) -> ShardReceivingEnd<M> {
self.inner.shard_recv_channel(origin)
}
}

impl<'a> Context<'a, NotSharded> {
pub fn new(participant: &'a PrssEndpoint, gateway: &'a Gateway) -> Self {
Self::new_with_gate(participant, gateway, Gate::default(), NotSharded)
Expand Down
1 change: 1 addition & 0 deletions ipa-core/src/protocol/context/semi_honest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
pub struct Context<'a, B: ShardBinding> {
inner: Base<'a, B>,
}

impl ShardConfiguration for Context<'_, Sharded> {
fn shard_id(&self) -> ShardIndex {
self.inner.shard_id()
Expand Down
26 changes: 8 additions & 18 deletions ipa-core/src/protocol/ipa_prf/shuffle/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
let mut x_2 = x_1.clone();
add_single_shares_in_place(&mut x_2, z_31);
x_2.shuffle(&mut rng_perm_l);
send_to_peer(&x_2, ctx, &OPRFShuffleStep::TransferX2, Direction::Right).await?;
send_to_peer(&x_2, ctx, &OPRFShuffleStep::TransferXY, Direction::Right).await?;

let res = combine_single_shares(a_hat, b_hat).collect::<Vec<_>>();
// we only need to store x_1 in IntermediateShuffleMessage
Expand Down Expand Up @@ -130,12 +130,12 @@ where

let mut x_2: Vec<S> = Vec::with_capacity(batch_size.get());
future::try_join(
send_to_peer(&y_1, ctx, &OPRFShuffleStep::TransferY1, Direction::Right),
send_to_peer(&y_1, ctx, &OPRFShuffleStep::TransferXY, Direction::Right),
receive_from_peer_into(
&mut x_2,
batch_size,
ctx,
&OPRFShuffleStep::TransferX2,
&OPRFShuffleStep::TransferXY,
Direction::Left,
),
)
Expand All @@ -153,17 +153,12 @@ where

let mut c_hat_2 = repurpose_allocation(x_3);
future::try_join(
send_to_peer(
&c_hat_1,
ctx,
&OPRFShuffleStep::TransferCHat,
Direction::Right,
),
send_to_peer(&c_hat_1, ctx, &OPRFShuffleStep::TransferC, Direction::Right),
receive_from_peer_into(
&mut c_hat_2,
batch_size,
ctx,
&OPRFShuffleStep::TransferCHat,
&OPRFShuffleStep::TransferC,
Direction::Right,
),
)
Expand Down Expand Up @@ -199,7 +194,7 @@ where
&mut y_1,
batch_size,
ctx,
&OPRFShuffleStep::TransferY1,
&OPRFShuffleStep::TransferXY,
Direction::Left,
)
.await?;
Expand All @@ -224,17 +219,12 @@ where
let c_hat_2: Vec<S> = add_single_shares(y_3.iter(), a_hat.iter()).collect();
let mut c_hat_1 = repurpose_allocation(y_3);
future::try_join(
send_to_peer(
&c_hat_2,
ctx,
&OPRFShuffleStep::TransferCHat,
Direction::Left,
),
send_to_peer(&c_hat_2, ctx, &OPRFShuffleStep::TransferC, Direction::Left),
receive_from_peer_into(
&mut c_hat_1,
batch_size,
ctx,
&OPRFShuffleStep::TransferCHat,
&OPRFShuffleStep::TransferC,
Direction::Left,
),
)
Expand Down
Loading

0 comments on commit d5cc8f8

Please sign in to comment.