Save groth16 inputs

pull/4717/head
ioedeveloper 7 months ago
parent fc5a4f1169
commit 710f8ea3d3
  1. 6
      libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts
  2. 4
      libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts
  3. 9
      libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts
  4. 1
      libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts
  5. 6
      libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts
  6. 4
      libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts

@ -64,6 +64,12 @@ const logger = {
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/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) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
_pubSignals: publicSignals,
_proof: [ _proof: [
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32),
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).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_s1).toHexString(), 32),
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s2).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s2).toHexString(), 32),
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32),
] ],
_pubSignals: publicSignals
}, null, 2)) }, null, 2))
console.log('proof done.') console.log('proof done.')

@ -54,6 +54,15 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); 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 { return {
proof, proof,
x: publicSignals[3], x: publicSignals[3],

@ -108,6 +108,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const zkey_final = { const zkey_final = {
type: "mem", type: "mem",
// @ts-ignore
data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null })) data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null }))
} }
const wtns = { type: "mem" }; const wtns = { type: "mem" };

@ -102,6 +102,12 @@ function hash(message: any): bigint {
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/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) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
_pubSignals: publicSignals,
_proof: [ _proof: [
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32),
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).toHexString(), 32),
@ -129,7 +128,8 @@ function hash(message: any): bigint {
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s1).toHexString(), 32), 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_s2).toHexString(), 32),
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32),
] ],
_pubSignals: publicSignals
}, null, 2)) }, null, 2))
console.log('proof done.') console.log('proof done.')

Loading…
Cancel
Save