Hash verify between JS and noir-lang circuit

Hello Aztec community,
I have several questions :grinning:
Here’s a function to check whether a value is in the hash’s integrity:

fn main(hash: pub Field, a: Field, b: Field, c: Field, d: Field) {
    let hashPoseidon = std::hash::poseidon::bn254::hash_4([a, b, c, d]);
    std::println(hashPoseidon);
    assert(hash == hashPoseidon);
}

Am I using the most efficient hash function? (Compared to pedersen)
This function works very well with nargo test, prove, verify, but it’s only when I generate a proof with JS.
Sometimes i have this message:

“Error: the string “Error calling foreign_call_callback: Unknown” was thrown, throw an Error”

And sometimes I am told that the constraints are not respected.
What should I send? a hexadecimal string? a bigInt? an uint8Array?

I have an older version of JS-project that uses:
"@noir-lang/acvm_js": "git+https://git@github.com/noir-lang/acvm-simulator-wasm.git#b9d9ca9dfc5140839f23998d9466307215607c42"

What do you recommend? I’m stuck

Thank in advance.

10 Likes

I found a solution for certain problems:
the error: foreign_call_callback
come from a circuit compile with a std::println inside. :sweat_smile:
With my hardhat JS project, I send a BigInt for the Poseidon hash, and it fulfills all the constraints for the proof generation.

I still don’t have an answer about the efficiency of hash functions. :upside_down_face:

29 Likes

Hi there! Sorry for the late reply.

To find out which design approach is more efficient in general, you can run the nargo info command to gather the constraint count of your code.

The lower the number, the faster it proves.

In case you’re still running into any problems with JS, the latest recommended workflow is described here.

If that’s already what you are using, it’d be very helpful if you could file a bug report with code + steps to reproduce the problem you’re facing on the Noir GitHub :pray:

Thank you and hope you enjoy Noir!

54 Likes