From bf32995d0604a65a0e16f66843fa20bf75e2325e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 25 Feb 2024 07:34:12 +0000 Subject: [PATCH] rm commented old code --- encoding/fft/fft_fr.go | 20 +------ encoding/fft/recover_from_samples.go | 29 +++++----- encoding/fft/zero_poly.go | 34 ++++++------ encoding/kzg/prover/parametrized_prover.go | 4 +- encoding/kzg/prover/prover.go | 22 -------- encoding/kzg/setup.go | 13 ++--- .../kzg/verifier/batch_commit_equivalence.go | 7 +-- encoding/kzg/verifier/multiframe.go | 26 ++++----- encoding/kzg/verifier/verifier.go | 9 +-- encoding/rs/decode.go | 2 +- encoding/rs/encode.go | 2 - encoding/rs/interpolation.go | 17 +++--- encoding/test/testCrypto.go | 55 +------------------ encoding/utils/reverseBits/reverseBits.go | 9 +-- encoding/utils/toeplitz/toeplitz.go | 14 ++--- 15 files changed, 73 insertions(+), 190 deletions(-) diff --git a/encoding/fft/fft_fr.go b/encoding/fft/fft_fr.go index 2705d74155..2fae4af69d 100644 --- a/encoding/fft/fft_fr.go +++ b/encoding/fft/fft_fr.go @@ -46,13 +46,8 @@ func (fs *FFTSettings) simpleFT(vals []fr.Element, valsOffset uint64, valsStride v.Mul(jv, r) tmp.Set(&last) last.Add(&tmp, &v) - - //bls.MulModFr(&v, jv, r) - //bls.CopyFr(&tmp, &last) - //bls.AddModFr(&last, &tmp, &v) } out[i].Set(&last) - //bls.CopyFr(&out[i], &last) } } @@ -75,16 +70,10 @@ func (fs *FFTSettings) _fft(vals []fr.Element, valsOffset uint64, valsStride uin x.Set(&out[i]) y.Set(&out[i+half]) - //bls.CopyFr(&x, &out[i]) - //bls.CopyFr(&y, &out[i+half]) root := &rootsOfUnity[i*rootsOfUnityStride] yTimesRoot.Mul(&y, root) out[i].Add(&x, &yTimesRoot) out[i+half].Sub(&x, &yTimesRoot) - - //bls.MulModFr(&yTimesRoot, &y, root) - //bls.AddModFr(&out[i], &x, &yTimesRoot) - //bls.SubModFr(&out[i+half], &x, &yTimesRoot) } } @@ -98,11 +87,10 @@ func (fs *FFTSettings) FFT(vals []fr.Element, inv bool) ([]fr.Element, error) { valsCopy := make([]fr.Element, n) for i := 0; i < len(vals); i++ { valsCopy[i].Set(&vals[i]) - //bls.CopyFr(&valsCopy[i], &vals[i]) + } for i := uint64(len(vals)); i < n; i++ { valsCopy[i].SetZero() - //bls.CopyFr(&valsCopy[i], &bls.ZERO) } out := make([]fr.Element, n) if err := fs.InplaceFFT(valsCopy, out, inv); err != nil { @@ -121,9 +109,9 @@ func (fs *FFTSettings) InplaceFFT(vals []fr.Element, out []fr.Element, inv bool) } if inv { var invLen fr.Element - //bls.AsFr(&invLen, n) + invLen.SetInt64(int64(n)) - //bls.InvModFr(&invLen, &invLen) + invLen.Inverse(&invLen) rootz := fs.ReverseRootsOfUnity[:fs.MaxWidth] stride := fs.MaxWidth / n @@ -132,9 +120,7 @@ func (fs *FFTSettings) InplaceFFT(vals []fr.Element, out []fr.Element, inv bool) var tmp fr.Element for i := 0; i < len(out); i++ { tmp.Mul(&out[i], &invLen) - //bls.MulModFr(&tmp, &out[i], &invLen) out[i].Set(&tmp) - //bls.CopyFr(&out[i], &tmp) // TODO: depending on Fr implementation, allow to directly write back to an input } return nil } else { diff --git a/encoding/fft/recover_from_samples.go b/encoding/fft/recover_from_samples.go index 0172f1e7cc..bbb6b942d7 100644 --- a/encoding/fft/recover_from_samples.go +++ b/encoding/fft/recover_from_samples.go @@ -33,27 +33,24 @@ import ( // unshift poly, in-place. Multiplies each coeff with 1/shift_factor**i func (fs *FFTSettings) ShiftPoly(poly []fr.Element) { var shiftFactor fr.Element - //bls.AsFr(&shiftFactor, 5) // primitive root of unity shiftFactor.SetInt64(int64(5)) var factorPower fr.Element factorPower.SetOne() - //bls.CopyFr(&factorPower, &ONE) var invFactor fr.Element - //bls.InvModFr(&invFactor, &shiftFactor) invFactor.Inverse(&shiftFactor) var tmp fr.Element for i := 0; i < len(poly); i++ { - //bls.CopyFr(&tmp, &poly[i]) + tmp.Set(&poly[i]) - //bls.MulModFr(&poly[i], &tmp, &factorPower) + poly[i].Mul(&tmp, &factorPower) // TODO: pre-compute all these shift scalars - //bls.CopyFr(&tmp, &factorPower) + tmp.Set(&factorPower) - //bls.MulModFr(&factorPower, &tmp, &invFactor) + factorPower.Mul(&tmp, &invFactor) } } @@ -61,21 +58,21 @@ func (fs *FFTSettings) ShiftPoly(poly []fr.Element) { // unshift poly, in-place. Multiplies each coeff with shift_factor**i func (fs *FFTSettings) UnshiftPoly(poly []fr.Element) { var shiftFactor fr.Element - //bls.AsFr(&shiftFactor, 5) // primitive root of unity + shiftFactor.SetInt64(int64(5)) var factorPower fr.Element factorPower.SetOne() - //bls.CopyFr(&factorPower, &bls.ONE) + var tmp fr.Element for i := 0; i < len(poly); i++ { tmp.Set(&poly[i]) - //bls.CopyFr(&tmp, &poly[i]) + poly[i].Mul(&tmp, &factorPower) - //bls.MulModFr(&poly[i], &tmp, &factorPower) + // TODO: pre-compute all these shift scalars - //bls.CopyFr(&tmp, &factorPower) + tmp.Set(&factorPower) - //bls.MulModFr(&factorPower, &tmp, &shiftFactor) + factorPower.Mul(&tmp, &shiftFactor) } } @@ -104,10 +101,10 @@ func (fs *FFTSettings) RecoverPolyFromSamples(samples []*fr.Element, zeroPolyFn polyEvaluationsWithZero := make([]fr.Element, len(samples)) for i, s := range samples { if s == nil { - //bls.CopyFr(&polyEvaluationsWithZero[i], &ZERO) + polyEvaluationsWithZero[i].SetZero() } else { - //bls.MulModFr(&polyEvaluationsWithZero[i], s, &zeroEval[i]) + polyEvaluationsWithZero[i].Mul(s, &zeroEval[i]) } } @@ -133,7 +130,7 @@ func (fs *FFTSettings) RecoverPolyFromSamples(samples []*fr.Element, zeroPolyFn evalShiftedReconstructedPoly := evalShiftedPolyWithZero for i := 0; i < len(evalShiftedReconstructedPoly); i++ { - //bls.DivModFr(&evalShiftedReconstructedPoly[i], &evalShiftedPolyWithZero[i], &evalShiftedZeroPoly[i]) + evalShiftedReconstructedPoly[i].Div(&evalShiftedPolyWithZero[i], &evalShiftedZeroPoly[i]) } shiftedReconstructedPoly, err := fs.FFT(evalShiftedReconstructedPoly, true) diff --git a/encoding/fft/zero_poly.go b/encoding/fft/zero_poly.go index 74f992f4b7..9394e240f4 100644 --- a/encoding/fft/zero_poly.go +++ b/encoding/fft/zero_poly.go @@ -47,9 +47,9 @@ func (fs *FFTSettings) makeZeroPolyMulLeaf(dst []fr.Element, indices []uint64, d // zero out the unused slots for i := len(indices) + 1; i < len(dst); i++ { dst[i].SetZero() - //bls.CopyFr(&dst[i], &ZERO) + } - //bls.CopyFr(&dst[len(indices)], &bls.ONE) + dst[len(indices)].SetOne() var negDi fr.Element @@ -57,20 +57,19 @@ func (fs *FFTSettings) makeZeroPolyMulLeaf(dst []fr.Element, indices []uint64, d frZero.SetZero() for i, v := range indices { - //bls.SubModFr(&negDi, &bls.ZERO, &fs.ExpandedRootsOfUnity[v*domainStride]) + negDi.Sub(&frZero, &fs.ExpandedRootsOfUnity[v*domainStride]) - //bls.CopyFr(&dst[i], &negDi) + dst[i].Set(&negDi) if i > 0 { - //bls.AddModFr(&dst[i], &dst[i], &dst[i-1]) + dst[i].Add(&dst[i], &dst[i-1]) for j := i - 1; j > 0; j-- { dst[j].Mul(&dst[j], &negDi) - //bls.MulModFr(&dst[j], &dst[j], &negDi) - //bls.AddModFr(&dst[j], &dst[j], &dst[j-1]) + dst[j].Add(&dst[j], &dst[j-1]) } - //bls.MulModFr(&dst[0], &dst[0], &negDi) + dst[0].Mul(&dst[0], &negDi) } } @@ -80,11 +79,11 @@ func (fs *FFTSettings) makeZeroPolyMulLeaf(dst []fr.Element, indices []uint64, d // Copy all of the values of poly into out, and fill the remainder of out with zeroes. func padPoly(out []fr.Element, poly []fr.Element) { for i := 0; i < len(poly); i++ { - //bls.CopyFr(&out[i], &poly[i]) + out[i].Set(&poly[i]) } for i := len(poly); i < len(out); i++ { - //bls.CopyFr(&out[i], &bls.ZERO) + out[i].SetZero() } } @@ -137,7 +136,7 @@ func (fs *FFTSettings) reduceLeaves(scratch []fr.Element, dst []fr.Element, ps [ for i := uint64(0); i < last; i++ { p := ps[i] for j := 0; j < len(p); j++ { - //bls.CopyFr(&pPadded[j], &p[j]) + pPadded[j].Set(&p[j]) } if err := fs.InplaceFFT(pPadded, pEval, false); err != nil { @@ -145,7 +144,7 @@ func (fs *FFTSettings) reduceLeaves(scratch []fr.Element, dst []fr.Element, ps [ } for j := uint64(0); j < n; j++ { mulEvalPs[j].Mul(&mulEvalPs[j], &pEval[j]) - //bls.MulModFr(&mulEvalPs[j], &mulEvalPs[j], &pEval[j]) + } } if err := fs.InplaceFFT(mulEvalPs, dst, true); err != nil { @@ -279,27 +278,26 @@ func (fs *FFTSettings) ZeroPolyViaMultiplication(missingIndices []uint64, length func EvalPolyAt(dst *fr.Element, coeffs []fr.Element, x *fr.Element) { if len(coeffs) == 0 { - //CopyFr(dst, &ZERO) + dst.SetZero() return } if x.IsZero() { - //CopyFr(dst, &coeffs[0]) + dst.Set(&coeffs[0]) return } // Horner's method: work backwards, avoid doing more than N multiplications // https://en.wikipedia.org/wiki/Horner%27s_method var last fr.Element - //CopyFr(&last, &coeffs[len(coeffs)-1]) + last.Set(&coeffs[len(coeffs)-1]) var tmp fr.Element for i := len(coeffs) - 2; i >= 0; i-- { tmp.Mul(&last, x) - //MulModFr(&tmp, &last, x) - //AddModFr(&last, &tmp, &coeffs[i]) + last.Add(&tmp, &coeffs[i]) } - //CopyFr(dst, &last) + dst.Set(&last) } diff --git a/encoding/kzg/prover/parametrized_prover.go b/encoding/kzg/prover/parametrized_prover.go index 011c9840f3..bc35603e56 100644 --- a/encoding/kzg/prover/parametrized_prover.go +++ b/encoding/kzg/prover/parametrized_prover.go @@ -58,7 +58,6 @@ func (g *ParametrizedProver) Encode(inputFr []fr.Element) (*bn254.G1Affine, *bn2 if err != nil { return nil, nil, nil, nil, nil, err } - //lowDegreeCommitment := bls.LinCombG2(g.Srs.G2[:len(poly.Coeffs)], poly.Coeffs) config := ecc.MultiExpConfig{} @@ -207,7 +206,6 @@ func (p *ParametrizedProver) ProveAllCosetThreads(polyFr []fr.Element, numChunks fmt.Printf("mult-th %v, msm %v,fft1 %v, fft2 %v,\n", t0.Sub(begin), t1.Sub(t0), t2.Sub(t1), t3.Sub(t2)) - //rb.ReverseBitOrderG1Point(proofs) return proofs, nil } @@ -251,7 +249,7 @@ func (p *ParametrizedProver) GetSlicesCoeff(polyFr []fr.Element, dimE, j, l uint toeV := make([]fr.Element, 2*dimE-1) for i := uint64(0); i < dim; i++ { - //bls.CopyFr(&toeV[i], &polyFr[m-(j+i*l)]) + toeV[i].Set(&polyFr[m-(j+i*l)]) } diff --git a/encoding/kzg/prover/prover.go b/encoding/kzg/prover/prover.go index b9b3671bb7..6dedb74381 100644 --- a/encoding/kzg/prover/prover.go +++ b/encoding/kzg/prover/prover.go @@ -243,28 +243,6 @@ func (g *Prover) newProver(params encoding.EncodingParams) (*ParametrizedProver, }, nil } -// get Fiat-Shamir challenge -// func createFiatShamirChallenge(byteArray [][32]byte) *fr.Element { -// alphaBytesTmp := make([]byte, 0) -// for i := 0; i < len(byteArray); i++ { -// for j := 0; j < len(byteArray[i]); j++ { -// alphaBytesTmp = append(alphaBytesTmp, byteArray[i][j]) -// } -// } -// alphaBytes := crypto.Keccak256(alphaBytesTmp) -// alpha := new(fr.Element) -// fr.ElementSetBytes(alpha, alphaBytes) -// -// return alpha -// } - -// invert the divisor, then multiply -// func polyFactorDiv(dst *fr.Element, a *fr.Element, b *fr.Element) { -// // TODO: use divmod instead. -// var tmp fr.Element -// bls.InvModFr(&tmp, b) -// bls.MulModFr(dst, &tmp, a) -// } // Detect the precomputed table from the specified directory // the file name follow the name convention of diff --git a/encoding/kzg/setup.go b/encoding/kzg/setup.go index 503df99634..3a6eba8b75 100644 --- a/encoding/kzg/setup.go +++ b/encoding/kzg/setup.go @@ -55,10 +55,10 @@ func GenerateTestingSetup(secret string, n uint64) ([]bn254.G1Affine, []bn254.G2 s1Out := make([]bn254.G1Affine, n) s2Out := make([]bn254.G2Affine, n) for i := uint64(0); i < n; i++ { - //bls.MulG1(&s1Out[i], &GenG1, &sPow) + s1Out[i].ScalarMultiplication(&GenG1, sPow.BigInt(new(big.Int))) - //bls.MulG2(&s2Out[i], &GenG2, &sPow) + s2Out[i].ScalarMultiplication(&GenG2, sPow.BigInt(new(big.Int))) sPow.Mul(&sPow, &s) @@ -75,11 +75,11 @@ func WriteGeneratorPoints(n uint64) error { if err != nil { return err } - //bls.SetFr(&s, secret) + var sPow fr.Element sPow.SetOne() - //bls.CopyFr(&sPow, &bls.ONE) + g1f, err := os.Create("g1.point." + ns) if err != nil { @@ -95,15 +95,14 @@ func WriteGeneratorPoints(n uint64) error { } g2w := bufio.NewWriter(g2f) - //delimiter := [1]byte{'\n'} + start := time.Now() for i := uint64(0); i < n; i++ { var s1Out bn254.G1Affine var s2Out bn254.G2Affine s1Out.ScalarMultiplication(&GenG1, sPow.BigInt(new(big.Int))) - //bls.MulG1(&s1Out, &bls.GenG1, &sPow) - //bls.MulG2(&s2Out, &bls.GenG2, &sPow) + s2Out.ScalarMultiplication(&GenG2, sPow.BigInt(new(big.Int))) g1Byte := s1Out.Bytes() diff --git a/encoding/kzg/verifier/batch_commit_equivalence.go b/encoding/kzg/verifier/batch_commit_equivalence.go index b5e0a92d25..fb3f1ed01f 100644 --- a/encoding/kzg/verifier/batch_commit_equivalence.go +++ b/encoding/kzg/verifier/batch_commit_equivalence.go @@ -57,17 +57,16 @@ func CreateRandomnessVector(g1commits []bn254.G1Affine, g2commits []bn254.G2Affi n := len(g1commits) if len(g1commits) != len(g2commits) { - return nil, errors.New("Inconsistent number of blobs for g1 and g2") + return nil, errors.New("inconsistent number of blobs for g1 and g2") } randomsFr := make([]fr.Element, n) - //bn254.CopyFr(&randomsFr[0], &r) + randomsFr[0].Set(&r) // power of r for j := 0; j < n-1; j++ { randomsFr[j+1].Mul(&randomsFr[j], &r) - //bn254.MulModFr(&randomsFr[j+1], &randomsFr[j], &r) } return randomsFr, nil @@ -105,10 +104,8 @@ func (group *Verifier) BatchVerifyCommitEquivalence(commitmentsPair []Commitment return err } - //lhsG1 := bn254.LinCombG1(g1commits, randomsFr) lhsG2 := &kzg.GenG2 - //rhsG2 := bn254.LinCombG2(g2commits, randomsFr) var rhsG2 bn254.G2Affine _, err = rhsG2.MultiExp(g2commits, randomsFr, ecc.MultiExpConfig{}) if err != nil { diff --git a/encoding/kzg/verifier/multiframe.go b/encoding/kzg/verifier/multiframe.go index 65235b3cb7..7ae8955a1d 100644 --- a/encoding/kzg/verifier/multiframe.go +++ b/encoding/kzg/verifier/multiframe.go @@ -88,17 +88,17 @@ func genRhsG1(samples []Sample, randomsFr []fr.Element, m int, params encoding.E for k := 0; k < n; k++ { s := samples[k] row := s.RowIndex - //bls.AddModFr(&aggCommitCoeffs[row], &aggCommitCoeffs[row], &randomsFr[k]) + aggCommitCoeffs[row].Add(&aggCommitCoeffs[row], &randomsFr[k]) if !setCommit[row] { commits[row].Set(&s.Commitment) - //bls.CopyG1(&commits[row], &s.Commitment) + setCommit[row] = true } else { - //bls.EqualG1(&commits[row], &s.Commitment) + if !commits[row].Equal(&s.Commitment) { - return nil, errors.New("Samples of the same row has different commitments") + return nil, errors.New("samples of the same row has different commitments") } } } @@ -135,7 +135,6 @@ func genRhsG1(samples []Sample, randomsFr []fr.Element, m int, params encoding.E if err != nil { return nil, err } - //aggPolyG1 := bls.LinCombG1(ks.Srs.G1[:D], aggPolyCoeffs) // third term // leading coset is an evaluation index, here we compute the weighted leading coset evaluation by random fields @@ -150,22 +149,19 @@ func genRhsG1(samples []Sample, randomsFr []fr.Element, m int, params encoding.E h := ks.ExpandedRootsOfUnity[samples[k].X] var hPow fr.Element hPow.SetOne() - //bls.CopyFr(&hPow, &bls.ONE) // raising the power for each leading coset for j := uint64(0); j < D; j++ { hPow.Mul(&hPow, &h) - //bls.MulModFr(&tmp, &hPow, &h) - //bls.CopyFr(&hPow, &tmp) } - //bls.CopyFr(&leadingDs[k], &hPow) + leadingDs[k].Set(&hPow) } // applying the random weights to leading coset elements for k := 0; k < n; k++ { rk := randomsFr[k] - //bls.MulModFr(&lcCoeffs[k], &rk, &leadingDs[k]) + lcCoeffs[k].Mul(&rk, &leadingDs[k]) } @@ -175,12 +171,10 @@ func genRhsG1(samples []Sample, randomsFr []fr.Element, m int, params encoding.E return nil, err } - //offsetG1 := bls.LinCombG1(proofs, lcCoeffs) - var rhsG1 bn254.G1Affine - //bls.SubG1(&rhsG1, aggCommit, aggPolyG1) + rhsG1.Sub(&aggCommit, &aggPolyG1) - //bls.AddG1(&rhsG1, &rhsG1, offsetG1) + rhsG1.Add(&rhsG1, &offsetG1) return &rhsG1, nil } @@ -253,12 +247,12 @@ func (group *Verifier) UniversalVerify(params encoding.EncodingParams, samples [ // array of proofs proofs := make([]bn254.G1Affine, n) for i := 0; i < n; i++ { - //bls.CopyG1(&proofs[i], &samples[i].Proof) + proofs[i].Set(&samples[i].Proof) } // lhs g1 - //lhsG1 := bls.LinCombG1(proofs, randomsFr) + var lhsG1 bn254.G1Affine _, err = lhsG1.MultiExp(proofs, randomsFr, ecc.MultiExpConfig{}) if err != nil { diff --git a/encoding/kzg/verifier/verifier.go b/encoding/kzg/verifier/verifier.go index d1b312cab6..fd145034ee 100644 --- a/encoding/kzg/verifier/verifier.go +++ b/encoding/kzg/verifier/verifier.go @@ -262,8 +262,6 @@ func VerifyFrame(f *encoding.Frame, ks *kzg.KZGSettings, commitment *bn254.G1Aff xnMinusYn.Sub(g2Atn, &xn2) // [interpolation_polynomial(s)]_1 - //is1 := bls.LinCombG1(ks.Srs.G1[:len(f.Coeffs)], f.Coeffs) - var is1 bn254.G1Affine config := ecc.MultiExpConfig{} _, err := is1.MultiExp(ks.Srs.G1[:len(f.Coeffs)], f.Coeffs, config) @@ -274,7 +272,6 @@ func VerifyFrame(f *encoding.Frame, ks *kzg.KZGSettings, commitment *bn254.G1Aff // [commitment - interpolation_polynomial(s)]_1 = [commit]_1 - [interpolation_polynomial(s)]_1 var commitMinusInterpolation bn254.G1Affine commitMinusInterpolation.Sub(commitment, &is1) - //bls.SubG1(&commitMinusInterpolation, commitment, is1) // Verify the pairing equation // @@ -313,10 +310,10 @@ func toUint64Array(chunkIndices []encoding.ChunkNumber) []uint64 { func PairingsVerify(a1 *bn254.G1Affine, a2 *bn254.G2Affine, b1 *bn254.G1Affine, b2 *bn254.G2Affine) error { var negB1 bn254.G1Affine - negB1.Neg((*bn254.G1Affine)(b1)) + negB1.Neg(b1) - P := [2]bn254.G1Affine{*(*bn254.G1Affine)(a1), negB1} - Q := [2]bn254.G2Affine{*(*bn254.G2Affine)(a2), *(*bn254.G2Affine)(b2)} + P := [2]bn254.G1Affine{*a1, negB1} + Q := [2]bn254.G2Affine{*a2, *b2} ok, err := bn254.PairingCheck(P[:], Q[:]) if err != nil { diff --git a/encoding/rs/decode.go b/encoding/rs/decode.go index 09b1d33449..6bb67be3e6 100644 --- a/encoding/rs/decode.go +++ b/encoding/rs/decode.go @@ -42,7 +42,7 @@ func (g *Encoder) Decode(frames []Frame, indices []uint64, maxInputSize uint64) for j := uint64(0); j < g.ChunkLength; j++ { p := j*g.NumChunks + uint64(e) samples[p] = new(fr.Element) - //bls.CopyFr(samples[p], &evals[j]) + samples[p].Set(&evals[j]) } } diff --git a/encoding/rs/encode.go b/encoding/rs/encode.go index 28900fe8df..68bf2438bd 100644 --- a/encoding/rs/encode.go +++ b/encoding/rs/encode.go @@ -114,12 +114,10 @@ func (g *Encoder) ExtendPolyEval(coeffs []fr.Element) ([]fr.Element, []fr.Elemen pdCoeffs := make([]fr.Element, g.NumEvaluations()) for i := 0; i < len(coeffs); i++ { - //bls.CopyFr(&pdCoeffs[i], &coeffs[i]) pdCoeffs[i].Set(&coeffs[i]) } for i := len(coeffs); i < len(pdCoeffs); i++ { pdCoeffs[i].SetZero() - //bls.CopyFr(&pdCoeffs[i], &bls.ZERO) } evals, err := g.Fs.FFT(pdCoeffs, false) diff --git a/encoding/rs/interpolation.go b/encoding/rs/interpolation.go index 8f87db638d..5aa062edb7 100644 --- a/encoding/rs/interpolation.go +++ b/encoding/rs/interpolation.go @@ -54,11 +54,9 @@ func (g *Encoder) GetInterpolationPolyEval( //var tmp, tmp2 fr.Element for i := 0; i < len(interpolationPoly); i++ { shiftedInterpolationPoly[i].Mul(&interpolationPoly[i], &wPow) - //bls.MulModFr(&tmp2, &interpolationPoly[i], &wPow) - //bls.CopyFr(&shiftedInterpolationPoly[i], &tmp2) + wPow.Mul(&wPow, &w) - //bls.MulModFr(&tmp, &wPow, &w) - //bls.CopyFr(&wPow, &tmp) + } err := g.Fs.InplaceFFT(shiftedInterpolationPoly, evals, false) @@ -76,18 +74,17 @@ func (g *Encoder) GetInterpolationPolyCoeff(chunk []fr.Element, k uint32) ([]fr. } var wPow fr.Element wPow.SetOne() - //bls.CopyFr(&wPow, &bls.ONE) + var tmp, tmp2 fr.Element for i := 0; i < len(chunk); i++ { tmp.Inverse(&wPow) - //bls.InvModFr(&tmp, &wPow) + tmp2.Mul(&shiftedInterpolationPoly[i], &tmp) - //bls.MulModFr(&tmp2, &shiftedInterpolationPoly[i], &tmp) - //bls.CopyFr(&coeffs[i], &tmp2) + coeffs[i].Set(&tmp2) - //bls.MulModFr(&tmp, &wPow, &w) + tmp.Mul(&wPow, &w) - //bls.CopyFr(&wPow, &tmp) + wPow.Set(&tmp) } return coeffs, nil diff --git a/encoding/test/testCrypto.go b/encoding/test/testCrypto.go index 403deb3b2e..a40eba803c 100644 --- a/encoding/test/testCrypto.go +++ b/encoding/test/testCrypto.go @@ -130,57 +130,4 @@ func Verify(commitment *gkzg.Digest, proof *gkzg.OpeningProof, point fr.Element, } return nil -} - -// func newKZGSRS(kzgSize uint64) (*gkzg.SRS, error) { -// alpha, err := new(big.Int).SetString("1927409816240961209460912649125", 10) -// if !err { -// log.Fatal(err) -// } -// return gkzg.NewSRS(kzgSize, alpha) -// } -// -// func testBnFr() { -// -// a := [4]uint64{0, 1, 2, 3} -// aFr := makeBnFr(a[:]) -// fmt.Println("BnFr") -// printBnFr(aFr) -// -// diff := make([]bnl.Fr, 4) -// -// for i := 0; i < 4; i++ { -// a := aFr[i] -// var b bnl.Fr -// bnl.CopyFr(&a, &b) -// -// bnl.SubModFr(&diff[i], &a, &b) -// } -// fmt.Println("diff") -// printBnFr(diff) -// } - -// func makeBnFr(input []uint64) []bnl.Fr { -// inputFr := make([]bnl.Fr, len(input)) -// for i := 0; i < len(input); i++ { -// bnl.AsFr(&inputFr[i], input[i]) -// } -// return inputFr -// } -// -// func printBnFr(d []bnl.Fr) { -// for _, e := range d { -// fmt.Printf("%v ", e.String()) -// } -// fmt.Printf("\n") -// } -// -// func genText(M uint64) []byte { -// signal := make([]byte, M) -// rand.Seed(time.Now().UnixNano()) -// for i := uint64(0); i < M; i++ { -// r := rand.Intn(128) -// signal[i] = byte(r) -// } -// return signal -// } +} \ No newline at end of file diff --git a/encoding/utils/reverseBits/reverseBits.go b/encoding/utils/reverseBits/reverseBits.go index b000c31e98..d08d1bf1f6 100644 --- a/encoding/utils/reverseBits/reverseBits.go +++ b/encoding/utils/reverseBits/reverseBits.go @@ -124,11 +124,11 @@ func ReverseBitOrderFr(values []fr.Element) error { var tmp fr.Element err := ReverseBitOrder(uint32(len(values)), func(i, j uint32) { tmp.Set(&values[i]) - //bls.CopyFr(&tmp, &values[i]) + values[i].Set(&values[j]) - //bls.CopyFr(&values[i], &values[j]) + values[j].Set(&tmp) - //bls.CopyFr(&values[j], &tmp) + }) return err } @@ -154,9 +154,6 @@ func ReverseBitOrderG1Point(values []bn254.G1Affine) error { values[i].Set(&values[j]) values[j].Set(&tmp) - //bls.CopyG1(&tmp, &values[i]) - //bls.CopyG1(&values[i], &values[j]) - //bls.CopyG1(&values[j], &tmp) }) return err } diff --git a/encoding/utils/toeplitz/toeplitz.go b/encoding/utils/toeplitz/toeplitz.go index 631048e59b..7145c3541a 100644 --- a/encoding/utils/toeplitz/toeplitz.go +++ b/encoding/utils/toeplitz/toeplitz.go @@ -97,7 +97,7 @@ func (t *Toeplitz) ExtendCircularVec() []fr.Element { E[0].Set(&t.V[0]) for i := 1; i < numRow; i++ { - //bls.CopyFr(&E[i], &t.V[len(t.V)-i]) + E[i].Set(&t.V[len(t.V)-i]) } @@ -119,11 +119,11 @@ func (t *Toeplitz) ExtendCircularVec() []fr.Element { func (t *Toeplitz) FromColVToRowV(cv []fr.Element) []fr.Element { n := len(cv) rv := make([]fr.Element, n) - //bls.CopyFr(&rv[0], &cv[0]) + rv[0].Set(&cv[0]) for i := 1; i < n; i++ { - //bls.CopyFr(&rv[i], &cv[n-i]) + rv[i].Set(&cv[n-i]) } @@ -144,16 +144,16 @@ func (t *Toeplitz) DirectMultiply(x []fr.Element) []fr.Element { for i := 0; i < numCol; i++ { var sum fr.Element sum.SetZero() - //bls.CopyFr(&sum, &bls.ZERO) + for j := 0; j < numCol; j++ { idx := (j - i + n) % n var product fr.Element product.Mul(&t.V[idx], &x[j]) - //bls.MulModFr(&product, &t.V[idx], &x[j]) + sum.Add(&product, &sum) - //bls.AddModFr(&sum, &product, &sum) + } - //bls.CopyFr(&out[i], &sum) + out[i].Set(&sum) }