diff --git a/src/kzg_basic_prover.js b/src/kzg_basic_prover.js index 88a01a1..cb6fd1e 100644 --- a/src/kzg_basic_prover.js +++ b/src/kzg_basic_prover.js @@ -7,10 +7,7 @@ const readPTauHeader = require("./ptau_utils"); module.exports = async function kzg_basic_prover(evalsBufferArray, pTauFilename, options) { const logger = options.logger; - if (logger) { - logger.info("> KZG BASIC PROVER STARTED"); - logger.info(""); - } + if (logger) logger.info("> KZG BASIC PROVER STARTED"); const { fd: fdPTau, sections: pTauSections } = await readBinFile(pTauFilename, "ptau", 1, 1 << 22, 1 << 24); const { curve, power: nBitsPTau } = await readPTauHeader(fdPTau, pTauSections); @@ -32,7 +29,6 @@ module.exports = async function kzg_basic_prover(evalsBufferArray, pTauFilename, throw new Error("Polynomial length must be power of two."); } - // Ensure the powers of Tau file is sufficiently large if (nBitsPTau < nBits) { throw new Error("Powers of Tau has not enough values for this polynomial"); @@ -54,8 +50,6 @@ module.exports = async function kzg_basic_prover(evalsBufferArray, pTauFilename, let proof = {}; let challenges = {}; - // STEP 0. Get the settings and prepare the setup - // Ensure all polynomials have the same length const pols = []; for (let i = 0; i < evalsBufferArray.length; i++) { // Convert the evaluations to Montgomery form @@ -65,43 +59,39 @@ module.exports = async function kzg_basic_prover(evalsBufferArray, pTauFilename, pols[i] = await Polynomial.fromEvaluations(evals, curve, logger); } - // STEP 1. Generate the polynomial commitments of all polynomials + // STEP 1. Generate the polynomial commitments for all polynomials logger.info("> STEP 1. Compute polynomial commitments"); proof.commitments = []; for(let i=0; i STEP 2. Get challenge xi"); + // STEP 2. Compute opening evaluations + logger.info("> STEP 2. Compute opening evaluations"); + // STEP 2.1 Compute challenge xi const transcript = new Keccak256Transcript(curve); - for(let i=0; i STEP 3. Calculate the opening p(xi) = y"); + // STEP 2.2 Compute evaluations proof.evaluations = []; for(let i=0; i STEP 4. Get challenge alpha"); + // STEP 3. Calculate the polynomial q(X) + logger.info("> STEP 3. Calculate the polynomial q(X)"); + // STEP 3.1 Compute challenge alpha transcript.reset(); - for(let i=0; i STEP 5. Calculate the polynomial q(X)"); + // STEP 3.1 Calculate the polynomial q(X) let polQ = new Polynomial(new Uint8Array(curve.Fr.n8 * polLen), curve, logger); let currentAlpha = curve.Fr.one; @@ -115,12 +105,9 @@ module.exports = async function kzg_basic_prover(evalsBufferArray, pTauFilename, } proof.commitQ = await polQ.multiExponentiation(PTau, "Q"); - logger.info("··· [q(X)]_1 = ", curve.G1.toString(proof.commitQ)); + logger.info("··· [q(X)]_1 =", curve.G1.toString(proof.commitQ)); - if (logger) { - logger.info(""); - logger.info("> KZG BASIC PROVER FINISHED"); - } + if (logger) logger.info("> KZG BASIC PROVER FINISHED"); await fdPTau.close(); diff --git a/src/kzg_basic_verifier.js b/src/kzg_basic_verifier.js index 30539b3..ca953af 100644 --- a/src/kzg_basic_verifier.js +++ b/src/kzg_basic_verifier.js @@ -5,10 +5,7 @@ const readPTauHeader = require("./ptau_utils"); module.exports = async function kzg_basic_verifier(proof, pTauFilename, options) { const logger = options.logger; - if (logger) { - logger.info("> KZG BASIC VERIFIER STARTED"); - logger.info(""); - } + if (logger) logger.info("> KZG BASIC VERIFIER STARTED"); const { fd: fdPTau, sections: pTauSections } = await readBinFile(pTauFilename, "ptau", 1, 1 << 22, 1 << 24); const { curve } = await readPTauHeader(fdPTau, pTauSections); @@ -31,7 +28,7 @@ module.exports = async function kzg_basic_verifier(proof, pTauFilename, options) transcript.addPolCommitment(proof.commitments[i]); } challenges.xi = transcript.getChallenge(); - logger.info("··· xi = ", curve.Fr.toString(challenges.xi)); + logger.info("··· xi =", curve.Fr.toString(challenges.xi)); // STEP 2. Calculate challenge alpha from transcript logger.info("> STEP 2. Compute challenge alpha"); @@ -40,7 +37,7 @@ module.exports = async function kzg_basic_verifier(proof, pTauFilename, options) transcript.addEvaluation(proof.evaluations[i]); } challenges.alpha = transcript.getChallenge(); - logger.info("··· alpha = ", curve.Fr.toString(challenges.alpha)); + logger.info("··· alpha =", curve.Fr.toString(challenges.alpha)); // STEP 3. Compute [F]_1 let currentAlpha = curve.Fr.one; @@ -82,10 +79,7 @@ module.exports = async function kzg_basic_verifier(proof, pTauFilename, options) } } - if (logger) { - logger.info(""); - logger.info("> KZG BASIC VERIFIER FINISHED"); - } + if (logger) logger.info(""); await fdPTau.close();