Comments (6)
To the maintainers:
Was able to reproduct this issue in [email protected]
...
after some investigation I believe it is because the 'bfj' package is getting bundled into the IIFE package.
I would suggest to the maintainers to move away from ''bfj' ASAP as it has not been maintained for 3 years, and has been bundled in a way that makes it tricky to rebundle - rollup in particular now bundles it into every bundle as it cannot determine whether bfj's import has any needed side effects. See: webpack-contrib/webpack-bundle-analyzer#383 for more information.
For snarkjs, bfj is bundled into main.js even though it is only referenced in cli.js, and this is a problem because bfj depends on utils.inherits
which has been depreciated since 2015. As such polyfills do not support it.
In my testing Vite is able to sidestep this problem by bundling the main.cjs to ESM itself, but this remains an issue for anyone not using Vite. I would suggest revisiting the rollup scripts and bundling snarkjs to both esm and cjs, and redefining the "exports" field in package.json
to case on the "node" and/or "browser" conditions. In an ideal world snarkjs would distribute with a node-specific cjs/esm and a browser specific esm in addition to the current IIFE and minified file, or be rewritten such that runtime checks about the environment are safer/more conducive to code elimination and tree shaking.
I am working on a PR for this issue, but am having trouble with removing bfj from bundles targeting the browser because of the aforementioned side-effect static analysis/code elimination difficulty.
Though perhaps not as technically interesting, in my opinion browser-based proving remains the most philosophically necessary of ZKPs in terms of real world use cases where privacy is of utmost importance. Hopefully someone can provide insight/assistance/fixes into this problem.
from snarkjs.
We're waiting on a fastfile release.
Actually, I spent some time deep-diving here and found that the code was just written incorrectly for the browser.
I'll have a PR up soon.
from snarkjs.
Thanks for the investigation @sigmachirality! We aren't going to remove bfj from the CLI because it is needed to not crash on processing JSON too big to fit in memory.
I can look into removing it from the browser package though. Regardless, we can always shim inherits using rollup
from snarkjs.
I'm not suggesting removing bfj
entirely, but probably migrating to another package or writing a custom serializer (which is the approach the webpack contributors took) would be best. Though I also recognize the contributors have a limited amount of time and bfj works, so may not be worth it.
I found a way to remove bfj from the browser build which I pushed as part of #339. What you do is add the following to rollup's config:
treeshake: { moduleSideEffects: false },
This removes bfj
and fs
from the generated bundle. You can whitelist packages that need to be imported for their side-effects manually by passing an array to this treeshake.moduleSideEffects
property. Feel free to cherry-pick or patch with this change as needed.
from snarkjs.
Would prefer against shimming inherits as it will increase bundle size for code that isn't used in the main bundle.
from snarkjs.
Please fix the issue, unable to use snarkjs on the client-side
from snarkjs.
Related Issues (20)
- Receiving "Proof commitments are not valid" when verifying simple groth16 circuit HOT 1
- snarkjs pot contribute with same file as input and ouput causes issue
- Using BLS12-381 curve to generate groth16 solidity verifier results in out of range error in solidity HOT 1
- RangeError: Too many elements passed to Promise.all HOT 2
- The javascript prover and verifier will succeed when using public inputs > field prime
- Zkeys fail to be verified right after generations with custom R1CS and witness HOT 1
- How to call `soliditycalldata` in ethereum smart contract runtime? HOT 1
- Proof valiadation not working with cirtcuit that works fine with circom tester HOT 1
- snarkjs.groth16.verify is not working if pubSignals is empty
- snarkjs.groth16.fullProve run locally fine but doesn't run correctly on cloud
- Where is generate_witness.json๏ผ HOT 1
- Generating just a witness in browser HOT 2
- is there a cpp implementation of trusted setup? js runs too slow for my circuits
- Vulnerability report received? HOT 2
- Getting 'Scalar size does not match' error when proving a simple circuit with addition or subtraction
- Way to verify vkey for a circuit? HOT 2
- Troubleshooting Discrepancies: Validating Pre-Image Hashes in SnarkJS HOT 1
- `snarkjs` cannot be used with ES modules
- Not all available cores are used by taskmanager HOT 2
- Error generating a proof for Circom circuit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snarkjs.