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

feat: compile noir contracts with noir_wasm #2737

Merged
merged 35 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1035a8a
perf: avoid second yarn install
alexghr Oct 23, 2023
6dcff34
feat: add noir_wasm
alexghr Oct 23, 2023
9fe0024
refactor: remove nargo
alexghr Oct 23, 2023
50176b6
refactor: alternative way to patch ts-jest
alexghr Oct 25, 2023
ec6024c
fix: include yarn patches in yarn-project-base
alexghr Oct 25, 2023
007abef
fix: common package.json
alexghr Oct 25, 2023
d9c2810
ci: add noir-compiler-build to cci config
alexghr Oct 25, 2023
6466bb3
chore: update noir_wasm
alexghr Oct 25, 2023
6d0fba2
refactor: remove noir-contracts-build image
alexghr Oct 25, 2023
45e243b
fix: yarn-project docker image
alexghr Oct 25, 2023
ad8df0e
chore: purge noir-version.json
alexghr Oct 25, 2023
1d481e5
Merge branch 'master' into alexg/feat/noir-wasm
alexghr Oct 25, 2023
d299290
chore: lint
alexghr Oct 25, 2023
71c1bf3
chore: update acvm
alexghr Oct 26, 2023
1b328b2
fix: resolve project path before compiling
alexghr Oct 26, 2023
82c01e2
fix: throw an error if can't compile
alexghr Oct 26, 2023
ec25afb
test: update expected error messages
alexghr Oct 26, 2023
bea08d0
chore: restore nargo
alexghr Oct 26, 2023
f3fea51
chore: fix nargo snapshot tests in CI
alexghr Oct 26, 2023
e43465b
fix: specify correct type for compiler flag
alexghr Oct 26, 2023
89ea930
Update yarn-project/noir-compiler/src/compile/noir/dependencies/githu…
alexghr Oct 27, 2023
eb8c172
Update yarn-project/noir-compiler/src/compile/noir/dependencies/githu…
alexghr Oct 27, 2023
bdbb0af
Update yarn-project/noir-compiler/src/compile/noir/noir-wasm-compiler.ts
alexghr Oct 27, 2023
8317f5f
fix: address code review
alexghr Oct 27, 2023
f8c7c7d
fix: add zod to parse Nargo.toml
alexghr Oct 27, 2023
fed8f58
refactor: only look at src directory
alexghr Oct 27, 2023
66283b4
fix: safely generate a filename from a git url
alexghr Oct 27, 2023
bf4244d
fix: add comment to ts-jest patch
alexghr Oct 27, 2023
62975d3
refactor: use memfs
alexghr Oct 27, 2023
54a002e
fix: write deps to tmp files and atomically move
alexghr Oct 27, 2023
f957f14
fix: code review
alexghr Oct 27, 2023
f34ddf1
fix: binary is latin1
alexghr Oct 27, 2023
334d51f
fix: tmp directory when extracting
alexghr Oct 27, 2023
df88d72
Merge remote-tracking branch 'origin/master' into alexg/feat/noir-wasm
alexghr Oct 27, 2023
85d15c4
chore: update package.json
alexghr Oct 27, 2023
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: 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 @@ -1232,7 +1221,6 @@ workflows:
<<: *defaults

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

- mainnet-fork: *defaults

Expand All @@ -1245,7 +1233,6 @@ workflows:
- yarn-project:
requires:
- yarn-project-base
- noir-contracts-build
<<: *defaults
- yarn-project-formatting:
requires:
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ To build the C++ code, follow the [instructions in the circuits subdirectory](./

To build Typescript code, make sure to have [`nvm`](https://github.com/nvm-sh/nvm) (node version manager) installed.

To build noir code, make sure that you are using the version from `yarn-project/noir-compiler/src/noir-version.json`.
Install nargo by running `noirup -v TAG_FROM_THE_FILE`.
To build noir code build & use `yarn-project/noir-compiler`.

## Continuous Integration

Expand Down
14 changes: 1 addition & 13 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 @@ -106,11 +96,10 @@ yarn-project-base:
yarn-project:
buildDir: yarn-project
rebuildPatterns:
- ^yarn-project/.*\.(ts|js|cjs|mjs|json|html|md|sh)$
- ^yarn-project/.*\.(ts|js|cjs|mjs|json|html|md|sh|nr)$
- ^yarn-project/Dockerfile
dependencies:
- yarn-project-base
- noir-contracts-build

aztec-sandbox:
buildDir: yarn-project
Expand Down Expand Up @@ -191,7 +180,6 @@ docs:
- ^.*.cpp$
- ^.*.ts$
- ^.release-please-manifest.json$
- ^.*/noir-version.json$
- ^.*.nr$
dependencies:
- yarn-project
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import { AztecPackagesVersion } from "@site/src/components/Version";

### `#include_noir_version`

This macros will be replaced inline with the required nargo version, which is `0.11.1-aztec.0` at the time of these writing. This value is sourced from `yarn-project/noir-compiler/src/noir-version.json`.
This macros will be replaced inline with the required Noir version. This value is sourced from `yarn-project/noir-compiler/package.json`.

Alternatively, you can also use the `NoirVersion()` js function, which you need to import explicitly:

Expand Down
14 changes: 8 additions & 6 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ const config = {
name: "load-versions",
async loadContent() {
try {
const noirVersionPath = path.resolve(
const noirCompilerPackagePath = path.resolve(
__dirname,
"../yarn-project/noir-compiler/src/noir-version.json"
"../yarn-project/noir-compiler/package.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this use deployed NPM packages? Because on github / locally all package.json files are hardcoded to 0.1.0 version, which we then update in CI when releasing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this was using the version we got from npm. We only need @noir-lang/noir_wasm's version number

);
const noirVersion = JSON.parse(
fs.readFileSync(noirVersionPath).toString()
).tag;
const noirCompilerPackage = JSON.parse(
fs.readFileSync(noirCompilerPackagePath).toString()
);
const noir =
noirCompilerPackage.dependencies["@noir-lang/noir_wasm"];
const aztecVersionPath = path.resolve(
__dirname,
"../.release-please-manifest.json"
Expand All @@ -97,7 +99,7 @@ const config = {
fs.readFileSync(aztecVersionPath).toString()
)["."];
return {
noir: noirVersion,
noir,
"aztec-packages": `aztec-packages-v${aztecVersion}`,
};
} catch (err) {
Expand Down
13 changes: 7 additions & 6 deletions docs/src/preprocess/include_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ let versions;
async function getVersions() {
if (!versions) {
try {
const noirVersionPath = path.resolve(
const noirCompilerPackagePath = path.resolve(
__dirname,
"../../../yarn-project/noir-compiler/src/noir-version.json"
"../../../yarn-project/noir-compiler/package.json"
);
const noirVersion = JSON.parse(
fs.readFileSync(noirVersionPath).toString()
).tag;
const noirCompilerPackage = JSON.parse(
fs.readFileSync(noirCompilerPackagePath).toString()
);
const noir = noirCompilerPackage.dependencies["@noir-lang/noir_wasm"];
const aztecVersionPath = path.resolve(
__dirname,
"../../../.release-please-manifest.json"
Expand All @@ -22,7 +23,7 @@ async function getVersions() {
fs.readFileSync(aztecVersionPath).toString()
)["."];
versions = {
noir: noirVersion,
noir,
aztec: `aztec-packages-v${aztecVersion}`,
aztec_short: aztecVersion,
};
Expand Down
15 changes: 15 additions & 0 deletions yarn-project/.yarn/patches/ts-jest-npm-29.1.1-04e888e48e.patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why was this needed? Not something that can be fixed via jest config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noir-lang/source-resolver uses global scope to keep a function to read file contents with. This is used by @noir-lang/noir_wasm. The wasm compiler loads it as CJS so we have to load it as CJS also. I used .cts file to do this and the jest plugin we use to compile TS at runtime doesn't support .cts files yet kulshekhar/ts-jest#3996

alexghr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/dist/constants.js b/dist/constants.js
index 15a900a5ea36e38e7344d5713cdffa1edbdd539d..879c59892b4bd13470146d82a17691dd8ac0d25b 100644
--- a/dist/constants.js
+++ b/dist/constants.js
@@ -4,8 +4,8 @@ exports.DEFAULT_JEST_TEST_MATCH = exports.JS_EXT_TO_TREAT_AS_ESM = exports.TS_EX
exports.LINE_FEED = '\n';
exports.DECLARATION_TYPE_EXT = '.d.ts';
exports.JS_JSX_EXTENSIONS = ['.js', '.jsx'];
-exports.TS_TSX_REGEX = /\.m?tsx?$/;
-exports.JS_JSX_REGEX = /\.m?jsx?$/;
+exports.TS_TSX_REGEX = /\.[cm]?tsx?$/;
+exports.JS_JSX_REGEX = /\.[cm]?jsx?$/;
// `extensionsToTreatAsEsm` will throw error with `.mjs`
exports.TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts'];
exports.JS_EXT_TO_TREAT_AS_ESM = ['.jsx'];
20 changes: 8 additions & 12 deletions yarn-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# 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

# 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
# Build the project.
# bash & perl are needed for noir-contracts
RUN apk add bash perl &&\
yarn workspace @aztec/foundation build && \
yarn workspace @aztec/noir-compiler build && \
yarn workspace @aztec/noir-contracts noir:build:all && \
yarn tsc -b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to split this into 3 `RUN steps for more efficient caching

Suggested change
RUN apk add bash perl &&\
yarn workspace @aztec/foundation build && \
yarn workspace @aztec/noir-compiler build && \
yarn workspace @aztec/noir-contracts noir:build:all && \
yarn tsc -b
RUN apk add bash perl
RUN yarn workspace @aztec/foundation build && \
yarn workspace @aztec/noir-compiler build && \
yarn workspace @aztec/noir-contracts noir:build:all
RUN yarn tsc -b


# Build aztec.js web artifact
RUN cd /usr/src/yarn-project/aztec.js && yarn build:web
Expand All @@ -37,4 +33,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"]
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand All @@ -33,7 +33,7 @@
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/types": "workspace:^",
"@noir-lang/acvm_js": "0.30.0",
"@noir-lang/acvm_js": "0.30.0-3919619.aztec",
"levelup": "^5.1.1",
"memdown": "^6.1.1",
"tslib": "^2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-faucet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-sandbox/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createAztecNodeRpcServer } from '@aztec/aztec-node';
import { deployInitialSandboxAccounts } from '@aztec/aztec.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { fileURLToPath } from '@aztec/foundation/url';
import NoirVersion from '@aztec/noir-compiler/noir-version';
import { NoirVersion } from '@aztec/noir-compiler/noir-version';
import { createPXERpcServer } from '@aztec/pxe';

import { readFileSync } from 'fs';
Expand Down Expand Up @@ -52,7 +52,7 @@ async function main() {
const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json');
const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;

logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`);
logger.info(`Setting up Aztec Sandbox v${version} (noir ${NoirVersion}), please stand by...`);

const { pxe, node, stop, accounts } = await createAndInitialiseSandbox();

Expand Down Expand Up @@ -85,7 +85,7 @@ async function main() {
logger.info(
`${splash}\n${github}\n\n`
.concat(...accountStrings)
.concat(`Aztec Sandbox v${version} (nargo ${NoirVersion.tag}) is now ready for use!`),
.concat(`Aztec Sandbox v${version} (noir ${NoirVersion}) is now ready for use!`),
);
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ done
yarn --cwd circuits.js remake-bindings
yarn --cwd circuits.js remake-constants

(cd noir-contracts && ./bootstrap.sh)
yarn workspace @aztec/noir-contracts noir:build:all
yarn workspace @aztec/noir-contracts build

(cd boxes && ./bootstrap.sh)
(cd .. && l1-contracts/bootstrap.sh)

# Until we push .yarn/cache, we still need to install.
yarn
# We do not need to build individual packages, yarn build will build the root tsconfig.json
yarn build

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
Expand Down
36 changes: 1 addition & 35 deletions yarn-project/cli/src/unbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,6 @@ async function copyFolderFromGithub(data: JSZip, repositoryFolderPath: string, l
}
}

/**
* @param data - in memory unzipped clone of a github repo
* @param repositoryFile - path of the file to copy from github repo
* @param localOutputPath - local path to copy the file to
*/
async function copyFileFromGithub(data: JSZip, repositoryFile: string, localOutputPath: string, log: LogFn) {
log(`Downloading file from github: ${repositoryFile}`);

const file = data.files[repositoryFile];

if (!file || file.dir) {
throw new Error(`File not found or it's a directory: ${repositoryFile}`);
}

const filename = path.basename(repositoryFile);
const targetPath = `${localOutputPath}/${filename}`;

const content = await file.async('nodebuffer');
await fs.writeFile(targetPath, content);
}

/**
* Not flexible at at all, but quick fix to download a noir smart contract from our
* monorepo on github. this will copy over the `yarn-projects/boxes/{contract_name}` folder
Expand Down Expand Up @@ -119,12 +98,6 @@ async function downloadContractAndBoxFromGithub(
const boxPath = `${repoDirectoryPrefix}/${BOXES_PATH}/${contractName}/`;
await copyFolderFromGithub(data, boxPath, outputPath, log);

// the expected noir version is contained in
// aztec-packages/yarn-project/noir-compiler/src/noir-version.json
// copy it in and use to update the package.json script to install that version of noir
const noirVersionPath = `${repoDirectoryPrefix}/yarn-project/noir-compiler/src/noir-version.json`;
await copyFileFromGithub(data, noirVersionPath, outputPath, log);

const contractTargetDirectory = path.join(outputPath, 'src', 'contracts');
const boxContainsNoirSource = await isDirectoryNonEmpty(contractTargetDirectory);
if (boxContainsNoirSource) {
Expand Down Expand Up @@ -247,13 +220,6 @@ async function updatePackageJsonVersions(packageVersion: string, outputPath: str
}
}
}
// read the `noir-version.json`, grab the expected noir version, and patch the noir install script
const noirVersionPath = path.join(outputPath, 'noir-version.json');
const noirVersionContent = await fs.readFile(noirVersionPath, 'utf-8');
const noirVersionJSON = JSON.parse(noirVersionContent);
const noirTag = noirVersionJSON.tag;
packageData.scripts['install:noir'] = packageData.scripts['install:noir'].replace('NOIR_VERSION', `${noirTag}`);
log(`Updated Noir version to: ${noirTag}`);

// modify the version of the sandbox to pull - it's set to "latest" version in the monorepo,
// but we need to replace with the same tagVersion as the cli and the other aztec npm packages
Expand Down Expand Up @@ -320,7 +286,7 @@ export async function unboxContract(

if (!contractNames.includes(contractName)) {
log(
`The noir contract named "${contractName}" was not found in "@aztec/boxes" package. Valid options are:
`The noir contract named "${contractName}" was not found in "@aztec/boxes" package. Valid options are:
${contractNames.join('\n\t')}
We recommend "token" as a default.`,
);
Expand Down
Loading