Skip to content

Commit

Permalink
Fix compact gate import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akoshelev committed Feb 16, 2024
1 parent 6cbee84 commit c907336
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 50 deletions.
17 changes: 8 additions & 9 deletions ipa-core/src/protocol/basics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ pub use reveal::Reveal;
pub use share_known_value::ShareKnownValue;
pub use sum_of_product::SumOfProducts;

#[cfg(feature = "descriptive-gate")]
use crate::protocol::context::UpgradedMaliciousContext;
use crate::{
ff::Field,
protocol::{context::Context, RecordId},
secret_sharing::{
replicated::{
malicious::{AdditiveShare as MaliciousAdditiveShare, ExtendableField},
semi_honest::AdditiveShare,
},
SecretSharing, SharedValue,
secret_sharing::{replicated::semi_honest::AdditiveShare, SecretSharing, SharedValue},
};
#[cfg(feature = "descriptive-gate")]
use crate::{
protocol::context::UpgradedMaliciousContext,
secret_sharing::replicated::malicious::{
AdditiveShare as MaliciousReplicated, ExtendableField,
},
};

Expand All @@ -47,6 +46,6 @@ impl<C: Context, F: Field> BasicProtocols<C, F> for AdditiveShare<F> {}

#[cfg(feature = "descriptive-gate")]
impl<'a, F: ExtendableField> BasicProtocols<UpgradedMaliciousContext<'a, F>, F>
for MaliciousAdditiveShare<F>
for MaliciousReplicated<F>
{
}
15 changes: 7 additions & 8 deletions ipa-core/src/protocol/basics/reshare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ use std::iter::{repeat, zip};

use async_trait::async_trait;
use embed_doc_image::embed_doc_image;
use futures::future::try_join;

use crate::{
error::Error,
ff::Field,
helpers::{Direction, Role},
protocol::{context::Context, prss::SharedRandomness, NoRecord, RecordBinding, RecordId},
secret_sharing::replicated::{
malicious::{AdditiveShare as MaliciousReplicated, ExtendableField},
semi_honest::AdditiveShare as Replicated,
ReplicatedSecretSharing,
semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing,
},
};
#[cfg(feature = "descriptive-gate")]
use crate::{
protocol::basics::mul::malicious::Step::{RandomnessForValidation, ReshareRx},
protocol::context::SpecialAccessToUpgradedContext,
protocol::context::UpgradedMaliciousContext,
secret_sharing::replicated::malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious,
secret_sharing::replicated::malicious::{
AdditiveShare as MaliciousReplicated, ExtendableField,
},
};

#[embed_doc_image("reshare", "images/sort/reshare.png")]
Expand Down Expand Up @@ -118,10 +120,7 @@ impl<'a, F: ExtendableField> Reshare<UpgradedMaliciousContext<'a, F>, RecordId>
where
UpgradedMaliciousContext<'a, F>: 'fut,
{
use crate::{
protocol::context::SpecialAccessToUpgradedContext,
secret_sharing::replicated::malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious,
};
use futures::future::try_join;
let random_constant_ctx = ctx.narrow(&RandomnessForValidation);

let (rx, x) = try_join(
Expand Down
20 changes: 11 additions & 9 deletions ipa-core/src/protocol/basics/reveal.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use async_trait::async_trait;
use embed_doc_image::embed_doc_image;
use futures::future::try_join;

#[cfg(feature = "descriptive-gate")]
use crate::protocol::context::UpgradedMaliciousContext;
use crate::{
error::Error,
helpers::{Direction, Role},
protocol::{context::Context, RecordBinding, RecordId},
secret_sharing::{
replicated::{
malicious::{AdditiveShare as MaliciousReplicated, ExtendableField},
semi_honest::AdditiveShare as Replicated,
},
SharedValue,
secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, SharedValue},
};
#[cfg(feature = "descriptive-gate")]
use crate::{
protocol::context::UpgradedMaliciousContext,
secret_sharing::replicated::malicious::{
AdditiveShare as MaliciousReplicated, ExtendableField,
},
};

Expand Down Expand Up @@ -125,6 +123,8 @@ impl<'a, F: ExtendableField> Reveal<UpgradedMaliciousContext<'a, F>, RecordId>
where
UpgradedMaliciousContext<'a, F>: 'fut,
{
use futures::future::try_join;

use crate::secret_sharing::replicated::malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious;

let (left, right) = self.x().access_without_downgrade().as_tuple();
Expand Down Expand Up @@ -162,6 +162,8 @@ impl<'a, F: ExtendableField> Reveal<UpgradedMaliciousContext<'a, F>, RecordId>
where
UpgradedMaliciousContext<'a, F>: 'fut,
{
use futures::future::try_join;

use crate::secret_sharing::replicated::malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious;

let (left, right) = self.x().access_without_downgrade().as_tuple();
Expand Down
18 changes: 10 additions & 8 deletions ipa-core/src/protocol/basics/share_known_value.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#[cfg(feature = "descriptive-gate")]
use crate::protocol::context::UpgradedMaliciousContext;
use crate::{
ff::Field,
helpers::Role,
protocol::context::{Context, UpgradedContext},
protocol::context::Context,
secret_sharing::{
replicated::{
malicious::{AdditiveShare as MaliciousReplicated, ExtendableField},
semi_honest::AdditiveShare as Replicated,
ReplicatedSecretSharing,
},
replicated::{semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing},
SharedValue,
},
};
#[cfg(feature = "descriptive-gate")]
use crate::{
protocol::context::UpgradedContext,
protocol::context::UpgradedMaliciousContext,
secret_sharing::replicated::malicious::{
AdditiveShare as MaliciousReplicated, ExtendableField,
},
};

/// Produce a share of some pre-determined constant.
///
Expand Down
1 change: 1 addition & 0 deletions ipa-core/src/protocol/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ where

/// # Errors
/// This does multiplications which can have errors
#[cfg(feature = "descriptive-gate")]
pub(crate) async fn any_ones<F, C, S>(ctx: C, record_id: RecordId, x: &[S]) -> Result<S, Error>
where
F: Field,
Expand Down
4 changes: 4 additions & 0 deletions ipa-core/src/protocol/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pub mod malicious;
pub mod prss;
pub mod semi_honest;
pub mod upgrade;

/// Validators are not used in IPA v3 yet. Once we make use of MAC-based validation,
/// this flag can be removed
#[allow(dead_code)]
pub mod validator;

use std::num::NonZeroUsize;
Expand Down
2 changes: 1 addition & 1 deletion ipa-core/src/protocol/context/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ where

// This could also work on a record-bound context, but it's only used in one place for tests where
// that's not currently required.
#[cfg(test)]
#[cfg(all(test, feature = "descriptive-gate"))]
impl<'a, C: UpgradedContext<F>, F: ExtendableField> UpgradeContext<'a, C, F, NoRecord> {
pub(super) async fn upgrade_sparse(
self,
Expand Down
24 changes: 14 additions & 10 deletions ipa-core/src/protocol/context/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ use std::{
};

use async_trait::async_trait;
use futures::future::try_join;
use ipa_macros::Step;

#[cfg(feature = "descriptive-gate")]
use crate::protocol::context::{MaliciousContext, UpgradedMaliciousContext};
use crate::{
error::Error,
ff::Field,
helpers::Direction,
protocol::{
basics::Reveal,
context::{Base, Context, SemiHonestContext, UpgradableContext, UpgradedSemiHonestContext},
context::{Base, SemiHonestContext, UpgradableContext, UpgradedSemiHonestContext},
prss::SharedRandomness,
RecordId,
},
Expand All @@ -25,7 +19,15 @@ use crate::{
semi_honest::AdditiveShare as Replicated,
ReplicatedSecretSharing,
},
sync::{Arc, Mutex, Weak},
sync::{Mutex, Weak},
};
#[cfg(feature = "descriptive-gate")]
use crate::{
helpers::Direction,
protocol::basics::Reveal,
protocol::context::Context,
protocol::context::{MaliciousContext, UpgradedMaliciousContext},
sync::Arc,
};

#[async_trait]
Expand Down Expand Up @@ -68,15 +70,15 @@ impl<F: ExtendableField> Debug for SemiHonest<'_, F> {

/// Steps used by the validation component of malicious protocol execution.
/// In addition to these, an implicit step is used to initialize the value of `r`.
#[derive(Step)]
#[cfg_attr(feature = "descriptive-gate", derive(ipa_macros::Step))]
pub(crate) enum Step {
/// For the execution of the malicious protocol.
MaliciousProtocol,
/// The final validation steps.
Validate,
}

#[derive(Step)]
#[cfg_attr(feature = "descriptive-gate", derive(ipa_macros::Step))]
pub(crate) enum ValidateStep {
/// Propagate the accumulated values of `u` and `w`.
PropagateUAndW,
Expand Down Expand Up @@ -281,6 +283,8 @@ impl<'a, F: ExtendableField> Malicious<'a, F> {
async fn propagate_u_and_w(
&self,
) -> Result<(Replicated<F::ExtendedField>, Replicated<F::ExtendedField>), Error> {
use futures::future::try_join;

let propagate_ctx = self
.validate_ctx
.narrow(&ValidateStep::PropagateUAndW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub trait Downgrade: Send {
#[must_use = "You should not be downgrading `replicated::malicious::AdditiveShare` values without calling `MaliciousValidator::validate()`"]
pub struct UnauthorizedDowngradeWrapper<T>(T);
impl<T> UnauthorizedDowngradeWrapper<T> {
#[cfg(feature = "descriptive-gate")]
pub(crate) fn new(v: T) -> Self {
Self(v)
}
Expand Down
6 changes: 3 additions & 3 deletions ipa-core/src/secret_sharing/replicated/malicious/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod additive_share;

pub(crate) use additive_share::ThisCodeIsAuthorizedToDowngradeFromMalicious;
#[cfg(feature = "descriptive-gate")]
pub(crate) use additive_share::UnauthorizedDowngradeWrapper;
pub use additive_share::{AdditiveShare, Downgrade as DowngradeMalicious, ExtendableField};
pub(crate) use additive_share::{
ThisCodeIsAuthorizedToDowngradeFromMalicious, UnauthorizedDowngradeWrapper,
};
4 changes: 2 additions & 2 deletions ipa-core/src/test_fixture/sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
semi_honest::AdditiveShare as Replicated,
ReplicatedSecretSharing,
},
BitDecomposed, FieldSimd, SecretSharing, Vectorizable,
BitDecomposed, FieldSimd, Vectorizable,
},
};

Expand Down Expand Up @@ -154,7 +154,7 @@ where
impl<F, S> Reconstruct<F> for [crate::protocol::boolean::RandomBitsShare<F, S>; 3]
where
F: Field,
S: SecretSharing<F>,
S: crate::secret_sharing::SecretSharing<F>,
for<'a> [&'a S; 3]: Reconstruct<F>,
{
fn reconstruct(&self) -> F {
Expand Down

0 comments on commit c907336

Please sign in to comment.