forked from tokamak-network/tokamak-sybil-resistance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_verification.ts
54 lines (43 loc) · 1.51 KB
/
run_verification.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const snarkjs = require('snarkjs');
async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove')
console.log(zkey_final)
console.log(wtns)
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
console.log(typeof(publicSignals))
console.log(proof)
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified);
return {
proof,
x: publicSignals[3],
y: publicSignals[0]
}
}
(async () => {
console.log("few")
// @ts-ignore
const r1csBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/mult.r1cs', true);
// @ts-ignore
const r1cs = new Uint8Array(r1csBuffer);
// @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/mult.wasm', true);
// @ts-ignore
const wasm = new Uint8Array(wasmBuffer);
const zkey_final = {
type: "mem",
data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/zk_setup.txt')))
}
const wtns = { type: "mem" };
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/verification_key.json'))
const signals = {
in1: 3,
in2: 4
}
const proof = await prove(signals, wasm, wtns, r1cs, zkey_final, vKey)
}
)()