From c90733615c2ec682461050db9fc31f983e4fff70 Mon Sep 17 00:00:00 2001 From: Alex Koshelev Date: Fri, 16 Feb 2024 10:02:12 -0800 Subject: [PATCH] Fix compact gate import errors --- ipa-core/src/protocol/basics/mod.rs | 17 +++++++------ ipa-core/src/protocol/basics/reshare.rs | 15 ++++++------ ipa-core/src/protocol/basics/reveal.rs | 20 +++++++++------- .../src/protocol/basics/share_known_value.rs | 18 +++++++------- ipa-core/src/protocol/boolean/mod.rs | 1 + ipa-core/src/protocol/context/mod.rs | 4 ++++ ipa-core/src/protocol/context/upgrade.rs | 2 +- ipa-core/src/protocol/context/validator.rs | 24 +++++++++++-------- .../replicated/malicious/additive_share.rs | 1 + .../replicated/malicious/mod.rs | 6 ++--- ipa-core/src/test_fixture/sharing.rs | 4 ++-- 11 files changed, 62 insertions(+), 50 deletions(-) diff --git a/ipa-core/src/protocol/basics/mod.rs b/ipa-core/src/protocol/basics/mod.rs index 0412108f8..295301894 100644 --- a/ipa-core/src/protocol/basics/mod.rs +++ b/ipa-core/src/protocol/basics/mod.rs @@ -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, }, }; @@ -47,6 +46,6 @@ impl BasicProtocols for AdditiveShare {} #[cfg(feature = "descriptive-gate")] impl<'a, F: ExtendableField> BasicProtocols, F> - for MaliciousAdditiveShare + for MaliciousReplicated { } diff --git a/ipa-core/src/protocol/basics/reshare.rs b/ipa-core/src/protocol/basics/reshare.rs index d7048a755..e2bdec483 100644 --- a/ipa-core/src/protocol/basics/reshare.rs +++ b/ipa-core/src/protocol/basics/reshare.rs @@ -2,7 +2,6 @@ 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, @@ -10,15 +9,18 @@ use crate::{ 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")] @@ -118,10 +120,7 @@ impl<'a, F: ExtendableField> Reshare, 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( diff --git a/ipa-core/src/protocol/basics/reveal.rs b/ipa-core/src/protocol/basics/reveal.rs index 5a80fb29f..c35a1ffea 100644 --- a/ipa-core/src/protocol/basics/reveal.rs +++ b/ipa-core/src/protocol/basics/reveal.rs @@ -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, }, }; @@ -125,6 +123,8 @@ impl<'a, F: ExtendableField> Reveal, 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(); @@ -162,6 +162,8 @@ impl<'a, F: ExtendableField> Reveal, 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(); diff --git a/ipa-core/src/protocol/basics/share_known_value.rs b/ipa-core/src/protocol/basics/share_known_value.rs index bc041f74f..95df6375a 100644 --- a/ipa-core/src/protocol/basics/share_known_value.rs +++ b/ipa-core/src/protocol/basics/share_known_value.rs @@ -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. /// diff --git a/ipa-core/src/protocol/boolean/mod.rs b/ipa-core/src/protocol/boolean/mod.rs index a35953714..0522fcaae 100644 --- a/ipa-core/src/protocol/boolean/mod.rs +++ b/ipa-core/src/protocol/boolean/mod.rs @@ -98,6 +98,7 @@ where /// # Errors /// This does multiplications which can have errors +#[cfg(feature = "descriptive-gate")] pub(crate) async fn any_ones(ctx: C, record_id: RecordId, x: &[S]) -> Result where F: Field, diff --git a/ipa-core/src/protocol/context/mod.rs b/ipa-core/src/protocol/context/mod.rs index 3a39aa992..7019569aa 100644 --- a/ipa-core/src/protocol/context/mod.rs +++ b/ipa-core/src/protocol/context/mod.rs @@ -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; diff --git a/ipa-core/src/protocol/context/upgrade.rs b/ipa-core/src/protocol/context/upgrade.rs index 4dc806ac1..f9853c372 100644 --- a/ipa-core/src/protocol/context/upgrade.rs +++ b/ipa-core/src/protocol/context/upgrade.rs @@ -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: ExtendableField> UpgradeContext<'a, C, F, NoRecord> { pub(super) async fn upgrade_sparse( self, diff --git a/ipa-core/src/protocol/context/validator.rs b/ipa-core/src/protocol/context/validator.rs index 1a891ffdd..d38473a33 100644 --- a/ipa-core/src/protocol/context/validator.rs +++ b/ipa-core/src/protocol/context/validator.rs @@ -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, }, @@ -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] @@ -68,7 +70,7 @@ impl 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, @@ -76,7 +78,7 @@ pub(crate) enum Step { 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, @@ -281,6 +283,8 @@ impl<'a, F: ExtendableField> Malicious<'a, F> { async fn propagate_u_and_w( &self, ) -> Result<(Replicated, Replicated), Error> { + use futures::future::try_join; + let propagate_ctx = self .validate_ctx .narrow(&ValidateStep::PropagateUAndW) diff --git a/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs b/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs index 59b2fc0ca..8a74b9cae 100644 --- a/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs +++ b/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs @@ -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); impl UnauthorizedDowngradeWrapper { + #[cfg(feature = "descriptive-gate")] pub(crate) fn new(v: T) -> Self { Self(v) } diff --git a/ipa-core/src/secret_sharing/replicated/malicious/mod.rs b/ipa-core/src/secret_sharing/replicated/malicious/mod.rs index 6f052ba59..a8f5418d5 100644 --- a/ipa-core/src/secret_sharing/replicated/malicious/mod.rs +++ b/ipa-core/src/secret_sharing/replicated/malicious/mod.rs @@ -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, -}; diff --git a/ipa-core/src/test_fixture/sharing.rs b/ipa-core/src/test_fixture/sharing.rs index b65f01cdd..32286a853 100644 --- a/ipa-core/src/test_fixture/sharing.rs +++ b/ipa-core/src/test_fixture/sharing.rs @@ -8,7 +8,7 @@ use crate::{ semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing, }, - BitDecomposed, FieldSimd, SecretSharing, Vectorizable, + BitDecomposed, FieldSimd, Vectorizable, }, }; @@ -154,7 +154,7 @@ where impl Reconstruct for [crate::protocol::boolean::RandomBitsShare; 3] where F: Field, - S: SecretSharing, + S: crate::secret_sharing::SecretSharing, for<'a> [&'a S; 3]: Reconstruct, { fn reconstruct(&self) -> F {