Skip to content

Commit

Permalink
Merge pull request #73 from erhant/erhant/hardhat-concise
Browse files Browse the repository at this point in the history
fix skipLibCheck, add plonk optim check, formatting
  • Loading branch information
erhant authored Apr 15, 2024
2 parents e1f8c8c + ab0f9d7 commit 9612a1b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
6 changes: 3 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import {HardhatUserConfig} from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
solidity: "0.8.24",
solidity: '0.8.24',
};

export default config;
10 changes: 10 additions & 0 deletions src/circomkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ export class Circomkit {
throw new Error('Invalid protocol in configuration.');
}
if (this.config.optimization < 0) {
this.log('Optimization level must be at least 0, setting it to 0.', 'warn');
this.config.optimization = 0;
}

// PLONK protocol requires optimization level to be 1
if (this.config.protocol === 'plonk' && this.config.optimization !== 1) {
this.log(
'Optimization level for PLONK must be 1.\nSee: https://docs.circom.io/circom-language/circom-insight/simplification/',
'warn'
);
this.config.optimization = 1;
}
}

/** Parse circuit config from `circuits.json`. */
Expand Down
36 changes: 21 additions & 15 deletions tests/circomkit.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import forEach from 'mocha-each';
//@ts-ignore
import { ethers } from "hardhat";
//@ts-ignore
import solc from "solc";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {ethers} from 'hardhat';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import solc from 'solc';
import {PROTOCOLS} from '../src/utils/config';
import {Circomkit} from '../src';
import {expect} from 'chai';
Expand Down Expand Up @@ -87,39 +89,43 @@ forEach(PROTOCOLS).describe('protocol: %s', (protocol: (typeof PROTOCOLS)[number
const source = readFileSync(path, {encoding: 'utf-8'})
// XXX: snarkjs plonk template has an erroneous hardhat import
// See https://github.com/iden3/snarkjs/pull/464
// TODO: Remove this fix when the PR is merged
.replace('import "hardhat/console.sol";\n', '');

// Compile the contract
// compile the contract
const input = {
language: 'Solidity',
sources: {
'TestVerifier.sol': {
content: source
}
content: source,
},
},
settings: {
outputSelection: {
'*': {
'*': ['abi', 'evm.bytecode.object']
}
}
}
'*': ['abi', 'evm.bytecode.object'],
},
},
},
};

const output = JSON.parse(solc.compile(JSON.stringify(input)));
const contractName = Object.keys(output.contracts['TestVerifier.sol'])[0];
const bytecode = output.contracts['TestVerifier.sol'][contractName].evm.bytecode.object;
const abi = output.contracts['TestVerifier.sol'][contractName].abi;

// Deploy the contract using ethers
// deploy the contract using ethers
const ContractFactory = new ethers.ContractFactory(abi, bytecode, (await ethers.getSigners())[0]);
const contract = await ContractFactory.deploy();
await contract.waitForDeployment();

// Interaction with the contract
// interaction with the contract
const calldata = await circomkit.calldata(circuit.name, inputName);
const args = calldata.split('\n').filter(x=>!!x).map(x=>JSON.parse(x));
//@ts-ignore
const args = calldata
.split('\n')
.filter(x => !!x)
.map(x => JSON.parse(x));

expect(await contract.verifyProof(...args)).to.equal(true);
});

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"noEmit": false
"noEmit": false,
"skipLibCheck": true
},
"include": ["src/**/*.ts"]
}

0 comments on commit 9612a1b

Please sign in to comment.