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

Function to generate solidity parameters #112

Closed
connorbode opened this issue Dec 8, 2021 · 1 comment
Closed

Function to generate solidity parameters #112

connorbode opened this issue Dec 8, 2021 · 1 comment

Comments

@connorbode
Copy link

connorbode commented Dec 8, 2021

I had a lot of trouble discovering how to generate parameters to pass to an ethersjs contract function. It's possible that I've gone in the wrong direction, but I wanted to document the steps I took and the suggestions I have.

First, the unstringifyBigInts function is necessary & can be imported as follows:

const ffjavascript = require('ffjavascript')
const unstringifyBigInts = ffjavascript.utils.unstringifyBigInts

Next, here is the code I've used to submit a verifyProof call. Note that verifierContract is an instance of an ethersjs contract.

const { proof, publicSignals } = await snarkjs.plonk.prove(ZKEY_PATH, WITNESS_FILE)
const calldata = await snarkjs.plonk.exportSolidityCallData(unstringifyBigInts(proof), unstringifyBigInts(publicSignals))
const calldataSplit = calldata.split(',')
const proofFormatted = calldataSplit[0]
const publicSignalsFormatted = JSON.parse(values[1]).map(x => BigInt(x).toString())
const output = await verifierContract.verifyProof(proofFormatted, publicSignalsFormatted)

This all took a while for me to put together. A function like snarkjs.plonk.generateSolidityParams(proof, publicSignals) which formats the proof and publicSignals for web3 / ethers would be very useful for people new to snarkjs.

Hopefully this helps someone!

@phated
Copy link
Contributor

phated commented May 17, 2022

You should no longer need to unstringifyBigInts as of #146 - Can you test snarkjs v0.4.17 ?

@phated phated closed this as completed May 17, 2022
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

No branches or pull requests

2 participants