Skip to content

MSP curve is hardcoded in constructor, ignoring IdemixMSPConfig.CurveId #85#86

Merged
adecaro merged 2 commits into
mainfrom
85-msp-curve-is-hardcoded-in-constructor-ignoring-idemixmspconfigcurveid
Jul 8, 2026
Merged

MSP curve is hardcoded in constructor, ignoring IdemixMSPConfig.CurveId #85#86
adecaro merged 2 commits into
mainfrom
85-msp-curve-is-hardcoded-in-constructor-ignoring-idemixmspconfigcurveid

Conversation

@adecaro

@adecaro adecaro commented Jul 8, 2026

Copy link
Copy Markdown
Member

…urveId## Summary

  • Curve and BCCSP construction moved from the constructor into Setup, driven by IdemixMSPConfig.CurveId.
  • Setup now enforces that the config type matches the constructor used.
  • NewIdemixMspWithLogger / NewIdemixMspAriesWithLogger added for custom-logger injection.

Motivation

IdemixMSPConfig has carried a curve_id string since idemixgen began writing it, but
Setup never read the field — the curve was hardcoded per constructor. This meant loading
a config generated with idemixgen --curve BLS12_381 through NewIdemixMsp would silently
parse keys against the wrong curve and fail with a cryptographic error rather than a clear
message. There was also no guard against mixing a dlog constructor with an Aries config.

Changes

msp/idemixmsp.go

Idemixmsp struct — two new fields:

  • aries bool — set by the constructor to record which scheme was chosen.
  • exportable bool — carries the (always-true) exportable flag into the deferred BCCSP build.

ConstructorsNewIdemixMsp and NewIdemixMspAries no longer build a BCCSP eagerly.
They return a lightweight struct and delegate to the new WithLogger variants:

NewIdemixMsp(version)            → NewIdemixMspWithLogger(version, nil)
NewIdemixMspAries(version)       → NewIdemixMspAriesWithLogger(version, nil)
NewIdemixMspWithLogger(version, logger)       // dlog, custom logger
NewIdemixMspAriesWithLogger(version, logger)  // Aries, custom logger

Passing nil as the logger falls back to the default zap-based logger.

curveAndTranslator helper — maps curve_id strings to (*math.Curve, Translator),
mirroring the switch in tools/idemixgen/main.go. Supported values: FP256BN_AMCL,
BN254, FP256BN_AMCL_MIRACL, BLS12_377_GURVY, BLS12_381_GURVY, BLS12_381,
BLS12_381_BBS, BLS12_381_BBS_GURVY.

Setup — after unmarshalling the config:

  1. Enforces type/constructor match (IDEMIX ↔ dlog, IDEMIX_ARIES ↔ Aries).
  2. Resolves curve_id with per-scheme defaults and restrictions:
    • dlog: any valid curve; empty → FP256BN_AMCL.
    • Aries: only BLS12_381_BBS or BLS12_381_BBS_GURVY; empty → BLS12_381_BBS.
  3. Builds the BCCSP (idemix.New or idemix.NewAries) with the resolved curve.
  4. BCCSP construction failure is now a returned error instead of a panic.

msp/idemixmsp_test.go

Updated TestSetupBad: the error string check for a wrong config type is relaxed to
"setup error:" to match the now-more-descriptive message.

README.md

Added an "MSP Usage" section documenting the two constructors, the curve-selection
mechanism, the full curve_id table, and the enforcement rules.

Backward compatibility

All existing callers are unaffected:

  • NewIdemixMsp / NewIdemixMspAries signatures are unchanged.
  • Empty curve_id in a config falls back to the same curve that was previously hardcoded.

@adecaro adecaro requested a review from ale-linux July 8, 2026 12:20
@adecaro adecaro self-assigned this Jul 8, 2026
@adecaro adecaro added the msp label Jul 8, 2026
ale-linux
ale-linux previously approved these changes Jul 8, 2026

@ale-linux ale-linux left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall - just a couple of Qs

Comment thread msp/idemixmsp.go
Comment on lines +257 to +265
if msp.aries {
switch curveID {
case "", curveIDBLS12_381_BBS:
curveID = curveIDBLS12_381_BBS
case curveIDBLS12_381_BBS_GURVY:
// accepted
default:
return fmt.Errorf("setup error: aries MSP requires a BBS curve, got %q", curveID)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only support these 2?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you explicitly called NewIdemixMspAries, then we enforce this because the constructor was enforcing that curve

Comment thread CLAUDE.md
@@ -0,0 +1 @@
@AGENTS.md No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected? We have CLAUDE.md pointing to @AGENTS.md, and AGENTS.md whose first line is CLAUDE.md?

Comment thread README.md Outdated
Comment on lines +44 to +45
| `BLS12_381` | Kilic | |
| `BLS12_381_BBS` | Kilic | Default for Aries |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer correct right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

adecaro added 2 commits July 8, 2026 18:52
…urveId

Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>

# Conflicts:
#	msp/idemixmsp.go
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
@adecaro adecaro force-pushed the 85-msp-curve-is-hardcoded-in-constructor-ignoring-idemixmspconfigcurveid branch from dc79876 to 3b51521 Compare July 8, 2026 16:54

@ale-linux ale-linux left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - please squash-merge and don't rebase :)

@adecaro adecaro merged commit 145fcb0 into main Jul 8, 2026
3 checks passed
@adecaro adecaro deleted the 85-msp-curve-is-hardcoded-in-constructor-ignoring-idemixmspconfigcurveid branch July 8, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants