mirror of
https://github.com/logos-storage/nim-groth16.git
synced 2026-01-05 23:23:08 +00:00
fix msm
This commit is contained in:
parent
37f0f5393d
commit
3123948164
@ -26,12 +26,12 @@ import constantine/math/config/curves
|
||||
import constantine/math/config/type_ff as tff
|
||||
|
||||
import constantine/math/extension_fields/towers as ext
|
||||
import constantine/math/ec_shortweierstrass as wst
|
||||
import constantine/math/elliptic/ec_shortweierstrass_affine as aff
|
||||
import constantine/math/elliptic/ec_shortweierstrass_projective as prj
|
||||
import constantine/math/pairings/pairings_bn as ate
|
||||
import constantine/math/elliptic/ec_scalar_mul as scl
|
||||
import constantine/math/elliptic/ec_multi_scalar_mul as msm
|
||||
import constantine/math/isogenies/frobenius as frb
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@ -674,14 +674,38 @@ func msmG1*( coeffs: openArray[Fr] , points: openArray[G1] ): G1 =
|
||||
for x in coeffs:
|
||||
bigcfs.add( x.toBig() )
|
||||
|
||||
var r : G1
|
||||
var r : ProjG1
|
||||
|
||||
# [Fp,aff.G1]
|
||||
msm.multiScalarMul_vartime( wst.ECP_ShortW[Fp, Subgroup.G1](r),
|
||||
msm.multiScalarMul_vartime( r,
|
||||
toOpenArray(bigcfs, 0, N-1),
|
||||
toOpenArray(points, 0, N-1) )
|
||||
|
||||
return r
|
||||
var rAff: G1
|
||||
prj.affine(rAff, r)
|
||||
|
||||
return rAff
|
||||
|
||||
func msmG2*( coeffs: openArray[Fr] , points: openArray[G2] ): G2 =
|
||||
|
||||
let N = coeffs.len
|
||||
assert( N == points.len, "incompatible sequence lengths" )
|
||||
|
||||
var bigcfs : seq[BigInt[254]]
|
||||
for x in coeffs:
|
||||
bigcfs.add( x.toBig() )
|
||||
|
||||
var r : ProjG2
|
||||
|
||||
# [Fp,aff.G1]
|
||||
msm.multiScalarMul_vartime( r,
|
||||
toOpenArray(bigcfs, 0, N-1),
|
||||
toOpenArray(points, 0, N-1) )
|
||||
|
||||
var rAff: G2
|
||||
prj.affine(rAff, r)
|
||||
|
||||
return rAff
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#
|
||||
@ -764,15 +788,6 @@ func msmNaiveG2( coeffs: seq[Fr] , points: seq[G2] ): G2 =
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# TODO: proper MSM implementation (couldn't make constantine work at first...)
|
||||
# func msmG1*( coeffs: seq[Fr] , points: seq[G1] ): G1 =
|
||||
# return msmNaiveG1( coeffs, points )
|
||||
|
||||
func msmG2*( coeffs: seq[Fr] , points: seq[G2] ): G2 =
|
||||
return msmNaiveG2( coeffs, points )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc sanityCheckGroupGen*() =
|
||||
echo( "gen1 on the curve = ", checkCurveEqG1(gen1.x,gen1.y) )
|
||||
echo( "gen2 on the curve = ", checkCurveEqG2(gen2.x,gen2.y) )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user