|
|
@ -1,6 +1,6 @@ |
|
|
|
const bn128 = require("snarkjs").bn128; |
|
|
|
const bigInt = require("snarkjs").bigInt; |
|
|
|
const Web3 = require("web3"); |
|
|
|
const Web3Utils = require("web3-utils"); |
|
|
|
const F = bn128.Fr; |
|
|
|
|
|
|
|
const SEED = "mimc"; |
|
|
@ -8,8 +8,8 @@ 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 c = Web3Utils.keccak256(seed+"_iv"); |
|
|
|
const cn = bigInt(Web3Utils.toBN(c).toString()); |
|
|
|
const iv = cn.mod(F.q); |
|
|
|
return iv; |
|
|
|
}; |
|
|
@ -18,13 +18,13 @@ 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); |
|
|
|
let c = Web3Utils.keccak256(SEED); |
|
|
|
for (let i=1; i<nRounds; i++) { |
|
|
|
c = Web3.utils.keccak256(c); |
|
|
|
c = Web3Utils.keccak256(c); |
|
|
|
|
|
|
|
const n1 = Web3.utils.toBN(c).mod(Web3.utils.toBN(F.q.toString())); |
|
|
|
const c2 = Web3.utils.padLeft(Web3.utils.toHex(n1), 64); |
|
|
|
cts[i] = bigInt(Web3.utils.toBN(c2).toString()); |
|
|
|
const n1 = Web3Utils.toBN(c).mod(Web3Utils.toBN(F.q.toString())); |
|
|
|
const c2 = Web3Utils.padLeft(Web3Utils.toHex(n1), 64); |
|
|
|
cts[i] = bigInt(Web3Utils.toBN(c2).toString()); |
|
|
|
} |
|
|
|
cts[0] = bigInt(0); |
|
|
|
return cts; |
|
|
|