mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-06 18:56:43 +01:00
Change bases and IV
This commit is contained in:
15
src/mimc7.js
15
src/mimc7.js
@@ -3,11 +3,20 @@ const bigInt = require("snarkjs").bigInt;
|
||||
const Web3 = require("web3");
|
||||
const F = bn128.Fr;
|
||||
|
||||
const SEED = "iden3_mimc";
|
||||
const nRounds = 91;
|
||||
const SEED = "mimc";
|
||||
const NROUNDS = 91;
|
||||
|
||||
exports.getIV = (seed) => {
|
||||
if (typeof seed === "undefined") seed = SEED;
|
||||
const c = Web3.utils.keccak256(seed+"_iv");
|
||||
const cn = bigInt(Web3.utils.toBN(c).toString());
|
||||
const iv = cn.mod(F.q);
|
||||
return iv;
|
||||
};
|
||||
|
||||
exports.getConstants = (seed, nRounds) => {
|
||||
if (typeof seed === "undefined") seed = SEED;
|
||||
if (typeof nRounds === "undefined") nRounds = NROUNDS;
|
||||
const cts = new Array(nRounds);
|
||||
let c = Web3.utils.keccak256(SEED);
|
||||
for (let i=1; i<nRounds; i++) {
|
||||
@@ -27,7 +36,7 @@ exports.hash = (_x_in, _k) =>{
|
||||
const x_in = bigInt(_x_in);
|
||||
const k = bigInt(_k);
|
||||
let r;
|
||||
for (let i=0; i<nRounds; i++) {
|
||||
for (let i=0; i<NROUNDS; i++) {
|
||||
const c = cts[i];
|
||||
const t = (i==0) ? F.add(x_in, k) : F.add(F.add(r, k), c);
|
||||
r = F.exp(t, 7);
|
||||
|
||||
3
src/mimc_print_iv.js
Normal file
3
src/mimc_print_iv.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const mimc7 = require("./mimc7.js");
|
||||
|
||||
console.log("IV: "+mimc7.getIV().toString());
|
||||
13
src/mimc_printconstants..js
Normal file
13
src/mimc_printconstants..js
Normal file
@@ -0,0 +1,13 @@
|
||||
const mimc7 = require("./mimc7.js");
|
||||
|
||||
const nRounds = 91;
|
||||
let S = "[\n";
|
||||
const cts = mimc7.getConstants();
|
||||
for (let i=0; i<nRounds; i++) {
|
||||
S = S + cts[i].toString();
|
||||
if (i<nRounds-1) S = S + ",";
|
||||
S=S+"\n";
|
||||
}
|
||||
S = S + "]\n";
|
||||
|
||||
console.log(S);
|
||||
@@ -1,6 +1,6 @@
|
||||
const mimcGenContract = require("./mimc_gencontract");
|
||||
|
||||
const SEED = "iden3_mimc";
|
||||
const SEED = "mimc";
|
||||
|
||||
let nRounds;
|
||||
if (typeof process.argv[2] != "undefined") {
|
||||
@@ -10,3 +10,4 @@ if (typeof process.argv[2] != "undefined") {
|
||||
}
|
||||
|
||||
console.log(mimcGenContract.createCode(SEED, nRounds));
|
||||
|
||||
@@ -4,7 +4,7 @@ const babyJub = require("./babyjub");
|
||||
const assert = require("assert");
|
||||
const createBlakeHash = require("blake-hash");
|
||||
|
||||
const GENPOINT_PREFIX = "Iden3_PedersenGenerator";
|
||||
const GENPOINT_PREFIX = "PedersenGenerator";
|
||||
const windowSize = 4;
|
||||
const nWindowsPerSegment = 50;
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
const bigInt = require("snarkjs").bigInt;
|
||||
|
||||
const SMTMemDB = require("./smt_memdb");
|
||||
const mimc7 = require("./mimc7").hash;
|
||||
const mimc7 = require("./mimc7");
|
||||
|
||||
function smtHash(arr) {
|
||||
let r = bigInt(0);
|
||||
let r = mimc7.getIV();
|
||||
for (let i=0; i<arr.length; i++) {
|
||||
r = mimc7(r, bigInt(arr[i]));
|
||||
r = mimc7.hash(r, bigInt(arr[i]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user