import fs from "fs"; import path from "path"; import {Scalar, ZqField, utils} from "ffjavascript"; const { unstringifyBigInts } = utils; // Version to write in hexadecimal function stringifyBigInts(o) { if ((typeof(o) == "bigint") || o.eq !== undefined) { return "0x"+o.toString(16); } else if (o instanceof Uint8Array) { return Scalar.fromRprLE(o, 0); } else if (Array.isArray(o)) { return o.map(stringifyBigInts); } else if (typeof o == "object") { const res = {}; const keys = Object.keys(o); keys.forEach( (k) => { res[k] = stringifyBigInts(o[k]); }); return res; } else { return o; } } const { C, M } = unstringifyBigInts(JSON.parse(fs.readFileSync(path.join("src", "poseidon_constants.json"), "utf8"))); const N_ROUNDS_F = 8; const N_ROUNDS_P = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68]; function matrix_inverse(Fr, A) { const m = A.length; const B=[]; for (let i=0; i=0; i--) { for (let i2=i+1; i20) S = S + ", "; S = S + Fr.toString(A[i][j]); } console.log(S); } } function vec_print(Fr, v) { for (let i=0; i=nRoundsF/2; r--) { const accp = vec_mul_matrix(Fr, acc, Minv); partialConst.push(accp[0]); accp[0] = Fr.zero; for (let k=0; k0) &&(j>0)) { m_hat[i-1][j-1] = m[i][j]; mp[i][j] = m[i][j]; } else { mp[i][j] = ((i==0)&&(j==0)) ? Fr.one : Fr.zero; } if ((i>0)&&(j==0)) w[i-1] = m[i][j]; } } const m_hat_inv = matrix_inverse(Fr, m_hat); const wp = matrix_mul_vec(Fr, m_hat_inv, w); const S = []; S.push(m[0][0]); for (let k=0; k { process.exit(0); }, (err) => { // console.log(err); console.log(err.stack); process.exit(1); });