/* Copyright 2018 0kims association. This file is part of snarkjs. snarkjs is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. snarkjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with snarkjs. If not, see . */ /* Implementation of this paper: https://eprint.iacr.org/2016/260.pdf */ import { Scalar } from "ffjavascript"; import * as curves from "./curves.js"; import { utils } from "ffjavascript"; const {unstringifyBigInts} = utils; export default async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { /* let cpub = vk_verifier.IC[0]; for (let s= 0; s< vk_verifier.nPublic; s++) { cpub = G1.add( cpub, G1.timesScalar( vk_verifier.IC[s+1], publicSignals[s])); } */ const vk_verifier = unstringifyBigInts(_vk_verifier); const proof = unstringifyBigInts(_proof); const publicSignals = unstringifyBigInts(_publicSignals); const curve = await curves.getCurveFromName(vk_verifier.curve); const IC0 = curve.G1.fromObject(vk_verifier.IC[0]); const IC = new Uint8Array(curve.G1.F.n8*2 * publicSignals.length); const w = new Uint8Array(curve.Fr.n8 * publicSignals.length); if (!publicInputsAreValid(curve, publicSignals)) { if (logger) logger.error("Public inputs are not valid."); return false; } for (let i=0; i