diff --git a/README.md b/README.md index abae8ea..8a97122 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ at your choice. ### TODO -- [ ] find and fix the _second_ totally surreal bug +- [x] find and fix the _second_ totally surreal bug - [ ] clean up the code - [ ] make it compatible with the latest constantine and also Nim 2.0.x - [x] make it a nimble package - [ ] compare `.r1cs` to the "coeffs" section of `.zkey` - [x] generate fake circuit-specific setup ourselves - [x] make a CLI interface -- [ ] multithreading support (MSM, and possibly also FFT) +- [x] multithreading support (MSM, and possibly also FFT) - [ ] add Groth16 notes - [ ] document the `snarkjs` circuit-specific setup `H` points convention - [ ] make it work for different curves diff --git a/cli/nim.cfg b/cli/nim.cfg index b20433f..abe4065 100644 --- a/cli/nim.cfg +++ b/cli/nim.cfg @@ -1,2 +1,3 @@ --path:".." ---threads:on \ No newline at end of file +--threads:on +--mm:arc \ No newline at end of file diff --git a/groth16/bn128/msm.nim b/groth16/bn128/msm.nim index d98b949..71f51e9 100644 --- a/groth16/bn128/msm.nim +++ b/groth16/bn128/msm.nim @@ -102,10 +102,6 @@ proc msmMultiThreadedG1*( nthreads_hint: int, coeffs: seq[Fr] , points: seq[G1] var pool = Taskpool.new(num_threads = nthreads) var pending : seq[FlowVar[mycurves.G1]] = newSeq[FlowVar[mycurves.G1]](ntasks) - # nim is just batshit crazy... - GC_ref(coeffs) - GC_ref(points) - var a : int = 0 var b : int for k in 0.. # -proc computeSnarkjsScalarCoeffs( nthreads: int, abc: ABC ): seq[Fr] = +proc computeSnarkjsScalarCoeffs( nthreads: int, abc: ABC): seq[Fr] = let n = abc.valuesAz.len assert( abc.valuesBz.len == n ) assert( abc.valuesCz.len == n ) @@ -166,16 +163,11 @@ proc computeSnarkjsScalarCoeffs( nthreads: int, abc: ABC ): seq[Fr] = let eta = createDomain(2*n).domainGen var pool = Taskpool.new(num_threads = nthreads) - GCref(abc.valuesAz) - GCref(abc.valuesBz) - GCref(abc.valuesCz) + var A1fv : FlowVar[seq[Fr]] = pool.spawn shiftEvalDomain( abc.valuesAz, D, eta ) var B1fv : FlowVar[seq[Fr]] = pool.spawn shiftEvalDomain( abc.valuesBz, D, eta ) var C1fv : FlowVar[seq[Fr]] = pool.spawn shiftEvalDomain( abc.valuesCz, D, eta ) - pool.syncAll() - GCunref(abc.valuesAz) - GCunref(abc.valuesBz) - GCunref(abc.valuesCz) + let A1 = sync A1fv let B1 = sync B1fv let C1 = sync C1fv @@ -183,9 +175,34 @@ proc computeSnarkjsScalarCoeffs( nthreads: int, abc: ABC ): seq[Fr] = var ys : seq[Fr] = newSeq[Fr]( n ) for j in 0..