-
Notifications
You must be signed in to change notification settings - Fork 53
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
Constantine backend #251
Constantine backend #251
Conversation
82e29f6
to
4c5210e
Compare
4c5210e
to
2824ac3
Compare
Great work! Could you check https://github.com/mratsim/constantine/tree/constantine-public-sys that @mratsim just created. We should ask |
04093ed
to
247e0f9
Compare
@lynxcs is there anything else we need from Constantine to ship this PR? |
@sauliusgrigaitis Technically can be merged already, however (as noted in description), we are still missing constantine equivalents for Binary<->Big255<->Fr type conversions as well as for G1/G2 mul with Fr. AFAIK @Armantidas already asked for these functions to be exposed (and I think G1*Mul should have been added but was removed by mistake? Due to there is some issues with G2 code gen on constantine side). So TL;DR I think it can be merged since it works and is 99% finished. BLST parts can be removed in small PRs as constantine versions become available. |
@mratsim any chance to look at this? |
All added in mratsim/constantine#338, including G2 scalar mul, found a workaround. |
Thanks @mratsim! @lynxcs @Armantidas could you update and confirm that we don't need to use |
There's always going to be dependency on blst due to how it's used in eip_4844. But main parts have been changed. EDIT: Also still used in pairings verify & CtFr from_bytes_unchecked because there's no Bytes->Big255 conversion which doesn't validate data |
1ac498c
to
d08d3f9
Compare
I assume it's a function similar to: https://github.com/mratsim/constantine/blob/2aac21d/research/kzg/polynomials.nim#L39-L72 I don't provide Fp12 at the moment because serialization is different between arkworks, geth, blst. See: supranational/blst#101. What may be possible is providing:
I have limited bandwidth at the moment though.
The data check has almost no cost.
i.e. the check is false if the byte-array is bigger than what the Bigint can physically store so for a big255 if the byte array takes more than 32 bytes. If the length you specify is less than 32, conversion to a big255 will not fail. |
Actually, just used ctt_big255_unmarshalBE instead & it worked for our use case 😄 EDIT: yeah regarding pairing, https://github.com/mratsim/constantine/blob/2aac21d/research/kzg/polynomials.nim#L39-L72 is exactly what we need |
For the pairing addition, don't wait on me if it's just for tests, I don't have the bandwidth to do it at the moment. |
No probs, we will merge as it is now. Benchmarks:
Seems there is a significant penalty converting types, and this needs to be further investigated. |
5e48edd
into
grandinetech:integration
Constantine backend wasn't fully integrated / has some caveats:
To be fair to constantine ECC backend in benchmarks, a total of 3 versions were created:
On top of that, feature flag
constantine_msm
was added to replace our g1_linear_combination MSM func with the one provided by constantineMethods which partly use blst & weren't/can't (currently) be replaced to use constantine:
CtFr from_bytes_unchecked() Big255 deserialize without validationCtFr rand() - requires Big255/u64[4] -> Fr conversion, though only used in tests, so can be skippedCtFr from_bytes() - requires Big255 -> Fr conversionCtFr from_bytes_unchecked() - seems like no equivalent for deserializing to scalar without validity checks, but only used in tests, so can be skippedCtFr from_u64_arr() - requires Big255/u64[4] -> Fr conversionCtFr to_bytes() - requires Fr -> Big255 conversionCtFr to_u64_arr() - requires Fr -> Big255/u64[4] conversionCtFr to_scalar() -> requires Fr- > Big255 conversionCtG1 mul() -> requires G1 * Fr(or Big255/Scalar) operationCtG2 mul() -> requires G2 * Fr(or Big255/Scalar) operationBatched G1 -> Affine conversion (falling back to singular variant of constantine)For now we use a fork of constantine rust bindings where the fields were made public (+ Default derived, though it's possible to avoid doing this if really required by using MaybeUninit), because it was required by our implementationAlso having some linker errors with c-kzg-4844 <-> rust lib <-> constantine lib bindingsIssue was because constantine doesn't compile with position independent code, which is required when linking static <-> shared library. Rust does this by default, so should consider changing make_rust_lib in constantine to also compile with -fPIC, or alternatively add option in build.rs of constantine-sys to enable this featurePR for enabling -fPIC in constantine was merged