diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts index e4be9baa1c..daea2ed230 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts @@ -64,6 +64,12 @@ const logger = { const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) await remix.call('fileManager', 'writeFile', './zk/build/groth16/zk_verifier.sol', solidityContract) + await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ + _pA: [proof.pi_a[0], proof.pi_a[1]], + _pB: [[proof.pi_b[0][1], proof.pi_b[0][0]], [proof.pi_b[1][1], proof.pi_b[1][0]]], + _pC: [proof.pi_c[0], proof.pi_c[1]], + _pubSignals: publicSignals, + }, null, 2)) } catch (e) { console.error(e.message) } diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts index 730c98135a..31b2b8a1f9 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts @@ -56,7 +56,6 @@ const logger = { await remix.call('fileManager', 'writeFile', 'zk/build/plonk/zk_verifier.sol', solidityContract) await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ - _pubSignals: publicSignals, _proof: [ ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).toHexString(), 32), @@ -82,7 +81,8 @@ const logger = { ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s1).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s2).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), - ] + ], + _pubSignals: publicSignals }, null, 2)) console.log('proof done.') diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts index 3c3fe6b20e..f8cef8c28e 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts @@ -54,6 +54,15 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); console.log('zk proof validity', verified); + + await remix.call('fileManager', 'writeFile', `zk/build/groth16/input-${Date.now()}.json`, JSON.stringify({ + _pA: [proof.pi_a[0], proof.pi_a[1]], + _pB: [[proof.pi_b[0][1], proof.pi_b[0][0]], [proof.pi_b[1][1], proof.pi_b[1][0]]], + _pC: [proof.pi_c[0], proof.pi_c[1]], + _pubSignals: publicSignals, + }, null, 2)) + + console.log('proof done.') return { proof, x: publicSignals[3], diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts index e6010af4dc..09b0a885f8 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts @@ -108,9 +108,10 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { const zkey_final = { type: "mem", + // @ts-ignore data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null })) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json')) diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts index 0ac12e2d7b..d477342506 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts @@ -102,6 +102,12 @@ function hash(message: any): bigint { const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) await remix.call('fileManager', 'writeFile', './zk/build/groth16/zk_verifier.sol', solidityContract) + await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ + _pA: [proof.pi_a[0], proof.pi_a[1]], + _pB: [[proof.pi_b[0][1], proof.pi_b[0][0]], [proof.pi_b[1][1], proof.pi_b[1][0]]], + _pC: [proof.pi_c[0], proof.pi_c[1]], + _pubSignals: publicSignals + }, null, 2)) } catch (e) { console.error(e.message) } diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts index 224c866018..6472567bb1 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts @@ -103,7 +103,6 @@ function hash(message: any): bigint { await remix.call('fileManager', 'writeFile', './zk/build/plonk/zk_verifier.sol', solidityContract) await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ - _pubSignals: publicSignals, _proof: [ ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).toHexString(), 32), @@ -129,11 +128,12 @@ function hash(message: any): bigint { ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s1).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s2).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), - ] + ], + _pubSignals: publicSignals }, null, 2)) console.log('proof done.') } catch (e) { console.error(e.message) } -})() \ No newline at end of file +})()