Closed alexroan closed 7 months ago
hardhat.config.js
require("@nomicfoundation/hardhat-toolbox"); require("hardhat-circom"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: { compilers: [ { version: "0.6.11", }, ], }, circom: { inputBasePath: "./circuits", ptau: "https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_15.ptau", circuits: [ { name: "quadratic", }, ], }, };
quadratic.test.js : `const hre = require("hardhat"); const { ethers } = require("hardhat"); const { assert, expect } = require("chai"); const snarkjs = require("snarkjs");
describe("quadratic circuit", () => { let circuit;
const sampleInput = { x: "2", };
const sanityCheck = true;
before(async () => { circuit = await hre.circuitTest.setup("quadratic"); });
describe('circuit tests', () => { it("produces a witness with valid constraints", async () => { const witness = await circuit.calculateWitness(sampleInput, sanityCheck); await circuit.checkConstraints(witness); });
it("has expected witness values", async () => {
const witness = await circuit.calculateLabeledWitness(
sampleInput,
sanityCheck
);
assert.propertyVal(witness, "main.x", sampleInput.x);
assert.propertyVal(witness, "main.right", "11");
});
it("has the correct output", async () => {
const expected = { right: 11 };
const witness = await circuit.calculateWitness(sampleInput, sanityCheck);
await circuit.assertOut(witness, expected);
});
it("fails if the input is wrong", async () => {
await expect(circuit.calculateWitness({x: 3}, sanityCheck)).to.be.rejectedWith(Error);
});
}) });`
error :
1) quadratic circuit
"before all" hook in "quadratic circuit":
HardhatPluginError: Unable to compile circuit named: quadratic
at Proxy.setup (C:\Users\Ben\Desktop\zk-project\node_modules\hardhat-circom\dist\index.js:77:31)
at Context.
Caused by: Error: invalid input file
previous errors were found
at Union.writeSync (C:\Users\Ben\Desktop\zk-project\node_modules\hardhat-circom\dist\index.js:276:31)
at C:\Users\Ben\Desktop\zk-project\node_modules\circom2\vendor\wasi.js:561:38
at Array.forEach (<anonymous>)
at C:\Users\Ben\Desktop\zk-project\node_modules\circom2\vendor\wasi.js:558:40
at C:\Users\Ben\Desktop\zk-project\node_modules\circom2\vendor\wasi.js:82:20
at _ZN4wasi13lib_generated8fd_write17haa4cf180bdf29f25E (wasm://wasm/022748c2:1:4475403)
at _ZN60_$LT$std..io..stdio..StderrRaw$u20$as$u20$std..io..Write$GT$9write_all17h2e976193d972fd22E (wasm://wasm/022748c2:1:4450919)
at _ZN80_$LT$std..io..Write..write_fmt..Adapter$LT$T$GT$$u20$as$u20$core..fmt..Write$GT$9write_str17h7f76a5949d4f581dE (wasm://wasm/022748c2:1:4422969)
at _ZN4core3fmt9Formatter9write_str17hf4406380bce0428fE (wasm://wasm/022748c2:1:4550535)
at _ZN87_$LT$ansi_term..display..ANSIGenericString$LT$str$GT$$u20$as$u20$core..fmt..Display$GT$3fmt17h463dacb9748933e5E (wasm://wasm/022748c2:1:4416858)
Figured it had something to do with the snarkjs package in the quadratic.test.js, but even after an 'npm install -g snarkjs@latest' , still can't seem to get it to work. Thanks again!
quadratic.test.js didn't copy over properly, but has exact code as the tutorial.
Could you push your code up to a new repo that I could clone @benreichman ?
@alexroan Figured that might be the easiest way to debug it. Posted here : https://github.com/benreichman/ZK_DEBUG.git
Thanks.
It looks as though hardhat is not installed correctly, a lot of hardhat related dependencies missing.
Try running yarn add hardhat
.
After that, running yarn hardhat
will relay any other missing deps.
Still can't get it to run. Was using npm as my package manager but switched over to yarn to eliminate any potential issues there. I updated my git repository to reflect that change with a new project. Let me know if I'm still missing dependencies, though that didn't seem to resolve anthing as i still get the same error when I run the test.
For clairification, I'm setting up my project as follows 👍
1)mkdir ZK, cd ZK/ 2)yarn init -y 3)yarn add --dev hardhat 4)npx hardhat 5)yarn add hardhat-circom 6)create quadratic.circom file inside /circuits 7)configure hardhat.config.js 8)create quadratic.test.js inside /test 9)yarn hardhat test
Let me know if I'm missing something within setup & configuration of my hardhat itself within the updated repo i created. I tried forking the repo you created but still can't seem to get it to work & am still receiving the same error with the test. Possible global dependency missing? Thanks for taking the time.
Machine i can't get it to run on is a windows machine. Have it running fine on a separate mac machine fyi.
Most likely has to do with my hardhat installation on my machine. Can probably consider this issue closed. One more thing though, all tests pass, though i do receive an error log for circuit tests."has the correct output".
Error message : "ERROR : 4 Error in template Quadratic_0 line: 31"
Seems to be the issue here : https://github.com/projectsophon/hardhat-circom/issues/78
Can confirm the "Error: Invalid input file" seems to be connected to running hardhat-circom on windows machines. Fixed by running WSL https://learn.microsoft.com/en-us/windows/wsl/install . Thanks for debugging help, issue can be closed. As far as the seperate "ERROR : 4 Error in template Quadratic_0 line: 31" when running tests, let me know if you'd like me to open a separate issue. Thanks again.
Continuation of tweet thread