Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("Verify proof-of-vote", () => {
// Verify the proof
const vk_verifier = setup.vk_verifier;
assert.isTrue(zkSnark.original.isValid(vk_verifier, proof.proof, proof.publicSignals));
}).timeout(10000000);
});
it("Create a trusted setup", () => {
// Trusted setup
setup = zkSnark.original.setup(circuit);
setup.toxic // Must be discarded.
assert.equal(setup.vk_verifier.nPublic, 7);
}).timeout(10000000);
// @flow
const provingKey = require('../circuits/proving_key.json')
const verificationKey = require('../circuits/verification_key.json')
const circuitDef = require('../circuits/circuit.json')
const { eddsa, mimc7 } = require('circomlib')
const { Circuit } = require('snarkjs')
const zkSnark = require('snarkjs').original
const { unstringifyBigInts } = require('snarkjs/src/stringifybigint')
const alicePrvKey = Buffer.from('1'.toString().padStart(64, '0'), 'hex')
const alicePubKey = eddsa.prv2pub(alicePrvKey)
const bobPrvKey = Buffer.from('2'.toString().padStart(64, '0'), 'hex')
const bobPubKey = eddsa.prv2pub(bobPrvKey)
// accounts (1 = Yes, 0 = No)
const Alice = {
pubkey: alicePubKey,
detail: 1
}
const aliceHash = mimc7.multiHash(
[Alice.pubkey[0], Alice.pubkey[1], BigInt(Alice.detail)]
)
const createTrustedSetup = async (compiledCircuitFiles) => {
console.log('===== Trusted Setup Started =====');
console.log('===== Generating pk and vk =====');
for (compiledCircuit of compiledCircuitFiles) {
let extension = path.extname(compiledCircuit, 'json');
let nameOfFile = path.basename(compiledCircuit, extension);
const file = require(`${process.cwd()}/${compiledCircuit}`);
let circuit = new zkSnark.Circuit(file);
let setup = zkSnark.original.setup(circuit);
fs.writeFileSync(`${trustedSetup}/${nameOfFile}_proving_key.json`, JSON.stringify(zkSnark.stringifyBigInts(setup.vk_proof), null, 1), "utf8");
fs.writeFileSync(`${trustedSetup}/${nameOfFile}_verification_key.json`, JSON.stringify(zkSnark.stringifyBigInts(setup.vk_verifier), null, 1), "utf8");
}
}
const generateProof = (provingKey, witness, circuit) => {
console.log('===== Generating Proof =====');
const proofObject = zkSnark.original.genProof(provingKey, witness);
let extension = path.extname(circuit, 'json');
let nameOfFile = path.basename(circuit, extension);
fs.writeFileSync(`${generatedProofPath}/${nameOfFile}_proof.json`, JSON.stringify(zkSnark.stringifyBigInts(proofObject.proof), null, 1), "utf8");
fs.writeFileSync(`${generatedProofPath}/${nameOfFile}_public_signals.json`, JSON.stringify(zkSnark.stringifyBigInts(proofObject.publicSignals), null, 1), "utf8");
}
const verifyProof = async (publicSignals, generatedProof, verifierKey) => {
console.log('===== Verifying Proof =====');
const verified = await zkSnark.original.isValid(verifierKey, generatedProof, publicSignals);
const timestamp = new Date().getTime();
const object = {
verified,
timestamp
}
fs.writeFileSync(`${verifiedProof}/output.json`, JSON.stringify(object, null, 1), "utf8");
}