-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Groth16 prover buggy draft #463
base: master
Are you sure you want to change the base?
Conversation
The code previously accidentally only return 3 for the case 5.
Otherwise when performing operations on EC points in Jacobian, depending on import these can be missing.
I just had another look at SnarkJS to see if I can figure out the double Montgomery encoding situation. As it turns out at least I could identify the SnarkJS code that writes the coefficients as doubly Montgomery encoded. This happens here: const nR2 = curve.Fr.mul(n, R2r);
curve.Fr.toRprLE(buffCoeff, 12, nR2); where const R2r = curve.Fr.e(Scalar.mod(Scalar.mul(Rr,Rr), primeR)); Which at the very least finally ends the question of whether I'm imagining things or not. I still have no clue why this is done to be honest. The commits touching these lines are not very illuminating either. |
Table of Contents
buildABC
results for A, B, C in SnarkJS vs CTTjoinABC
result SnarkJS vs CTTcoeff
,witness
also used?α1
,δ1
r
,s
As[i]
incalcAp
forwt[i] * As[i]
wt * As
This is a work in progress Groth16 prover. While there is a way to get
correct proofs, I have not fully understood why the code produces
the right result in those circumstances.
I added 3 different
{.booldefine.}
variables to run one of the threedifferent cases.
The first case
-d:CM_WN=true
is the most "natural" one. zkeycoefficients are Montgomery encoded and the witness data is treated as
being in normal representation.
The second case
-d:CM_WM=true
reads both the coefficients andwitness data as Montgomery encoded.
In the final case
-d:CMM_WN=true
we treat the zkey coefficients asdoubly Montgomery encoded and the Witness data as being in normal
rep.
Why these 3 cases?
gB.
sensible, given that everything else is.
doubly Montgomery encoded". So I tried that, to find out that
indeed that makes it work. I just don't get it.
We will now compare a selection of different intermediate results and
try to narrow down the underlying issue.
In SnarkJS we use two functions to print the values. The inbuilt
ffjavascript.toString
function, which converts values to theirnormal representation and a custom
asHex
, which prints the internaldata as hex:
(and a similar one for arrays & elliptic curve points)
Target: Match SnarkJS
toString
values exactly, because theyrepresent the normal form of the numbers. If they match we know our
numbers represent the same values.
How to compare
For SnarkJS I just added a whole bunch of stuff into my local SnarkJS
code. I can provide a diff / the whole file if someone wants to run
those.
For Constantine, all the numbers below are from running:
Compare witness data & zkey coefficients data SnarkJS vs CTT
Let's print the coefficients & witness data after reading in
SnarkJS
coefficients
witness data
Let's print coefficients and witness data for the 3 different
cases
CMWN
asHex
) up toendianness. Implies it's wrong.
toString
CMWM
toString
toString
-> implies we read the data correctly!
CMMWN
CM_WN
for witness data, matchesthat 4 of the 6 are 1.
buildABC
results for A, B, C in SnarkJS vs CTTSnarkJS output for A, B, C calculations in
buildABC1
:CTT output for A, B, C for the different cases
CMWN
endianness
are different
CMWM
CMMWN
just
coeff * witness
, does that imply that in this context theMontgomery rep
R
commutes between the two scalars?A, B, C after FFT (NTT) transformations SnarkJS vs CTT
SnarkJS:
CTT output for A, B, C after
itf
CMWN
again
CMWM
CMMWN
buildABC
were identical.joinABC
result SnarkJS vs CTTSnarkJS:
CTT output for
joinABC
CMWN
buildABC
CMWM
buildABC
was the same? join ABC shouldjust be:
A[i] * B[i] - C[i]
CMMWN
CM_WM
, so no match either.None of these match.
Proof results gA, gB, gC
Proof from SnarkJS:
CTT proofs
CMWN
joinABC logic
CMWM
CMMWN
joinABC
is different fromSnarkJS, but the same as
CM_WM
, it implies it must come fromanother occurrence of
coeff
orwitness
, where the "other"version is "correct".
Despite
joinABC
not matching, the proof forCMM_WN
does match?!Where is
coeff
,witness
also used?-> Indeed, only usage in
buildABC
witness
used?-> Calculation of
calcAp
,calcBp
,calcB1
,buildABC
and theprivate elements entering proof for gC
DONE Compare
α1
,δ1
SnarkJS
CMWN, CMWM, CMMWN are all identical here:
DONE Compare
r
,s
SnarkJS:
CTT (all cases the same):
Compare
As[i]
incalcAp
forwt[i] * As[i]
SnarkJS:
CTT (all cases the same):
Compare MSM of
wt * As
From the fact that
wt
andAs
are equivalent forCM_WM
the MSMportion of
g^A
should be identical only in that case?SnarkJS
CTT
CMWN
CMWM
CMMWM, should be the same as CMWN
So why does
CM_WM
not yield the right result if both inputs areidentical?