const {unstringifyBigInts} = require("./stringifybigint.js"); const fs = require("fs"); const bigInt = require("big-integer"); const assert = require("assert"); const version = require("../package").version; const argv = require("yargs") .version(version) .usage(`node buildpkey.js -i "proving_key.json" -o "proving_key.bin" Default: circuit.json `) .alias("i", "input") .alias("o", "output") .help("h") .alias("h", "help") .epilogue(`Copyright (C) 2018 0kims association This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions; see the COPYING file in the official repo directory at https://github.com/iden3/circom `) .argv; const inputName = (argv.input) ? argv.input : "proving_key.json"; const outputName = (argv.output) ? argv.output : "proving_key.bin"; const provingKey = unstringifyBigInts(JSON.parse(fs.readFileSync(inputName, "utf8"))); function writeUint32(h, val) { h.dataView.setUint32(h.offset, val, true); h.offset += 4; } function writeUint32ToPointer(h, p, val) { h.dataView.setUint32(p, val, true); } function alloc(h, n) { const o = h.offset; h.offset += n; return o; } function writeBigInt(h, bi) { for (let i=0; i<8; i++) { const v = bi.shiftRight(i*32).and(0xFFFFFFFF).toJSNumber(); writeUint32(h, v); } } function toMontgomeryQ(p) { const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); return p.times(bigInt.one.shiftLeft(256)).mod(q); } function toMontgomeryR(p) { const r = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); return p.times(bigInt.one.shiftLeft(256)).mod(r); } function writePoint(h, p) { writeBigInt(h, toMontgomeryQ(p[0])); writeBigInt(h, toMontgomeryQ(p[1])); } function writePoint2(h, p) { writeBigInt(h, toMontgomeryQ(p[0][0])); writeBigInt(h, toMontgomeryQ(p[0][1])); writeBigInt(h, toMontgomeryQ(p[1][0])); writeBigInt(h, toMontgomeryQ(p[1][1])); } function writeTransformedPolynomial(h, p) { const keys = Object.keys(p); writeUint32(h, keys.length); for (let i=0; i