FhenixProtocol / fhenix.js

The JavaScript SDK for Fhenix
https://fhenixjs.fhenix.zone/
Other
2 stars 1 forks source link

tfhe_bg.wasm not found in Client Side Rendering - Multiple reports #29

Open kkoshiya opened 1 month ago

kkoshiya commented 1 month ago

I think this might be similar to the other error relating to AWS, I'm not certain. This has been reported multiple times. I heard from a dev that works w Zama stack directly that Zama patched this, but again I'm not certain.

Error: ENOENT: no such file or directory, open '/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/tfhe_bg.wasm' at Object.openSync (node:fs:596:3) at Object.readFileSync (node:fs:464:35) at 42046 (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:10:275) at t (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/webpack-runtime.js:1:143) at 8641 (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:2:16131) at n (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:2:481370) at 9920 (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:1:66913) at n (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:2:481370) at 3731 (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:1:64237) at n (/Users/user/workspace/n00b/fhe-voting/frontend/.next/server/app/page.js:2:481370)

Cashmaney commented 1 month ago

Any chance you could share a repro, or more details on some of these reports? I started looking at this, and a few examples would be helpful in making sure that the problem is properly solved

kkoshiya commented 1 month ago

I think both of these projects reported this error. https://github.com/zkoranges/fhe-voting and https://github.com/encrypted-state/dex/blob/main/contracts/SwapPair.sol

im not sure but i think it has something do with not being able to find the path the file

kkoshiya commented 1 month ago

this one as well: https://github.com/kkomelin/create-fhenix-dapp

running this command should cause the error: pnpm create fhenix-dapp@latest

vmathur commented 1 month ago

I'm having the same issue after I do npm install fhenixjs, and try to import FhenixClient into my nextjs app

vmathur commented 1 month ago

Linking my repo here: https://github.com/vmathur/prisoners-dilemma

Cashmaney commented 1 month ago

Thanks. Looking into this

Cashmaney commented 1 month ago

@kkoshiya @vmathur sorry for the delay, it was way more annoying than I expected. I pushed 0.3.0-alpha.0 for testing to see whether some things are still broken, but hopefully everything should be good now. Can you please check that next.js plays nicer now?

vmathur commented 1 month ago

The error looks resolved! Does this package also include the ability to encrypt bools?

Cashmaney commented 1 month ago

Glad to hear it!

Bool, uint8-256 & address should all be supported.

I want to run some more tests (serverless, other edge cases) before I merge this. I'll keep the issue open in the meantime so others can chime in if needed

kkoshiya commented 2 weeks ago

great just checked, seems to be working now. thanks Itzik

alexandrecarvalheira commented 2 weeks ago

0.3.0-alpha.0 Worked for me, thanks.

Cashmaney commented 2 weeks ago

I just created alpha.1 that has better support for nodejs and non browser environments (and a smaller size), but might come at the cost of having to either do a bit of config for next.js or directly use the prebundled version (which is the default for alpha.0).

Leaving this issue open while we continue to test/iterate

alexandrecarvalheira commented 2 weeks ago

i had no tfhe_bg.wasm error when running build on 0.3.0-alpha.0, but was getting:

Error: Failed to initialize fhenixjs - is the network FHE-enabled? Error: Error initializing FhenixClient - maybe try calling with initSdk: false. LinkError: WebAssembly.instantiate(): Import #39 "wbg" "__wbindgen_add": function import requires a callable

what i did was change version to 0.2.1 again and did a dynamic import with ssr false on the component that has the FhenixClient and it worked:

const Token = dynamic(() => import("../components/token"), { ssr: false })

The tfhe_bg.wasm error was being caused on server side render components, so i just had to disable that.

here is my repo: https://github.com/encrypted-state/dex

Cashmaney commented 1 week ago

@alexandrecarvalheira Did you try alpha.1? Issues like this should have been fixed. Also, fwiw you should always be running fhenix.js in CSR, as it is purely for user interaction, not for fetching anything static from the chain