From 52858cb80fc412532fc81c09ea9a6e8d705be96c Mon Sep 17 00:00:00 2001 From: Balazs Komuves Date: Tue, 16 Jun 2026 13:50:28 +0200 Subject: [PATCH] merge the two witness MSM-s into a single one --- groth16/dynamic/v2/finish.nim | 79 ++++++++++++++++++++++++++++++- groth16/dynamic/v2/preprocess.nim | 43 +++++++++++++++-- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/groth16/dynamic/v2/finish.nim b/groth16/dynamic/v2/finish.nim index fbb7e93..7ba2acf 100644 --- a/groth16/dynamic/v2/finish.nim +++ b/groth16/dynamic/v2/finish.nim @@ -40,6 +40,83 @@ import groth16/dynamic/v2/setup #------------------------------------------------------------------------------- +# you can turn on/off the computation of the nonlinear term (useful for the "dynark" version) +proc finishLinearTerms( zkey: ZKey, wtns: Witness, partialProof: PartialProof, mask: Mask, pool: Taskpool, printTimings: bool): Proof = + + assert( zkey.header.curve == wtns.curve ) + + let witness = wtns.values + + let hdr : GrothHeader = zkey.header + let spec : SpecPoints = zkey.specPoints + let pts : ProverPoints = zkey.pPoints + + let nvars = hdr.nvars + let npubs = hdr.npubs + + assert( nvars == witness.len , "wrong witness length" ) + + let partial_mask = partialProof.partial_mask + + # remark: with the special variable "1" we actuall have (npub+1) public IO variables + var pubIO = newSeq[Fr[BN254_Snarks]]( npubs + 1) + for i in 0..npubs: pubIO[i] = witness[i] + + # note: we have to ignore public inputs (plus 1 for the special first entry) + let startIdx : int = npubs + 1 + var count : int = countFalses(partial_mask) # number of NEW witness elements + + # compactify the stuff so we can call normal vector MSM + var compact_witness: seq[F] = newSeq[F](count) + var compact_pointsA1: seq[G1] = newSeq[G1](count) + var compact_pointsB1: seq[G1] = newSeq[G1](count) + var compact_pointsB2: seq[G2] = newSeq[G2](count) + block: + var j: int = 0; + for i in 0..= startIdx: + compact_pointsC1[j] = pts.pointsC1[ i - startIdx ] + else: + compact_pointsC1[j] = infG1 + j += 1 + + assert( nvars - npubs - 1 == pts.pointsC1.len ) + + return compact_pointsC1 + +#------------------------------------------------------------------------------- + +proc dynaPreprocessV2*(zkey: ZKey, setup: DynaSetupV2, partialAB: PartialAB, partial_mask: seq[bool], zdeltaMask: seq[bool] ): DynaPreprocessV2 = let N = zkey.header.domainSize let D = createDomain(N) @@ -69,6 +99,8 @@ proc dynaPreprocessV2*(zkey: ZKey, setup: DynaSetupV2, partialAB: PartialAB, zde let m = countTrues(zdeltaMask) var Xs: seq[G1] = newSeq[G1]( m ) + let points_C1 = compactifyPointsC1( zkey, partial_mask ) + withMeasureTime(true," + the \"unified\" points X_j"): let matABC = zkeyToSparseMatrices(zkey) @@ -76,7 +108,7 @@ proc dynaPreprocessV2*(zkey: ZKey, setup: DynaSetupV2, partialAB: PartialAB, zde let colsB = selectTrues( zdeltaMask , matABC.B.columns ) for j in 0..