mirror of
https://github.com/logos-storage/nim-groth16.git
synced 2026-07-22 00:19:28 +00:00
preparation for multiple versions of the dynamic prover
This commit is contained in:
parent
e532d67046
commit
257e2e20f0
@ -100,6 +100,16 @@ func orBoolSeqs*( us: seq[bool] , vs: seq[bool]): seq[bool] =
|
||||
ws[i] = us[i] or vs[i]
|
||||
return ws
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# int arrays
|
||||
|
||||
func sumIntSeq*(xs : seq[int]): int =
|
||||
let n = xs.len
|
||||
var s = 0
|
||||
for i in 0..<n:
|
||||
s += xs[i]
|
||||
return s
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Fr arrays
|
||||
|
||||
|
||||
@ -34,25 +34,6 @@ type
|
||||
imageB* : seq[bool] # image of the witness update space under B
|
||||
imageAB* : seq[bool] # union of the previous two
|
||||
|
||||
# things we can compute at circuit setup time
|
||||
DynaSetupV1* = object
|
||||
weightVec* : seq[F] # the values `W_k` (it's surprisingly slow to re-compute in the finish part!)
|
||||
pointsDeltaLZ* : seq[G1] # the points `delta^-1 * L_i(tau) * Z(tau) * g1` where `Z(x) = x^N-1`
|
||||
wConvDeltaLZ* : seq[G1] # the convolution of `W` and `pointsDeltaLZ`
|
||||
diagPhiPoints* : seq[G1] # the points `delta^-1 * phi_ii(tau) * Z(tau) * g1` from the Dynark paper
|
||||
|
||||
# things we can compute from the partial witness
|
||||
DynaPreprocessV1* = object
|
||||
projA0* : seq[G1] # the points `delta^-1 * A0(tau) * L_i(tau) * g1` (well, "modulo Z(tau)")
|
||||
projB0* : seq[G1] # the same for B0
|
||||
|
||||
# "pre-proof" of the Dynark paper, which we can finish
|
||||
DynaPreProofV1* = object
|
||||
partialProof* : PartialProof # linear part of the partial proof
|
||||
deltaImages* : DeltaImages # image of the witness delta under A and B (where can update happen)
|
||||
dynaSetup* : DynaSetupV1 # circuit-setup time calculations
|
||||
dynaPreprocess* : DynaPreprocessV1 # "Dynark"-style preprocessing
|
||||
|
||||
# this is used in the "cross-term"
|
||||
OnlyAB* = object
|
||||
valuesAz* : seq[F]
|
||||
|
||||
@ -34,9 +34,9 @@ import groth16/prover/types
|
||||
import groth16/prover/shared
|
||||
import groth16/partial/finish
|
||||
|
||||
import groth16/dynamic/types
|
||||
import groth16/dynamic/setup
|
||||
import groth16/dynamic/shared
|
||||
import groth16/dynamic/v1/types
|
||||
import groth16/dynamic/v1/setup
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@ -29,10 +29,10 @@ import groth16/math/poly
|
||||
|
||||
import groth16/partial/precalc
|
||||
|
||||
import groth16/dynamic/types
|
||||
import groth16/dynamic/setup
|
||||
import groth16/dynamic/shared
|
||||
import groth16/dynamic/finish
|
||||
import groth16/dynamic/v1/types
|
||||
import groth16/dynamic/v1/setup
|
||||
import groth16/dynamic/v1/finish
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -139,6 +139,31 @@ proc dynaPreProofV1*(zkey: ZKey, setup: DynaSetupV1, partialWitness: PartialWitn
|
||||
let N = zkey.header.domainSize
|
||||
let D = createDomain(N)
|
||||
|
||||
#[
|
||||
import groth16/math/matrix
|
||||
import std/tables # TODO: temporary!
|
||||
|
||||
# TODO: just tmp testing
|
||||
let M = zkey.header.nvars
|
||||
let matABC = zkeyToSparseMatrices(zkey)
|
||||
let dmask = notBoolSeq( partialWitnessMask(partialWitness) )
|
||||
let cntA = selectTrues( dmask , sparseMatrixColumnCounts(matABC.A) )
|
||||
let cntB = selectTrues( dmask , sparseMatrixColumnCounts(matABC.B) )
|
||||
# echo $cntA
|
||||
# echo $cntB
|
||||
echo $sumIntSeq(cntA)
|
||||
echo $sumIntSeq(cntB)
|
||||
echo $countTrues(dmask)
|
||||
for j in 0..<M:
|
||||
if dmask[j]:
|
||||
for (i,x) in matABC.A.columns[j].pairs:
|
||||
echo toDecimalFr(x)
|
||||
for j in 0..<M:
|
||||
if dmask[j]:
|
||||
for (i,x) in matABC.B.columns[j].pairs:
|
||||
echo toDecimalFr(x)
|
||||
]#
|
||||
|
||||
var partialAB : PartialAB
|
||||
withMeasureTime(printTimings,"build partial AB"):
|
||||
partialAB = buildPartialAB( zkey, partialWitness.values )
|
||||
@ -18,8 +18,8 @@ import groth16/math/convert
|
||||
|
||||
import groth16/zkey_types
|
||||
|
||||
import groth16/dynamic/types
|
||||
import groth16/dynamic/shared
|
||||
import groth16/dynamic/v1/types
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
40
groth16/dynamic/v1/types.nim
Normal file
40
groth16/dynamic/v1/types.nim
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
{.push raises:[].}
|
||||
|
||||
#import constantine/named/properties_fields
|
||||
|
||||
import groth16/bn128
|
||||
import groth16/math/domain
|
||||
#import groth16/math/ntt
|
||||
#import groth16/math/poly
|
||||
|
||||
import groth16/partial/types as ptypes
|
||||
import groth16/dynamic/types as dtypes
|
||||
|
||||
export ptypes
|
||||
export dtypes
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
type
|
||||
|
||||
# things we can compute at circuit setup time
|
||||
DynaSetupV1* = object
|
||||
weightVec* : seq[F] # the values `W_k` (it's surprisingly slow to re-compute in the finish part!)
|
||||
pointsDeltaLZ* : seq[G1] # the points `delta^-1 * L_i(tau) * Z(tau) * g1` where `Z(x) = x^N-1`
|
||||
wConvDeltaLZ* : seq[G1] # the convolution of `W` and `pointsDeltaLZ`
|
||||
diagPhiPoints* : seq[G1] # the points `delta^-1 * phi_ii(tau) * Z(tau) * g1` from the Dynark paper
|
||||
|
||||
# things we can compute from the partial witness
|
||||
DynaPreprocessV1* = object
|
||||
projA0* : seq[G1] # the points `delta^-1 * A0(tau) * L_i(tau) * g1` (well, "modulo Z(tau)")
|
||||
projB0* : seq[G1] # the same for B0
|
||||
|
||||
# "pre-proof" of the Dynark paper, which we can finish
|
||||
DynaPreProofV1* = object
|
||||
partialProof* : PartialProof # linear part of the partial proof
|
||||
deltaImages* : DeltaImages # image of the witness delta under A and B (where can update happen)
|
||||
dynaSetup* : DynaSetupV1 # circuit-setup time calculations
|
||||
dynaPreprocess* : DynaPreprocessV1 # "Dynark"-style preprocessing
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -125,7 +125,7 @@ proc finishPartialProofWithMaskGeneric*( nonlinear_term: bool, zkey: ZKey, wtns:
|
||||
|
||||
var rho : G1 = partialProof.partial_rho
|
||||
withMeasureTime(printTimings,"computing rho (G1 MSM)"):
|
||||
rho += s ** spec.delta1
|
||||
# rho += s ** spec.delta1
|
||||
rho += msmMultiThreadedG1( compact_witness , compact_pointsB1, pool )
|
||||
|
||||
var pi_b : G2 = partialProof.partial_pi_b
|
||||
@ -137,7 +137,7 @@ proc finishPartialProofWithMaskGeneric*( nonlinear_term: bool, zkey: ZKey, wtns:
|
||||
withMeasureTime(printTimings,"computing pi_C linear part (G1 MSM)"):
|
||||
pi_c += s ** pi_a
|
||||
pi_c += r ** rho
|
||||
pi_c += negFr(r*s) ** spec.delta1
|
||||
# pi_c += negFr(r*s) ** spec.delta1
|
||||
pi_c += msmMultiThreadedG1( compact_zs , compact_pointsC1, pool )
|
||||
|
||||
withMeasureTime(printTimings,"computing pi_C nonlinear part (large G1 MSM)"):
|
||||
|
||||
@ -77,7 +77,7 @@ func extractVKey*(zkey: Zkey): VKey =
|
||||
return VKey(curve:curve, spec:spec, vpoints:vpts)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# extract the three matrices from the ZKey
|
||||
# extract the three matrices from the ZKey (TODO: C is actually not there...)
|
||||
|
||||
func coeffsToSparseMatrices*( dims: MatrixDims, coeffs: seq[Coeff]): SparseMatrices =
|
||||
var A: SparseMatrixColumns[Fr[BN254_Snarks]] = newSeq[SparseColumn[Fr[BN254_Snarks]]] ( dims.ncols )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user