Skip to content

Commit 6ec92a2

Browse files
committed
bulletproof improvements
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 35aeffb commit 6ec92a2

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-31
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/DATA-DOG/go-sqlmock v1.5.2
99
github.com/IBM/idemix v0.0.2-0.20250313153527-832db18b9478
1010
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478
11-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe
11+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42
1212
github.com/dgraph-io/ristretto/v2 v2.3.0
1313
github.com/gin-gonic/gin v1.10.0
1414
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20250313153527-832db18b9478 h
643643
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20250313153527-832db18b9478/go.mod h1:k4Q5EYKRnYC6t80ipSCY3G8H4FdcxRa8jjlsJdGfNCY=
644644
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478 h1:Uzmcb4pNb54/fbAjnrZTiJwWV74+twP60N4qBGm4PvU=
645645
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478/go.mod h1:Pi1QIuIZ+1OXIbnYe27vNwJOnSq2WvkHRT/sfweTw8E=
646-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe h1:EwFXJqfqz0lnsOtqSEswQ0kond3a8waLUfIXbaTgB4A=
647-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe/go.mod h1:rq67W1H6L1eorrE7DZ/HcSY/pfMDjbPWOx12SeUfQDk=
646+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42 h1:1jsS5+0xrluqw6fAZF466C15JZyTX4m9oN4Ueluh7dY=
647+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42/go.mod h1:rq67W1H6L1eorrE7DZ/HcSY/pfMDjbPWOx12SeUfQDk=
648648
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
649649
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
650650
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=

token/core/common/crypto/math/curves.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ func init() {
2525
math.Curves = append(
2626
math.Curves,
2727
math.NewCurve(
28-
NewCurveWithFastRNG(bls12381.NewBls12_381BBS()),
29-
math.NewG1(bls12381.NewBls12_381BBS().GenG1(), BLS12_381_BBS_GURVY_FAST_RNG),
30-
math.NewG2(bls12381.NewBls12_381BBS().GenG2(), BLS12_381_BBS_GURVY_FAST_RNG),
31-
math.NewGt(bls12381.NewBls12_381BBS().GenGt(), BLS12_381_BBS_GURVY_FAST_RNG),
32-
math.NewZr(bls12381.NewBls12_381().GroupOrder(), BLS12_381_BBS_GURVY_FAST_RNG),
33-
bls12381.NewBls12_381BBS().CoordinateByteSize(),
34-
bls12381.NewBls12_381BBS().G1ByteSize(),
35-
bls12381.NewBls12_381BBS().CompressedG1ByteSize(),
36-
bls12381.NewBls12_381BBS().G2ByteSize(),
37-
bls12381.NewBls12_381BBS().CompressedG2ByteSize(),
38-
bls12381.NewBls12_381BBS().ScalarByteSize(),
28+
NewCurveWithFastRNG(bls12381.NewBBSCurve()),
29+
math.NewG1(bls12381.NewBBSCurve().GenG1(), BLS12_381_BBS_GURVY_FAST_RNG),
30+
math.NewG2(bls12381.NewBBSCurve().GenG2(), BLS12_381_BBS_GURVY_FAST_RNG),
31+
math.NewGt(bls12381.NewBBSCurve().GenGt(), BLS12_381_BBS_GURVY_FAST_RNG),
32+
math.NewZr(bls12381.NewCurve().GroupOrder(), BLS12_381_BBS_GURVY_FAST_RNG),
33+
bls12381.NewBBSCurve().CoordinateByteSize(),
34+
bls12381.NewBBSCurve().G1ByteSize(),
35+
bls12381.NewBBSCurve().CompressedG1ByteSize(),
36+
bls12381.NewBBSCurve().G2ByteSize(),
37+
bls12381.NewBBSCurve().CompressedG2ByteSize(),
38+
bls12381.NewBBSCurve().ScalarByteSize(),
3939
BLS12_381_BBS_GURVY_FAST_RNG,
4040
),
4141
)

token/core/zkatdlog/nogh/v1/crypto/rp/bulletproof.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
275275
}
276276
rho := p.Curve.NewRandomZr(rand)
277277
eta := p.Curve.NewRandomZr(rand)
278+
one := p.Curve.NewZrFromInt(1)
279+
two := p.Curve.NewZrFromInt(2)
278280
for i := range p.BitLength {
279281
b := 1 << i & p.value
280282
if b > 0 {
@@ -283,7 +285,7 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
283285
// this is an array of the bits b_i of p.value
284286
left[i] = p.Curve.NewZrFromUint64(b)
285287
// this is an array of b_i - 1
286-
right[i] = p.Curve.ModSub(left[i], p.Curve.NewZrFromInt(1), p.Curve.GroupOrder)
288+
right[i] = p.Curve.ModSub(left[i], one, p.Curve.GroupOrder)
287289
// these are randomly generated arrays
288290
randomLeft[i] = p.Curve.NewRandomZr(rand)
289291
randomRight[i] = p.Curve.NewRandomZr(rand)
@@ -315,7 +317,7 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
315317

316318
zPrime := make([]*math.Zr, len(left))
317319
// z^2
318-
zSquare := z.PowMod(p.Curve.NewZrFromInt(2))
320+
zSquare := z.PowMod(two)
319321
var y2i *math.Zr
320322
for i := range left {
321323
// compute L_i - z
@@ -324,7 +326,7 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
324326
rightPrime[i] = p.Curve.ModAdd(right[i], z, p.Curve.GroupOrder)
325327
// compute y^i
326328
if i == 0 {
327-
y2i = p.Curve.NewZrFromInt(1)
329+
y2i = one
328330
} else {
329331
y2i = p.Curve.ModMul(y, y2i, p.Curve.GroupOrder)
330332
}
@@ -333,7 +335,7 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
333335
// compute V_iy^i
334336
randRightPrime[i] = p.Curve.ModMul(randomRight[i], y2i, p.Curve.GroupOrder)
335337
// compute 2^iz^2
336-
zPrime[i] = p.Curve.ModMul(zSquare, p.Curve.NewZrFromInt(2).PowMod(p.Curve.NewZrFromInt(int64(i))), p.Curve.GroupOrder)
338+
zPrime[i] = p.Curve.ModMul(zSquare, two.PowMod(p.Curve.NewZrFromInt(int64(i))), p.Curve.GroupOrder)
337339
}
338340

339341
// compute \sum y^iV_i(L_i-z)
@@ -344,15 +346,13 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
344346
t1 = p.Curve.ModAdd(t1, InnerProduct(zPrime, randomLeft, p.Curve), p.Curve.GroupOrder)
345347
// commit to t1
346348
tau1 := p.Curve.NewRandomZr(rand)
347-
T1 := p.CommitmentGenerators[0].Mul(t1)
348-
T1.Add(p.CommitmentGenerators[1].Mul(tau1))
349+
T1 := p.CommitmentGenerators[0].Mul2(t1, p.CommitmentGenerators[1], tau1)
349350

350351
// compute = \sum y^iU_iV_i
351352
t2 := InnerProduct(randomLeft, randRightPrime, p.Curve)
352353
// commit to t2
353354
tau2 := p.Curve.NewRandomZr(rand)
354-
T2 := p.CommitmentGenerators[0].Mul(t2)
355-
T2.Add(p.CommitmentGenerators[1].Mul(tau2))
355+
T2 := p.CommitmentGenerators[0].Mul2(t2, p.CommitmentGenerators[1], tau2)
356356

357357
// compute challenge x
358358
array = common.GetG1Array([]*math.G1{T1, T2})
@@ -368,14 +368,14 @@ func (p *rangeProver) preprocess() ([]*math.Zr, []*math.Zr, *math.Zr, *RangeProo
368368
// f(z, y) = \sum (z-z^2)*y^i - z^3*2^i
369369
for i := 0; i < len(left); i++ {
370370
// compute (L_i-z) + xU_i
371-
left[i] = p.Curve.ModAdd(leftPrime[i], p.Curve.ModMul(x, randomLeft[i], p.Curve.GroupOrder), p.Curve.GroupOrder)
371+
left[i] = p.Curve.ModAddMul2(leftPrime[i], one, x, randomLeft[i], p.Curve.GroupOrder)
372372
// compute y^i((R_i+z)+xV_i)+2^iz^2
373373
right[i] = p.Curve.ModAdd(rightPrime[i], p.Curve.ModMul(x, randRightPrime[i], p.Curve.GroupOrder), p.Curve.GroupOrder)
374374
right[i] = p.Curve.ModAdd(right[i], zPrime[i], p.Curve.GroupOrder)
375375
}
376376
// tau = t1x + t2x^2 + z^2p.blindingFactor
377377
tau := p.Curve.ModMul(x, tau1, p.Curve.GroupOrder)
378-
tau = p.Curve.ModAdd(tau, p.Curve.ModMul(tau2, x.PowMod(p.Curve.NewZrFromInt(2)), p.Curve.GroupOrder), p.Curve.GroupOrder)
378+
tau = p.Curve.ModAdd(tau, p.Curve.ModMul(tau2, x.PowMod(two), p.Curve.GroupOrder), p.Curve.GroupOrder)
379379
tau = p.Curve.ModAdd(tau, p.Curve.ModMul(zSquare, p.blindingFactor, p.Curve.GroupOrder), p.Curve.GroupOrder)
380380

381381
// delta = rho + eta*x

token/core/zkatdlog/nogh/v1/crypto/rp/bulletproof_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414

1515
math "github.com/IBM/mathlib"
16+
"github.com/hyperledger-labs/fabric-smart-client/node/start/profile"
1617
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/crypto/rp"
1718
"github.com/stretchr/testify/assert"
1819
"github.com/stretchr/testify/require"
@@ -108,6 +109,10 @@ func TestBFProofVerify(t *testing.T) {
108109
}
109110

110111
func BenchmarkBFProver(b *testing.B) {
112+
pp, err := profile.New(profile.WithAll(), profile.WithPath("./profile"))
113+
require.NoError(b, err)
114+
require.NoError(b, pp.Start())
115+
defer pp.Stop()
111116
envs := make([]*bfSetup, 0, 128)
112117
for i := 0; i < 128; i++ {
113118
setup, err := NewBfSetup(math.BLS12_381_BBS_GURVY)

token/core/zkatdlog/nogh/v1/crypto/rp/ipa.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (p *ipaProver) reduce(X, com *mathlib.G1) (*mathlib.Zr, *mathlib.Zr, []*mat
203203

204204
// compute 1/x
205205
xInv := x.Copy()
206-
xInv.InvModP(p.Curve.GroupOrder)
206+
xInv.InvModOrder()
207207

208208
// reduce the generators by 1/2, as a function of the old generators and x and 1/x
209209
leftGen, rightGen = reduceGenerators(leftGen, rightGen, x, xInv)
@@ -213,7 +213,7 @@ func (p *ipaProver) reduce(X, com *mathlib.G1) (*mathlib.Zr, *mathlib.Zr, []*mat
213213

214214
xSquare := p.Curve.ModMul(x, x, p.Curve.GroupOrder)
215215
xSquareInv := xSquare.Copy()
216-
xSquareInv.InvModP(p.Curve.GroupOrder)
216+
xSquareInv.InvModOrder()
217217

218218
// compute the commitment to left, right and their inner product
219219
CPrime := LArray[i].Mul2(xSquare, RArray[i], xSquareInv)
@@ -311,13 +311,13 @@ func (v *ipaVerifier) Verify(proof *IPA) error {
311311
x = v.Curve.HashToZr(raw)
312312
// 1/x
313313
xInv := x.Copy()
314-
xInv.InvModP(v.Curve.GroupOrder)
314+
xInv.InvModOrder()
315315

316316
// x^2
317317
xSquare := v.Curve.ModMul(x, x, v.Curve.GroupOrder)
318318
// 1/x^2
319319
xSquareInv := xSquare.Copy()
320-
xSquareInv.InvModP(v.Curve.GroupOrder)
320+
xSquareInv.InvModOrder()
321321
// compute a commitment to the reduced vectors and their inner product
322322
CPrime := proof.L[i].Mul2(xSquare, proof.R[i], xSquareInv)
323323
CPrime.Add(C)

token/services/identity/storage/kvs/hashicorp/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/IBM/idemix v0.0.2-0.20250313153527-832db18b9478 // indirect
2121
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20250313153527-832db18b9478 // indirect
2222
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478 // indirect
23-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe // indirect
23+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42 // indirect
2424
github.com/Microsoft/go-winio v0.6.2 // indirect
2525
github.com/beorn7/perks v1.0.1 // indirect
2626
github.com/bits-and-blooms/bitset v1.20.0 // indirect

token/services/identity/storage/kvs/hashicorp/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20250313153527-832db18b9478 h
1111
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20250313153527-832db18b9478/go.mod h1:k4Q5EYKRnYC6t80ipSCY3G8H4FdcxRa8jjlsJdGfNCY=
1212
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478 h1:Uzmcb4pNb54/fbAjnrZTiJwWV74+twP60N4qBGm4PvU=
1313
github.com/IBM/idemix/bccsp/types v0.0.0-20250313153527-832db18b9478/go.mod h1:Pi1QIuIZ+1OXIbnYe27vNwJOnSq2WvkHRT/sfweTw8E=
14-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe h1:EwFXJqfqz0lnsOtqSEswQ0kond3a8waLUfIXbaTgB4A=
15-
github.com/IBM/mathlib v0.0.3-0.20251210060400-7e58831c9abe/go.mod h1:rq67W1H6L1eorrE7DZ/HcSY/pfMDjbPWOx12SeUfQDk=
14+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42 h1:1jsS5+0xrluqw6fAZF466C15JZyTX4m9oN4Ueluh7dY=
15+
github.com/IBM/mathlib v0.0.3-0.20251210155508-86dd03c0dc42/go.mod h1:rq67W1H6L1eorrE7DZ/HcSY/pfMDjbPWOx12SeUfQDk=
1616
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
1717
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
1818
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=

0 commit comments

Comments
 (0)