-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: run smart contract verification integration tests inside hardh…
…at (#2957)
- Loading branch information
1 parent
0764cf4
commit 2cb4749
Showing
13 changed files
with
2,219 additions
and
105 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 |
---|---|---|
@@ -1 +1,14 @@ | ||
foundry-project | ||
contracts | ||
crs | ||
|
||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
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,17 @@ | ||
import { HardhatUserConfig } from 'hardhat/config'; | ||
import '@nomicfoundation/hardhat-chai-matchers'; | ||
import '@nomicfoundation/hardhat-ethers'; | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: { | ||
version: '0.8.19', | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
compiler/integration-tests/test/node/smart_contract_verifier.test.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,76 @@ | ||
import { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
|
||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'path'; | ||
import toml from 'toml'; | ||
|
||
import { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm'; | ||
import { Noir } from '@noir-lang/noir_js'; | ||
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; | ||
import { separatePublicInputsFromProof } from '../shared/proof'; | ||
|
||
compilerLogLevel('INFO'); | ||
|
||
const test_cases = [ | ||
{ | ||
case: 'tooling/nargo_cli/tests/execution_success/1_mul', | ||
compiled: 'contracts/1_mul.sol:UltraVerifier', | ||
numPublicInputs: 0, | ||
}, | ||
{ | ||
case: 'compiler/integration-tests/circuits/main', | ||
compiled: 'contracts/main.sol:UltraVerifier', | ||
numPublicInputs: 1, | ||
}, | ||
]; | ||
|
||
async function getCircuit(entry_point: string) { | ||
return compile({ entry_point }); | ||
} | ||
|
||
test_cases.forEach((testInfo) => { | ||
const test_name = testInfo.case.split('/').pop(); | ||
|
||
it(`${test_name} (smart contract verifier)`, async () => { | ||
const base_relative_path = '../..'; | ||
const test_case = testInfo.case; | ||
|
||
const noir_source_path = resolve(`${base_relative_path}/${test_case}/src/main.nr`); | ||
|
||
let compile_output; | ||
try { | ||
compile_output = await getCircuit(noir_source_path); | ||
|
||
expect(await compile_output, 'Compile output ').to.be.an('object'); | ||
} catch (e) { | ||
expect(e, 'Compilation Step').to.not.be.an('error'); | ||
throw e; | ||
} | ||
|
||
const noir_program = { bytecode: compile_output.circuit, abi: compile_output.abi }; | ||
const backend = new BarretenbergBackend(noir_program); | ||
const program = new Noir(noir_program, backend); | ||
|
||
// JS Proving | ||
|
||
const prover_toml = readFileSync(resolve(`${base_relative_path}/${test_case}/Prover.toml`)).toString(); | ||
const inputs = toml.parse(prover_toml); | ||
|
||
const proofWithPublicInputs = await program.generateFinalProof(inputs); | ||
|
||
// JS verification | ||
|
||
const verified = await program.verifyFinalProof(proofWithPublicInputs); | ||
expect(verified, 'Proof fails verification in JS').to.be.true; | ||
|
||
// Smart contract verification | ||
|
||
const contract = await ethers.deployContract(testInfo.compiled, [], {}); | ||
|
||
const { proof, publicInputs } = separatePublicInputsFromProof(proofWithPublicInputs, testInfo.numPublicInputs); | ||
const result = await contract.verify(proof, publicInputs); | ||
|
||
expect(result).to.be.true; | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["test/integration/node/**/*"] | ||
} |
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 |
---|---|---|
|
@@ -40,4 +40,4 @@ | |
"prettier": "3.0.3", | ||
"typescript": "5.1.5" | ||
} | ||
} | ||
} |
Oops, something went wrong.