Skip to content

Commit

Permalink
feat: compile noir contracts with noir_wasm (#2737)
Browse files Browse the repository at this point in the history
This PR adds support for compiling contracts with `noir_wasm` instead of
`nargo`.

Fix #2644

Requires:
- [x] #2728
- [x] noir-lang/noir#3036
- [x] noir-lang/noir#3049
- [x] noir-lang/noir#3091
- [x] noir-lang/noir#3213
- [x] updates to `noir-contracts` to add `pub` modifiers to return types
(TBD)
e.g. `getThisAddress() -> pub Field` here
https://github.com/AztecProtocol/aztec-packages/blob/4881414ceb30590674c244ef9bc4c8416eacd6bc/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr#L45
- [x] build `noir_wasm` with `aztec` feature enabled (based on
noir-lang/noir#3049)
- [x] output compilation errors (based on noir-lang/noir#3091)

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
  • Loading branch information
alexghr and spalladino authored Oct 27, 2023
1 parent 89e7c21 commit 524cecf
Show file tree
Hide file tree
Showing 58 changed files with 1,650 additions and 71 deletions.
16 changes: 16 additions & 0 deletions yarn-project/.yarn/patches/ts-jest-npm-29.1.1-04e888e48e.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/dist/constants.js b/dist/constants.js
index 15a900a5ea36e38e7344d5713cdffa1edbdd539d..850352d4b76ac7518c3cd46010023dee0dd8cca0 100644
--- a/dist/constants.js
+++ b/dist/constants.js
@@ -4,8 +4,9 @@ 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?$/;
+// Remove this patch when this issue is fixed https://github.com/kulshekhar/ts-jest/issues/3996
+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'];
2 changes: 1 addition & 1 deletion 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 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
2 changes: 1 addition & 1 deletion 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
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
2 changes: 0 additions & 2 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ yarn --cwd circuits.js remake-constants
(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
2 changes: 1 addition & 1 deletion yarn-project/cli/src/unbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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
2 changes: 1 addition & 1 deletion yarn-project/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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/foundation/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc', 'jsdoc', 'no-only-tests'],
overrides: [
{
files: ['*.ts', '*.tsx'],
files: ['*.cts', '*.mts', '*.ts', '*.tsx'],
parserOptions: {
// hacky workaround for CI not having the same tsconfig setup
project: true,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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/key-store/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 Down
2 changes: 1 addition & 1 deletion yarn-project/merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
19 changes: 16 additions & 3 deletions yarn-project/noir-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"moduleFileExtensions": [
"js",
"ts",
"cts"
],
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
"rootDir": "./src",
"transform": {
"^.+\\.cts$": "ts-jest"
}
},
"dependencies": {
"@aztec/foundation": "workspace:^",
"@noir-lang/noir_wasm": "0.18.0-3919619.aztec",
"@noir-lang/source-resolver": "0.18.0-3919619.aztec",
"base64-js": "^1.5.1",
"commander": "^9.0.0",
"fs-extra": "^11.1.1",
Expand All @@ -46,9 +56,12 @@
"lodash.compact": "^3.0.1",
"lodash.times": "^4.3.2",
"lodash.upperfirst": "^4.3.1",
"memfs": "^4.6.0",
"pako": "^2.1.0",
"toml": "^3.0.0",
"tslib": "^2.4.0"
"tslib": "^2.4.0",
"unzipit": "^1.4.3",
"zod": "^3.22.4"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
Loading

0 comments on commit 524cecf

Please sign in to comment.