-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue with caching parsedInputs
- Loading branch information
Showing
9 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function deepClone<T>(value: T): T { | ||
const visited = new WeakSet(); | ||
|
||
const replacer = (_: any, obj: any) => { | ||
if (typeof obj === "object" && obj !== null) { | ||
if (visited.has(obj)) { | ||
return "[Circular]"; | ||
} | ||
visited.add(obj); | ||
} | ||
|
||
return obj; | ||
}; | ||
|
||
return JSON.parse(JSON.stringify(value, replacer)); | ||
} |
6 changes: 6 additions & 0 deletions
6
test/fixture-projects/hardhat-project-with-duplicated-circuits/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/cache | ||
/artifacts | ||
|
||
compilers | ||
contracts/verifiers | ||
zkit |
5 changes: 5 additions & 0 deletions
5
test/fixture-projects/hardhat-project-with-duplicated-circuits/circuits/mul3Arr.circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma circom 2.0.0; | ||
|
||
include "templates/mul3Arr.circom"; | ||
|
||
component main = Multiplier3Arr(3); |
5 changes: 5 additions & 0 deletions
5
test/fixture-projects/hardhat-project-with-duplicated-circuits/circuits/mul3Arr2.circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma circom 2.0.0; | ||
|
||
include "templates/mul3Arr.circom"; | ||
|
||
component main = Multiplier3Arr(6); |
12 changes: 12 additions & 0 deletions
12
...xture-projects/hardhat-project-with-duplicated-circuits/circuits/templates/mul3Arr.circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pragma circom 2.0.0; | ||
|
||
template Multiplier3Arr(count){ | ||
signal input in[count]; | ||
|
||
signal output out; | ||
signal output result[count]; | ||
|
||
signal tmp <-- in[0] * in[1]; | ||
|
||
out <== tmp * in[2]; | ||
} |
24 changes: 24 additions & 0 deletions
24
test/fixture-projects/hardhat-project-with-duplicated-circuits/hardhat.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { HardhatUserConfig } from "hardhat/config"; | ||
|
||
import config from "../hardhat.config"; | ||
|
||
const defaultConfig: HardhatUserConfig = { | ||
...config, | ||
zkit: { | ||
circuitsDir: "circuits", | ||
compilationSettings: { | ||
artifactsDir: "zkit/artifacts", | ||
skipFiles: ["vendor"], | ||
}, | ||
setupSettings: { | ||
ptauDir: "zkit/ptau", | ||
ptauDownload: true, | ||
}, | ||
quiet: true, | ||
verifiersSettings: { | ||
verifiersDir: "contracts/verifiers", | ||
}, | ||
}, | ||
}; | ||
|
||
export default defaultConfig; |
8 changes: 8 additions & 0 deletions
8
test/fixture-projects/hardhat-project-with-duplicated-circuits/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "hardhat-project-with-complex-circuits", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"compile": "hardhat compile --force", | ||
"clean": "hardhat clean && rm -rf artifacts && rm -rf cache" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useEnvironment } from "@test-helpers"; | ||
import { TASK_CIRCUITS_MAKE, ZKIT_SCOPE_NAME } from "../../../../src/task-names"; | ||
import fsExtra from "fs-extra"; | ||
import path from "path"; | ||
import { CircuitArtifact } from "../../../../src/types/artifacts/circuit-artifacts"; | ||
import { expect } from "chai"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
describe.only("Types Generation", () => { | ||
describe("types generation:with duplicated main components", () => { | ||
useEnvironment("with-duplicated-circuits"); | ||
|
||
beforeEach(async function () { | ||
await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_CIRCUITS_MAKE }); | ||
}); | ||
|
||
function getCircuitArtifact(hre: HardhatRuntimeEnvironment, pathToCircuit: string): CircuitArtifact { | ||
return JSON.parse(fsExtra.readFileSync(path.join(hre.config.paths.root, pathToCircuit)) as any); | ||
} | ||
|
||
it("should correctly resolve dimensions for circuits with multiple main components", async function () { | ||
const artifact1: CircuitArtifact = getCircuitArtifact( | ||
this.hre, | ||
"zkit/artifacts/circuits/mul3Arr.circom/Multiplier3Arr_artifacts.json", | ||
); | ||
const artifact2: CircuitArtifact = getCircuitArtifact( | ||
this.hre, | ||
"zkit/artifacts/circuits/mul3Arr2.circom/Multiplier3Arr_artifacts.json", | ||
); | ||
|
||
expect(artifact1.baseCircuitInfo.signals[0].dimension).to.be.deep.eq([3]); | ||
expect(artifact2.baseCircuitInfo.signals[0].dimension).to.be.deep.eq([6]); | ||
}); | ||
|
||
it.only("should correctly resolve dimensions for circuits with multiple main components from cache", async function () { | ||
const initialFileContent = fsExtra | ||
.readFileSync(path.join(this.hre.config.paths.root, "circuits/mul3Arr.circom")) | ||
.toString(); | ||
|
||
fsExtra.appendFileSync(path.join(this.hre.config.paths.root, "circuits/mul3Arr.circom"), "// comment"); | ||
|
||
await this.hre.run({ scope: ZKIT_SCOPE_NAME, task: TASK_CIRCUITS_MAKE }); | ||
|
||
const artifact2: CircuitArtifact = getCircuitArtifact( | ||
this.hre, | ||
"zkit/artifacts/circuits/mul3Arr2.circom/Multiplier3Arr_artifacts.json", | ||
); | ||
const artifact1: CircuitArtifact = getCircuitArtifact( | ||
this.hre, | ||
"zkit/artifacts/circuits/mul3Arr.circom/Multiplier3Arr_artifacts.json", | ||
); | ||
|
||
expect(artifact1.baseCircuitInfo.signals[0].dimension).to.be.deep.eq([3]); | ||
expect(artifact2.baseCircuitInfo.signals[0].dimension).to.be.deep.eq([6]); | ||
|
||
fsExtra.writeFileSync(path.join(this.hre.config.paths.root, "circuits/mul3Arr.circom"), initialFileContent); | ||
}); | ||
}); | ||
}); |