Skip to content

Commit 6231b41

Browse files
committed
ptauId calculation fix
1 parent 8ad4219 commit 6231b41

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/core/compile/CompilationProcessor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ import { HardhatZKitError } from "../../errors";
1111
import { CIRCUIT_ARTIFACT_VERSION, NODE_MODULES } from "../../constants";
1212
import { Reporter } from "../../reporter";
1313

14-
import { getGroth16ConstraintsNumber } from "../../utils/constraints-utils";
15-
import { getNormalizedFullPath, renameFilesRecursively, readDirRecursively } from "../../utils/path-utils";
14+
import {
15+
getNormalizedFullPath,
16+
renameFilesRecursively,
17+
readDirRecursively,
18+
getR1CSConstraintsNumber,
19+
terminateCurve,
20+
} from "../../utils";
1621

1722
import { ZKitConfig } from "../../types/zkit-config";
1823
import { ArtifactsFileType, CircuitArtifact, ICircuitArtifacts } from "../../types/artifacts/circuit-artifacts";
@@ -104,9 +109,11 @@ export class CompilationProcessor {
104109

105110
for (const info of compilationInfoArr) {
106111
const r1csFilePath = getNormalizedFullPath(info.tempArtifactsPath, `${info.circuitName}.r1cs`);
107-
info.constraintsNumber = await getGroth16ConstraintsNumber(r1csFilePath);
112+
info.constraintsNumber = await getR1CSConstraintsNumber(r1csFilePath);
108113
}
109114

115+
await terminateCurve();
116+
110117
await this._moveFromTempDirToArtifacts(compilationInfoArr);
111118

112119
await this._emitArtifacts(compilationInfoArr);

src/core/setup/SetupProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class SetupProcessor {
229229

230230
const maxConstraintsNumber = Math.max(...circuitsConstraintsNumber);
231231

232-
const ptauId = Math.max(Math.ceil(Math.log2(maxConstraintsNumber)), 8);
232+
const ptauId = Math.max(Math.ceil(Math.log2(maxConstraintsNumber - 1)) + 1, 8);
233233

234234
let entries: fsExtra.Dirent[] = [];
235235

src/utils/constraints-utils.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as binfileutils from "@iden3/binfileutils";
66

77
import { LinearCombination, R1CSConstraint } from "../../src/types/utils";
88

9-
export async function getGroth16ConstraintsNumber(r1csFilePath: string): Promise<number> {
9+
export async function getR1CSConstraintsNumber(r1csFilePath: string): Promise<number> {
1010
return (await snarkjs.r1cs.info(r1csFilePath)).nConstraints;
1111
}
1212

@@ -19,10 +19,13 @@ export async function getPlonkConstraintsNumber(r1csFilePath: string, Fr: any):
1919

2020
const join = (lc1: LinearCombination, k: bigint, lc2: LinearCombination) => {
2121
const res = { ...lc1 };
22+
2223
Object.keys(lc2).forEach((s) => {
2324
res[s] = res[s] ? Fr.add(res[s], Fr.mul(k, lc2[s])) : lc2[s];
2425
});
26+
2527
normalize(res);
28+
2629
return res;
2730
};
2831

@@ -45,12 +48,14 @@ export async function getPlonkConstraintsNumber(r1csFilePath: string, Fr: any):
4548
let n = 0;
4649

4750
Object.keys(lc).forEach((key) => {
48-
if (lc[key] !== 0n) {
49-
if (key === "0") {
50-
k = Fr.add(k, lc[key]);
51-
} else {
52-
n++;
53-
}
51+
if (lc[key] === 0n) {
52+
return;
53+
}
54+
55+
if (key === "0") {
56+
k = Fr.add(k, lc[key]);
57+
} else {
58+
n++;
5459
}
5560
});
5661

0 commit comments

Comments
 (0)