UNPKG

@nori-zk/proof-conversion

Version:

Verifying zkVM proofs inside o1js circuits, to generate Mina compatible proof

79 lines 3.06 kB
import { G2Affine } from '../ec/g2.js'; import { computeLineCoeffs } from '../lines/index.js'; import { Fp12, Fp2, FpC } from '../towers/index.js'; import fs from 'fs'; import { bn254 } from '../ec/g1.js'; class GrothVk { // Named accessors for backward compatibility get ic0() { return this.icPoints[0]; } get ic1() { return this.icPoints[1]; } get ic2() { return this.icPoints[2]; } get ic3() { return this.icPoints[3]; } get ic4() { return this.icPoints[4]; } get ic5() { return this.icPoints[5]; } get ic6() { return this.icPoints[6]; } getIcPoint(index) { return this.icPoints[index]; } constructor(alpha_beta, w27, delta, gamma, icPoints) { this.delta_lines = computeLineCoeffs(delta); this.gamma_lines = computeLineCoeffs(gamma); this.alpha_beta = alpha_beta; this.w27 = w27; this.w27_square = w27.mul(w27); this.icPoints = icPoints; // Must have at least ic0, the constant if (this.icPoints.length === 0) { throw new Error('VK must contain at least ic0 point'); } } static parse(path) { const data = fs.readFileSync(path, 'utf-8'); const obj = JSON.parse(data); // Detect available IC points from VK structure const availableIcFields = Object.keys(obj) .filter(key => key.startsWith('ic') && /^ic\d+$/.test(key)) .sort((a, b) => { const numA = parseInt(a.substring(2)); const numB = parseInt(b.substring(2)); return numA - numB; }); if (availableIcFields.length === 0 || !availableIcFields.includes('ic0')) { throw new Error('VK must contain at least ic0 point'); } const dx = new Fp2({ c0: FpC.from(obj.delta.x_c0), c1: FpC.from(obj.delta.x_c1), }); const dy = new Fp2({ c0: FpC.from(obj.delta.y_c0), c1: FpC.from(obj.delta.y_c1), }); const delta = new G2Affine({ x: dx, y: dy }); const gx = new Fp2({ c0: FpC.from(obj.gamma.x_c0), c1: FpC.from(obj.gamma.x_c1), }); const gy = new Fp2({ c0: FpC.from(obj.gamma.y_c0), c1: FpC.from(obj.gamma.y_c1), }); const gamma = new G2Affine({ x: gx, y: gy }); const alpha_beta = Fp12.loadFromJSON(obj.alpha_beta); const w27 = Fp12.loadFromJSON(obj.w27); // Parse all available IC points FIXME CHECKME what if we have skipped some?? const icPoints = availableIcFields.map(field => { const icData = obj[field]; if (!icData || !icData.x || !icData.y) { throw new Error(`Invalid IC point data for field: ${field}`); } return new bn254({ x: FpC.from(icData.x), y: FpC.from(icData.y) }); }); return new GrothVk(alpha_beta, w27, delta, gamma, icPoints); } } export { GrothVk }; //# sourceMappingURL=vk.js.map