semaphore-protocol / semaphore

A zero-knowledge protocol for anonymous interactions.
https://semaphore.pse.dev
MIT License
883 stars 193 forks source link

generateProof() prevents program from exiting #736

Closed brianblank closed 4 months ago

brianblank commented 5 months ago

Describe the bug Upon calling generateProof(), while the function returns with a valid answer, the program never exits back to the OS upon completion.

To Reproduce This program produces the problem. Note I commented out the last two lines to identify which call is causing the issue. I'm including it for completeness.

#!/usr/bin/env node

import { Identity } from "@semaphore-protocol/identity"
import { Group } from "@semaphore-protocol/group" 
import { generateProof } from "@semaphore-protocol/proof"
import { verifyProof } from "@semaphore-protocol/proof"

// Create new identities
const identity1 = new Identity()
const identity2 = new Identity()
const identity3 = new Identity()

const members = [
    identity1.commitment,
    identity2.commitment,
    identity3.commitment
]

const group = new Group(members)

const scope = group.root
const message = "Hello, World!"
const proof = await generateProof(identity1, group, message, scope)
console.log(`Proof: ${JSON.stringify(proof)}`)

// const proofIsValid = await verifyProof(proof)
// console.log(`Proof is valid: ${proofIsValid}`)

Expected behavior After completion of the code, the program should return back to the Operating System.

Screenshots

Here is a sample execution of the program. Note the "^C" at the end which is me forcing exit of the program which is stuck indefinitely.

brian@PC2024:~/dev/semaphore/my-semaphore$ npm exec semaphore-test
Proof: {"merkleTreeDepth":2,"merkleTreeRoot":"10911039934799539845414338062982480922838882535997216000587896732709048366642","nullifier":"21010560346614310038787909365376793825352778182963214616082342351945676821339","message":"32745724963525307109523713280444231124987508675532689804809885653891645702144","scope":"10911039934799539845414338062982480922838882535997216000587896732709048366642","points":["17201793473354116423591391683949808455563542687795108223371420678917958728833","19413141945641013042151771639504818005696033087545846461652214990370734420041","6013976044313108783367369421723939043738141196370251925305653622637079141479","5993718082660377565245243633831495074693670805573702697292324259590438270383","13895242153157977922193745732907313395522289625036079153493613696253233320935","18123084389446254662304040463263825322694296315412271770826477065571286072045","12237885797658033732515767455343975000397936640045213081183104191768177598782","655755471800889827261402214263052277201751098833431474891848689883216293348"]}
Proof is valid: true
^C
brian@PC2024:~/dev/semaphore/my-semaphore$ 

Technologies (please complete the following information):

Additional context The code was derived from documentation in your getting started guide here: https://docs.semaphore.pse.dev/guides/identities

vplasencia commented 5 months ago

Hey @brianblank !

You can find more information about this issue and how to solve it here: https://github.com/semaphore-protocol/semaphore/issues/579#issuecomment-1906740091

I think we should add it to the troubleshooting page in the docs. Thank you very much for pointing it out.

cedoor commented 4 months ago

I think the bn128 curve needs to be terminated explicitly. An example here: https://github.com/semaphore-protocol/semaphore/blob/a522fff4483e0409afbeb7ae85de24f4506c9ec0/packages/proof/tests/index.test.ts#L24

cedoor commented 4 months ago

We'll close this issue as duplicate: https://github.com/semaphore-protocol/semaphore/issues/318