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

feat: binary field #90

Merged
merged 8 commits into from
Jun 20, 2024
Merged

feat: binary field #90

merged 8 commits into from
Jun 20, 2024

Conversation

lonerapier
Copy link
Collaborator

@lonerapier lonerapier commented Jun 14, 2024

It changes the following:

  • binary field
  • binary field extensions using tower field arithmetic

I've kept the implementation closer to theory as described in Section 2.3 of Binius. let me know if anything needs more work.

TODO:

  • figure out primitive_element_generator in extension fields
  • docs and tests
  • demonstrate power of binary fields by showing examples of embedding and small-by-large multiplication as described in the paper

@lonerapier lonerapier changed the title Feat/binary field feat: binary field Jun 14, 2024
Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

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

This is looking good my friend!!!

Suggestions so far only. Hopefully nothing nitpicky :)

Comment on lines 11 to 16
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct BinaryFieldExtension<const K: usize>
where [(); 1 << K]: {
/// coefficients of field element
pub coefficients: [BinaryField; 1 << K],
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This guy is a const expr fiend now!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

everywhere I go, I see compile time constants now :)


/// binary field containing element `{0,1}`
#[derive(Debug, Default, Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct BinaryField(u8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a type alias instead with:

Suggested change
pub struct BinaryField(u8);
pub type BinaryField = PrimeField<2>;

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that would collapse a lot of this module here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that'll work flawlessly, but i believe it wouldn't allow us to showcase the main properties of binary field, i.e. addition being bitwise XOR and multiplication bitwise AND.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if you use a trait impl override/default/specialization? There are some Rust unstable feats that may help here to let us specialize to the binary case.

I thought we had it in the project, but don't seem to anymore. Anyway, here is an RFC for it:
https://rust-lang.github.io/rfcs/1210-impl-specialization.html

There could be others.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Autoparallel i need some more time to check and iterate on this. so, i'll open a new PR for this. don't want to block AES implementations due to this change, so merging it.

@lonerapier lonerapier marked this pull request as ready for review June 17, 2024 18:12
@lonerapier
Copy link
Collaborator Author

@0xJepsen @Autoparallel this is ready for review now, I have added binary fields using our ronk traits in tests.

my reasoning being, I want to showcase the ease of arithmetic in binary fields and their efficient embedding and small by large multiplication properties. this obviously bloats the code a bit

can remove this entirely, and directly use our traits, if we feel that's the better approach.

Copy link
Contributor

@0xJepsen 0xJepsen left a comment

Choose a reason for hiding this comment

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

Very nice work on this sir

Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

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

This looks good to me! I just had a few clarifying thoughts.

One on a previous comment, one in this review.

pub coefficients: [BinaryField; 1 << K],
}

impl<const K: usize> BinaryFieldExtension<K>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should I be thinking of BinaryFieldExtension<K> as the binary tower with height K?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup correct, BinarFieldExtension<K> is isomorphic to $GF(2^{2^K})$

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nice. Probably a nit, but what do you think of naming this BinaryTower so we can think of GaloisField<K, 2> as degree K extensions over PrimeField<2>?

Let it be known that it doesn't bother me either way, you should choose what you think is proper :)

@lonerapier lonerapier merged commit e023cea into pluto:main Jun 20, 2024
4 checks passed
@lonerapier lonerapier deleted the feat/binary-field branch June 20, 2024 16:34
@github-actions github-actions bot mentioned this pull request Jul 1, 2024
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.

3 participants