diff --git a/cli/nim.cfg b/cli/nim.cfg index abe4065..40003bd 100644 --- a/cli/nim.cfg +++ b/cli/nim.cfg @@ -1,3 +1,3 @@ --path:".." --threads:on ---mm:arc \ No newline at end of file +--mm:refc \ No newline at end of file diff --git a/groth16.nimble b/groth16.nimble index 8c74b38..29b38d3 100644 --- a/groth16.nimble +++ b/groth16.nimble @@ -1,3 +1,4 @@ + version = "0.1.1" author = "Balazs Komuves" description = "Groth16 proof system" diff --git a/groth16/bn128/msm.nim b/groth16/bn128/msm.nim index b471e01..f4c0cb0 100644 --- a/groth16/bn128/msm.nim +++ b/groth16/bn128/msm.nim @@ -22,6 +22,7 @@ import constantine/math/elliptic/ec_multi_scalar_mul as msm except Su #import groth16/bn128/fields import groth16/bn128/curves as mycurves +import groth16/sharedbuf #import groth16/misc # TEMP DEBUGGING #import std/cpuinfo @@ -79,6 +80,33 @@ func msmConstantineG2*( coeffs: openArray[Fr[BN254_Snarks]] , points: openArray[ return rAff +#------------------------------------------------------------------------------- +# spawnable wrappers: take SharedBuf views, delegate to the core. +# These are what `pool.spawn` calls, so they carry {.gcsafe, raises: [].}. +# +# Local aliases `AffG1`/`AffG2` are required because taskpools' `spawn` macro +# does `getImpl().replaceSymsByIdents()`, which strips qualifications. With +# `SharedBuf[mycurves.G1]` the bare ident `G1` then re-resolves to the enum +# value `aff.G1` (of type `Subgroup`), not the type alias. Renaming dodges +# the collision. + +type + AffG1 = mycurves.G1 + AffG2 = mycurves.G2 + FrBN = Fr[BN254_Snarks] + +func msmConstantineG1Range( coeffs: SharedBuf[FrBN] , + points: SharedBuf[AffG1] ): AffG1 + {.gcsafe, raises: [].} = + msmConstantineG1( toOpenArray(coeffs.payload, 0, coeffs.len - 1), + toOpenArray(points.payload, 0, points.len - 1) ) + +func msmConstantineG2Range( coeffs: SharedBuf[FrBN] , + points: SharedBuf[AffG2] ): AffG2 + {.gcsafe, raises: [].} = + msmConstantineG2( toOpenArray(coeffs.payload, 0, coeffs.len - 1), + toOpenArray(points.payload, 0, points.len - 1) ) + #------------------------------------------------------------------------------- const task_multiplier : int = 1 @@ -105,9 +133,9 @@ proc msmMultiThreadedG1*( coeffs: seq[Fr[BN254_Snarks]] , points: seq[G1], pool: b = (N*(k+1)) div ntasks else: b = N - let cs = coeffs[a..