Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Field trait #958

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

andyleiserson
Copy link
Collaborator

  • Remove Field trait impl from Boolean arrays.
  • Remove u128 conversions from Fp25519.
  • Add select variant of if_else. select is bus multiplexer with a single-bit control input. if_else is a vectorizable multiplexer, with condition input the same width as the data inputs.
  • Remove Field (or replace with SharedValue) in various trait bounds.
  • Implement Vectorizable and related traits for more boolean arrays.

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.47%. Comparing base (9e5a4d4) to head (fb191e0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #958      +/-   ##
==========================================
+ Coverage   88.43%   88.47%   +0.04%     
==========================================
  Files         158      158              
  Lines       21472    21515      +43     
==========================================
+ Hits        18988    19035      +47     
+ Misses       2484     2480       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +269 to +275
boolean_vector!(3, BA3);
boolean_vector!(5, BA5);
boolean_vector!(8, BA8);
boolean_vector!(20, BA20);
boolean_vector!(32, BA32);
boolean_vector!(64, BA64);
boolean_vector!(256, BA256);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set of sizes we generate values for isn't consistent. I hope that is OK. Will someone be surprised if they try to invoke something for which there is one implementation and not another?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For vectorization in general, because rust's const generic support is limited, the supported vectorizations need to be enumerated explicitly in the source. I did the same thing here (listing only the ones that we use). Also, arbitrary vectorization dimensions are only needed where we're using the record-wise vectorization support to implement bit-wise vectorization within a record. Implementing only the necessary vectorizations helps to discourage that.

* Remove `Field` trait impl from Boolean arrays.
* Remove u128 conversions from `Fp25519`.
* Add `select` variant of `if_else`. `select` is bus multiplexer with
  a single-bit control input. `if_else` is a vectorizable multiplexer,
  with condition input the same width as the data inputs.
* Remove `Field` (or replace with `SharedValue`) in various trait bounds.
* Implement `Vectorizable` and related traits for more boolean arrays.

Fixes private-attribution#812
/// This macro uses a bit of recursive repetition to produce those zeros.
///
/// The longest call is 8 bits, which involves `2(n+1)` macro expansions in addition to `bitarr!`.
macro_rules! bitarr_one {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we don't need this awesome macro anymore? :)

let mut max_value = $name::ZERO.0;
max_value[..$bits].fill(true);
deserialize(max_value).unwrap();

let mut rnd_value = $name::ZERO.0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it check something that this test doesn't already?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think it does. I added this one to replace the test case in this function that deserialized the ONE value, but I can drop it in favor of the other test.

Comment on lines 78 to 80
let false_value = false_value.clone().into();
let true_value = true_value.clone().into();
let condition = B::expand(condition).into();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use From so the types for these values become obvious?

record_id: RecordId,
a: &'fut Self::Vectorized,
b: &'fut Self::Vectorized,
) -> impl Future<Output = Result<Self::Vectorized, Error>> + Send + 'fut
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

TV: SharedValue + U128Conversions + CustomArray<Element = Boolean>,
TS: SharedValue + U128Conversions + CustomArray<Element = Boolean>,
SS: SharedValue + U128Conversions + CustomArray<Element = Boolean>,
Replicated<BK>: BooleanArrayMul,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you tried it already, but I am going to ask anyway - have you tried to provide blanket implementation BooleanArrayMul for all boolean shares?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's another consequence of const generic limitations -- see this comment.

Part of why things get weird here is that we're using the record-wise vectorization support for bit-wise vectorization. To make a fully vectorized version of these protocols we'd need to change that, and could probably get rid of BooleanArrayMul in the process.

Copy link
Collaborator

@danielmasny danielmasny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up. I just have one small comment.

let f: Fp25519 = Fp25519::ONE;
f.serialize((&mut bits).into());
Ok(f)
fn from_random(src: GenericArray<u128, Self::SourceLength>) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use a u8 as a base and increase the SourceLength? I think even Aes uses a GenericArray over u8

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea we have #951 for that

@andyleiserson andyleiserson merged commit 57b4d49 into private-attribution:main Feb 23, 2024
11 checks passed
@andyleiserson andyleiserson deleted the field-cleanup branch February 23, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants