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

Generalize IsMontgomeryConfiguration and MontgomeryBackendPrimeField #126

Closed
GianfrancoBazzani opened this issue Feb 27, 2023 · 5 comments
Closed

Comments

@GianfrancoBazzani
Copy link
Contributor

In order to solve #95 without repeat code i tried to generalize IsMontgomeryConfiguration trait and MontgomeryBackendPrimeField struct to allow usage with any UnsignedInteger.

Tried something like this:
image

If i use a generic U: IsUnsignedInteger :

image

Any idea to define a generic to generalize any type UnsignedInteger<_> struct like?

@GianfrancoBazzani GianfrancoBazzani changed the title Generalize IsMontgomeryConfiguration and 'MontgomeryBackendPrimeField' Generalize IsMontgomeryConfiguration and MontgomeryBackendPrimeField Feb 27, 2023
@MauroToscano
Copy link
Collaborator

MauroToscano commented Feb 27, 2023

Don't generalize it over the trait, we just need it to work with UnsignedInteger<u: usize> for now. This will enable the auto paramater generator we added to work smoothly, since rust don't like const functions in traits.

@MauroToscano
Copy link
Collaborator

MauroToscano commented Feb 27, 2023

This backend is to make generally optimized code and enable a fast implementation of any field. The IsUnsignedInteger is for everything to keep working if you want to make a really specific optimization, or swap the native type for another one.

@MauroToscano
Copy link
Collaborator

Leaving that aside, the problem there is that you are using a trait, so you can't use UnsignedInteger functions directly if you define the variable as U. You are limited to the trait functions, because the U could be something different.

@GianfrancoBazzani
Copy link
Contributor Author

GianfrancoBazzani commented Feb 27, 2023

Tanks a lot Mauro, you are truly a Rust warlock. So instead of generalize for any object with IsUnsignedInteger trait implementation, I generalized for any NUM_LIMBS constant value and used UnsignedInteger<NUM_LIMBS> to generalize for any object following custom multiprecision unsigned integer struct like (Types: U256, U384,....). Seems Works and passes the tests:

Screenshot from 2023-02-27 15-55-39

@GianfrancoBazzani
Copy link
Contributor Author

GianfrancoBazzani commented Feb 27, 2023

Leaving that aside, the problem there is that you are using a trait, so you can't use UnsignedInteger functions directly if you define the variable as U. You are limited to the trait functions, because the U could be something different.

I see the difference, thanks a lot. Generalizing through NUM_LIMS I can access all methods of UnsignedInteger that is what I wanted.

GianfrancoBazzani added a commit to GianfrancoBazzani/lambdaworks that referenced this issue Feb 27, 2023
ilitteri pushed a commit that referenced this issue Mar 4, 2023
* fix mul_two_256_bit_integers_works_4() test

Test mul_two_256_bit_integers_works_4() fixed after the bug  in the * operator patched

* Update element.rs

* Update element.rs

* get rid of space

* Update element.rs

* Generalize IsMontgomeryConfiguration and MontgomeryBackendPrimeField

Solves #126

* Extended U256 Montgomery backed prime fields test

* Implemented U256PrimeField

solves #95

* Conflicts fixed

* fmt

* Get rid of unused commented lines

* Update montgomery_backed_prime_fields.rs
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

No branches or pull requests

2 participants