Consensys / gnark

gnark is a fast zk-SNARK library that offers a high-level API to design circuits. The library is open source and developed under the Apache 2.0 license
https://hackmd.io/@gnark
Apache License 2.0
1.45k stars 380 forks source link

Feat: 4-dimensional fake GLV #1296

Closed yelhousni closed 1 month ago

yelhousni commented 1 month ago

Description

https://ethresear.ch/t/fake-glv-you-dont-need-an-efficient-endomorphism-to-implement-glv-like-scalar-multiplication-in-snark-circuits/20394/7

Type of change

How has this been tested?

Correctness tests are implemented in emulated/sw_emulated/point_test.go and native/sw_bls12377/g1_test.go.

How has this been benchmarked?

All benchmarks are in plonkish constraints (scs).

scalar mul old (scs) new (scs)
Secp256k1 385,461 282,223
BN254 381,467 279,262
BW6-761 1,367,067 1,010,785
BLS12-381 539,973 390,294
scalar mul old (scs) new (scs)
BLS12-377 3,587 3,567
precompiles old (scs) new (scs)
ECMUL (BN254) 384,782 280,123
Recursion old (scs) new (scs)
BW6-761 in BN254 (emulated) 28,206,642 27,137,821

Checklist:

yelhousni commented 1 month ago

I'm not fully sure about the possible overflow in BLS12-377, but I think with this approach we have a slight problem. Imo it looks good for the emulated 4-dim, but not for 2-chain.

Applied the suggestions and resolved conversations. For BLS12-377, we only use the GLV+Fake-GLV for testing purposes as it is currently more expensive constraint-wise compared to classical GLV. If we do the scalars decomposition check in non-native then definitely way more expensive.

ivokub commented 1 month ago

Thanks for all the changes! All good from my side now. I'll postpone the general interfaces for different curves for a separate PR (https://github.com/Consensys/gnark/issues/1303)