semaphore-protocol/semaphore

Generating a new identity with a user-provided private key results in inconsistent behavior

gubsheep opened this issue · 4 comments

Describe the bug
Initialize two fresh Semaphore identities: a new Identity() with empty args, and another new Identity(<private key>) passing in the private key generated for the first identity. These two identities will have different public keys and commitments, though they should be identical.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize a fresh Semaphore identity: const id1 = new Identity()
  2. Copy the private key of this identity: const privkey = id1.privateKey.
  3. Initialize a second Semaphore identity, passing in the private key as an argument to constructor: const id2 = new Identity(privkey).

Expected behavior

console.log(id1.privateKey === id2.privateKey) // expect true, got true
console.log(id1.commitment === id2.commitment) // expect true, got false

Screenshots
id1 in this screenshot was generated as a fresh Semaphore identity with no args passed into constructor. id2 is generated with id1's private key passed as argument to constructor. Both of these Identities appear to have the same privateKey, but have different publicKey and commitment values.

image

Technologies (please complete the following information):

  • Node.js version: v22.1.0
  • NPM version: 10.7.0
  • Solidity version: n/a

Additional context

Prepending the private key with 0x prefix does not solve the issue: for example, run const id3 = new Identity('0x' + privkey). Now, id3's commitment and publicKey will be different from both the freshly generated Semaphore ID as well as the identity generated by passing in the first privateKey as a constructor argument.

This issue has existed since this commit c88175b

@zkfriendly yess, I found the problem and I'm currently working to solve it.

@zkfriendly yess, I found the problem and I'm currently working to solve it.

@cedoor Ow, I was working on a fix at same time too!

@cedoor Ow, I was working on a fix at same time too!

Ahh please, take a look at the assignees before working on the next task. Sorry for this misunderstanding!