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

chore: Add unified linting setup for JS code and enforce in CI #2728

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "prettier"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
"comma-spacing": ["error", { before: false, after: true }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"prettier/prettier": "error",
},
};
17 changes: 16 additions & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Clippy
name: Formatting

on:
pull_request:
Expand Down Expand Up @@ -48,3 +48,18 @@ jobs:

- name: Run `cargo fmt`
run: cargo fmt --all --check

eslint:
name: eslint
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Run `yarn lint`
run: yarn lint
1 change: 1 addition & 0 deletions compiler/integration-tests/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
18 changes: 1 addition & 17 deletions compiler/integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "prettier"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
"comma-spacing": ["error", { before: false, after: true }],
// "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"prettier/prettier": "error",
}
extends: ["../../.eslintrc.js"],
};
3 changes: 2 additions & 1 deletion compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "yarn test:browser",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test//integration/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/integration/browser/**/*.test.ts --watch"
"test:integration:browser:watch": "web-test-runner test/integration/browser/**/*.test.ts --watch",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@aztec/bb.js": "^0.5.1",
Expand Down
1 change: 1 addition & 0 deletions compiler/integration-tests/test/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "@aztec/bb.js";
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { expect } from '@esm-bundle/chai';
import { expect } from "@esm-bundle/chai";
import { initializeResolver } from "@noir-lang/source-resolver";
import newCompiler, {
compile,
init_log_level as compilerLogLevel
compile,
init_log_level as compilerLogLevel,
} from "@noir-lang/noir_wasm";
import { decompressSync as gunzip } from 'fflate';
import { decompressSync as gunzip } from "fflate";
import newABICoder, { abiEncode } from "@noir-lang/noirc_abi";
import initACVM, {
executeCircuit,
WitnessMap,
compressWitness,
executeCircuit,
WitnessMap,
compressWitness,
} from "@noir-lang/acvm_js";

// @ts-ignore
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
import { Barretenberg, RawBuffer, Crs } from '@aztec/bb.js';

import * as TOML from 'smol-toml'
import { Barretenberg, RawBuffer, Crs } from "@aztec/bb.js";

import * as TOML from "smol-toml";

await newCompiler();
await newABICoder();
Expand All @@ -25,133 +23,141 @@ await initACVM();
compilerLogLevel("DEBUG");

async function getFile(url: URL): Promise<string> {
const response = await fetch(url);

const response = await fetch(url)

if (!response.ok) throw new Error('Network response was not OK');
if (!response.ok) throw new Error("Network response was not OK");

return await response.text();
return await response.text();
}

const CIRCUIT_SIZE = 2 ** 19;


const test_cases = [
{
case: "tooling/nargo_cli/tests/execution_success/1_mul"
},
{
case: "tooling/nargo_cli/tests/execution_success/double_verify_proof"
}
{
case: "tooling/nargo_cli/tests/execution_success/1_mul",
},
{
case: "tooling/nargo_cli/tests/execution_success/double_verify_proof",
},
];

const numberOfThreads = navigator.hardwareConcurrency || 1;

let suite = Mocha.Suite.create(mocha.suite, "Noir end to end test");
const suite = Mocha.Suite.create(mocha.suite, "Noir end to end test");

suite.timeout(60*20e3);//20mins
suite.timeout(60 * 20e3); //20mins

test_cases.forEach((testInfo) => {
const test_name = testInfo.case.split("/").pop();
const mochaTest = new Mocha.Test(`${test_name} (Compile, Execute, Prove, Verify)`, async () => {

const base_relative_path = "../../../../..";
const test_case = testInfo.case;

const noir_source_url = new URL(`${base_relative_path}/${test_case}/src/main.nr`, import.meta.url);
const prover_toml_url = new URL(`${base_relative_path}/${test_case}/Prover.toml`, import.meta.url);

const noir_source = await getFile(noir_source_url);
const prover_toml = await getFile(prover_toml_url);

expect(noir_source).to.be.a.string;

initializeResolver((id: String) => {
console.log("Resolving:", id);
return noir_source;
});

const inputs = TOML.parse(prover_toml);

expect(inputs, "Prover.toml").to.be.an('object');

let compile_output;

try {

compile_output = await compile({});

expect(await compile_output, "Compile output ").to.be.an('object');

} catch (e) {
expect(e, "Compilation Step").to.not.be.an('error');
throw e;
}


let witnessMap: WitnessMap;
try {

witnessMap = abiEncode(compile_output.abi, inputs, null);

} catch (e) {
expect(e, "Abi Encoding Step").to.not.be.an('error');
throw e;
}

let solvedWitness: WitnessMap;
let compressedByteCode;
try {
compressedByteCode = Uint8Array.from(atob(compile_output.circuit), c => c.charCodeAt(0));

solvedWitness = await executeCircuit(
compressedByteCode,
witnessMap,
() => {
throw Error("unexpected oracle");
}
);

} catch (e) {
expect(e, "Abi Encoding Step").to.not.be.an('error');
throw e;
}

try {
const compressedWitness = compressWitness(solvedWitness);
const acirUint8Array = gunzip(compressedByteCode);
const witnessUint8Array = gunzip(compressedWitness);

const isRecursive = true;
const api = await Barretenberg.new(numberOfThreads);
await api.commonInitSlabAllocator(CIRCUIT_SIZE);

// Plus 1 needed!
const crs = await Crs.new(CIRCUIT_SIZE + 1);
await api.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));

const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE);

// This took ~6.5 minutes!
const proof = await api.acirCreateProof(
acirComposer,
acirUint8Array,
witnessUint8Array,
isRecursive
);

// And this took ~5 minutes!
const verified = await api.acirVerifyProof(acirComposer, proof, isRecursive);

expect(verified).to.be.true;

} catch (e) {
expect(e, "Proving and Verifying").to.not.be.an('error');
throw e;
}

});

suite.addTest(mochaTest);
const test_name = testInfo.case.split("/").pop();
const mochaTest = new Mocha.Test(
`${test_name} (Compile, Execute, Prove, Verify)`,
async () => {
const base_relative_path = "../../../../..";
const test_case = testInfo.case;

const noir_source_url = new URL(
`${base_relative_path}/${test_case}/src/main.nr`,
import.meta.url
);
const prover_toml_url = new URL(
`${base_relative_path}/${test_case}/Prover.toml`,
import.meta.url
);

const noir_source = await getFile(noir_source_url);
const prover_toml = await getFile(prover_toml_url);

expect(noir_source).to.be.a.string;

initializeResolver((id: string) => {
console.log("Resolving:", id);
return noir_source;
});

const inputs = TOML.parse(prover_toml);

expect(inputs, "Prover.toml").to.be.an("object");

let compile_output;

try {
compile_output = await compile({});

expect(await compile_output, "Compile output ").to.be.an("object");
} catch (e) {
expect(e, "Compilation Step").to.not.be.an("error");
throw e;
}

let witnessMap: WitnessMap;
try {
witnessMap = abiEncode(compile_output.abi, inputs, null);
} catch (e) {
expect(e, "Abi Encoding Step").to.not.be.an("error");
throw e;
}

let solvedWitness: WitnessMap;
let compressedByteCode;
try {
compressedByteCode = Uint8Array.from(
atob(compile_output.circuit),
(c) => c.charCodeAt(0)
);

solvedWitness = await executeCircuit(
compressedByteCode,
witnessMap,
() => {
throw Error("unexpected oracle");
}
);
} catch (e) {
expect(e, "Abi Encoding Step").to.not.be.an("error");
throw e;
}

try {
const compressedWitness = compressWitness(solvedWitness);
const acirUint8Array = gunzip(compressedByteCode);
const witnessUint8Array = gunzip(compressedWitness);

const isRecursive = true;
const api = await Barretenberg.new(numberOfThreads);
await api.commonInitSlabAllocator(CIRCUIT_SIZE);

// Plus 1 needed!
const crs = await Crs.new(CIRCUIT_SIZE + 1);
await api.srsInitSrs(
new RawBuffer(crs.getG1Data()),
crs.numPoints,
new RawBuffer(crs.getG2Data())
);

const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE);

// This took ~6.5 minutes!
const proof = await api.acirCreateProof(
acirComposer,
acirUint8Array,
witnessUint8Array,
isRecursive
);

// And this took ~5 minutes!
const verified = await api.acirVerifyProof(
acirComposer,
proof,
isRecursive
);

expect(verified).to.be.true;
} catch (e) {
expect(e, "Proving and Verifying").to.not.be.an("error");
throw e;
}
}
);

suite.addTest(mochaTest);
});
1 change: 1 addition & 0 deletions compiler/source-resolver/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions compiler/source-resolver/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["../../.eslintrc.js"],
};
3 changes: 2 additions & 1 deletion compiler/source-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build:web": "tsc -p tsconfig.esm.json",
"build": "npm run clean-modules && npm run build:node && npm run build:web && npm run generate-types",
"test": "ava",
"generate-types": "tsc src/*.ts --declaration --emitDeclarationOnly --outDir types"
"generate-types": "tsc src/*.ts --declaration --emitDeclarationOnly --outDir types",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"devDependencies": {
"@types/node": "^20.5.7",
Expand Down
Loading