diff --git a/groth16.nimble b/groth16.nimble index 8c74b38..d1f8ecf 100644 --- a/groth16.nimble +++ b/groth16.nimble @@ -12,3 +12,13 @@ requires "nim >= 2.2.0" requires "https://github.com/status-im/nim-taskpools >= 0.0.5" requires "https://github.com/mratsim/constantine" # requires "https://github.com/mratsim/constantine#bc3845aa492b52f7fef047503b1592e830d1a774" + +task test_arc, "run the test suite under --mm:arc": + exec "nim c -r --threads:on --mm:arc tests/test.nim" + +task test_refc, "run the test suite under --mm:refc": + exec "nim c -r --threads:on --mm:refc tests/test.nim" + +task test, "run the test suite under both --mm:arc and --mm:refc": + exec "nim c -r --threads:on --mm:arc tests/test.nim" + exec "nim c -r --threads:on --mm:refc tests/test.nim" 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..