Skip to content

Commit d083438

Browse files
authored
feat!: Unify ABIs between nargo and yarn-project (AztecProtocol#3989)
Changes the output of `nargo` and `noir-wasm` to generate a single artifact that includes debug information. Compiled contracts now have a `file_map` at the root of the artifact, and a `debug_symbols` within each function. For consistency, compiled programs also have `file_map` and `debug_symbols`. Debug symbols are compressed and base64-encoded, as they were by the former `noir-compiler` postprocessing. The `debug` json artifact is no longer emitted. Removes all code related to generating `yarn-project`-specific ABIs from noir compiler. Instead, `types` now exposes a `loadContractArtifact` that renames fields as needed (and use camel instead of snake case), and is required when loading a noir contract artifact. Autogenerated types run this automatically. Since we are no longer post-processing artifacts, the `noir-contracts` project shape is changed. JSON files live in the `target` folder where nargo outputs them (this is not configurable), and are loaded by the autogenerated typescript interfaces from there. As part of the refactor, moves functions for getting functions debug info out of `acir-simulator` and into `types`. **Breaking change**: This removes the need to run `codegen` for using a compiled contract. However, when creating a new contract object from aztec.js, a dev needs to call `loadContractArtifact`. **Future changes**: Type information for a compilation artifact is now spread all over the place, and duplicated in more than one place. There are types defined within rust code in Noir as `[wasm_bindgen(typescript_custom_section)]`, others defined within typescript code in the `noir_wasm` package, others in `foundation`, and others in `types`. We should unify it in a single place. Fixes AztecProtocol#3812 Supersedes AztecProtocol#3906 Noir subrepo has been pushed to noir-lang/noir#4035 to run the Noir CI
1 parent bdbe963 commit d083438

88 files changed

Lines changed: 706 additions & 795 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

boxes/blank-react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"skipLibCheck": true,
2222
"jsx": "react-jsx"
2323
},
24-
"include": ["src", "src/artifacts/Blank.json"]
24+
"include": ["src", "src/contracts/target/*.json"]
2525
}

boxes/blank/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"skipLibCheck": true,
2222
"jsx": "react-jsx"
2323
},
24-
"include": ["src", "src/artifacts/Blank.json"]
24+
"include": ["src", "src/contracts/target/*.json"]
2525
}

boxes/token/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"skipLibCheck": true,
2222
"jsx": "react-jsx"
2323
},
24-
"include": ["src", "src/artifacts/Token.json"]
24+
"include": ["src", "src/contracts/target/*.json"]
2525
}

docs/docs/dev_docs/contracts/compiling.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,11 @@ aztec-nargo compile
1818

1919
This will output a JSON [artifact](./artifacts.md) for each contract in the project to a `target` folder containing the Noir ABI artifacts.
2020

21-
Before you can use the ABI it currently needs to be validated as being Aztec compatible, and transformed to an Aztec compatible ABI using `aztec-cli codegen`, passing a Noir ABI file or folder, and output location, e.g:
22-
23-
```bash
24-
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts
25-
```
26-
27-
It can be useful to perform this compilation, validation and transformation in one go, so you may wish to chain the commands and perhaps add them to a package.json script. The below assumes your contract is in a folder called `contract` at your project root:
28-
29-
```bash
30-
(cd contract && aztec-nargo compile && aztec-cli codegen target -o ../src/artifacts)
31-
```
32-
3321
### Typescript Interfaces
3422

35-
You can use the codegenerator to autogenerate type-safe typescript classes for each of your contracts. These classes define type-safe methods for deploying and interacting with your contract based on their artifact.
23+
You can use the code generator to autogenerate type-safe typescript classes for each of your contracts. These classes define type-safe methods for deploying and interacting with your contract based on their artifact.
3624

37-
To generate them, include a `--ts` option in the codegen command with a path to the target folder for the typescript files:
25+
To generate them, include a `--ts` option in the `codegen` command with a path to the target folder for the typescript files:
3826

3927
```bash
4028
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts --ts

docs/docs/dev_docs/contracts/deploying.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Compile the contract:
3333
aztec-nargo compile
3434
```
3535

36-
Generate the ABI and typescript class:
36+
Generate the typescript class:
3737

3838
```bash
3939
aztec-cli codegen ./aztec-nargo/output/target/path -o src/artifacts --ts

docs/docs/dev_docs/getting_started/aztecnr-getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ aztec-nargo compile
156156

157157
This will compile the smart contract and create a `target` folder with a `.json` artifact inside.
158158

159-
After compiling, you need to generate the ABI and typescript class. In the same directory, run this:
159+
After compiling, you can generate a typescript class. In the same directory, run this:
160160

161161
```bash
162162
aztec-cli codegen target -o src/artifacts --ts

docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ and the each of the Aztec.nr contracts by going into each folder and running:
3333
aztec-nargo compile
3434
```
3535

36-
And then generate the ABIs and typescript interface:
36+
And then generate the typescript interface:
3737

3838
```bash
3939
aztec-cli codegen ./target/ -o ../../../src/test/fixtures uniswap --ts

docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ Now run the following from your contract folder (containing Nargo.toml):
4242
aztec-nargo compile
4343
```
4444

45-
Once you have compiled your contracts, you need to generate the ABIs:
46-
47-
```sh
48-
aztec-cli codegen ./target/path -o src/artifacts --ts
49-
```
50-
51-
This should have created an artifact `contracts/token/src/artifacts/Token.json` with the interface and bytecode for your contract.
52-
5345
## Deploy your contracts
5446

5547
Let's now write a script for deploying your contracts to the Sandbox. We'll create a Private eXecution Environment (PXE) client, and then use the `ContractDeployer` class to deploy our contracts, and store the deployment address to a local JSON file.
@@ -61,7 +53,8 @@ Create a new file `src/deploy.mjs`:
6153
import { writeFileSync } from 'fs';
6254
import { Contract, ContractDeployer, createPXEClient } from '@aztec/aztec.js';
6355
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
64-
import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" };
56+
import TokenContractJson from "../contracts/token/target/token_contract-Token.json" assert { type: "json" };
57+
6558

6659
#include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw
6760

docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To do this, let's first initialize a new `Contract` instance using `aztec.js` th
1818
// src/contracts.mjs
1919
import { Contract } from "@aztec/aztec.js";
2020
import { readFileSync } from "fs";
21-
import TokenContractArtifact from "../contracts/token/src/artifacts/Token.json" assert { type: "json" };
21+
import TokenContractJson from "../contracts/token/target/token_contract-Token.json" assert { type: "json" };
2222
```
2323

2424
And then add the following code for initializing the `Contract` instances:

docs/docs/dev_docs/tutorials/writing_private_voting_contract.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ The easiest way to compile the contract is with `aztec-nargo`. Run the following
193193
aztec-nargo compile
194194
```
195195

196-
This will create a new directory called `target` and a JSON artifact inside it. To create the Aztec contract ABI and typescript interface, run:
196+
This will create a new directory called `target` and a JSON artifact inside it. To optionally create a typescript interface, run:
197197

198198
```bash
199199
aztec-cli codegen target -o src/artifacts --ts
200200
```
201201

202-
This will create the ABI called `Voting.json` in `src/artifacts`. If you are getting some errors here you might want to check out the [debugging page](../debugging/main.md).
203-
204202
Once it is compiled you can [deploy](../contracts/deploying.md) it to the sandbox. Ensure your [sandbox is running](../cli/sandbox-reference.md) and run this in the same dir as before:
205203

206204
```bash
207-
aztec-cli deploy ./src/artifacts/Voting.json --args $ADMIN_ADDRESS
205+
aztec-cli deploy ./target/Voting.json --args $ADMIN_ADDRESS
208206
```
209207

210208
The constructor takes an address as an argument to set the admin, so you can use an address that is deployed with the sandbox - check the sandbox terminal or run `aztec-cli get-accounts`.
@@ -214,7 +212,7 @@ You should see a success message with the contract address. Now we can start cal
214212
Cast a vote like this:
215213

216214
```bash
217-
aztec-cli send cast_vote --contract-artifact ./src/artifacts/Voting.json --contract-address $CONTRACT_ADDRESS --args 1 --private-key $PRIVATE_KEY
215+
aztec-cli send cast_vote --contract-artifact ./target/Voting.json --contract-address $CONTRACT_ADDRESS --args 1 --private-key $PRIVATE_KEY
218216
```
219217

220218
You can get the contract address from the sandbox terminal or the message printed when you deployed the contract. You can also get a private key from the sandbox terminal, or generate one with `aztec-cli generate-private-key`.
@@ -226,7 +224,7 @@ You can now try running this command again to ensure our nullifier works.
226224
Get the number of votes like this:
227225

228226
```bash
229-
aztec-cli call get_vote --contract-artifact ./src/artifacts/Voting.json --contract-address $CONTRACT_ADDRESS --args 1
227+
aztec-cli call get_vote --contract-artifact ./target/Voting.json --contract-address $CONTRACT_ADDRESS --args 1
230228
```
231229

232230
This should return `1n`.

0 commit comments

Comments
 (0)