semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

verifyProof hangs in node.js environment

Open carlbarrdahl opened this issue 11 months ago • 1 comments

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):

  • Node.js version 20.9.0
  • NPM version 10.1.0
  • Semaphore 4.0.0-beta.1
  • Solidity version N/A

Additional context Using it in Next.js and bun.

Link to repo:

  • https://github.com/carlbarrdahl/squarevote/pull/1

carlbarrdahl avatar Mar 01 '24 15:03 carlbarrdahl

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?

vplasencia avatar Mar 11 '24 10:03 vplasencia

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 avatar Mar 12 '24 07:03 carlbarrdahl

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

carlbarrdahl avatar Mar 16 '24 11:03 carlbarrdahl

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

vplasencia avatar Mar 19 '24 13:03 vplasencia

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

carlbarrdahl avatar Mar 19 '24 14:03 carlbarrdahl

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.

vplasencia avatar Mar 19 '24 18:03 vplasencia