Giter Club home page Giter Club logo

Comments (6)

sigmachirality avatar sigmachirality commented on July 29, 2024 1

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.

phated avatar phated commented on July 29, 2024 1

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.

phated avatar phated commented on July 29, 2024

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.

sigmachirality avatar sigmachirality commented on July 29, 2024

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.

sigmachirality avatar sigmachirality commented on July 29, 2024

Would prefer against shimming inherits as it will increase bundle size for code that isn't used in the main bundle.

from snarkjs.

yagnadeepxo avatar yagnadeepxo commented on July 29, 2024

Please fix the issue, unable to use snarkjs on the client-side

from snarkjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.