arnaucube / go-snark-study

zkSNARK library implementation in Go from scratch (compiler, setup, prover, verifier)
GNU General Public License v3.0
255 stars 57 forks source link

Possible overflow in r1csqap/LagrangeInterpolation #21

Open ShuangWu121 opened 3 years ago

ShuangWu121 commented 3 years ago

The function "NewPolZeroAt" in r1csqap.go, which is used by function "LagrangeInterpolation"

has the following code

fac := 1
    for i := 1; i < totalPoints+1; i++ {
        if i != pointPos {
            fac = fac * (pointPos - i)
        }
    }
facBig := big.NewInt(int64(fac))

I am facing a problem that 'fac' can be larger than int64, which make the algorithm generate wrong polynomial. Has anyone else faced this problem as well?