Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] curve not properly terminated after usage in groth16Vk(zkey, fd, sections) and plonkVk(zkey), causing process hang #292

Closed
nnabuuu opened this issue Dec 21, 2022 · 1 comment

Comments

@nnabuuu
Copy link

nnabuuu commented Dec 21, 2022

This happens as I was calling snarkjs.zKey.exportVerificationKey(zkeyName) in my own code.

Below is the message printed by package "why-is-node-running".

# MESSAGEPORT
node:internal/async_hooks:201                                                                              
node:internal/worker:223                                                                                   
/Users/niex/WebstormProjects/zkey-export/node_modules/web-worker/cjs/node.js:111                            - const worker = new threads.Worker(__filename, {
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:4486 - tm.workers[i] = new Worker__default["default"](workerSource);
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5780 - const tm = await buildThreadManager(params.wasm, params.singleThread);
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5877 - const curve = await buildEngine(params);
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/build/main.cjs:53                             - curve = await ffjavascript.buildBn128();
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/build/main.cjs:398                            - zkey.curve = await getCurveFromQ(zkey.q);
/Users/niex/WebstormProjects/zkey-export/node_modules/snarkjs/build/main.cjs:339                            - return await readHeaderPlonk(fd, sections, toObject);

It shows that after snarkjs calls getCurveFromQ(zkey.q); to create the curve, there is a ThreadManager started and holds internal web-workers running, until curve.terminate() is called.

As neither groth16Vk(zkey, fd, sections) nor plonkVk(zkey) explicitly calls curve.terminate(), those web_works never ends.

A quick fix could be adding the following code in groth16Vk(zkey, fd, sections) and plonkVk(zkey) to terminate the curve right before return vKey, though I am not sure if this is the best way to fix this bug.

console.log("===DEBUG=== There is curve still running, terminating it...")
await curve.terminate();

I am interested in submitting the pull request to fix this issue, but surely I don't want to introduce new bugs...

@phated
Copy link
Contributor

phated commented Dec 21, 2022

Duplicate of #152

Curves are attached to a global, which you can choose to end whenever you need.

As stated in the linked issue, it would be heavy handed to kill the curve cache between every run (and drastically hurt performance).

@phated phated closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants