How to use the snarkjs.original function in snarkjs

To help you get started, we’ve selected a few snarkjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eddieoz / haal / test / vote_zk.js View on Github external
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);
});
github eddieoz / haal / test / vote_zk.js View on Github external
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);
github barryWhiteHat / maci / app / utils / generate_circuit_input.js View on Github external
// @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)]
)
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / trusted-setup.js View on Github external
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");
	}
}
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / generate-proof.js View on Github external
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");

}
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / verify-proof.js View on Github external
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");
}