Skip to content

Commit

Permalink
chore: restore nargo
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Oct 26, 2023
1 parent ec25afb commit 90c3566
Show file tree
Hide file tree
Showing 40 changed files with 883 additions and 65 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ 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 @@ -1221,6 +1232,7 @@ workflows:
<<: *defaults

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

- mainnet-fork: *defaults

Expand All @@ -1233,6 +1245,7 @@ workflows:
- yarn-project:
requires:
- yarn-project-base
- noir-contracts-build
<<: *defaults
- yarn-project-formatting:
requires:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ 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 build & use `yarn-project/noir-compiler`.
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`.

## Continuous Integration

Expand Down
14 changes: 13 additions & 1 deletion build_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ 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 @@ -96,10 +106,11 @@ yarn-project-base:
yarn-project:
buildDir: yarn-project
rebuildPatterns:
- ^yarn-project/.*\.(ts|js|cjs|mjs|json|html|md|sh|nr)$
- ^yarn-project/.*\.(ts|js|cjs|mjs|json|html|md|sh)$
- ^yarn-project/Dockerfile
dependencies:
- yarn-project-base
- noir-contracts-build

aztec-sandbox:
buildDir: yarn-project
Expand Down Expand Up @@ -180,6 +191,7 @@ 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 Noir version. This value is sourced from `yarn-project/noir-compiler/package.json`.
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`.
Alternatively, you can also use the `NoirVersion()` js function, which you need to import explicitly:
Expand Down
14 changes: 6 additions & 8 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ const config = {
name: "load-versions",
async loadContent() {
try {
const noirCompilerPackagePath = path.resolve(
const noirVersionPath = path.resolve(
__dirname,
"../yarn-project/noir-compiler/package.json"
"../yarn-project/noir-compiler/src/noir-version.json"
);
const noirCompilerPackage = JSON.parse(
fs.readFileSync(noirCompilerPackagePath).toString()
);
const noir =
noirCompilerPackage.dependencies["@noir-lang/noir_wasm"];
const noirVersion = JSON.parse(
fs.readFileSync(noirVersionPath).toString()
).tag;
const aztecVersionPath = path.resolve(
__dirname,
"../.release-please-manifest.json"
Expand All @@ -99,7 +97,7 @@ const config = {
fs.readFileSync(aztecVersionPath).toString()
)["."];
return {
noir,
noir: noirVersion,
"aztec-packages": `aztec-packages-v${aztecVersion}`,
};
} catch (err) {
Expand Down
13 changes: 6 additions & 7 deletions docs/src/preprocess/include_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ let versions;
async function getVersions() {
if (!versions) {
try {
const noirCompilerPackagePath = path.resolve(
const noirVersionPath = path.resolve(
__dirname,
"../../../yarn-project/noir-compiler/package.json"
"../../../yarn-project/noir-compiler/src/noir-version.json"
);
const noirCompilerPackage = JSON.parse(
fs.readFileSync(noirCompilerPackagePath).toString()
);
const noir = noirCompilerPackage.dependencies["@noir-lang/noir_wasm"];
const noirVersion = JSON.parse(
fs.readFileSync(noirVersionPath).toString()
).tag;
const aztecVersionPath = path.resolve(
__dirname,
"../../../.release-please-manifest.json"
Expand All @@ -23,7 +22,7 @@ async function getVersions() {
fs.readFileSync(aztecVersionPath).toString()
)["."];
versions = {
noir,
noir: noirVersion,
aztec: `aztec-packages-v${aztecVersion}`,
aztec_short: aztecVersion,
};
Expand Down
20 changes: 12 additions & 8 deletions yarn-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# 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 . .

# 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
# 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 aztec.js web artifact
RUN cd /usr/src/yarn-project/aztec.js && yarn build:web
Expand All @@ -33,4 +37,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"]
2 changes: 1 addition & 1 deletion yarn-project/acir-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/types": "workspace:^",
"@noir-lang/acvm_js": "0.30.0-3919619.aztec",
"@noir-lang/acvm_js": "0.30.0",
"levelup": "^5.1.1",
"memdown": "^6.1.1",
"tslib": "^2.4.0"
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 @@ -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} (noir ${NoirVersion}), please stand by...`);
logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`);

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

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ done
yarn --cwd circuits.js remake-bindings
yarn --cwd circuits.js remake-constants

yarn workspace @aztec/noir-contracts noir:build:all
yarn workspace @aztec/noir-contracts build

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

Expand Down
34 changes: 34 additions & 0 deletions yarn-project/cli/src/unbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ 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 @@ -98,6 +119,12 @@ 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 @@ -220,6 +247,13 @@ 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
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('e2e_cross_chain_messaging', () => {
secretForL2MessageConsumption,
)
.simulate(),
).rejects.toThrowError('Cannot satisfy constraint');
).rejects.toThrowError("Cannot satisfy constraint 'l1_to_l2_message_data.message.content == content");

// send the right one -
const consumptionTx = l2Bridge
Expand Down Expand Up @@ -231,6 +231,8 @@ describe('e2e_cross_chain_messaging', () => {
.withWallet(user2Wallet)
.methods.claim_public(ownerAddress, bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption)
.simulate(),
).rejects.toThrowError('Failed to solve brillig function, reason: explicit trap hit in brillig');
).rejects.toThrowError(
"Failed to solve brillig function, reason: explicit trap hit in brillig 'l1_to_l2_message_data.message.content == content'",
);
}, 50_000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ describe('e2e_public_cross_chain_messaging', () => {
.withWallet(user2Wallet)
.methods.claim_private(secretHash, bridgeAmount, ethAccount, messageKey, secret)
.simulate(),
).rejects.toThrowError('Cannot satisfy constraint');
).rejects.toThrowError("Cannot satisfy constraint 'l1_to_l2_message_data.message.content == content");
});
});
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ export const uniswapL1L2TestSuite = (
await ownerWallet.setPublicAuth(swapMessageHash, true).send().wait();

// Swap!
await expect(action.simulate()).rejects.toThrowError('Assertion failed: Message not authorized by account');
await expect(action.simulate()).rejects.toThrowError(
"Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'",
);
});

it("uniswap can't pull funds without transfer approval", async () => {
Expand Down Expand Up @@ -621,7 +623,7 @@ export const uniswapL1L2TestSuite = (
Fr.ZERO,
)
.simulate(),
).rejects.toThrowError('Assertion failed: Message not authorized by account');
).rejects.toThrowError(`Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'`);
});

// tests when trying to mix private and public flows:
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/noir-compiler/.dockerignore

This file was deleted.

Loading

0 comments on commit 90c3566

Please sign in to comment.