How to use the circomlib.mimc7 function in circomlib

To help you get started, we’ve selected a few circomlib 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 barryWhiteHat / maci / src / legacy / Add_New_Leaf / MiMCMerkle.js View on Github external
const circomlib = require('circomlib')
const mimcjs = circomlib.mimc7
const bigInt = require('snarkjs').bigInt

module.exports = {

  // cache empty tree values
  getZeroCache: function (zeroLeafHash, depth) {
    var zeroCache = new Array(depth)
    zeroCache[0] = zeroLeafHash
    for (var i = 1; i < depth; i++) {
      zeroCache[i] = mimcjs.multiHash([zeroCache[i - 1], zeroCache[i - 1]])
    }
    return zeroCache
  },

  getProof: function (leafIdx, tree, leaves) {
    depth = tree.length
github kobigurk / semaphore / test / circuit / circuit.js View on Github external
const chai = require('chai');
const path = require('path');
const snarkjs = require('snarkjs');
const compiler = require('circom');
const fs = require('fs');
const circomlib = require('circomlib');

const test_util = require('../../src/test_util');
const build_merkle_tree_example = test_util.build_merkle_tree_example;

const assert = chai.assert;

const bigInt = snarkjs.bigInt;

const eddsa = circomlib.eddsa;
const mimc7 = circomlib.mimc7;

describe('circuit test', function () {
    let circuit;

    this.timeout(100000);

    before( async () => {
      const cirDef = JSON.parse(fs.readFileSync(path.join(__dirname,'../../build/circuit.json')).toString());
      circuit = new snarkjs.Circuit(cirDef);

      console.log('NConstrains Semaphore: ' + circuit.nConstraints);
  });

  it('does it', () => {
        const prvKey = Buffer.from('0001020304050607080900010203040506070809000102030405060708090001', 'hex');
github kobigurk / semaphore / test / contracts / semaphore.js View on Github external
const chai = require('chai');

const crypto = require('crypto');
const fs = require('fs');
const del = require('del');
const path = require('path');

const snarkjs = require('snarkjs');
const circomlib = require('circomlib');

const test_util = require('../../src/test_util');

const bigInt = snarkjs.bigInt;

const eddsa = circomlib.eddsa;
const mimc7 = circomlib.mimc7;

const groth = snarkjs.groth;
const {unstringifyBigInts} = require('snarkjs/src/stringifybigint.js');

const assert = chai.assert;

const Semaphore = artifacts.require('Semaphore');

const RocksDb = require('../../../sbmtjs/src/storage/rocksdb');
const MerkleTree = require('../../../sbmtjs/src/tree');
const Mimc7Hasher = require('../../../sbmtjs/src/hasher/mimc7');

beBuff2int = function(buff) {
    let res = bigInt.zero;
    for (let i=0; i
github kobigurk / semaphore / sbmtjs / src / hasher / mimc7 / index.js View on Github external
* sbmtjs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * sbmtjs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with sbmtjs.  If not, see .
 */

const circomlib = require('circomlib');
const mimc7 = circomlib.mimc7;
const snarkjs = require('snarkjs');

const bigInt = snarkjs.bigInt;

class Mimc7Hasher {
    hash(level, left, right) {
        return mimc7.multiHash([bigInt(left), bigInt(right)]).toString();
    }
}

module.exports = Mimc7Hasher;