semaphore-protocol / semaphore

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

verifyProof hangs in node.js environment #675

Closed carlbarrdahl closed 6 months ago

carlbarrdahl commented 8 months ago

Describe the bug I have a backend service that receives a proof from a frontend to verify it. It never finishes running the verifyProof function.

Verifying on frontend works as expected.

To Reproduce Steps to reproduce the behavior:

  1. Create proof in a browser
  2. Send to a Next.js server
  3. verifyProof(proof)
  4. Nothing happens

Expected behavior Expecting verifyProof to return true or false in nodejs environment.

Technologies (please complete the following information):

Additional context Using it in Next.js and bun.

Link to repo:

vplasencia commented 7 months ago

Hey! Semaphore does not work with Bun. You can take a look at this: https://github.com/vplasencia/semaphore-bun

Regarding Nextjs and node, did you try other package manager like npm, yarn or pnpm? Is it working?

carlbarrdahl commented 7 months ago

Hey! Semaphore does not work with Bun. You can take a look at this: https://github.com/vplasencia/semaphore-bun

Regarding Nextjs and node, did you try other package manager like npm, yarn or pnpm? Is it working?

I tried both npm run dev as well as building the project and then next start (via npm). Still hangs at verifying proof.

I was able to get it working easily in an isolated environment with bun init and then running the code with npx tsx index.ts.

carlbarrdahl commented 7 months ago

After some more testing it seems it works with npm run build && npm run start (but npm run dev doesn't).

I created a minimal repo here with create-next-app:

https://github.com/carlbarrdahl/next-semaphore https://replit.com/@CarlBarrdahl/next-semaphore

Relevant files: https://github.com/carlbarrdahl/next-semaphore/blob/49643e0b563170b164aaf8098ae109c4bf4c5d33/components/ZkProof.tsx#L7-L20 https://github.com/carlbarrdahl/next-semaphore/blob/49643e0b563170b164aaf8098ae109c4bf4c5d33/app/api/route.ts#L5-L10

vplasencia commented 7 months ago

Hey @carlbarrdahl

Thank you so much for the information and code. It's very interesting that it works with npm run build && npm run start and not with npm run dev.

It seems that Semaphore v3 and v4 don't work with Nextjs 14 with the app folder. Semaphore v3 is working with Nextjs 13 with pages (this is an example of project: https://github.com/bandada-infra/bandada-semaphore-demo). Semaphore v4 is not working with Nextjs 13 because of this issue we are trying to solve: https://github.com/semaphore-protocol/semaphore/issues/713

carlbarrdahl commented 7 months ago

Great to hear you've identified the bug and tracking it!

vplasencia commented 7 months ago

Hey @carlbarrdahl

Regarding the issue https://github.com/semaphore-protocol/semaphore/issues/713 I mentioned before, one quick fix for now could be to use resolutions with yarn or overrides with npm inside your project.