Skip to content

Commit c7632e9

Browse files
authored
deprecate the use of some mathlib curves #1203 (#1204)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 20f2d32 commit c7632e9

File tree

68 files changed

+381
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+381
-438
lines changed

cmd/tokengen/cobra/pp/zkatdlognoghv1/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func Gen(args *GeneratorArgs) ([]byte, error) {
131131
// TODO: update the curve here
132132
curveID := math3.BN254
133133
if args.Aries {
134-
curveID = math3.BLS12_381_BBS
134+
curveID = math3.BLS12_381_BBS_GURVY
135135
}
136136
// todo range is hardcoded, to be changed
137137
ver := v1.ProtocolV1

docs/core/extension/zkatdlog/nogh/v2/driver/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (d *base) newWalletService(
6767
) (*wallet.Service, error) {
6868
pp := publicParams.(*v2.PublicParams)
6969
roles := wallet.NewRoles()
70-
deserializerManager := deserializer.NewMultiplexDeserializer()
70+
deserializerManager := deserializer.NewTypedSignerDeserializerMultiplex()
7171
tmsID := tmsConfig.ID()
7272
identityDB, err := storageProvider.IdentityStore(tmsID)
7373
if err != nil {

integration/nwo/token/generators/crypto/zkatdlognoghv1/gen.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/IBM/idemix"
18-
math3 "github.com/IBM/mathlib"
18+
mathlib "github.com/IBM/mathlib"
1919
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
2020
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
2121
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
@@ -65,12 +65,12 @@ type CryptoMaterialGenerator struct {
6565
RevocationHandlerIndex int
6666
}
6767

68-
func NewCryptoMaterialGenerator(tokenPlatform generators.TokenPlatform, defaultCurveID math3.CurveID, builder api.Builder) *CryptoMaterialGenerator {
68+
func NewCryptoMaterialGenerator(tokenPlatform generators.TokenPlatform, defaultCurveID mathlib.CurveID, builder api.Builder) *CryptoMaterialGenerator {
6969
return &CryptoMaterialGenerator{
7070
FabTokenGenerator: fabtokenv1.NewCryptoMaterialGenerator(tokenPlatform, builder),
7171
TokenPlatform: tokenPlatform,
7272
EventuallyTimeout: 10 * time.Minute,
73-
DefaultCurve: CurveIDToString(defaultCurveID),
73+
DefaultCurve: mathlib.CurveIDToString(defaultCurveID),
7474
}
7575
}
7676

@@ -91,7 +91,7 @@ func (d *CryptoMaterialGenerator) Setup(tms *topology.TMS) (string, error) {
9191

9292
curveID := d.DefaultCurve
9393
if IsAries(tms) {
94-
curveID = CurveIDToString(math3.BLS12_381_BBS)
94+
curveID = mathlib.CurveIDToString(mathlib.BLS12_381_BBS_GURVY)
9595
}
9696

9797
// notice that if aries is enabled, curve is ignored
@@ -117,7 +117,7 @@ func (d *CryptoMaterialGenerator) GenerateOwnerIdentities(tms *topology.TMS, n *
117117

118118
curveID := d.DefaultCurve
119119
if IsAries(tms) {
120-
curveID = CurveIDToString(math3.BLS12_381_BBS)
120+
curveID = mathlib.CurveIDToString(mathlib.BLS12_381_BBS_GURVY)
121121
}
122122

123123
var res []topology.Identity
@@ -239,20 +239,3 @@ func (d *CryptoMaterialGenerator) nextColor() string {
239239
d.ColorIndex++
240240
return fmt.Sprintf("%dm", color)
241241
}
242-
243-
func CurveIDToString(id math3.CurveID) string {
244-
switch id {
245-
case math3.BN254:
246-
return "BN254"
247-
case math3.FP256BN_AMCL:
248-
return "FP256BN_AMCL"
249-
case math3.FP256BN_AMCL_MIRACL:
250-
return "FP256BN_AMCL_MIRACL"
251-
case math3.BLS12_377_GURVY:
252-
return "BLS12_377_GURVY"
253-
case math3.BLS12_381_BBS:
254-
return "BLS12_381_BBS"
255-
default:
256-
panic("invalid curve id")
257-
}
258-
}

integration/nwo/token/generators/pp/zkatdlognoghv1/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (d *DLogPublicParamsGenerator) Generate(tms *topology.TMS, wallets *topolog
4949

5050
curveID := d.DefaultCurveID
5151
if zkatdlognoghv1.IsAries(tms) {
52-
curveID = math3.BLS12_381_BBS
52+
curveID = math3.BLS12_381_BBS_GURVY
5353
}
5454

5555
bits := uint64(64)

integration/token/interop/dlog/dlog_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func newTestSuiteSingleFabric(commType fsc.P2PCommunicationType, factor int, nam
5555
ReplicationOpts: opts,
5656
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: zkatdlognoghv1.DriverIdentifier},
5757
SDKs: []nodepkg.SDK{&fdlog.SDK{}},
58-
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:info",
58+
// FSCLogSpec: "debug",
5959
}))
6060
return ts, selector
6161
}
@@ -67,7 +67,7 @@ func newTestSuiteTwoFabric(commType fsc.P2PCommunicationType, factor int, names
6767
ReplicationOpts: opts,
6868
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: zkatdlognoghv1.DriverIdentifier},
6969
SDKs: []nodepkg.SDK{&fdlog.SDK{}},
70-
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:info",
70+
// FSCLogSpec: "debug",
7171
}))
7272
return ts, selector
7373
}
@@ -79,7 +79,7 @@ func newTestSuiteNoCrossClaimFabric(commType fsc.P2PCommunicationType, factor in
7979
ReplicationOpts: opts,
8080
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: zkatdlognoghv1.DriverIdentifier},
8181
SDKs: []nodepkg.SDK{&fdlog.SDK{}},
82-
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:info",
82+
// FSCLogSpec: "debug",
8383
FinalityType: config.Delivery,
8484
}))
8585
return ts, selector

integration/token/interop/fabtoken/fabtoken_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newTestSuiteSingleFabric(commType fsc.P2PCommunicationType, factor int, nam
5454
ReplicationOpts: opts,
5555
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: fabtokenv1.DriverIdentifier},
5656
SDKs: []nodepkg.SDK{&ffabtoken.SDK{}},
57-
FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:info",
57+
// FSCLogSpec: "debug",
5858
}))
5959
return ts, selector
6060
}
@@ -66,6 +66,7 @@ func newTestSuiteTwoFabric(commType fsc.P2PCommunicationType, factor int, names
6666
ReplicationOpts: opts,
6767
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: fabtokenv1.DriverIdentifier},
6868
SDKs: []nodepkg.SDK{&ffabtoken.SDK{}},
69+
// FSCLogSpec: "debug",
6970
}))
7071
return ts, selector
7172
}
@@ -77,6 +78,7 @@ func newTestSuiteNoCrossClaimFabric(commType fsc.P2PCommunicationType, factor in
7778
ReplicationOpts: opts,
7879
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: fabtokenv1.DriverIdentifier},
7980
SDKs: []nodepkg.SDK{&ffabtoken.SDK{}},
81+
// FSCLogSpec: "debug",
8082
}))
8183
return ts, selector
8284
}

token/core/common/authrorization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (o *AuthorizationMultiplexer) Issued(ctx context.Context, issuer token.Iden
116116
}
117117

118118
// OwnerType returns the type of owner (e.g. 'idemix' or 'htlc') and the identity bytes
119-
func (o *AuthorizationMultiplexer) OwnerType(raw []byte) (string, []byte, error) {
119+
func (o *AuthorizationMultiplexer) OwnerType(raw []byte) (driver.IdentityType, []byte, error) {
120120
owner, err := identity.UnmarshalTypedIdentity(raw)
121121
if err != nil {
122122
return "", nil, err

token/core/fabtoken/v1/driver/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (d *base) newWalletService(
5353
) (*wallet.Service, error) {
5454
tmsID := tmsConfig.ID()
5555

56-
deserializerManager := deserializer.NewMultiplexDeserializer()
56+
deserializerManager := deserializer.NewTypedSignerDeserializerMultiplex()
5757
identityDB, err := storageProvider.IdentityStore(tmsID)
5858
if err != nil {
5959
return nil, errors.Wrapf(err, "failed to open identity db for tms [%s]", tmsID)

token/core/zkatdlog/nogh/v1/audit/auditor_test.go

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ package audit_test
99
import (
1010
"context"
1111
"os"
12-
"time"
1312

1413
"github.com/IBM/idemix/bccsp/types"
1514
math "github.com/IBM/mathlib"
16-
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
1715
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/audit"
1816
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/audit/mock"
1917
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
@@ -22,7 +20,7 @@ import (
2220
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
2321
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
2422
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/deserializer"
25-
idemix2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix"
23+
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix"
2624
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix/crypto"
2725
kvs2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
2826
"github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
@@ -42,14 +40,14 @@ var _ = Describe("Auditor", func() {
4240
BeforeEach(func() {
4341
var err error
4442
fakeSigningIdentity = &mock.SigningIdentity{}
45-
ipk, err := os.ReadFile("./testdata/idemix/msp/IssuerPublicKey")
43+
ipk, err := os.ReadFile("./testdata/bls12_381_bbs/idemix/msp/IssuerPublicKey")
4644
Expect(err).NotTo(HaveOccurred())
47-
pp, err = v1.Setup(32, ipk, math.FP256BN_AMCL)
45+
pp, err = v1.Setup(32, ipk, math.BLS12_381_BBS_GURVY)
4846
Expect(err).NotTo(HaveOccurred())
49-
idemixDes, err := idemix2.NewDeserializer(slices.GetUnique(pp.IdemixIssuerPublicKeys).PublicKey, math.FP256BN_AMCL)
47+
idemixDes, err := idemix.NewDeserializer(slices.GetUnique(pp.IdemixIssuerPublicKeys).PublicKey, math.BLS12_381_BBS_GURVY)
5048
Expect(err).NotTo(HaveOccurred())
5149
des := deserializer.NewTypedVerifierDeserializerMultiplex()
52-
des.AddTypedVerifierDeserializer(idemix2.IdentityType, deserializer.NewTypedIdentityVerifierDeserializer(idemixDes, idemixDes))
50+
des.AddTypedVerifierDeserializer(idemix.IdentityType, deserializer.NewTypedIdentityVerifierDeserializer(idemixDes, idemixDes))
5351
auditor = audit.NewAuditor(
5452
logging.MustGetLogger(),
5553
&noop.Tracer{},
@@ -92,7 +90,7 @@ var _ = Describe("Auditor", func() {
9290
It("fails", func() {
9391
transfer, metadata, tokens := createTransfer(pp)
9492
// test idemix info
95-
_, auditinfo := getIdemixInfo("./testdata/idemix")
93+
_, auditinfo := getIdemixInfo("./testdata/bls12_381_bbs/idemix")
9694
raw, err := auditinfo.Bytes()
9795
Expect(err).NotTo(HaveOccurred())
9896
metadata.Inputs[0].Senders[0].AuditInfo = raw
@@ -109,7 +107,7 @@ var _ = Describe("Auditor", func() {
109107
It("fails", func() {
110108
transfer, metadata, tokens := createTransfer(pp)
111109
// test idemix info
112-
_, auditinfo := getIdemixInfo("./testdata/idemix")
110+
_, auditinfo := getIdemixInfo("./testdata/bls12_381_bbs/idemix")
113111
raw, err := auditinfo.Bytes()
114112
Expect(err).NotTo(HaveOccurred())
115113
metadata.Outputs[0].OutputAuditInfo = raw
@@ -126,7 +124,7 @@ var _ = Describe("Auditor", func() {
126124
})
127125

128126
func createTransfer(pp *v1.PublicParams) (*transfer.Action, *driver.TransferMetadata, [][]*token.Token) {
129-
id, auditInfo := getIdemixInfo("./testdata/idemix")
127+
id, auditInfo := getIdemixInfo("./testdata/bls12_381_bbs/idemix")
130128
transfer, meta, inputs := prepareTransfer(pp, id)
131129

132130
auditInfoRaw, err := auditInfo.Bytes()
@@ -166,7 +164,7 @@ func createTransfer(pp *v1.PublicParams) (*transfer.Action, *driver.TransferMeta
166164
}
167165

168166
func createTransferWithBogusOutput(pp *v1.PublicParams) (*transfer.Action, *driver.TransferMetadata, [][]*token.Token) {
169-
id, auditInfo := getIdemixInfo("./testdata/idemix")
167+
id, auditInfo := getIdemixInfo("./testdata/bls12_381_bbs/idemix")
170168
transfer, inf, inputs := prepareTransfer(pp, id)
171169

172170
c := math.Curves[pp.Curve]
@@ -214,69 +212,18 @@ func createTransferWithBogusOutput(pp *v1.PublicParams) (*transfer.Action, *driv
214212
return transfer, metadata, tokns
215213
}
216214

217-
type fakeProv struct {
218-
typ string
219-
}
220-
221-
func (f *fakeProv) GetString(key string) string {
222-
return f.typ
223-
}
224-
225-
func (f *fakeProv) GetInt(key string) int {
226-
return 0
227-
}
228-
229-
func (f *fakeProv) GetDuration(key string) time.Duration {
230-
return time.Duration(0)
231-
}
232-
233-
func (f *fakeProv) GetBool(key string) bool {
234-
return false
235-
}
236-
237-
func (f *fakeProv) GetStringSlice(key string) []string {
238-
return nil
239-
}
240-
241-
func (f *fakeProv) IsSet(key string) bool {
242-
return false
243-
}
244-
245-
func (f *fakeProv) UnmarshalKey(key string, rawVal interface{}) error {
246-
return nil
247-
}
248-
249-
func (f *fakeProv) ConfigFileUsed() string {
250-
return ""
251-
}
252-
253-
func (f *fakeProv) GetPath(key string) string {
254-
return ""
255-
}
256-
257-
func (f *fakeProv) TranslatePath(path string) string {
258-
return ""
259-
}
260-
261215
func getIdemixInfo(dir string) (driver.Identity, *crypto.AuditInfo) {
262-
sp := view.NewServiceProvider()
263-
configService := &fakeProv{typ: "memory"}
264-
Expect(sp.RegisterService(configService)).NotTo(HaveOccurred())
265-
266216
backend, err := kvs2.NewInMemory()
267-
Expect(err).NotTo(HaveOccurred())
268-
err = sp.RegisterService(backend)
269-
Expect(err).NotTo(HaveOccurred())
270-
271217
Expect(err).NotTo(HaveOccurred())
272218
config, err := crypto.NewConfig(dir)
273219
Expect(err).NotTo(HaveOccurred())
220+
curveID := math.BLS12_381_BBS_GURVY
274221

275-
keyStore, err := crypto.NewKeyStore(math.FP256BN_AMCL, kvs2.Keystore(backend))
222+
keyStore, err := crypto.NewKeyStore(curveID, kvs2.Keystore(backend))
276223
Expect(err).NotTo(HaveOccurred())
277-
cryptoProvider, err := crypto.NewBCCSP(keyStore, math.FP256BN_AMCL, false)
224+
cryptoProvider, err := crypto.NewBCCSP(keyStore, curveID)
278225
Expect(err).NotTo(HaveOccurred())
279-
p, err := idemix2.NewKeyManager(config, types.EidNymRhNym, cryptoProvider)
226+
p, err := idemix.NewKeyManager(config, types.EidNymRhNym, cryptoProvider)
280227
Expect(err).NotTo(HaveOccurred())
281228
Expect(p).NotTo(BeNil())
282229

@@ -292,7 +239,7 @@ func getIdemixInfo(dir string) (driver.Identity, *crypto.AuditInfo) {
292239
err = auditInfo.Match(context.Background(), id)
293240
Expect(err).NotTo(HaveOccurred())
294241

295-
id, err = identity.WrapWithType(idemix2.IdentityType, id)
242+
id, err = identity.WrapWithType(idemix.IdentityType, id)
296243
Expect(err).NotTo(HaveOccurred())
297244

298245
return id, auditInfo

token/core/zkatdlog/nogh/v1/audit/testdata/bls12_381_bbs/ca/ca/IssuerPublicKey

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
��7�;XoaFI�-�'�始($�F0��u�]��� �aE�Pig��m�'Y�}�vI
2+
����D����� ��H�=�N��#��a�5���b���J

0 commit comments

Comments
 (0)