Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HardhatPluginError: Unable to compile circuit named: quadratic #2

Closed
alexroan opened this issue Jun 8, 2023 · 10 comments
Closed

HardhatPluginError: Unable to compile circuit named: quadratic #2

alexroan opened this issue Jun 8, 2023 · 10 comments

Comments

@alexroan
Copy link
Owner

alexroan commented Jun 8, 2023

Continuation of tweet thread

@benreichman
Copy link

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. (C:\Users\Ben\Desktop\zk-project\test\quadratic.test.js:16:15)

    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 ()
    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!

@benreichman
Copy link

quadratic.test.js didn't copy over properly, but has exact code as the tutorial.

@alexroan
Copy link
Owner Author

alexroan commented Jun 8, 2023

Could you push your code up to a new repo that I could clone @benreichman ?

@benreichman
Copy link

@alexroan Figured that might be the easiest way to debug it. Posted here : https://github.com/benreichman/ZK_DEBUG.git

Thanks.

@alexroan
Copy link
Owner Author

alexroan commented Jun 8, 2023

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.

@benreichman
Copy link

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.

@benreichman
Copy link

Machine i can't get it to run on is a windows machine. Have it running fine on a separate mac machine fyi.

@benreichman
Copy link

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"

@benreichman
Copy link

Seems to be the issue here : projectsophon/hardhat-circom#78

@benreichman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants