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

Add verifier contract using constantine library #174

Merged
merged 6 commits into from
Jul 7, 2023

Conversation

kkirkov
Copy link
Contributor

@kkirkov kkirkov commented Jun 29, 2023

No description provided.

@EmilIvanichkovv EmilIvanichkovv added Cosmos Tasks and Issues related to the Cosmos contracts EOS Tasks and Issues related to the EOS contracts Verifier labels Jun 29, 2023
Copy link
Contributor

@EmilIvanichkovv EmilIvanichkovv left a comment

Choose a reason for hiding this comment

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

Minimize the presence of duplicate files.

@kkirkov kkirkov force-pushed the constantine-verifier branch 4 times, most recently from e9bb284 to a6713bd Compare July 3, 2023 13:23
@EmilIvanichkovv EmilIvanichkovv force-pushed the constantine-verifier branch 2 times, most recently from 9fe22de to 457180b Compare July 7, 2023 10:06
Copy link

@mratsim mratsim left a comment

Choose a reason for hiding this comment

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

Multipairings can optimize speed by almost 2x.

prod(sum, alphaBetaPairing, preparedInputsGammaPairing)
prod(sum, sum, proofCVkDeltaPairing)

if (sum == aBPairing).bool:
Copy link

@mratsim mratsim Jul 8, 2023

Choose a reason for hiding this comment

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

It would be almost 2x faster if multipairings were used there and the result checked for one:

with the signature

func pairing*[N: static int, C](
       gt: var Fp12[C],
       Ps: array[N, ECP_ShortW_Aff[Fp[C], G1]],
       Qs: array[N, ECP_ShortW_Aff[Fp2[C], G2]]) =

from https://github.com/mratsim/constantine/blob/d69c7bf/constantine/math/pairings/pairings_generic.nim#L16C1-L22
forwarding to https://github.com/mratsim/constantine/blob/d69c7bf/constantine/math/pairings/pairings_bn.nim#L178-L181

prf.a needs to be negated beforehand because:

e(prf.a, prf.b) = e(vk.alpha, vk.beta).e(preparedInputs.data, vk.gamma).e(prf.c,vk.delta)

is equivalent to

e(-prf.a, prf.b).e(vk.alpha, vk.beta).e(preparedInputs.data, vk.gamma).e(prf.c,vk.delta) = 1

see BLS signatures: https://github.com/mratsim/constantine/blob/d69c7bf/constantine/signatures/bls_signatures.nim#L123-L127

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice! #184
Gas usage:
using Bncurve - around 1695k
using Constantine(no multipairings) - around 1400k
using Constantine(with) - around 870k

@@ -3,7 +3,7 @@ import
std/[strutils,json]

import
../../../contracts/cosmos/verifier/lib/nim/verify/verify_helpers
../../../contracts/cosmos/verifier/verifier-bncurve/lib/nim/verify/verify_helpers
Copy link

Choose a reason for hiding this comment

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

I'm surprised the dash is accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cosmos Tasks and Issues related to the Cosmos contracts EOS Tasks and Issues related to the EOS contracts Verifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants