Skip to content

Commit

Permalink
Merge pull request #869 from private-attribution/fix_collect_steps
Browse files Browse the repository at this point in the history
Fixing error when running collect steps
  • Loading branch information
benjaminsavage authored Nov 30, 2023
2 parents 9e9a663 + 71474ae commit 1977afa
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 127 deletions.
4 changes: 0 additions & 4 deletions ipa-core/benches/oneshot/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ async fn run(args: Args) -> Result<(), Error> {
CappingOrder::CapOldestFirst
};

// TODO: Remove the below comment once #844 is landed.
// Note that how we apply the attribution window to IPA and OPRF IPA is different.
// For IPA, trigger events are considered within the window if [0..window] (upper bound inclusive).
// For OPRF, trigger events are considered within the window if [0..window) (upper bound exclusive).
let expected_results = ipa_in_the_clear(
&raw_data,
args.per_user_cap,
Expand Down
113 changes: 32 additions & 81 deletions ipa-core/src/ff/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> Iterator for BAIterator<'a> {

//macro for implementing Boolean array, only works for a byte size for which Block is defined
macro_rules! boolean_array_impl {
($modname:ident, $name:ident, $bits:expr, $bytes:expr, $one:expr) => {
($modname:ident, $name:ident, $bits:expr, $bytes:expr, [$($one:expr),+]) => {
#[allow(clippy::suspicious_arithmetic_impl)]
#[allow(clippy::suspicious_op_assign_impl)]
mod $modname {
Expand Down Expand Up @@ -128,7 +128,7 @@ macro_rules! boolean_array_impl {
}

impl Field for $name {
const ONE: Self = Self($one);
const ONE: Self = Self(bitarr![const u8, Lsb0; $($one),+]);

fn as_u128(&self) -> u128 {
(*self).into()
Expand Down Expand Up @@ -307,49 +307,30 @@ store_impl!(U8, 64);
store_impl!(U32, 256);

//impl BA3
boolean_array_impl!(
boolean_array_3,
BA3,
3,
1,
bitarr ! ( const u8, Lsb0;
1, 0, 0
)
);
boolean_array_impl!(boolean_array_3, BA3, 3, 1, [1, 0, 0]);

//impl BA4
boolean_array_impl!(boolean_array_4, BA4, 4, 1, [1, 0, 0, 0]);

//impl BA5
boolean_array_impl!(
boolean_array_5,
BA5,
5,
1,
bitarr ! ( const u8, Lsb0;
1, 0, 0, 0, 0
)
);
boolean_array_impl!(boolean_array_5, BA5, 5, 1, [1, 0, 0, 0, 0]);

//impl BA6
boolean_array_impl!(boolean_array_6, BA6, 6, 1, [1, 0, 0, 0, 0, 0]);

//impl BA7
boolean_array_impl!(boolean_array_7, BA7, 7, 1, [1, 0, 0, 0, 0, 0, 0]);

//impl BA8
boolean_array_impl!(
boolean_array_8,
BA8,
8,
1,
bitarr ! ( const u8, Lsb0;
1, 0, 0, 0, 0, 0, 0, 0
)
);
boolean_array_impl!(boolean_array_8, BA8, 8, 1, [1, 0, 0, 0, 0, 0, 0, 0]);

//impl BA20
boolean_array_impl!(
boolean_array_20,
BA20,
20,
3,
bitarr ! ( const u8, Lsb0;
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
)
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
);

//impl BA32
Expand All @@ -358,11 +339,9 @@ boolean_array_impl!(
BA32,
32,
4,
bitarr![const u8, Lsb0;
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
[
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
]
);

Expand All @@ -372,15 +351,10 @@ boolean_array_impl!(
BA64,
64,
8,
bitarr![const u8, Lsb0;
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0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0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
[
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
);
10 changes: 5 additions & 5 deletions ipa-core/src/protocol/ipa_prf/prf_sharding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ where
/// Propagates errors from multiplications
/// # Panics
/// Propagates errors from multiplications
pub async fn attribution_and_capping_and_aggregation<C, BK, TV, TS, SS, S, F>(
pub async fn attribute_cap_aggregate<C, BK, TV, TS, SS, S, F>(
sh_ctx: C,
input_rows: Vec<PrfShardedIpaInputRow<BK, TV, TS>>,
attribution_window_seconds: Option<NonZeroU32>,
Expand Down Expand Up @@ -823,7 +823,7 @@ pub mod tests {
boolean_array::{BA20, BA3, BA5, BA8},
CustomArray, Field, Fp32BitPrime,
},
protocol::ipa_prf::prf_sharding::attribution_and_capping_and_aggregation,
protocol::ipa_prf::prf_sharding::attribute_cap_aggregate,
rand::Rng,
secret_sharing::{
replicated::semi_honest::AdditiveShare as Replicated, IntoShares, WeakSharedValue,
Expand Down Expand Up @@ -1003,7 +1003,7 @@ pub mod tests {

let result: Vec<_> = world
.semi_honest(records.into_iter(), |ctx, input_rows| async move {
attribution_and_capping_and_aggregation::<
attribute_cap_aggregate::<
_,
BA5,
BA3,
Expand Down Expand Up @@ -1057,7 +1057,7 @@ pub mod tests {

let result: Vec<_> = world
.semi_honest(records.into_iter(), |ctx, input_rows| async move {
attribution_and_capping_and_aggregation::<
attribute_cap_aggregate::<
_,
BA5,
BA3,
Expand Down Expand Up @@ -1150,7 +1150,7 @@ pub mod tests {

let result: Vec<_> = world
.semi_honest(records.into_iter(), |ctx, input_rows| async move {
attribution_and_capping_and_aggregation::<
attribute_cap_aggregate::<
_,
BA8,
BA3,
Expand Down
Loading

0 comments on commit 1977afa

Please sign in to comment.