import * as binFileUtils from "./binfileutils.js"; import * as zkeyUtils from "./zkey_utils.js"; import * as fastFile from "fastfile"; import { getCurveFromQ as getCurve } from "./curves.js"; export default async function phase2exportMPCParams(zkeyName, mpcparamsName, logger) { const {fd: fdZKey, sections: sectionsZKey} = await binFileUtils.readBinFile(zkeyName, "zkey", 2); const zkey = await zkeyUtils.readHeader(fdZKey, sectionsZKey, "groth16"); const curve = await getCurve(zkey.q); const sG1 = curve.G1.F.n8*2; const sG2 = curve.G2.F.n8*2; const mpcParams = await zkeyUtils.readMPCParams(fdZKey, curve, sectionsZKey); const fdMPCParams = await fastFile.createOverride(mpcparamsName); ///////////////////// // Verification Key Section ///////////////////// await writeG1(zkey.vk_alpha_1); await writeG1(zkey.vk_beta_1); await writeG2(zkey.vk_beta_2); await writeG2(zkey.vk_gamma_2); await writeG1(zkey.vk_delta_1); await writeG2(zkey.vk_delta_2); // IC let buffBasesIC; buffBasesIC = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 3); buffBasesIC = await curve.G1.batchLEMtoU(buffBasesIC); await writePointArray("G1", buffBasesIC); ///////////////////// // h Section ///////////////////// const buffBasesH_Lodd = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 9); let buffBasesH_Tau; buffBasesH_Tau = await curve.G1.fft(buffBasesH_Lodd, "affine", "jacobian", logger); buffBasesH_Tau = await curve.G1.batchApplyKey(buffBasesH_Tau, curve.Fr.neg(curve.Fr.e(2)), curve.Fr.w[zkey.power+1], "jacobian", "affine", logger); // Remove last element. (The degree of H will be allways m-2) buffBasesH_Tau = buffBasesH_Tau.slice(0, buffBasesH_Tau.byteLength - sG1); buffBasesH_Tau = await curve.G1.batchLEMtoU(buffBasesH_Tau); await writePointArray("G1", buffBasesH_Tau); ///////////////////// // L section ///////////////////// let buffBasesC; buffBasesC = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 8); buffBasesC = await curve.G1.batchLEMtoU(buffBasesC); await writePointArray("G1", buffBasesC); ///////////////////// // A Section (C section) ///////////////////// let buffBasesA; buffBasesA = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 5); buffBasesA = await curve.G1.batchLEMtoU(buffBasesA); await writePointArray("G1", buffBasesA); ///////////////////// // B1 Section ///////////////////// let buffBasesB1; buffBasesB1 = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 6); buffBasesB1 = await curve.G1.batchLEMtoU(buffBasesB1); await writePointArray("G1", buffBasesB1); ///////////////////// // B2 Section ///////////////////// let buffBasesB2; buffBasesB2 = await binFileUtils.readFullSection(fdZKey, sectionsZKey, 7); buffBasesB2 = await curve.G2.batchLEMtoU(buffBasesB2); await writePointArray("G2", buffBasesB2); await fdMPCParams.write(mpcParams.csHash); await writeU32(mpcParams.contributions.length); for (let i=0; i