Skip to content
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
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ jobs:
name: "Build and test"
command: build aztec.js

acir-simulator:
machine:
image: ubuntu-2004:202010-01
resource_class: large
steps:
- *checkout
- *setup_env
- run:
name: "Build and test"
command: build acir-simulator

end-to-end:
machine:
image: ubuntu-2004:202010-01
Expand Down Expand Up @@ -149,11 +160,13 @@ workflows:
<<: *defaults
- ethereum-js: *yarn_project
- aztec-js: *yarn_project
- acir-simulator: *yarn_project
- end-to-end: *yarn_project
- e2e-join:
requires:
- ethereum-js
- aztec-js
- acir-simulator
- end-to-end
<<: *defaults
- e2e-deploy-contract: *e2e_test
3 changes: 3 additions & 0 deletions yarn-project/acir-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
"devDependencies": {
"@aztec/eslint-config": "workspace:^",
"@jest/globals": "^29.4.3",
"@noir-lang/noir-source-resolver": "^1.1.0",
"@noir-lang/noir_wasm": "0.3.2-29b1f7df",
"@rushstack/eslint-patch": "^1.1.4",
"@types/jest": "^29.4.0",
"@types/node": "^18.7.23",
"jest": "^28.1.3",
"toml": "^3.0.0",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
Expand Down
1 change: 1 addition & 0 deletions yarn-project/acir-simulator/src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@noir-lang/noir-source-resolver';
9 changes: 9 additions & 0 deletions yarn-project/acir-simulator/src/fixtures/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { compileCircuit } from './index.js';

test('it should compile the constructor circuit', () => {
const { circuit, abi } = compileCircuit('constructor');

expect(circuit.length).toBeGreaterThan(0);
expect(abi.parameters.length).toBe(4);
expect(abi.return_type).toBe(null);
});
121 changes: 121 additions & 0 deletions yarn-project/acir-simulator/src/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { compile } from '@noir-lang/noir_wasm';
import { dirname, join as pathJoin } from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
import { initialiseResolver } from '@noir-lang/noir-source-resolver';
import toml from 'toml';

const circuitsPath = pathJoin(dirname(fileURLToPath(import.meta.url)), 'circuits');

/**
* A dependency entry of Nargo.toml.
*/
interface Dependency {
/**
* Path to the dependency.
*/
path?: string;
/**
* Git repository of the dependency.
*/
git?: string;
}

/**
* A circuit type.
*/
interface CircuitType {
/**
* The actual type.
*/
kind: any;
}

/**
* A parameter to the circuit.
*/
interface Parameter {
/**
* The name of the parameter.
*/
name: string;
/**
* The type of the parameter.
*/
type: CircuitType;
/**
* The visibility of the parameter.
*/
visibility: 'private' | 'public';
}

/**
* The representation of a compiled circuit.
*/
interface CompiledCircuit {
/**
* The bytecode of the circuit.
*/
circuit: Array<number>;
/**
* The Noir ABI of the circuit.
*/
abi: {
/**
* The circuit parameters.
*/
parameters: Array<Parameter>;
/**
* The witness indices for the parameters.
*/
param_witnesses: Record<string, Array<number>>;
/**
* The circuit return type.
*/
return_type: CircuitType | null;
/**
* The witness indices for the return value.
*/
return_witnesses: Array<number>;
};
}

/**
*
* @param circuitPath - Path to the circuit crate.
* @returns The dependencies of the circuit as a map of name to dependency entry.
*/
function readDependencies(circuitPath: string) {
const { dependencies } = toml.parse(fs.readFileSync(pathJoin(circuitPath, 'Nargo.toml'), { encoding: 'utf8' }));
return dependencies as Record<string, Dependency>;
}

/**
* Compiles a noir circuit fixture by name.
* @param circuitName - Name of the circuit fixture to compile.
* @returns The compiled circuit.
*/
export function compileCircuit(circuitName: string) {
const circuitPath = pathJoin(circuitsPath, circuitName);
const dependenciesMap = readDependencies(circuitPath);

initialiseResolver((id: `${string}/lib.nr` | 'main.nr') => {
let path;
if (id === 'main.nr') {
path = pathJoin(circuitPath, 'src/main.nr');
} else {
const [dependencyName] = id.split('/');
const dependency = dependenciesMap[dependencyName];
if (!dependency.path) {
throw new Error(`Don't know how to resolve dependency ${dependencyName}`);
}
path = pathJoin(circuitPath, dependency.path, 'src/lib.nr');
}
const result = fs.readFileSync(path, { encoding: 'utf8' });
return result;
});

return compile({
optional_dependencies_set: Object.keys(dependenciesMap), // eslint-disable-line camelcase
}) as CompiledCircuit;
}
26 changes: 26 additions & 0 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ __metadata:
dependencies:
"@aztec/eslint-config": "workspace:^"
"@jest/globals": ^29.4.3
"@noir-lang/noir-source-resolver": ^1.1.0
"@noir-lang/noir_wasm": 0.3.2-29b1f7df
"@rushstack/eslint-patch": ^1.1.4
"@types/jest": ^29.4.0
"@types/node": ^18.7.23
jest: ^28.1.3
toml: ^3.0.0
ts-jest: ^28.0.7
ts-node: ^10.9.1
tslib: ^2.4.0
Expand Down Expand Up @@ -1535,6 +1538,22 @@ __metadata:
languageName: node
linkType: hard

"@noir-lang/noir-source-resolver@npm:^1.1.0":
version: 1.1.0
resolution: "@noir-lang/noir-source-resolver@npm:1.1.0"
checksum: c3077f6740e613fd7866715ba01053f9711cff47c1196a780ff7b2683a5e500d08791ac304515ccbe906d32cdabf658df6fc825c775bb7d181abbf16e87cee92
languageName: node
linkType: hard

"@noir-lang/noir_wasm@npm:0.3.2-29b1f7df":
version: 0.3.2-29b1f7df
resolution: "@noir-lang/noir_wasm@npm:0.3.2-29b1f7df"
peerDependencies:
"@noir-lang/noir-source-resolver": 1.1.0
checksum: f5e61eb256783dca9d35345e77e9137d5fb2a6e3ecc8122b4a10ef0a6871e9e4b3842944f5b9fdbf82fef02bd6c1b27af28a6ed204728718ca89b9b394a09b32
languageName: node
linkType: hard

"@npmcli/fs@npm:^2.1.0":
version: 2.1.2
resolution: "@npmcli/fs@npm:2.1.2"
Expand Down Expand Up @@ -6318,6 +6337,13 @@ __metadata:
languageName: node
linkType: hard

"toml@npm:^3.0.0":
version: 3.0.0
resolution: "toml@npm:3.0.0"
checksum: 5d7f1d8413ad7780e9bdecce8ea4c3f5130dd53b0a4f2e90b93340979a137739879d7b9ce2ce05c938b8cc828897fe9e95085197342a1377dd8850bf5125f15f
languageName: node
linkType: hard

"ts-essentials@npm:^7.0.3":
version: 7.0.3
resolution: "ts-essentials@npm:7.0.3"
Expand Down