@@ -12,7 +12,7 @@ import (
1212 "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/asn1"
1313 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/crypto/common"
1414 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/crypto/math"
15- "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/crypto/rp"
15+ rp "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/crypto/rp/executor "
1616)
1717
1818// IPA contains the proof for the inner product argument.
@@ -111,9 +111,14 @@ type ipaProver struct {
111111 NumberOfRounds uint64
112112 // Curve is the mathematical curve.
113113 Curve * mathlib.Curve
114+ // Provider creates a fresh Executor for each Prove call.
115+ // If nil, DefaultProvider (SerialProvider) is used.
116+ Provider rp.ExecutorProvider
114117}
115118
116119// NewIPAProver returns a new ipaProver instance.
120+ // exec controls how generator reduction is parallelised; pass nil
121+ // to use SerialExecutor (equivalent to the previous behaviour).
117122func NewIPAProver (
118123 innerProduct * mathlib.Zr ,
119124 leftVector , rightVector []* mathlib.Zr ,
@@ -122,7 +127,12 @@ func NewIPAProver(
122127 Commitment * mathlib.G1 ,
123128 rounds uint64 ,
124129 c * mathlib.Curve ,
130+ provider rp.ExecutorProvider ,
125131) * ipaProver {
132+ if provider == nil {
133+ provider = rp .DefaultProvider
134+ }
135+
126136 return & ipaProver {
127137 InnerProduct : innerProduct ,
128138 rightVector : rightVector ,
@@ -133,6 +143,7 @@ func NewIPAProver(
133143 NumberOfRounds : rounds ,
134144 Commitment : Commitment ,
135145 Q : Q ,
146+ Provider : provider ,
136147 }
137148}
138149
@@ -206,7 +217,7 @@ func (p *ipaProver) reduce(X, com *mathlib.G1) (*mathlib.Zr, *mathlib.Zr, []*mat
206217 xInv .InvModOrder ()
207218
208219 // reduce the generators by 1/2, as a function of the old generators and x and 1/x
209- leftGen , rightGen = reduceGenerators (leftGen , rightGen , x , xInv )
220+ leftGen , rightGen = reduceGenerators (leftGen , rightGen , x , xInv , p . Provider )
210221
211222 // reduce the vectors by 1/2, a function of the old vectors and x and 1/x
212223 left , right = reduceVectors (left , right , x , xInv , p .Curve )
@@ -241,17 +252,27 @@ type ipaVerifier struct {
241252 NumberOfRounds uint64
242253 // Curve is the mathematical curve.
243254 Curve * mathlib.Curve
255+ // Provider creates a fresh Executor for each Prove call.
256+ // If nil, DefaultProvider (SerialProvider) is used.
257+ Provider rp.ExecutorProvider
244258}
245259
246260// NewIPAVerifier returns an ipaVerifier instance.
261+ // exec controls how generator reduction is parallelised; pass nil
262+ // to use SerialExecutor (equivalent to the previous behaviour).
247263func NewIPAVerifier (
248264 innerProduct * mathlib.Zr ,
249265 Q * mathlib.G1 ,
250266 leftGens , rightGens []* mathlib.G1 ,
251267 Commitment * mathlib.G1 ,
252268 rounds uint64 ,
253269 c * mathlib.Curve ,
270+ provider rp.ExecutorProvider ,
254271) * ipaVerifier {
272+ if provider == nil {
273+ provider = rp .DefaultProvider
274+ }
275+
255276 return & ipaVerifier {
256277 InnerProduct : innerProduct ,
257278 RightGenerators : rightGens ,
@@ -260,6 +281,7 @@ func NewIPAVerifier(
260281 NumberOfRounds : rounds ,
261282 Commitment : Commitment ,
262283 Q : Q ,
284+ Provider : provider ,
263285 }
264286}
265287
@@ -384,22 +406,21 @@ func reduceVectors(left, right []*mathlib.Zr, x, xInv *mathlib.Zr, c *mathlib.Cu
384406
385407// reduceGenerators reduces the number of generators passed in the parameters by 1/2,
386408// as a function of the old generators, x and 1/x
387- func reduceGenerators (leftGen , rightGen []* mathlib.G1 , x , xInv * mathlib.Zr ) ([]* mathlib.G1 , []* mathlib.G1 ) {
409+ func reduceGenerators (leftGen , rightGen []* mathlib.G1 , x , xInv * mathlib.Zr , provider rp. ExecutorProvider ) ([]* mathlib.G1 , []* mathlib.G1 ) {
388410 l := len (leftGen ) / 2
389411 // Use the Executor abstraction so that the execution strategy can be
390412 // swapped without changing this function. SerialExecutor runs each task
391413 // immediately with no locks or goroutine overhead.
392- executor := rp .NewSerialExecutor ()
393-
414+ exec := provider .New ()
394415 for i := range l {
395- executor .Submit (func () {
416+ exec .Submit (func () {
396417 // G_i = G_i^{x_inv} * G_{i+l}^x
397418 leftGen [i ].Mul2InPlace (xInv , leftGen [i + l ], x )
398419 // H_i = H_i^x * H_{i+l}^{x_inv}
399420 rightGen [i ].Mul2InPlace (x , rightGen [i + l ], xInv )
400421 })
401422 }
402- executor .Wait ()
423+ exec .Wait ()
403424
404425 return leftGen [:l ], rightGen [:l ]
405426}
0 commit comments