|
1 | 1 | import * as snarkjs from "snarkjs";
|
2 |
| -// @ts-expect-error: No type definitions available for the "r1csfile" package |
3 |
| -import * as r1csfile from "r1csfile"; |
4 |
| -// @ts-expect-error: No type definitions available for the "@iden3/binfileutils" package |
5 |
| -import * as binfileutils from "@iden3/binfileutils"; |
6 | 2 |
|
7 | 3 | import { LinearCombination, R1CSConstraint } from "../../src/types/utils";
|
8 | 4 |
|
9 | 5 | export async function getR1CSConstraintsNumber(r1csFilePath: string): Promise<number> {
|
10 | 6 | return (await snarkjs.r1cs.info(r1csFilePath)).nConstraints;
|
11 | 7 | }
|
12 | 8 |
|
| 9 | +export async function getGroth16ConstraintsNumber(r1csFilePath: string): Promise<number> { |
| 10 | + const r1cs = await snarkjs.r1cs.info(r1csFilePath); |
| 11 | + |
| 12 | + return r1cs.nConstraints + r1cs.nPubInputs + r1cs.nOutputs; |
| 13 | +} |
| 14 | + |
13 | 15 | export async function getPlonkConstraintsNumber(r1csFilePath: string, Fr: any): Promise<number> {
|
14 | 16 | const normalize = (lc: LinearCombination) => {
|
15 | 17 | Object.keys(lc).forEach((key) => {
|
@@ -79,20 +81,11 @@ export async function getPlonkConstraintsNumber(r1csFilePath: string, Fr: any):
|
79 | 81 | }
|
80 | 82 | };
|
81 | 83 |
|
82 |
| - const { fd: fdR1cs, sections: sectionsR1cs } = await binfileutils.readBinFile( |
83 |
| - r1csFilePath, |
84 |
| - "r1cs", |
85 |
| - 1, |
86 |
| - 1 << 22, |
87 |
| - 1 << 24, |
88 |
| - ); |
89 |
| - const r1cs = await r1csfile.readR1csFd(fdR1cs, sectionsR1cs, { loadConstraints: true, loadCustomGates: true }); |
| 84 | + const r1cs = await snarkjs.r1cs.info(r1csFilePath); |
90 | 85 |
|
91 | 86 | let plonkConstraintsCount = r1cs.nOutputs + r1cs.nPubInputs;
|
92 | 87 |
|
93 | 88 | r1cs.constraints.forEach((constraint: R1CSConstraint) => process(...constraint));
|
94 | 89 |
|
95 |
| - await fdR1cs.fd.close(); |
96 |
| - |
97 | 90 | return plonkConstraintsCount;
|
98 | 91 | }
|
0 commit comments