Skip to content

Commit

Permalink
feat: make noir_wasm the default compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Oct 27, 2023
1 parent 85d15c4 commit d84918b
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 125 deletions.
13 changes: 0 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,6 @@ jobs:
name: "Build and test"
command: build l1-contracts

noir-contracts-build:
machine:
image: ubuntu-2204:2023.07.2
resource_class: large
steps:
- *checkout
- *setup_env
- run:
name: Build
command: build noir-contracts-build | add_timestamps

yarn-project-base:
machine:
image: ubuntu-2204:2023.07.2
Expand Down Expand Up @@ -1210,7 +1199,6 @@ workflows:
<<: *defaults

- l1-contracts: *defaults
- noir-contracts-build: *defaults

- mainnet-fork: *defaults
- deploy-mainnet-fork:
Expand All @@ -1227,7 +1215,6 @@ workflows:
- yarn-project:
requires:
- yarn-project-base
- noir-contracts-build
<<: *defaults
- yarn-project-formatting:
requires:
Expand Down
11 changes: 0 additions & 11 deletions build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ circuits-x86_64-linux-clang-assert:
l1-contracts:
buildDir: l1-contracts

# We should move the noir source code to the top of the repo.
# It's currently under yarn-project which looks very circular, but it isn't.
# We're specific with our rebuild patterns as we depend on aztec.nr, but it doesn't have its own build.
noir-contracts-build:
buildDir: yarn-project
projectDir: yarn-project/noir-contracts
rebuildPatterns:
- ^yarn-project/noir-contracts/
- ^yarn-project/aztec-nr/

yarn-project-base:
buildDir: yarn-project
projectDir: yarn-project/yarn-project-base
Expand All @@ -110,7 +100,6 @@ yarn-project:
- ^yarn-project/Dockerfile
dependencies:
- yarn-project-base
- noir-contracts-build

aztec-sandbox:
buildDir: yarn-project
Expand Down
19 changes: 7 additions & 12 deletions yarn-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# This base dockerfile adds all the remaining source files, performs artifact generation, and builds the project.
# See yarn-project-base/Dockerfile for deeper insight into why things are how they are.
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/noir-contracts-build as noir
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base as builder

RUN apk add bash perl

# Copy in the entire workspace.
COPY . .

# Generate Noir contract TypeScript artifacts.
COPY --from=noir /usr/src/yarn-project/noir-contracts/target /usr/src/yarn-project/noir-contracts/target
# Run yarn build to have the json artifacts available for the types generator, generate types, build again.
RUN apk add perl
RUN cd /usr/src/yarn-project/noir-contracts && yarn build && ./scripts/types_all.sh && yarn build
# Cleanup to reduce final image size.
RUN rm -rf noir-contracts/target

# Build the entire project.
RUN yarn tsc -b
RUN yarn workspace @aztec/foundation build && \
yarn workspace @aztec/noir-compiler build && \
yarn workspace @aztec/noir-contracts noir:build:all && \
yarn tsc -b

# Build aztec.js web artifact
RUN cd /usr/src/yarn-project/aztec.js && yarn build:web
Expand All @@ -37,4 +32,4 @@ RUN cp /usr/src/circuits/cpp/build-wasm/bin/aztec3-circuits.wasm /usr/src/yarn-p

WORKDIR /usr/src/yarn-project

ENTRYPOINT ["yarn"]
ENTRYPOINT ["yarn"]

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions yarn-project/noir-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
},
"dependencies": {
"@aztec/foundation": "workspace:^",
"@noir-lang/noir_wasm": "0.18.0-3919619.aztec",
"@noir-lang/source-resolver": "0.18.0-3919619.aztec",
"@noir-lang/noir_wasm": "0.18.0-56ee9e3.aztec",
"@noir-lang/source-resolver": "0.18.0-56ee9e3.aztec",
"base64-js": "^1.5.1",
"commander": "^9.0.0",
"fs-extra": "^11.1.1",
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-compiler/src/cli/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function compileContract(program: Command, name = 'contract', log: LogFn
.option('-o, --outdir <path>', 'Output folder for the binary artifacts, relative to the project path', 'target')
.option('-ts, --typescript <path>', 'Optional output folder for generating typescript wrappers', undefined)
.option('-i, --interface <path>', 'Optional output folder for generating an Aztec.nr contract interface', undefined)
.option('-c --compiler <string>', 'Which compiler to use. Either nargo or wasm. Defaults to nargo', 'nargo')
.option('-c --compiler <string>', 'Which compiler to use. Either nargo or wasm. Defaults to nargo', 'wasm')
.description('Compiles the contracts in the target project')

.action(
Expand All @@ -40,7 +40,7 @@ export function compileContract(program: Command, name = 'contract', log: LogFn
},
/* eslint-enable jsdoc/require-jsdoc */
) => {
const { outdir, typescript, interface: noirInterface, compiler = 'nargo' } = options;
const { outdir, typescript, interface: noirInterface, compiler } = options;
if (typeof projectPath !== 'string') throw new Error(`Missing project path argument`);
if (compiler !== 'nargo' && compiler !== 'wasm') throw new Error(`Invalid compiler: ${compiler}`);
const currentDir = process.cwd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ export class NoirWasmContractCompiler {
initializeResolver(this.#resolveFile);

try {
const contract = await compile(this.#package.getEntryPointPath(), true, {
const result = compile(this.#package.getEntryPointPath(), true, {
/* eslint-disable camelcase */
root_dependencies: this.#dependencyManager.getEntrypointDependencies(),
library_dependencies: this.#dependencyManager.getLibraryDependencies(),
/* eslint-enable camelcase */
});

return [{ contract }];
if (!('contract' in result)) {
throw new Error('No contract found in compilation result');
}

return [result];
} catch (err) {
if (err instanceof Error && err.name === 'CompileError') {
this.#processCompileError(err as CompileError);
Expand Down
20 changes: 0 additions & 20 deletions yarn-project/noir-contracts/Dockerfile

This file was deleted.

12 changes: 1 addition & 11 deletions yarn-project/noir-contracts/scripts/compile_all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#!/bin/bash
# Compiles all noir contracts

source ./scripts/nargo_check.sh

echo "Checking noir version"
nargo_check

# Runs the compile scripts for all contracts.
echo "Compiling all contracts"

# ./scripts/compile.sh $(./scripts/get_all_contracts.sh)
nargo compile --workspace --no-backend
./scripts/compile.sh $(./scripts/get_all_contracts.sh)
3 changes: 0 additions & 3 deletions yarn-project/noir-contracts/scripts/types_all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/bash
# Run the types script for all files
./scripts/types.sh $(./scripts/get_all_contracts.sh)

# Remove the debug files as they are no longer needed and can cause prettier and build issues
rm -r ./target/debug*
38 changes: 3 additions & 35 deletions yarn-project/noir-contracts/src/scripts/copy_output.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ContractArtifact } from '@aztec/foundation/abi';
import { createConsoleLogger } from '@aztec/foundation/log';
import {
generateContractArtifact,
generateNoirContractInterface,
generateTypescriptContractInterface,
} from '@aztec/noir-compiler';
import { generateNoirContractInterface, generateTypescriptContractInterface } from '@aztec/noir-compiler';

import { readFileSync, writeFileSync } from 'fs';
import camelCase from 'lodash.camelcase';
Expand Down Expand Up @@ -45,42 +41,14 @@ function writeToProject(artifact: any) {
}
}

/**
* Processes nargo workspace artifacts
* @param projectName - The project name
* @param contractName - The contract name
*/
function processNargoWorkspaceArtifact(projectName: string, contractName: string) {
const artifactFile = `${projectName}-${contractName}.json`;

const buildJsonFilePath = `./target/${artifactFile}`;
const buildJson = JSON.parse(readFileSync(buildJsonFilePath).toString());

const debugArtifactFile = `debug_${artifactFile}`;
let debug = undefined;

try {
const debugJsonFilePath = `./target/${debugArtifactFile}`;
const debugJson = JSON.parse(readFileSync(debugJsonFilePath).toString());
if (debugJson) {
debug = debugJson;
}
} catch (err) {
// Ignore
}
// Remove extraneous information from the buildJson (which was output by Nargo) to hone in on the function data we actually care about:
const artifactJson: ContractArtifact = generateContractArtifact({ contract: buildJson, debug });
return artifactJson;
}

/**
* Processes an artifact generated by noir-compiler.
* Currently unused. This should be used once contracts are compiled with `noir-compiler` instead of Nargo.
*
* @param projectName - The name of the project
* @param contractName - The name of the contract
*/
function _processNoirCompilerArtifact(projectName: string, contractName: string) {
function processNoirCompilerArtifact(projectName: string, contractName: string) {
const artifactJsonFilePath = `src/contracts/${projectName}/target/${contractName}.json`;
const artifactJson: ContractArtifact = JSON.parse(readFileSync(artifactJsonFilePath).toString());
return artifactJson;
Expand All @@ -92,7 +60,7 @@ const main = () => {

const projectName = `${snakeCase(name)}_contract`;
const contractName = upperFirst(camelCase(name));
const artifactJson = processNargoWorkspaceArtifact(projectName, contractName);
const artifactJson = processNoirCompilerArtifact(projectName, contractName);

// Write the artifact:
const artifactsDir = 'src/artifacts';
Expand Down
22 changes: 11 additions & 11 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ __metadata:
dependencies:
"@aztec/foundation": "workspace:^"
"@jest/globals": ^29.5.0
"@noir-lang/noir_wasm": 0.18.0-3919619.aztec
"@noir-lang/source-resolver": 0.18.0-3919619.aztec
"@noir-lang/noir_wasm": 0.18.0-56ee9e3.aztec
"@noir-lang/source-resolver": 0.18.0-56ee9e3.aztec
"@rushstack/eslint-patch": ^1.1.4
"@types/fs-extra": ^11.0.1
"@types/jest": ^29.5.0
Expand Down Expand Up @@ -3544,12 +3544,12 @@ __metadata:
languageName: node
linkType: hard

"@noir-lang/noir_wasm@npm:0.18.0-3919619.aztec":
version: 0.18.0-3919619.aztec
resolution: "@noir-lang/noir_wasm@npm:0.18.0-3919619.aztec"
"@noir-lang/noir_wasm@npm:0.18.0-56ee9e3.aztec":
version: 0.18.0-56ee9e3.aztec
resolution: "@noir-lang/noir_wasm@npm:0.18.0-56ee9e3.aztec"
peerDependencies:
"@noir-lang/source-resolver": 0.18.0-3919619.aztec
checksum: 34102eaeaf250cf6c324ba9021ffb88695de2eaf6c648b882ad1bd9f1db3434f3af854a5b13302972a0e9cf34b7921008ca162c4ea68807590e567d343f2cec0
"@noir-lang/source-resolver": 0.18.0-56ee9e3.aztec
checksum: 7d8f315246d62972ebfdfbe72fae16f257489482d15f17cd425467df8991e43fe1bdc4035884eceb65c9c0722c48b7caeae505fa6a414641cbb0eac442abd0c8
languageName: node
linkType: hard

Expand All @@ -3560,10 +3560,10 @@ __metadata:
languageName: node
linkType: hard

"@noir-lang/source-resolver@npm:0.18.0-3919619.aztec":
version: 0.18.0-3919619.aztec
resolution: "@noir-lang/source-resolver@npm:0.18.0-3919619.aztec"
checksum: c7f39beba745fe9ca1b05c1df91bfb76c82704c18390740dbfea480e5e5ed98b7861e62341e2179fa4f5db3e327825336e1f8fe3452e081f4974be438c6b00f5
"@noir-lang/source-resolver@npm:0.18.0-56ee9e3.aztec":
version: 0.18.0-56ee9e3.aztec
resolution: "@noir-lang/source-resolver@npm:0.18.0-56ee9e3.aztec"
checksum: a70d92b52e8e7a3a48de5c10cb45ea2f3de68ef8f94179dd01e6e76008cbcfe6ecaff5c116e1189a40ef9435f315f24edc308b2bc36197e1bca75bc231859453
languageName: node
linkType: hard

Expand Down

0 comments on commit d84918b

Please sign in to comment.