Skip to content

Commit

Permalink
Merge pull request #223 from akoshelev/reveal-trait
Browse files Browse the repository at this point in the history
Reveal trait and its implementations for `ProtocolContext`
  • Loading branch information
martinthomson authored Nov 15, 2022
2 parents f8556eb + 6dd9b4b commit 7565647
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 223 deletions.
6 changes: 5 additions & 1 deletion src/protocol/boolean/prefix_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ mod tests {
test_fixture::{make_contexts, make_world, share, validate_and_reconstruct, TestWorld},
};
use futures::future::try_join_all;
use rand::distributions::{Distribution, Standard};
use rand::{rngs::mock::StepRng, Rng};
use std::iter::zip;

const BITS: [usize; 2] = [16, 32];
const TEST_TRIES: usize = 16;

async fn prefix_or<F: Field>(input: &[F]) -> Result<Vec<F>, BoxError> {
async fn prefix_or<F: Field>(input: &[F]) -> Result<Vec<F>, BoxError>
where
Standard: Distribution<F>,
{
let world: TestWorld = make_world(QueryId);
let ctx = make_contexts::<F>(&world);
let mut rand = StepRng::new(1, 1);
Expand Down
8 changes: 6 additions & 2 deletions src/protocol/check_zero.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::protocol::mul::SecureMul;
use crate::protocol::reveal::Reveal;
use crate::{
error::BoxError,
ff::Field,
protocol::{context::ProtocolContext, reveal::reveal, RecordId},
protocol::{context::ProtocolContext, RecordId},
secret_sharing::Replicated,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -72,7 +73,10 @@ pub async fn check_zero<F: Field>(
.narrow(&Step::MultiplyWithR)
.multiply(record_id, r_sharing, v)
.await?;
let rv = reveal(ctx.narrow(&Step::RevealR), record_id, rv_share).await?;
let rv = ctx
.narrow(&Step::RevealR)
.reveal(record_id, rv_share)
.await?;

Ok(rv == F::ZERO)
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::secret_sharing::{MaliciousReplicated, Replicated, SecretSharing};
/// Context used by each helper to perform computation. Currently they need access to shared
/// randomness generator (see `Participant`) and communication trait to send messages to each other.
#[derive(Clone, Debug)]
pub struct ProtocolContext<'a, S: SecretSharing<F>, F> {
pub struct ProtocolContext<'a, S, F> {
role: Role,
step: Step,
prss: &'a PrssEndpoint,
Expand Down
10 changes: 7 additions & 3 deletions src/protocol/malicious.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::protocol::reveal::Reveal;
use crate::{
error::{BoxError, Error},
ff::Field,
helpers::Direction,
protocol::{
check_zero::check_zero, context::ProtocolContext, prss::IndexedSharedRandomness,
reveal::reveal, RecordId, RECORD_0, RECORD_1, RECORD_2,
check_zero::check_zero, context::ProtocolContext, prss::IndexedSharedRandomness, RecordId,
RECORD_0, RECORD_1, RECORD_2,
},
secret_sharing::{MaliciousReplicated, Replicated},
};
Expand Down Expand Up @@ -183,7 +184,10 @@ impl<F: Field> SecurityValidator<F> {
let w_share = Replicated::new(w_left, state.w);

// This should probably be done in parallel with the futures above
let r = reveal(ctx.narrow(&Step::RevealR), RECORD_0, self.r_share).await?;
let r = ctx
.narrow(&Step::RevealR)
.reveal(RECORD_0, self.r_share)
.await?;
let t = u_share - (w_share * r);

let is_valid = check_zero(ctx.narrow(&Step::CheckZero), RECORD_0, t).await?;
Expand Down
7 changes: 4 additions & 3 deletions src/protocol/modulus_conversion/convert_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::{
error::BoxError,
ff::{Field, Fp2},
protocol::{
context::ProtocolContext, modulus_conversion::double_random::DoubleRandom,
reveal::reveal_malicious, RecordId,
context::ProtocolContext, modulus_conversion::double_random::DoubleRandom, RecordId,
},
secret_sharing::Replicated,
};

use crate::protocol::reveal::Reveal;
use futures::future::{try_join, try_join_all};
use std::iter::{repeat, zip};

Expand Down Expand Up @@ -78,7 +78,8 @@ impl ConvertShares {
let input_xor_r = input + r_binary;
let (r_big_field, revealed_output) = try_join(
DoubleRandom::execute(ctx.narrow(&Step::DoubleRandom), record_id, r_binary),
reveal_malicious::<F, Fp2>(ctx.narrow(&Step::BinaryReveal), record_id, input_xor_r),
ctx.narrow(&Step::BinaryReveal)
.reveal(record_id, input_xor_r),
)
.await?;

Expand Down
211 changes: 0 additions & 211 deletions src/protocol/reveal.rs

This file was deleted.

Loading

0 comments on commit 7565647

Please sign in to comment.