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

How to fix wtns calculate error? #217

Closed
3for opened this issue Aug 23, 2022 · 10 comments · Fixed by #222
Closed

How to fix wtns calculate error? #217

3for opened this issue Aug 23, 2022 · 10 comments · Fixed by #222

Comments

@3for
Copy link

3for commented Aug 23, 2022

Hi, I'm following our README guide from step 0 to step 15, and run in snarkjs_example folder:

$ node ../build/cli.cjs wtns calculate  circuit_js/circuit.wasm input.json  witness.wtns
[ERROR] snarkJS: LinkError: WebAssembly.instantiate(): Import #1 module="runtime" function="printErrorMessage" error: function import requires a callable
    at Object.builder [as WitnessCalculatorBuilder] (/Users/lanyu/zyd/snarkjs/node_modules/circom_runtime/build/main.cjs:100:40)
    at async wtnsCalculate$1 (/Users/lanyu/zyd/snarkjs/build/cli.cjs:5856:16)
    at async Object.wtnsCalculate [as action] (/Users/lanyu/zyd/snarkjs/build/cli.cjs:8267:5)
    at async clProcessor (/Users/lanyu/zyd/snarkjs/build/cli.cjs:456:27)

and my env:

$ node -v
v18.7.0
$ circom --version
circom compiler 2.0.7
@phated
Copy link
Contributor

phated commented Aug 23, 2022

circom 2.0.7 changed the wasm imports. If you are on the bleeding-edge of circom, you need to be using witness calculator that they write to your file system.

It takes us (the snarkjs team) a while to sync the changes to circom_runtime to support the newest circom version

@3for
Copy link
Author

3for commented Aug 24, 2022

Thanks for reply @phated . I've fixed by adding dummy implementation of printErrorMessage and writeBufferMessage func in the runtime module:

const instance = await WebAssembly.instantiate(wasmModule, {
    env: {
        "memory": memory
    },
    runtime: {
        exceptionHandler: function(code) {
            let errStr;
            if (code == 1) {
                errStr = "Signal not found. ";
            } else if (code == 2) {
                errStr = "Too many signals set. ";
            } else if (code == 3) {
                errStr = "Signal already set. ";
            } else if (code == 4) {
                errStr = "Assert Failed. ";
            } else if (code == 5) {
                errStr = "Not enough memory. ";
            } else if (code == 6) {
                errStr = "Input signal array access exceeds the size";
            } else {
                errStr = "Unknown error.";
            }
            console.log("ERROR: ", code, errStr);
            throw new Error(errStr);
        },
        showSharedRWMemory: function() {
            const shared_rw_memory_size = instance.exports.getFieldNumLen32();
            const arr = new Uint32Array(shared_rw_memory_size);
            for (let j=0; j<shared_rw_memory_size; j++) {
                arr[shared_rw_memory_size-1-j] = instance.exports.readSharedRWMemory(j);
            }
            console.log(ffjavascript.Scalar.fromArray(arr, 0x100000000));
        },
        error: function(code, pstr, a,b,c,d) {
            let errStr;
            if (code == 7) {
                errStr=p2str(pstr) + " " + wc.getFr(b).toString() + " != " + wc.getFr(c).toString() + " " +p2str(d);
            } else if (code == 9) {
                errStr=p2str(pstr) + " " + wc.getFr(b).toString() + " " +p2str(c);
            } else if ((code == 5)&&(options.sym)) {
                errStr=p2str(pstr)+ " " + options.sym.labelIdx2Name[c];
            } else {
                errStr=p2str(pstr)+ " " + a + " " + b + " " + c + " " + d;
            }
            console.log("ERROR: ", code, errStr);
            throw new Error(errStr);
        },
        printErrorMessage: function(a) {
            console.log(wc.getFr(a).toString());
        },
        writeBufferMessage: function(a) {
            console.log(wc.getFr(a).toString());
        },
        log: function(a) {
            console.log(wc.getFr(a).toString());
        },
        logGetSignal: function(signal, pVal) {
            if (options.logGetSignal) {
                options.logGetSignal(signal, wc.getFr(pVal) );
            }
        },
        logSetSignal: function(signal, pVal) {
            if (options.logSetSignal) {
                options.logSetSignal(signal, wc.getFr(pVal) );
            }
        },
        logStartComponent: function(cIdx) {
            if (options.logStartComponent) {
                options.logStartComponent(cIdx);
            }
        },
        logFinishComponent: function(cIdx) {
            if (options.logFinishComponent) {
                options.logFinishComponent(cIdx);
            }
        }
    }
});

@phated
Copy link
Contributor

phated commented Aug 24, 2022

Those are incorrect and will make your code not work correctly. Don't stub them like that. Don't use snarkjs with Circom 2.0.7 until we properly fix it.

@3for
Copy link
Author

3for commented Aug 24, 2022

Okay, thanks @phated

@flyingnobita
Copy link

I got this problem and using circom v2.0.6 indeed fixes it.

Right now the circom doc suggest to git clone and thus we always use the latest circom version. Is there anywhere in the snarkjs docs (or future plans) that suggest the circom version that is fully compatible with snarkjs?

@phated
Copy link
Contributor

phated commented Aug 26, 2022

The snarkjs maintainers are not the developers of circom anymore and the circom developers don't follow semver. It is a large effort to try to follow behind them to make it work when they break things.

@phated phated linked a pull request Aug 29, 2022 that will close this issue
@phated
Copy link
Contributor

phated commented Aug 29, 2022

This was fixed in circom_runtime 0.1.19 - circom doesn't follow semantic versioning, and as I said it that PR:

This relies on my patch at iden3/circom#105 which added getMinorVersion and getPatchVersion to the WASM exports.

Technically, someone could have a cloned version of circom between the log change and my patch, but we can't really solve that (we will just tell them to pull the latest changes).

Hopefully a new release of snarkjs will be out soon.

@remi-gai
Copy link

I'm currently facing the same issue with circom compiler 2.0.8. How can I downgrade or download the 2.0.6 version?

@phated
Copy link
Contributor

phated commented Aug 31, 2022

Snarkjs 0.4.26 contains the fix

@zlemon819
Copy link

Snarkjs 0.4.26 contains the fix

hi, Is Snarkjs 0.5.0 compatible with Circom compiler 2.1.2 now ? i run "npm run test" in the ed25519/circom directory and come across the same issues as follows:
LinkError: WebAssembly.instantiate(): Import #1 module="runtime" function="printErrorMessage" error: function import requires a callable

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

Successfully merging a pull request may close this issue.

5 participants