-
Notifications
You must be signed in to change notification settings - Fork 433
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
bun support for groth16.fullProve: add singleThreaded option #490
Conversation
* add singleThreaded option to groth16.fullProve * fix function call
Hi @cdrappi! Thank you for your PR! We just released a new version of snarkjs, which has some changes in the related code. Can you confirm that you still have issues with it? |
Id love to get this merged to main and also fix the types |
I can confirm this continues to happen on the latest version (v0.7.4) and master (0c580e5) using bun 1.1.26. Steps to reproduce: Create a file named import { getCurveFromName } from "./src/curves";
getCurveFromName("bn128")
.then(console.log)
.catch(console.error); Then run Throws with:
For some reason, running |
After a deeper investigation, it turns out that https://github.com/iden3/ffjavascript is using a web-worker polyfill that is explicitly stating to use it's browser entry point on bun but that information is lost in the way up to snarkjs and bun loads the node entrypoint which is specifically designed for node. HOWEVER, using the bun import { buildBn128 } from "ffjavascript";
console.log("start single thread");
await buildBn128(true);
console.log("ok single thread");
console.log("start multi thread");
await buildBn128(false);
console.log("ok multi thread"); and if you comment out the
My conclusion is that this PR is needed as a first step to make 0xPolygonID/js-sdk run on bun. |
Thanks @prevostc for your research! I will take a look at how to proceed with this PR. |
@OBrezhniev I can confirm that the test file does not crash when passed with that extra argument import { getCurveFromName } from "./src/curves";
getCurveFromName("bn128", { singleThread: true })
.then(console.log)
.catch(console.error); |
Thank you for your contributions! Closing this PR as alternative one #533 got merged and added to release v0.7.5. |
When calling groth16.fullProve with bun (instead of node), the function getCurveFromQ hangs forever. I tracked this down a bit, and it seems the root cause is usage of the worker threads. Bun claims to have supported this, but I was unable to get it working with changes further upstream. It's possible that bun doesn't fully support node Workers; it's also possible I wasn't making the correct upstream changes. However, this solution works for my use-case and should work for anyone else who wishes to use bun
If you guys are interested in merging this, I'm happy to follow up with an update to @types/snarkjs
Maintainers, thank you for your work! I am a big fan of this library