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

BigInt const generics #372

Merged
merged 25 commits into from
Jan 7, 2022
Merged

Conversation

mmagician
Copy link
Member

Description

This is an updated PR based on the subset of #186, i.e. replacing the macros with const generics only for BigInt crate. As such, it should be easier to merge.
Breaking change -> will need an accompanying PR in the curves repo.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@mmagician mmagician mentioned this pull request Dec 30, 2021
6 tasks
@mmagician mmagician marked this pull request as ready for review December 30, 2021 16:58
@burdges
Copy link
Contributor

burdges commented Jan 2, 2022

cc @tarcieri

@tarcieri
Copy link

tarcieri commented Jan 3, 2022

I talked with @Pratyush about crypto-bigint in the past.

This PR is doing something somewhat similar, but the main difference would be crypto-bigint uses [Limb; N], where Limb is a newtype wrapper for u32 on 32-bit architectures and u64 on 64-bit architectures, which seems like it'd be a bigger change than what's in this PR, so perhaps this is a good incremental step if there's an eventual desire to use crypto-bigint in the future.

It sure would be nice to have one place to collaborate on these sorts of problems.

@Pratyush Pratyush self-requested a review January 6, 2022 18:22
@Pratyush
Copy link
Member

Pratyush commented Jan 6, 2022

One additional thing we might want to consider doing is moving all the impls in the traits directly to inherent methods, and having the trait forward to those inherent impls. This would enable calling the BigInt methods in const contexts.

@@ -102,7 +103,7 @@ impl FpParameters for FrParameters {
]);

// (mod - 1) / 2 = 2972938801625915898129258746014768257744324656783561314222519104145798272973804394996417217026588261812051162269696
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::<6>([
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use the BigInteger::new method here to avoid specifying the number of limbs. (It's unfortunate that we can't use the type alias as the constructor =()

Copy link
Member

Choose a reason for hiding this comment

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

Ditto for the fixes in curves

Copy link
Member

Choose a reason for hiding this comment

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

One repo needs to move first. It can be algebra.

@tarcieri
Copy link

tarcieri commented Jan 6, 2022

One additional thing we might want to consider doing is moving all the impls in the traits directly to inherent methods, and having the trait forward to those inherent impls. This would enable calling the BigInt methods in const contexts.

This is what crypto-bigint does but it does have a downside: it prevents the usage of intrinsics.

One workaround is to keep the intrinsics in the trait impls, and const pure Rust.

@Pratyush
Copy link
Member

Pratyush commented Jan 6, 2022

This is what crypto-bigint does but it does have a downside: it prevents the usage of intrinsics.

Good point.

One workaround is to keep the intrinsics in the trait impls, and const pure Rust.

Yeah, that's a good trade-off, but in that case we might need to name the inherent and trait methods differently, to avoid accidentally using the slower one. Maybe it's just better to wait for const in trait impls...

@Pratyush Pratyush merged commit 2ee8d2a into arkworks-rs:master Jan 7, 2022
@mmagician mmagician deleted the bigint-const-generics branch January 9, 2022 21:54
@Pratyush Pratyush mentioned this pull request Feb 9, 2022
6 tasks
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.

6 participants