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

Implement BN curves #225

Merged
merged 7 commits into from
Jun 22, 2020
Merged

Implement BN curves #225

merged 7 commits into from
Jun 22, 2020

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented Jun 18, 2020

This PR implements infrastructure for BN family of curves and instantiate BN256 from Etherem (EDIT: curve renamed to BN254).
Type: Feature
Label: Ready to review
Priority: Medium

Motivation

Support of BN family that is widely used for pairing-based cryptography (Ethereum, libsnark, DIZK, Halo).

Followups

@yelhousni
Copy link
Contributor Author

@Pratyush @howardwu @kobigurk That would be great if you can review this!

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
Copy link
Member

@Pratyush Pratyush left a comment

Choose a reason for hiding this comment

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

Looks great, just some naming suggestions (bn256 -> bn254).

(Should be accompanied by renaming the file in the file-system)

Comment on lines 43 to 44
/// COFACTOR =
#[rustfmt::skip]
Copy link
Member

Choose a reason for hiding this comment

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

Do we know what the cofactor is?

Copy link
Contributor Author

@yelhousni yelhousni Jun 20, 2020

Choose a reason for hiding this comment

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

Yes, in sage:

q=21888242871839275222246405745257275088696311157297823662689037894645226208583
Fq=GF(q)
E=EllipticCurve(Fq,[0,3])
ZZ.<z>=Fq[]
Fq2.<u>=GF(q^2, modulus=z^2+1)
Et=EllipticCurve(Fq2,[0,3/(9+u)])
cofactor = Et.order() // E.order()

Copy link

@mratsim mratsim Jun 21, 2020

Choose a reason for hiding this comment

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

The order on G2 for BN curves is r∗(2p−r) with r the G1 curve order, so the G2 cofactor is always (2p-r)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Pratyush
Copy link
Member

Pratyush commented Jun 20, 2020 via email

@kobigurk
Copy link
Contributor

IMO bn254.

@Pratyush
Copy link
Member

Ok sounds good then!

@yelhousni
Copy link
Contributor Author

yelhousni commented Jun 21, 2020

Thank you Kobi for the chronology! If we are to choose the name that makes most sense, then bn254 is the best option indeed. We just need to mention (in mod.rs for instance) that the curve is known also as bn256 in Geth and bn128 in libff.

yelhousni and others added 2 commits June 21, 2020 02:28
bn256 -> bn254

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
@yelhousni yelhousni requested a review from Pratyush June 21, 2020 00:47
@mratsim
Copy link

mratsim commented Jun 21, 2020

For naming I suggest BN254_Snarks as in the literature BN254 often (always?) refers to the one from Nogami et al with parameter -(2^62 + 2^55 + 1)

MCL also uses similar scheme to differentiate both: https://github.com/herumi/mcl#support-curves

@Pratyush
Copy link
Member

Pratyush commented Jun 22, 2020

Hey @mratsim, thanks for the additional perspective!

I still feel that bn254 is fine as it is well known in the context of SNARK systems (which this library is largely targeted towards). I also think that the literature moving forward will probably not use any BN254 curve, as these curves are not secure. For the same reason, existing systems will probably eventually be deprecated the curve anyway.

Copy link
Member

@Pratyush Pratyush left a comment

Choose a reason for hiding this comment

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

LGTM!

@Pratyush Pratyush changed the title BN curve Implement BN curves Jun 22, 2020
@Pratyush Pratyush merged commit 3255276 into arkworks-rs:master Jun 22, 2020
kobigurk pushed a commit to celo-org/zexe that referenced this pull request Aug 6, 2020
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