diff --git a/docs/docs/about_aztec/roadmap/features_initial_ldt.md b/docs/docs/about_aztec/roadmap/features_initial_ldt.md index 34b86912cba..7b7f96d40d8 100644 --- a/docs/docs/about_aztec/roadmap/features_initial_ldt.md +++ b/docs/docs/about_aztec/roadmap/features_initial_ldt.md @@ -52,7 +52,7 @@ A typescript wrapper for making RPC calls to an Aztec Sandbox node. See the sour - Similar in purpose to `web3.js`/`ethers.js`/`viem`, but for interacting with Aztec Network nodes. The RPC interface for an Aztec node is necessarily different from that of an Ethereum node, because it deals with encrypted transactions and state variables. - A library for public/private key management. -- Construct `Contract` instances from a Aztec.nr contract's JSON ABI. +- Construct `Contract` instances from a Aztec.nr contract's JSON artifact. - Deploy new contracts to the Aztec Sandbox. - Construct tx requests, passing arguments to a function of a contract. - Sign tx requests. diff --git a/docs/docs/concepts/advanced/contract_creation.md b/docs/docs/concepts/advanced/contract_creation.md index 9e054f5eacb..882e57f0743 100644 --- a/docs/docs/concepts/advanced/contract_creation.md +++ b/docs/docs/concepts/advanced/contract_creation.md @@ -40,7 +40,7 @@ Each contract's function data is stored in a Merkle tree, where each leaf contai ### How are function signatures defined? -We can take a leaf from Ethereum and make them the first 4 bytes of a hash of the function definition (defined according to the contract ABI, TBD). +We can take a leaf from Ethereum and make them the first 4 bytes of a hash of the function definition (defined according to the contract artifact, TBD). ## Contract Representation in Aztec @@ -284,7 +284,7 @@ The set of functions of a contract is represented as a mini Merkle tree of verif - Distributing L2 contract data - Linking to an L1 Portal Contract -These topics are reflected in the layout of the contract deployment ABI: +These topics are reflected in the layout of the contract deployment artifact: ```js publicInputs = { diff --git a/docs/docs/dev_docs/cli/main.md b/docs/docs/dev_docs/cli/main.md index 8f6d0a584ce..8abcec843d5 100644 --- a/docs/docs/dev_docs/cli/main.md +++ b/docs/docs/dev_docs/cli/main.md @@ -52,7 +52,7 @@ We have shipped a number of example contracts in the `@aztec/noir-contracts` npm You can see all of our example contracts in the monorepo [here](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/src/contracts). -In the following sections there will be commands that require contracts as options. You can either specify the full directory path to the contract abi, or you can use the name of one of these examples as the option value. This will become clearer later on. +In the following sections there will be commands that require contracts as options. You can either specify the full directory path to the contract artifact, or you can use the name of one of these examples as the option value. This will become clearer later on. ## Creating Accounts @@ -101,7 +101,7 @@ export CONTRACT_ADDRESS= If you use a different address in the constructor above, you will get an error when running the deployment. This is because you need to register an account in the sandbox before it can receive private notes. When you create a new account, it gets automatically registered. Alternatively, you can register an account you do not own along with its public key using the `register-recipient` command. ::: -This command takes 1 mandatory positional argument which is the path to the contract ABI file in a JSON format (e.g. `contracts/target/PrivateToken.json`). +This command takes 1 mandatory positional argument which is the path to the contract artifact file in a JSON format (e.g. `contracts/target/PrivateToken.json`). Alternatively you can pass the name of an example contract as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to see the full list of contracts available). The command takes a few optional arguments while the most important one is: @@ -121,7 +121,7 @@ When we deployed the token contract, an initial supply of tokens was minted to t The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are: - `--args` - The address for which we want to retrieve the balance. -- `--contract-abi` - The abi of the contract we are calling. +- `--contract-artifact` - The artifact of the contract we are calling. - `--contract-address` - The address of the deployed contract As you can see from the result, this address has a balance of 1000000, as expected. When using the Sandbox, you are able to query the balance of any account that has been created in the system, even the accounts created by default. You may wonder why this is, as you haven't provided the private keys for these accounts. The Sandbox contains a component known as the Private Execution Environment (PXE). When an account is created, this component stores the provided encryption private key and is able to read the account's private state meaning that the Sandbox can report the balance of any of it's accounts. More information about the account model can be found [here](../../concepts/foundation/accounts/main.md). @@ -135,7 +135,7 @@ We can now send a transaction to the network. We will transfer funds from the ow We called the `transfer` function of the contract and provided these arguments: - `--args` - The list of arguments to the function call. -- `--contract-abi` - The abi of the contract to call. +- `--contract-artifact` - The artifact of the contract to call. - `--contract-address` - The deployed address of the contract to call. - `--private-key` - The private key of the sender diff --git a/docs/docs/dev_docs/contracts/compiling.md b/docs/docs/dev_docs/contracts/compiling.md index a9c1a346954..95b0388e4ca 100644 --- a/docs/docs/dev_docs/contracts/compiling.md +++ b/docs/docs/dev_docs/contracts/compiling.md @@ -28,11 +28,11 @@ Then run the `compile` command with the path to your [contract project folder](. aztec-cli compile ./path/to/my_aztec_contract_project ``` -This will output a JSON [artifact](./artifacts.md) for each contract in the project to a `target` folder containing their ABI, which you can use for deploying or interacting with your contracts. +This will output a JSON [artifact](./artifacts.md) for each contract in the project to a `target` folder containing their artifact, which you can use for deploying or interacting with your contracts. ### Typescript Interfaces -You can use the compiler 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 ABI. +You can use the compiler 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. To generate them, include a `--typescript` option in the compile command with a path to the target folder for the typescript files: @@ -77,7 +77,7 @@ Read more about interacting with contracts using `aztec.js` [here](../getting_st An Aztec.nr contract can [call a function](./syntax/functions.md) in another contract via `context.call_private_function` or `context.call_public_function`. However, this requires manually assembling the function selector and manually serialising the arguments, which is not type-safe. -To make this easier, the compiler can generate contract interface structs that expose a convenience method for each function listed in a given contract ABI. These structs are intended to be used from another contract project that calls into the current one. For each contract, two interface structs are generated: one to be used from private functions with a `PrivateContext`, and one to be used from open functions with a `PublicContext`. +To make this easier, the compiler can generate contract interface structs that expose a convenience method for each function listed in a given contract artifact. These structs are intended to be used from another contract project that calls into the current one. For each contract, two interface structs are generated: one to be used from private functions with a `PrivateContext`, and one to be used from open functions with a `PublicContext`. To generate them, include a `--interface` option in the compile command with a path to the target folder for the generated Aztec.nr interface files: @@ -140,8 +140,8 @@ You can also programmatically access the compiler via the `@aztec/noir-compiler` The compiler exposes the following functions: - `compileUsingNargo`: Compiles an Aztec.nr project in the target folder using the `nargo` binary available on the shell `PATH` and returns the generated ABIs. -- `generateTypescriptContractInterface`: Generates a typescript class for the given contract ABI. -- `generateNoirContractInterface`: Generates a Aztec.nr interface struct for the given contract ABI. +- `generateTypescriptContractInterface`: Generates a typescript class for the given contract artifact. +- `generateNoirContractInterface`: Generates a Aztec.nr interface struct for the given contract artifact. ## Next steps diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index 0753fa10c61..303196229e1 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -19,7 +19,7 @@ import TabItem from '@theme/TabItem'; ```bash -aztec-cli deploy /path/to/contract/abi.json +aztec-cli deploy /path/to/contract/artifact.json ``` @@ -31,7 +31,7 @@ Pre-requisite - Generate type-safe typescript classes for your contract when com import { readFileSync, writeFileSync } from 'fs'; import { compileUsingNargo, generateTypescriptContractInterface} from '@aztec/noir-compiler'; -const compiled: ContractAbi[] = await compileUsingNargo(projectPathToContractFolder); +const compiled: ContractArtifact[] = await compileUsingNargo(projectPathToContractFolder); const abiImportPath = "../target/Example.json"; writeFileSync(tsInterfaceDestFilePath, generateTypescriptContractInterface(compiled[0], abiImportPath)); ``` @@ -54,7 +54,7 @@ There are several optional arguments that can be passed: -`aztec-cli deploy` takes 1 mandatory argument which is the path to the contract ABI file in a JSON format (e.g. `contracts/target/PrivateToken.json`). Alternatively you can pass the name of an example contract as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to see the full list of contracts available). +`aztec-cli deploy` takes 1 mandatory argument which is the path to the contract artifact file in a JSON format (e.g. `contracts/target/PrivateToken.json`). Alternatively you can pass the name of an example contract as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to see the full list of contracts available). The command also takes the following optional arguments: - `-args ` (default: `[]`): Arguments to pass to the contract constructor. @@ -128,7 +128,7 @@ Once the recipient is registered we can deploy the contract: ```bash -aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 +aztec-cli deploy PrivateTokenContractArtifact --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 ``` @@ -154,7 +154,7 @@ If we pass the salt as an argument: ```bash -aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123 +aztec-cli deploy PrivateTokenContractArtifact --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123 ``` diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md index d91c0b3db30..5e4557e2dc8 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md @@ -64,7 +64,7 @@ Create a new file `src/deploy.mjs`: // src/deploy.mjs import { writeFileSync } from 'fs'; import { Contract, ContractDeployer, createPXEClient, getSandboxAccountsWallets } from '@aztec/aztec.js'; -import TokenContractAbi from "../contracts/token/target/Token.json" assert { type: "json" }; +import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; #include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md index daed14e63fb..4d3d2ae0e22 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md @@ -18,7 +18,7 @@ To do this, let's first initialize a new `Contract` instance using `aztec.js` th // src/contracts.mjs import { Contract } from "@aztec/aztec.js"; import { readFileSync } from "fs"; -import TokenContractAbi from "../contracts/token/target/Token.json" assert { type: "json" }; +import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; ``` And then add the following code for initialising the `Contract` instances: diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/testing.md b/docs/docs/dev_docs/tutorials/writing_dapp/testing.md index ff9732be801..4c1a5e947b6 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/testing.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/testing.md @@ -27,7 +27,7 @@ Create a new file `src/index.test.mjs` with the imports we'll be using and an em ```js import { createSandbox } from "@aztec/aztec-sandbox"; import { Contract, createAccount } from "@aztec/aztec.js"; -import TokenContractAbi from "../contracts/token/target/Token.json" assert { type: "json" }; +import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; describe("token", () => {}); ``` diff --git a/docs/internal_notes/dev_docs/sandbox/components.md b/docs/internal_notes/dev_docs/sandbox/components.md index cc3f335c784..58ba7718f20 100644 --- a/docs/internal_notes/dev_docs/sandbox/components.md +++ b/docs/internal_notes/dev_docs/sandbox/components.md @@ -89,9 +89,9 @@ Responsibilities: These tasks are lower priority than providing a handcrafted ABI. - The ability for a dev to enclose a collection of Aztec.nr functions in a 'contract scope'. -- The ability to create an Aztec.nr contract abi from the above. +- The ability to create an Aztec.nr contract artifact from the above. -Design an Aztec.nr Contract ABI, similar to a Solidity ABI which is output by Solc (see [here](https://docs.soliditylang.org/en/v0.8.13/abi-spec.html#json)). It might include for each function: +Design an Aztec.nr contract artifact, similar to a Solidity ABI which is output by Solc (see [here](https://docs.soliditylang.org/en/v0.8.13/abi-spec.html#json)). It might include for each function: - ACIR opcodes (akin to Solidity bytecode). - Function name and parameter names & types. @@ -113,7 +113,7 @@ aztec.js should always be stateless. It offers the ability to interact with stat The analogous AC component would be the AztecSdk (wraps the CoreSdk which is more analogous to the private client). - Allows a user to create an Aztec keypair. Call `create_account` on Wallet. -- Create a `Contract` instance (similar to web3.js), given a path to an Aztec.nr Contract ABI. +- Create a `Contract` instance (similar to web3.js), given a path to an Aztec.nr contract artifact. - Construct `tx_request` by calling e.g. `contract.get_deployment_request(constructor_args)`. - Call wallet `sign_tx_request(tx_request)` to get signature. - Call `simulate_tx(signed_tx_request)` on the Private Client. In future this would help compute gas, for now we won't actually return gas (it's hard). Returns success or failure, so client knows if it should proceed, and computed kernel circuit public outputs. diff --git a/docs/static/img/sandbox_unconstrained_function.svg b/docs/static/img/sandbox_unconstrained_function.svg index 947e30edf8d..8ae15542142 100644 --- a/docs/static/img/sandbox_unconstrained_function.svg +++ b/docs/static/img/sandbox_unconstrained_function.svg @@ -7,7 +7,7 @@ width="1684.16" height="537.27997" viewBox="0 0 1684.16 537.27997" - sodipodi:docname="sandbox_view_call.svg" + sodipodi:docname="sandbox_unconstrained_function.svg" inkscape:version="1.3 (0e150ed, 2023-07-21)" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" @@ -37,8 +37,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath6"> @@ -46,8 +46,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath8"> @@ -56,7 +56,7 @@ id="clipPath10"> @@ -64,8 +64,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath12"> @@ -73,8 +73,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath14"> @@ -83,7 +83,7 @@ id="clipPath16"> @@ -91,8 +91,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath18"> @@ -101,7 +101,7 @@ id="clipPath20"> @@ -109,8 +109,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath22"> @@ -119,7 +119,7 @@ id="clipPath24"> @@ -127,15 +127,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath25"> @@ -160,7 +160,7 @@ id="clipPath32"> @@ -169,7 +169,7 @@ id="clipPath34"> @@ -178,7 +178,7 @@ id="clipPath36"> @@ -187,7 +187,7 @@ id="clipPath38"> @@ -196,7 +196,7 @@ id="clipPath40"> @@ -205,7 +205,7 @@ id="clipPath42"> @@ -214,7 +214,7 @@ id="clipPath44"> @@ -223,7 +223,7 @@ id="clipPath46"> @@ -232,7 +232,7 @@ id="clipPath48"> @@ -241,7 +241,7 @@ id="clipPath50"> @@ -250,7 +250,7 @@ id="clipPath52"> @@ -259,7 +259,7 @@ id="clipPath54"> @@ -267,15 +267,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath55"> @@ -300,7 +300,7 @@ id="clipPath62"> @@ -309,7 +309,7 @@ id="clipPath64"> @@ -318,7 +318,7 @@ id="clipPath66"> @@ -327,7 +327,7 @@ id="clipPath68"> @@ -335,15 +335,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath69"> @@ -368,7 +368,7 @@ id="clipPath76"> @@ -377,7 +377,7 @@ id="clipPath78"> @@ -385,15 +385,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath79"> @@ -418,7 +418,7 @@ id="clipPath86"> @@ -427,7 +427,7 @@ id="clipPath88"> @@ -436,7 +436,7 @@ id="clipPath90"> @@ -445,7 +445,7 @@ id="clipPath92"> @@ -454,7 +454,7 @@ id="clipPath94"> @@ -463,7 +463,7 @@ id="clipPath96"> @@ -471,15 +471,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath97"> @@ -504,7 +504,7 @@ id="clipPath104"> @@ -512,15 +512,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath105"> @@ -545,7 +545,7 @@ id="clipPath112"> @@ -554,7 +554,7 @@ id="clipPath114"> @@ -562,15 +562,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath115"> @@ -595,7 +595,7 @@ id="clipPath122"> @@ -604,7 +604,7 @@ id="clipPath124"> @@ -613,7 +613,7 @@ id="clipPath126"> @@ -622,7 +622,7 @@ id="clipPath128"> @@ -631,7 +631,7 @@ id="clipPath130"> @@ -640,7 +640,7 @@ id="clipPath132"> @@ -649,7 +649,7 @@ id="clipPath134"> @@ -658,7 +658,7 @@ id="clipPath136"> @@ -667,7 +667,7 @@ id="clipPath138"> @@ -676,7 +676,7 @@ id="clipPath140"> @@ -685,7 +685,7 @@ id="clipPath142"> @@ -694,7 +694,7 @@ id="clipPath144"> @@ -703,7 +703,7 @@ id="clipPath146"> @@ -711,15 +711,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath147"> @@ -744,7 +744,7 @@ id="clipPath154"> @@ -753,7 +753,7 @@ id="clipPath156"> @@ -762,7 +762,7 @@ id="clipPath158"> @@ -770,8 +770,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath160"> @@ -780,7 +780,7 @@ id="clipPath162"> @@ -789,7 +789,7 @@ id="clipPath164"> @@ -797,8 +797,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath166"> @@ -807,7 +807,7 @@ id="clipPath168"> @@ -815,8 +815,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath170"> @@ -825,7 +825,7 @@ id="clipPath172"> @@ -833,8 +833,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath174"> @@ -843,7 +843,7 @@ id="clipPath176"> @@ -852,7 +852,7 @@ id="clipPath178"> @@ -861,7 +861,7 @@ id="clipPath180"> @@ -870,7 +870,7 @@ id="clipPath182"> @@ -879,7 +879,7 @@ id="clipPath184"> @@ -888,7 +888,7 @@ id="clipPath186"> @@ -897,7 +897,7 @@ id="clipPath188"> @@ -906,7 +906,7 @@ id="clipPath190"> @@ -915,7 +915,7 @@ id="clipPath192"> @@ -923,8 +923,8 @@ clipPathUnits="userSpaceOnUse" id="clipPath194"> @@ -933,7 +933,7 @@ id="clipPath196"> @@ -942,7 +942,7 @@ id="clipPath198"> @@ -951,7 +951,7 @@ id="clipPath200"> @@ -960,7 +960,7 @@ id="clipPath202"> @@ -969,7 +969,7 @@ id="clipPath204"> @@ -978,7 +978,7 @@ id="clipPath206"> @@ -987,7 +987,7 @@ id="clipPath208"> @@ -996,7 +996,7 @@ id="clipPath210"> @@ -1005,7 +1005,7 @@ id="clipPath212"> @@ -1014,7 +1014,7 @@ id="clipPath214"> @@ -1023,7 +1023,7 @@ id="clipPath216"> @@ -1031,15 +1031,15 @@ clipPathUnits="userSpaceOnUse" id="clipPath217"> @@ -1064,7 +1064,7 @@ id="clipPath224"> @@ -1078,13 +1078,13 @@ inkscape:pageopacity="0.0" inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" - inkscape:zoom="0.46515707" - inkscape:cx="860.99949" - inkscape:cy="125.76397" + inkscape:zoom="0.52310942" + inkscape:cx="841.12421" + inkscape:cy="268.58625" inkscape:window-width="1408" - inkscape:window-height="1212" - inkscape:window-x="629" - inkscape:window-y="100" + inkscape:window-height="1200" + inkscape:window-x="782" + inkscape:window-y="35" inkscape:window-maximized="0" inkscape:current-layer="g1"> @@ -1206,109 +1206,109 @@ id="g31" /> @@ -1332,31 +1332,31 @@ id="g61" /> @@ -1380,19 +1380,19 @@ id="g75" /> @@ -1416,55 +1416,55 @@ id="g85" /> @@ -1488,10 +1488,10 @@ id="g103" /> @@ -1515,19 +1515,19 @@ id="g111" /> @@ -1551,100 +1551,100 @@ id="g121" /> @@ -1668,250 +1668,250 @@ id="g153" /> @@ -1935,10 +1935,10 @@ id="g223" /> diff --git a/yarn-project/Dockerfile b/yarn-project/Dockerfile index 57e3ba2bca3..331795d6dc0 100644 --- a/yarn-project/Dockerfile +++ b/yarn-project/Dockerfile @@ -8,7 +8,7 @@ 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 ABIs available for the types generator, generate types, build again. +# 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. diff --git a/yarn-project/acir-simulator/src/client/client_execution_context.ts b/yarn-project/acir-simulator/src/client/client_execution_context.ts index 2627802ef89..6e21f43e9d7 100644 --- a/yarn-project/acir-simulator/src/client/client_execution_context.ts +++ b/yarn-project/acir-simulator/src/client/client_execution_context.ts @@ -11,7 +11,7 @@ import { } from '@aztec/circuits.js'; import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; -import { FunctionAbi } from '@aztec/foundation/abi'; +import { FunctionArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr, Point } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -306,8 +306,8 @@ export class ClientExecutionContext extends ViewDataOracle { `Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.storageContractAddress}`, ); - const targetAbi = await this.db.getFunctionABI(targetContractAddress, functionSelector); - const targetFunctionData = FunctionData.fromAbi(targetAbi); + const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector); + const targetFunctionData = FunctionData.fromAbi(targetArtifact); const derivedTxContext = new TxContext( false, @@ -318,7 +318,7 @@ export class ClientExecutionContext extends ViewDataOracle { this.txContext.version, ); - const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetAbi, false, false); + const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, false, false); const context = new ClientExecutionContext( targetContractAddress, @@ -336,7 +336,7 @@ export class ClientExecutionContext extends ViewDataOracle { const childExecutionResult = await executePrivateFunction( context, - targetAbi, + targetArtifact, targetContractAddress, targetFunctionData, ); @@ -360,14 +360,14 @@ export class ClientExecutionContext extends ViewDataOracle { functionSelector: FunctionSelector, argsHash: Fr, ): Promise { - const targetAbi = await this.db.getFunctionABI(targetContractAddress, functionSelector); - const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetAbi, false, false); + const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector); + const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, false, false); const args = this.packedArgsCache.unpack(argsHash); const sideEffectCounter = this.sideEffectCounter.count(); const enqueuedRequest = PublicCallRequest.from({ args, callContext: derivedCallContext, - functionData: FunctionData.fromAbi(targetAbi), + functionData: FunctionData.fromAbi(targetArtifact), contractAddress: targetContractAddress, sideEffectCounter, }); @@ -388,14 +388,14 @@ export class ClientExecutionContext extends ViewDataOracle { /** * Derives the call context for a nested execution. * @param targetContractAddress - The address of the contract being called. - * @param targetAbi - The ABI of the function being called. + * @param targetArtifact - The artifact of the function being called. * @param isDelegateCall - Whether the call is a delegate call. * @param isStaticCall - Whether the call is a static call. * @returns The derived call context. */ private async deriveCallContext( targetContractAddress: AztecAddress, - targetAbi: FunctionAbi, + targetArtifact: FunctionArtifact, isDelegateCall = false, isStaticCall = false, ) { @@ -404,7 +404,7 @@ export class ClientExecutionContext extends ViewDataOracle { this.contractAddress, targetContractAddress, portalContractAddress, - FunctionSelector.fromNameAndParameters(targetAbi.name, targetAbi.parameters), + FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters), isDelegateCall, isStaticCall, false, diff --git a/yarn-project/acir-simulator/src/client/db_oracle.ts b/yarn-project/acir-simulator/src/client/db_oracle.ts index 3a259db8693..da9233c5453 100644 --- a/yarn-project/acir-simulator/src/client/db_oracle.ts +++ b/yarn-project/acir-simulator/src/client/db_oracle.ts @@ -1,5 +1,5 @@ import { CompleteAddress, GrumpkinPrivateKey, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; -import { FunctionAbi, FunctionDebugMetadata, FunctionSelector } from '@aztec/foundation/abi'; +import { FunctionArtifact, FunctionDebugMetadata, FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -8,9 +8,9 @@ import { NoteData } from '../acvm/index.js'; import { CommitmentsDB } from '../public/index.js'; /** - * A function ABI with optional debug metadata + * A function artifact with optional debug metadata */ -export interface FunctionAbiWithDebugMetadata extends FunctionAbi { +export interface FunctionArtifactWithDebugMetadata extends FunctionArtifact { /** * Debug metadata for the function. */ @@ -59,14 +59,17 @@ export interface DBOracle extends CommitmentsDB { getNotes(contractAddress: AztecAddress, storageSlot: Fr): Promise; /** - * Retrieve the ABI information of a specific function within a contract. + * Retrieve the artifact information of a specific function within a contract. * The function is identified by its selector, which is a unique identifier generated from the function signature. * * @param contractAddress - The contract address. * @param selector - The corresponding function selector. - * @returns A Promise that resolves to a FunctionAbi object containing the ABI information of the target function. + * @returns A Promise that resolves to a FunctionArtifact object. */ - getFunctionABI(contractAddress: AztecAddress, selector: FunctionSelector): Promise; + getFunctionArtifact( + contractAddress: AztecAddress, + selector: FunctionSelector, + ): Promise; /** * Retrieves the portal contract address associated with the given contract address. diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index d861fa8c6bf..ae918a69879 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -24,7 +24,7 @@ import { } from '@aztec/circuits.js/abis'; import { pedersenPlookupCommitInputs } from '@aztec/circuits.js/barretenberg'; import { makeContractDeploymentData } from '@aztec/circuits.js/factories'; -import { FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; +import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { asyncMap } from '@aztec/foundation/async-map'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; @@ -33,14 +33,14 @@ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { AppendOnlyTree, Pedersen, StandardTree, newTree } from '@aztec/merkle-tree'; import { - ChildContractAbi, - ImportTestContractAbi, - NonNativeTokenContractAbi, - ParentContractAbi, - PendingCommitmentsContractAbi, - PrivateTokenAirdropContractAbi, - StatefulTestContractAbi, - TestContractAbi, + ChildContractArtifact, + ImportTestContractArtifact, + NonNativeTokenContractArtifact, + ParentContractArtifact, + PendingCommitmentsContractArtifact, + PrivateTokenAirdropContractArtifact, + StatefulTestContractArtifact, + TestContractArtifact, } from '@aztec/noir-contracts/artifacts'; import { PackedArguments, TxExecutionRequest } from '@aztec/types'; @@ -49,7 +49,7 @@ import { MockProxy, mock } from 'jest-mock-extended'; import { default as levelup } from 'levelup'; import { type MemDown, default as memdown } from 'memdown'; -import { buildL1ToL2Message, getFunctionAbi } from '../test/utils.js'; +import { buildL1ToL2Message, getFunctionArtifact } from '../test/utils.js'; import { computeSlotForMapping } from '../utils.js'; import { DBOracle } from './db_oracle.js'; import { AcirSimulator } from './simulator.js'; @@ -90,22 +90,22 @@ describe('Private Execution test suite', () => { }; const runSimulator = async ({ - abi, + artifact, args = [], msgSender = AztecAddress.ZERO, contractAddress = defaultContractAddress, portalContractAddress = EthAddress.ZERO, txContext = {}, }: { - abi: FunctionAbi; + artifact: FunctionArtifact; msgSender?: AztecAddress; contractAddress?: AztecAddress; portalContractAddress?: EthAddress; args?: any[]; txContext?: Partial>; }) => { - const packedArguments = await PackedArguments.fromArgs(encodeArguments(abi, args), circuitsWasm); - const functionData = FunctionData.fromAbi(abi); + const packedArguments = await PackedArguments.fromArgs(encodeArguments(artifact, args), circuitsWasm); + const functionData = FunctionData.fromAbi(artifact); const txRequest = TxExecutionRequest.from({ origin: contractAddress, argsHash: packedArguments.hash, @@ -117,7 +117,7 @@ describe('Private Execution test suite', () => { return acirSimulator.run( txRequest, - abi, + artifact, functionData.isConstructor ? AztecAddress.ZERO : contractAddress, portalContractAddress, msgSender, @@ -179,10 +179,10 @@ describe('Private Execution test suite', () => { describe('empty constructor', () => { it('should run the empty constructor', async () => { - const abi = getFunctionAbi(TestContractAbi, 'constructor'); + const artifact = getFunctionArtifact(TestContractArtifact, 'constructor'); const contractDeploymentData = makeContractDeploymentData(100); const txContext = { isContractDeploymentTx: true, contractDeploymentData }; - const result = await runSimulator({ abi, txContext }); + const result = await runSimulator({ artifact, txContext }); const emptyCommitments = new Array(MAX_NEW_COMMITMENTS_PER_CALL).fill(Fr.ZERO); expect(result.callStackItem.publicInputs.newCommitments).toEqual(emptyCommitments); @@ -226,16 +226,16 @@ describe('Private Execution test suite', () => { throw new Error(`Unknown address ${address}`); }); - oracle.getFunctionABI.mockImplementation((_, selector) => + oracle.getFunctionArtifact.mockImplementation((_, selector) => Promise.resolve( - PrivateTokenAirdropContractAbi.functions.find(f => + PrivateTokenAirdropContractArtifact.functions.find(f => selector.equals(FunctionSelector.fromNameAndParameters(f.name, f.parameters)), )!, ), ); }); - it('should have an abi for computing note hash and nullifier', async () => { + it('should have an artifact for computing note hash and nullifier', async () => { const storageSlot = Fr.random(); const note = buildNote(60n, owner, storageSlot); @@ -262,9 +262,9 @@ describe('Private Execution test suite', () => { }); it('should a constructor with arguments that inserts notes', async () => { - const abi = getFunctionAbi(PrivateTokenAirdropContractAbi, 'constructor'); + const artifact = getFunctionArtifact(PrivateTokenAirdropContractArtifact, 'constructor'); - const result = await runSimulator({ args: [140, owner], abi }); + const result = await runSimulator({ args: [140, owner], artifact }); expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; @@ -280,9 +280,9 @@ describe('Private Execution test suite', () => { }); it('should run the mint function', async () => { - const abi = getFunctionAbi(PrivateTokenAirdropContractAbi, 'mint'); + const artifact = getFunctionArtifact(PrivateTokenAirdropContractArtifact, 'mint'); - const result = await runSimulator({ args: [140, owner], abi }); + const result = await runSimulator({ args: [140, owner], artifact }); expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; @@ -299,7 +299,7 @@ describe('Private Execution test suite', () => { it('should run the transfer function', async () => { const amountToTransfer = 100n; - const abi = getFunctionAbi(PrivateTokenAirdropContractAbi, 'transfer'); + const artifact = getFunctionArtifact(PrivateTokenAirdropContractArtifact, 'transfer'); const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField(), circuitsWasm); @@ -313,7 +313,7 @@ describe('Private Execution test suite', () => { await insertLeaves(consumedNotes.map(n => n.siloedNoteHash)); const args = [amountToTransfer, recipient]; - const result = await runSimulator({ args, abi, msgSender: owner }); + const result = await runSimulator({ args, artifact, msgSender: owner }); // The two notes were nullified const newNullifiers = result.callStackItem.publicInputs.newNullifiers.filter(field => !field.equals(Fr.ZERO)); @@ -346,7 +346,7 @@ describe('Private Execution test suite', () => { it('should be able to transfer with dummy notes', async () => { const amountToTransfer = 100n; const balance = 160n; - const abi = getFunctionAbi(PrivateTokenAirdropContractAbi, 'transfer'); + const artifact = getFunctionArtifact(PrivateTokenAirdropContractArtifact, 'transfer'); const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); @@ -359,7 +359,7 @@ describe('Private Execution test suite', () => { await insertLeaves(consumedNotes.map(n => n.siloedNoteHash)); const args = [amountToTransfer, recipient]; - const result = await runSimulator({ args, abi, msgSender: owner }); + const result = await runSimulator({ args, artifact, msgSender: owner }); const newNullifiers = result.callStackItem.publicInputs.newNullifiers.filter(field => !field.equals(Fr.ZERO)); expect(newNullifiers).toEqual(consumedNotes.map(n => n.innerNullifier)); @@ -407,16 +407,16 @@ describe('Private Execution test suite', () => { throw new Error(`Unknown address ${address}`); }); - oracle.getFunctionABI.mockImplementation((_, selector) => + oracle.getFunctionArtifact.mockImplementation((_, selector) => Promise.resolve( - StatefulTestContractAbi.functions.find(f => + StatefulTestContractArtifact.functions.find(f => selector.equals(FunctionSelector.fromNameAndParameters(f.name, f.parameters)), )!, ), ); }); - it('should have an abi for computing note hash and nullifier', async () => { + it('should have an artifact for computing note hash and nullifier', async () => { const storageSlot = Fr.random(); const note = buildNote(60n, owner, storageSlot); @@ -443,9 +443,9 @@ describe('Private Execution test suite', () => { }); it('should a constructor with arguments that inserts notes', async () => { - const abi = getFunctionAbi(StatefulTestContractAbi, 'constructor'); + const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'constructor'); - const result = await runSimulator({ args: [owner, 140], abi }); + const result = await runSimulator({ args: [owner, 140], artifact }); expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; @@ -461,9 +461,9 @@ describe('Private Execution test suite', () => { }); it('should run the create_note function', async () => { - const abi = getFunctionAbi(StatefulTestContractAbi, 'create_note'); + const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'create_note'); - const result = await runSimulator({ args: [owner, 140], abi }); + const result = await runSimulator({ args: [owner, 140], artifact }); expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; @@ -480,7 +480,7 @@ describe('Private Execution test suite', () => { it('should run the destroy_and_create function', async () => { const amountToTransfer = 100n; - const abi = getFunctionAbi(StatefulTestContractAbi, 'destroy_and_create'); + const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField(), circuitsWasm); @@ -494,7 +494,7 @@ describe('Private Execution test suite', () => { await insertLeaves(consumedNotes.map(n => n.siloedNoteHash)); const args = [recipient, amountToTransfer]; - const result = await runSimulator({ args, abi, msgSender: owner }); + const result = await runSimulator({ args, artifact, msgSender: owner }); // The two notes were nullified const newNullifiers = result.callStackItem.publicInputs.newNullifiers.filter(field => !field.equals(Fr.ZERO)); @@ -527,7 +527,7 @@ describe('Private Execution test suite', () => { it('should be able to destroy_and_create with dummy notes', async () => { const amountToTransfer = 100n; const balance = 160n; - const abi = getFunctionAbi(StatefulTestContractAbi, 'destroy_and_create'); + const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); @@ -540,7 +540,7 @@ describe('Private Execution test suite', () => { await insertLeaves(consumedNotes.map(n => n.siloedNoteHash)); const args = [recipient, amountToTransfer]; - const result = await runSimulator({ args, abi, msgSender: owner }); + const result = await runSimulator({ args, artifact, msgSender: owner }); const newNullifiers = result.callStackItem.publicInputs.newNullifiers.filter(field => !field.equals(Fr.ZERO)); expect(newNullifiers).toEqual(consumedNotes.map(n => n.innerNullifier)); @@ -557,30 +557,30 @@ describe('Private Execution test suite', () => { it('child function should be callable', async () => { const initialValue = 100n; - const abi = getFunctionAbi(ChildContractAbi, 'value'); - const result = await runSimulator({ args: [initialValue], abi }); + const artifact = getFunctionArtifact(ChildContractArtifact, 'value'); + const result = await runSimulator({ args: [initialValue], artifact }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(initialValue + privateIncrement)); }); it('parent should call child', async () => { - const childAbi = getFunctionAbi(ChildContractAbi, 'value'); - const parentAbi = getFunctionAbi(ParentContractAbi, 'entryPoint'); + const childArtifact = getFunctionArtifact(ChildContractArtifact, 'value'); + const parentArtifact = getFunctionArtifact(ParentContractArtifact, 'entryPoint'); const parentAddress = AztecAddress.random(); const childAddress = AztecAddress.random(); - const childSelector = FunctionSelector.fromNameAndParameters(childAbi.name, childAbi.parameters); + const childSelector = FunctionSelector.fromNameAndParameters(childArtifact.name, childArtifact.parameters); - oracle.getFunctionABI.mockImplementation(() => Promise.resolve(childAbi)); + oracle.getFunctionArtifact.mockImplementation(() => Promise.resolve(childArtifact)); oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); logger(`Parent deployed at ${parentAddress.toShortString()}`); logger(`Calling child function ${childSelector.toString()} at ${childAddress.toShortString()}`); const args = [Fr.fromBuffer(childAddress.toBuffer()), Fr.fromBuffer(childSelector.toBuffer())]; - const result = await runSimulator({ args, abi: parentAbi }); + const result = await runSimulator({ args, artifact: parentArtifact }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(privateIncrement)); - expect(oracle.getFunctionABI.mock.calls[0]).toEqual([childAddress, childSelector]); + expect(oracle.getFunctionArtifact.mock.calls[0]).toEqual([childAddress, childSelector]); expect(oracle.getPortalContractAddress.mock.calls[0]).toEqual([childAddress]); expect(result.nestedExecutions).toHaveLength(1); expect(result.nestedExecutions[0].callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(privateIncrement)); @@ -595,42 +595,42 @@ describe('Private Execution test suite', () => { describe('nested calls through autogenerated interface', () => { let args: any[]; let argsHash: Fr; - let testCodeGenAbi: FunctionAbi; + let testCodeGenArtifact: FunctionArtifact; beforeAll(async () => { // These args should match the ones hardcoded in importer contract const dummyNote = { amount: 1, secretHash: 2 }; const deepStruct = { aField: 1, aBool: true, aNote: dummyNote, manyNotes: [dummyNote, dummyNote, dummyNote] }; args = [1, true, 1, [1, 2], dummyNote, deepStruct]; - testCodeGenAbi = TestContractAbi.functions.find(f => f.name === 'testCodeGen')!; - const serializedArgs = encodeArguments(testCodeGenAbi, args); + testCodeGenArtifact = TestContractArtifact.functions.find(f => f.name === 'testCodeGen')!; + const serializedArgs = encodeArguments(testCodeGenArtifact, args); argsHash = await computeVarArgsHash(await CircuitsWasm.get(), serializedArgs); }); it('test function should be directly callable', async () => { logger(`Calling testCodeGen function`); - const result = await runSimulator({ args, abi: testCodeGenAbi }); + const result = await runSimulator({ args, artifact: testCodeGenArtifact }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(argsHash); }); it('test function should be callable through autogenerated interface', async () => { const testAddress = AztecAddress.random(); - const parentAbi = ImportTestContractAbi.functions.find(f => f.name === 'main')!; + const parentArtifact = ImportTestContractArtifact.functions.find(f => f.name === 'main')!; const testCodeGenSelector = FunctionSelector.fromNameAndParameters( - testCodeGenAbi.name, - testCodeGenAbi.parameters, + testCodeGenArtifact.name, + testCodeGenArtifact.parameters, ); - oracle.getFunctionABI.mockResolvedValue(testCodeGenAbi); + oracle.getFunctionArtifact.mockResolvedValue(testCodeGenArtifact); oracle.getPortalContractAddress.mockResolvedValue(EthAddress.ZERO); logger(`Calling importer main function`); const args = [testAddress]; - const result = await runSimulator({ args, abi: parentAbi }); + const result = await runSimulator({ args, artifact: parentArtifact }); expect(result.callStackItem.publicInputs.returnValues[0]).toEqual(argsHash); - expect(oracle.getFunctionABI.mock.calls[0]).toEqual([testAddress, testCodeGenSelector]); + expect(oracle.getFunctionArtifact.mock.calls[0]).toEqual([testAddress, testCodeGenSelector]); expect(oracle.getPortalContractAddress.mock.calls[0]).toEqual([testAddress]); expect(result.nestedExecutions).toHaveLength(1); expect(result.nestedExecutions[0].callStackItem.publicInputs.returnValues[0]).toEqual(argsHash); @@ -649,7 +649,7 @@ describe('Private Execution test suite', () => { it('Should be able to consume a dummy cross chain message', async () => { const bridgedAmount = 100n; - const abi = getFunctionAbi(NonNativeTokenContractAbi, 'mint'); + const artifact = getFunctionArtifact(NonNativeTokenContractArtifact, 'mint'); const secret = new Fr(1n); const canceller = EthAddress.random(); @@ -674,7 +674,7 @@ describe('Private Execution test suite', () => { }); const args = [bridgedAmount, recipient, messageKey, secret, canceller.toField()]; - const result = await runSimulator({ contractAddress, abi, args }); + const result = await runSimulator({ contractAddress, artifact, args }); // Check a nullifier has been inserted const newNullifiers = result.callStackItem.publicInputs.newNullifiers.filter(field => !field.equals(Fr.ZERO)); @@ -683,7 +683,7 @@ describe('Private Execution test suite', () => { it('Should be able to consume a dummy public to private message', async () => { const amount = 100n; - const abi = getFunctionAbi(NonNativeTokenContractAbi, 'redeemShield'); + const artifact = getFunctionArtifact(NonNativeTokenContractArtifact, 'redeemShield'); const wasm = await CircuitsWasm.get(); const secret = new Fr(1n); @@ -706,7 +706,7 @@ describe('Private Execution test suite', () => { ]); const result = await runSimulator({ - abi, + artifact, args: [amount, secret, recipient], }); @@ -723,26 +723,29 @@ describe('Private Execution test suite', () => { describe('enqueued calls', () => { it.each([false, true])('parent should enqueue call to child (internal %p)', async isInternal => { - const parentAbi = ParentContractAbi.functions.find(f => f.name === 'enqueueCallToChild')!; - const childContractAbi = ParentContractAbi.functions[0]; + const parentArtifact = ParentContractArtifact.functions.find(f => f.name === 'enqueueCallToChild')!; + const childContractArtifact = ParentContractArtifact.functions[0]; const childAddress = AztecAddress.random(); const childPortalContractAddress = EthAddress.random(); - const childSelector = FunctionSelector.fromNameAndParameters(childContractAbi.name, childContractAbi.parameters); + const childSelector = FunctionSelector.fromNameAndParameters( + childContractArtifact.name, + childContractArtifact.parameters, + ); const parentAddress = AztecAddress.random(); oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(childPortalContractAddress)); - oracle.getFunctionABI.mockImplementation(() => Promise.resolve({ ...childContractAbi, isInternal })); + oracle.getFunctionArtifact.mockImplementation(() => Promise.resolve({ ...childContractArtifact, isInternal })); const args = [Fr.fromBuffer(childAddress.toBuffer()), childSelector.toField(), 42n]; const result = await runSimulator({ msgSender: parentAddress, contractAddress: parentAddress, - abi: parentAbi, + artifact: parentArtifact, args, }); - // Alter function data (abi) to match the manipulated oracle - const functionData = FunctionData.fromAbi(childContractAbi); + // Alter function data to match the manipulated oracle + const functionData = FunctionData.fromAbi(childContractArtifact); functionData.isInternal = isInternal; const publicCallRequest = PublicCallRequest.from({ @@ -781,9 +784,9 @@ describe('Private Execution test suite', () => { }); beforeEach(() => { - oracle.getFunctionABI.mockImplementation((_, selector) => + oracle.getFunctionArtifact.mockImplementation((_, selector) => Promise.resolve( - PendingCommitmentsContractAbi.functions.find(f => + PendingCommitmentsContractArtifact.functions.find(f => selector.equals(FunctionSelector.fromNameAndParameters(f.name, f.parameters)), )!, ), @@ -796,14 +799,14 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const contractAddress = AztecAddress.random(); - const abi = PendingCommitmentsContractAbi.functions.find( + const artifact = PendingCommitmentsContractArtifact.functions.find( f => f.name === 'test_insert_then_get_then_nullify_flat', )!; const args = [amountToTransfer, owner]; const result = await runSimulator({ args: args, - abi: abi, + artifact: artifact, contractAddress, }); @@ -839,19 +842,26 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const contractAddress = AztecAddress.random(); - const abi = PendingCommitmentsContractAbi.functions.find( + const artifact = PendingCommitmentsContractArtifact.functions.find( f => f.name === 'test_insert_then_get_then_nullify_all_in_nested_calls', )!; - const insertAbi = PendingCommitmentsContractAbi.functions.find(f => f.name === 'insert_note')!; - const getThenNullifyAbi = PendingCommitmentsContractAbi.functions.find(f => f.name === 'get_then_nullify_note')!; - const getZeroAbi = PendingCommitmentsContractAbi.functions.find(f => f.name === 'get_note_zero_balance')!; + const insertArtifact = PendingCommitmentsContractArtifact.functions.find(f => f.name === 'insert_note')!; + const getThenNullifyArtifact = PendingCommitmentsContractArtifact.functions.find( + f => f.name === 'get_then_nullify_note', + )!; + const getZeroArtifact = PendingCommitmentsContractArtifact.functions.find( + f => f.name === 'get_note_zero_balance', + )!; - const insertFnSelector = FunctionSelector.fromNameAndParameters(insertAbi.name, insertAbi.parameters); + const insertFnSelector = FunctionSelector.fromNameAndParameters(insertArtifact.name, insertArtifact.parameters); const getThenNullifyFnSelector = FunctionSelector.fromNameAndParameters( - getThenNullifyAbi.name, - getThenNullifyAbi.parameters, + getThenNullifyArtifact.name, + getThenNullifyArtifact.parameters, + ); + const getZeroFnSelector = FunctionSelector.fromNameAndParameters( + getZeroArtifact.name, + getZeroArtifact.parameters, ); - const getZeroFnSelector = FunctionSelector.fromNameAndParameters(getZeroAbi.name, getZeroAbi.parameters); oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); @@ -864,7 +874,7 @@ describe('Private Execution test suite', () => { ]; const result = await runSimulator({ args: args, - abi: abi, + artifact: artifact, contractAddress: contractAddress, }); @@ -910,12 +920,14 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const contractAddress = AztecAddress.random(); - const abi = PendingCommitmentsContractAbi.functions.find(f => f.name === 'test_bad_get_then_insert_flat')!; + const artifact = PendingCommitmentsContractArtifact.functions.find( + f => f.name === 'test_bad_get_then_insert_flat', + )!; const args = [amountToTransfer, owner]; const result = await runSimulator({ args: args, - abi: abi, + artifact: artifact, contractAddress, }); @@ -948,9 +960,9 @@ describe('Private Execution test suite', () => { describe('get public key', () => { it('gets the public key for an address', async () => { - // Tweak the contract ABI so we can extract return values - const abi = getFunctionAbi(TestContractAbi, 'getPublicKey'); - abi.returnTypes = [{ kind: 'array', length: 2, type: { kind: 'field' } }]; + // Tweak the contract artifact so we can extract return values + const artifact = getFunctionArtifact(TestContractArtifact, 'getPublicKey'); + artifact.returnTypes = [{ kind: 'array', length: 2, type: { kind: 'field' } }]; // Generate a partial address, pubkey, and resulting address const completeAddress = await CompleteAddress.random(); @@ -958,7 +970,7 @@ describe('Private Execution test suite', () => { const pubKey = completeAddress.publicKey; oracle.getCompleteAddress.mockResolvedValue(completeAddress); - const result = await runSimulator({ abi, args }); + const result = await runSimulator({ artifact, args }); expect(result.returnValues).toEqual([pubKey.x.value, pubKey.y.value]); }); }); @@ -968,39 +980,39 @@ describe('Private Execution test suite', () => { const portalContractAddress = EthAddress.random(); const aztecAddressToQuery = AztecAddress.random(); - // Tweak the contract ABI so we can extract return values - const abi = getFunctionAbi(TestContractAbi, 'getPortalContractAddress'); - abi.returnTypes = [{ kind: 'field' }]; + // Tweak the contract artifact so we can extract return values + const artifact = getFunctionArtifact(TestContractArtifact, 'getPortalContractAddress'); + artifact.returnTypes = [{ kind: 'field' }]; const args = [aztecAddressToQuery.toField()]; // Overwrite the oracle return value oracle.getPortalContractAddress.mockResolvedValue(portalContractAddress); - const result = await runSimulator({ abi, args }); + const result = await runSimulator({ artifact, args }); expect(result.returnValues).toEqual(portalContractAddress.toField().value); }); it('this_address should return the current context address', async () => { const contractAddress = AztecAddress.random(); - // Tweak the contract ABI so we can extract return values - const abi = getFunctionAbi(TestContractAbi, 'getThisAddress'); - abi.returnTypes = [{ kind: 'field' }]; + // Tweak the contract artifact so we can extract return values + const artifact = getFunctionArtifact(TestContractArtifact, 'getThisAddress'); + artifact.returnTypes = [{ kind: 'field' }]; // Overwrite the oracle return value - const result = await runSimulator({ abi, args: [], contractAddress }); + const result = await runSimulator({ artifact, args: [], contractAddress }); expect(result.returnValues).toEqual(contractAddress.toField().value); }); it("this_portal_address should return the current context's portal address", async () => { const portalContractAddress = EthAddress.random(); - // Tweak the contract ABI so we can extract return values - const abi = getFunctionAbi(TestContractAbi, 'getThisPortalAddress'); - abi.returnTypes = [{ kind: 'field' }]; + // Tweak the contract artifact so we can extract return values + const artifact = getFunctionArtifact(TestContractArtifact, 'getThisPortalAddress'); + artifact.returnTypes = [{ kind: 'field' }]; // Overwrite the oracle return value - const result = await runSimulator({ abi, args: [], portalContractAddress }); + const result = await runSimulator({ artifact, args: [], portalContractAddress }); expect(result.returnValues).toEqual(portalContractAddress.toField().value); }); }); diff --git a/yarn-project/acir-simulator/src/client/private_execution.ts b/yarn-project/acir-simulator/src/client/private_execution.ts index 3de7e625b5f..c6e8483641a 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.ts @@ -9,7 +9,7 @@ import { extractPrivateCircuitPublicInputs } from '../acvm/deserialize.js'; import { Oracle, acvm, extractCallStack } from '../acvm/index.js'; import { ExecutionError } from '../common/errors.js'; import { ClientExecutionContext } from './client_execution_context.js'; -import { FunctionAbiWithDebugMetadata } from './db_oracle.js'; +import { FunctionArtifactWithDebugMetadata } from './db_oracle.js'; import { ExecutionResult } from './execution_result.js'; import { AcirSimulator } from './simulator.js'; @@ -18,7 +18,7 @@ import { AcirSimulator } from './simulator.js'; */ export async function executePrivateFunction( context: ClientExecutionContext, - abi: FunctionAbiWithDebugMetadata, + artifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, functionData: FunctionData, log = createDebugLogger('aztec:simulator:secret_execution'), @@ -26,7 +26,7 @@ export async function executePrivateFunction( const functionSelector = functionData.selector; log(`Executing external function ${contractAddress}:${functionSelector}`); - const acir = Buffer.from(abi.bytecode, 'base64'); + const acir = Buffer.from(artifact.bytecode, 'base64'); const initialWitness = context.getInitialWitness(); const acvmCallback = new Oracle(context); const { partialWitness } = await acvm(await AcirSimulator.getSolver(), acir, initialWitness, acvmCallback).catch( @@ -37,7 +37,7 @@ export async function executePrivateFunction( contractAddress, functionSelector, }, - extractCallStack(err, abi.debug), + extractCallStack(err, artifact.debug), { cause: err }, ); }, @@ -54,7 +54,7 @@ export async function executePrivateFunction( publicInputs.unencryptedLogPreimagesLength = new Fr(unencryptedLogs.getSerializedLength()); const callStackItem = new PrivateCallStackItem(contractAddress, functionData, publicInputs, false); - const returnValues = decodeReturnValues(abi, publicInputs.returnValues); + const returnValues = decodeReturnValues(artifact, publicInputs.returnValues); const readRequestPartialWitnesses = context.getReadRequestPartialWitnesses(publicInputs.readRequests); const newNotes = context.getNewNotes(); const nestedExecutions = context.getNestedExecutions(); @@ -69,7 +69,7 @@ export async function executePrivateFunction( returnValues, readRequestPartialWitnesses, newNotes, - vk: Buffer.from(abi.verificationKey!, 'hex'), + vk: Buffer.from(artifact.verificationKey!, 'hex'), nestedExecutions, enqueuedPublicFunctionCalls, encryptedLogs, diff --git a/yarn-project/acir-simulator/src/client/simulator.ts b/yarn-project/acir-simulator/src/client/simulator.ts index 2679f15e02a..46521e35c60 100644 --- a/yarn-project/acir-simulator/src/client/simulator.ts +++ b/yarn-project/acir-simulator/src/client/simulator.ts @@ -13,7 +13,7 @@ import { createSimulationError } from '../common/errors.js'; import { SideEffectCounter } from '../common/index.js'; import { PackedArgsCache } from '../common/packed_args_cache.js'; import { ClientExecutionContext } from './client_execution_context.js'; -import { DBOracle, FunctionAbiWithDebugMetadata } from './db_oracle.js'; +import { DBOracle, FunctionArtifactWithDebugMetadata } from './db_oracle.js'; import { ExecutionNoteCache } from './execution_note_cache.js'; import { ExecutionResult } from './execution_result.js'; import { executePrivateFunction } from './private_execution.js'; @@ -52,7 +52,7 @@ export class AcirSimulator { /** * Runs a private function. * @param request - The transaction request. - * @param entryPointABI - The ABI of the entry point function. + * @param entryPointArtifact - The artifact of the entry point function. * @param contractAddress - The address of the contract (should match request.origin) * @param portalContractAddress - The address of the portal contract. * @param msgSender - The address calling the function. This can be replaced to simulate a call from another contract or a specific account. @@ -60,13 +60,13 @@ export class AcirSimulator { */ public async run( request: TxExecutionRequest, - entryPointABI: FunctionAbiWithDebugMetadata, + entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, portalContractAddress: EthAddress, msgSender = AztecAddress.ZERO, ): Promise { - if (entryPointABI.functionType !== FunctionType.SECRET) { - throw new Error(`Cannot run ${entryPointABI.functionType} function as secret`); + if (entryPointArtifact.functionType !== FunctionType.SECRET) { + throw new Error(`Cannot run ${entryPointArtifact.functionType} function as secret`); } if (request.origin !== contractAddress) { @@ -82,7 +82,7 @@ export class AcirSimulator { msgSender, contractAddress, portalContractAddress, - FunctionSelector.fromNameAndParameters(entryPointABI.name, entryPointABI.parameters), + FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters), false, false, request.functionData.isConstructor, @@ -104,7 +104,7 @@ export class AcirSimulator { try { const executionResult = await executePrivateFunction( context, - entryPointABI, + entryPointArtifact, contractAddress, request.functionData, ); @@ -117,18 +117,18 @@ export class AcirSimulator { /** * Runs an unconstrained function. * @param request - The transaction request. - * @param entryPointABI - The ABI of the entry point function. + * @param entryPointArtifact - The artifact of the entry point function. * @param contractAddress - The address of the contract. * @param aztecNode - The AztecNode instance. */ public async runUnconstrained( request: FunctionCall, - entryPointABI: FunctionAbiWithDebugMetadata, + entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, aztecNode?: AztecNode, ) { - if (entryPointABI.functionType !== FunctionType.UNCONSTRAINED) { - throw new Error(`Cannot run ${entryPointABI.functionType} function as constrained`); + if (entryPointArtifact.functionType !== FunctionType.UNCONSTRAINED) { + throw new Error(`Cannot run ${entryPointArtifact.functionType} function as constrained`); } const historicBlockData = await this.db.getHistoricBlockData(); @@ -137,7 +137,7 @@ export class AcirSimulator { try { return await executeUnconstrainedFunction( context, - entryPointABI, + entryPointArtifact, contractAddress, request.functionData, request.args, @@ -161,38 +161,38 @@ export class AcirSimulator { storageSlot: Fr, notePreimage: Fr[], ) { - let abi: FunctionAbiWithDebugMetadata | undefined = undefined; + let artifact: FunctionArtifactWithDebugMetadata | undefined = undefined; // Brute force for (let i = notePreimage.length; i < MAX_NOTE_FIELDS_LENGTH; i++) { const signature = `compute_note_hash_and_nullifier(Field,Field,Field,[Field;${i}])`; const selector = FunctionSelector.fromSignature(signature); try { - abi = await this.db.getFunctionABI(contractAddress, selector); - if (abi !== undefined) break; + artifact = await this.db.getFunctionArtifact(contractAddress, selector); + if (artifact !== undefined) break; } catch (e) { // ignore } } - if (abi == undefined) { + if (artifact == undefined) { throw new Error( `Mandatory implementation of "compute_note_hash_and_nullifier" missing in noir contract ${contractAddress.toString()}.`, ); } - const preimageLen = (abi.parameters[3].type as ArrayType).length; + const preimageLen = (artifact.parameters[3].type as ArrayType).length; const extendedPreimage = notePreimage.concat(Array(preimageLen - notePreimage.length).fill(Fr.ZERO)); const execRequest: FunctionCall = { to: AztecAddress.ZERO, functionData: FunctionData.empty(), - args: encodeArguments(abi, [contractAddress, nonce, storageSlot, extendedPreimage]), + args: encodeArguments(artifact, [contractAddress, nonce, storageSlot, extendedPreimage]), }; const [innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier] = (await this.runUnconstrained( execRequest, - abi, + artifact, AztecAddress.ZERO, )) as bigint[]; @@ -209,7 +209,6 @@ export class AcirSimulator { * @param contractAddress - The address of the contract. * @param storageSlot - The storage slot. * @param notePreimage - The note preimage. - * @param abi - The ABI of the function `compute_note_hash`. * @returns The note hash. */ public async computeInnerNoteHash(contractAddress: AztecAddress, storageSlot: Fr, notePreimage: Fr[]) { @@ -228,7 +227,6 @@ export class AcirSimulator { * @param nonce - The nonce of the note hash. * @param storageSlot - The storage slot. * @param notePreimage - The note preimage. - * @param abi - The ABI of the function `compute_note_hash`. * @returns The note hash. */ public async computeUniqueSiloedNoteHash( @@ -252,7 +250,6 @@ export class AcirSimulator { * @param nonce - The nonce of the note hash. * @param storageSlot - The storage slot. * @param notePreimage - The note preimage. - * @param abi - The ABI of the function `compute_note_hash`. * @returns The note hash. */ public async computeSiloedNoteHash(contractAddress: AztecAddress, nonce: Fr, storageSlot: Fr, notePreimage: Fr[]) { @@ -271,7 +268,6 @@ export class AcirSimulator { * @param nonce - The nonce of the unique note hash. * @param storageSlot - The storage slot. * @param notePreimage - The note preimage. - * @param abi - The ABI of the function `compute_note_hash`. * @returns The note hash. */ public async computeInnerNullifier(contractAddress: AztecAddress, nonce: Fr, storageSlot: Fr, notePreimage: Fr[]) { diff --git a/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts b/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts index 2cb8fa654ac..34a4a9ced6e 100644 --- a/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/unconstrained_execution.test.ts @@ -2,7 +2,7 @@ import { CompleteAddress, FunctionData, HistoricBlockData } from '@aztec/circuit import { FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; -import { StatefulTestContractAbi } from '@aztec/noir-contracts/artifacts'; +import { StatefulTestContractArtifact } from '@aztec/noir-contracts/artifacts'; import { FunctionCall } from '@aztec/types'; import { mock } from 'jest-mock-extended'; @@ -40,7 +40,7 @@ describe('Unconstrained Execution test suite', () => { it('should run the summed_values function', async () => { const contractAddress = AztecAddress.random(); - const abi = StatefulTestContractAbi.functions.find(f => f.name === 'summed_values')!; + const artifact = StatefulTestContractArtifact.functions.find(f => f.name === 'summed_values')!; const preimages = [...Array(5).fill(buildNote(1n, owner)), ...Array(2).fill(buildNote(2n, owner))]; @@ -61,10 +61,10 @@ describe('Unconstrained Execution test suite', () => { const execRequest: FunctionCall = { to: contractAddress, functionData: new FunctionData(FunctionSelector.empty(), false, true, true), - args: encodeArguments(abi, [owner]), + args: encodeArguments(artifact, [owner]), }; - const result = await acirSimulator.runUnconstrained(execRequest, abi, AztecAddress.random()); + const result = await acirSimulator.runUnconstrained(execRequest, artifact, AztecAddress.random()); expect(result).toEqual(9n); }, 30_000); diff --git a/yarn-project/acir-simulator/src/client/unconstrained_execution.ts b/yarn-project/acir-simulator/src/client/unconstrained_execution.ts index 85504664c83..d197ec386fb 100644 --- a/yarn-project/acir-simulator/src/client/unconstrained_execution.ts +++ b/yarn-project/acir-simulator/src/client/unconstrained_execution.ts @@ -8,7 +8,7 @@ import { extractReturnWitness } from '../acvm/deserialize.js'; import { ACVMField, Oracle, acvm, extractCallStack, fromACVMField, toACVMWitness } from '../acvm/index.js'; import { ExecutionError } from '../common/errors.js'; import { AcirSimulator } from '../index.js'; -import { FunctionAbiWithDebugMetadata } from './db_oracle.js'; +import { FunctionArtifactWithDebugMetadata } from './db_oracle.js'; import { ViewDataOracle } from './view_data_oracle.js'; /** @@ -16,7 +16,7 @@ import { ViewDataOracle } from './view_data_oracle.js'; */ export async function executeUnconstrainedFunction( oracle: ViewDataOracle, - abi: FunctionAbiWithDebugMetadata, + artifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, functionData: FunctionData, args: Fr[], @@ -25,7 +25,7 @@ export async function executeUnconstrainedFunction( const functionSelector = functionData.selector; log(`Executing unconstrained function ${contractAddress}:${functionSelector}`); - const acir = Buffer.from(abi.bytecode, 'base64'); + const acir = Buffer.from(artifact.bytecode, 'base64'); const initialWitness = toACVMWitness(1, args); const { partialWitness } = await acvm( await AcirSimulator.getSolver(), @@ -39,11 +39,11 @@ export async function executeUnconstrainedFunction( contractAddress, functionSelector, }, - extractCallStack(err, abi.debug), + extractCallStack(err, artifact.debug), { cause: err }, ); }); const returnValues: ACVMField[] = extractReturnWitness(acir, partialWitness); - return decodeReturnValues(abi, returnValues.map(fromACVMField)); + return decodeReturnValues(artifact, returnValues.map(fromACVMField)); } diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 24fb47cad49..c8bb5c90924 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -8,17 +8,17 @@ import { L1_TO_L2_MSG_TREE_HEIGHT, } from '@aztec/circuits.js'; import { pedersenPlookupCommitInputs } from '@aztec/circuits.js/barretenberg'; -import { FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; +import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { toBigInt } from '@aztec/foundation/serialize'; import { - ChildContractAbi, - NonNativeTokenContractAbi, - ParentContractAbi, - PublicTokenContractAbi, - TestContractAbi, + ChildContractArtifact, + NonNativeTokenContractArtifact, + ParentContractArtifact, + PublicTokenContractArtifact, + TestContractArtifact, } from '@aztec/noir-contracts/artifacts'; import { MockProxy, mock } from 'jest-mock-extended'; @@ -63,9 +63,9 @@ describe('ACIR public execution simulator', () => { describe('mint', () => { it('should run the mint function', async () => { const contractAddress = AztecAddress.random(); - const mintAbi = PublicTokenContractAbi.functions.find(f => f.name === 'mint')!; - const functionData = FunctionData.fromAbi(mintAbi); - const args = encodeArguments(mintAbi, [140, recipient]); + const mintArtifact = PublicTokenContractArtifact.functions.find(f => f.name === 'mint')!; + const functionData = FunctionData.fromAbi(mintArtifact); + const args = encodeArguments(mintArtifact, [140, recipient]); const callContext = CallContext.from({ msgSender: AztecAddress.random(), @@ -77,7 +77,7 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintAbi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintArtifact.bytecode, 'base64')); // Mock the old value for the recipient balance to be 20 const previousBalance = new Fr(20n); @@ -100,7 +100,7 @@ describe('ACIR public execution simulator', () => { describe('transfer', () => { let contractAddress: AztecAddress; - let abi: FunctionAbi; + let artifact: FunctionArtifact; let functionData: FunctionData; let args: Fr[]; let sender: AztecAddress; @@ -111,9 +111,9 @@ describe('ACIR public execution simulator', () => { beforeEach(() => { contractAddress = AztecAddress.random(); - abi = PublicTokenContractAbi.functions.find(f => f.name === 'transfer')!; + artifact = PublicTokenContractArtifact.functions.find(f => f.name === 'transfer')!; functionData = new FunctionData(FunctionSelector.empty(), false, false, false); - args = encodeArguments(abi, [140, recipient]); + args = encodeArguments(artifact, [140, recipient]); sender = AztecAddress.random(); callContext = CallContext.from({ @@ -129,7 +129,7 @@ describe('ACIR public execution simulator', () => { recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField(), circuitsWasm); senderStorageSlot = computeSlotForMapping(new Fr(1n), Fr.fromBuffer(sender.toBuffer()), circuitsWasm); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(abi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(artifact.bytecode, 'base64')); execution = { contractAddress, functionData, args, callContext }; }); @@ -202,14 +202,14 @@ describe('ACIR public execution simulator', () => { 'calls the public entry point in the parent', async isInternal => { const parentContractAddress = AztecAddress.random(); - const parentEntryPointFn = ParentContractAbi.functions.find(f => f.name === 'pubEntryPoint')!; + const parentEntryPointFn = ParentContractArtifact.functions.find(f => f.name === 'pubEntryPoint')!; const parentEntryPointFnSelector = FunctionSelector.fromNameAndParameters( parentEntryPointFn.name, parentEntryPointFn.parameters, ); const childContractAddress = AztecAddress.random(); - const childValueFn = ChildContractAbi.functions.find(f => f.name === 'pubGetValue')!; + const childValueFn = ChildContractArtifact.functions.find(f => f.name === 'pubGetValue')!; const childValueFnSelector = FunctionSelector.fromNameAndParameters(childValueFn.name, childValueFn.parameters); const initialValue = 3n; @@ -285,8 +285,8 @@ describe('ACIR public execution simulator', () => { }); it('Should be able to create a commitment from the public context', async () => { - const shieldAbi = NonNativeTokenContractAbi.functions.find(f => f.name === 'shield')!; - const args = encodeArguments(shieldAbi, params); + const shieldArtifact = NonNativeTokenContractArtifact.functions.find(f => f.name === 'shield')!; + const args = encodeArguments(shieldArtifact, params); const callContext = CallContext.from({ msgSender: AztecAddress.random(), @@ -298,7 +298,7 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(shieldAbi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(shieldArtifact.bytecode, 'base64')); // mock initial balance to be greater than the amount being sent publicState.storageRead.mockResolvedValue(amount); @@ -318,8 +318,10 @@ describe('ACIR public execution simulator', () => { }); it('Should be able to create a L2 to L1 message from the public context', async () => { - const createL2ToL1MessagePublicAbi = TestContractAbi.functions.find(f => f.name === 'createL2ToL1MessagePublic')!; - const args = encodeArguments(createL2ToL1MessagePublicAbi, params); + const createL2ToL1MessagePublicArtifact = TestContractArtifact.functions.find( + f => f.name === 'createL2ToL1MessagePublic', + )!; + const args = encodeArguments(createL2ToL1MessagePublicArtifact, params); const callContext = CallContext.from({ msgSender: AztecAddress.random(), @@ -331,7 +333,7 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(createL2ToL1MessagePublicAbi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(createL2ToL1MessagePublicArtifact.bytecode, 'base64')); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; const result = await executor.simulate(execution, GlobalVariables.empty()); @@ -347,7 +349,7 @@ describe('ACIR public execution simulator', () => { }); it('Should be able to consume an Ll to L2 message in the public context', async () => { - const mintPublicAbi = NonNativeTokenContractAbi.functions.find(f => f.name === 'mintPublic')!; + const mintPublicArtifact = NonNativeTokenContractArtifact.functions.find(f => f.name === 'mintPublic')!; // Set up cross chain message const canceller = EthAddress.random(); @@ -366,7 +368,7 @@ describe('ACIR public execution simulator', () => { // Stub message key const messageKey = Fr.random(); - const args = encodeArguments(mintPublicAbi, [ + const args = encodeArguments(mintPublicArtifact, [ bridgedAmount, recipient.toField(), messageKey, @@ -384,7 +386,7 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintPublicAbi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintPublicArtifact.bytecode, 'base64')); publicState.storageRead.mockResolvedValue(Fr.ZERO); // Mock response @@ -403,9 +405,11 @@ describe('ACIR public execution simulator', () => { }); it('Should be able to create a nullifier from the public context', async () => { - const createNullifierPublicAbi = TestContractAbi.functions.find(f => f.name === 'createNullifierPublic')!; + const createNullifierPublicArtifact = TestContractArtifact.functions.find( + f => f.name === 'createNullifierPublic', + )!; - const args = encodeArguments(createNullifierPublicAbi, params); + const args = encodeArguments(createNullifierPublicArtifact, params); const callContext = CallContext.from({ msgSender: AztecAddress.random(), @@ -417,7 +421,7 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - publicContracts.getBytecode.mockResolvedValue(Buffer.from(createNullifierPublicAbi.bytecode, 'base64')); + publicContracts.getBytecode.mockResolvedValue(Buffer.from(createNullifierPublicArtifact.bytecode, 'base64')); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; const result = await executor.simulate(execution, GlobalVariables.empty()); diff --git a/yarn-project/acir-simulator/src/test/utils.ts b/yarn-project/acir-simulator/src/test/utils.ts index 7b0baafe2ae..6ba0b9d013e 100644 --- a/yarn-project/acir-simulator/src/test/utils.ts +++ b/yarn-project/acir-simulator/src/test/utils.ts @@ -1,10 +1,10 @@ import { AztecAddress, CircuitsWasm, EthAddress, Fr } from '@aztec/circuits.js'; import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; -import { ContractAbi, getFunctionDebugMetadata } from '@aztec/foundation/abi'; +import { ContractArtifact, getFunctionDebugMetadata } from '@aztec/foundation/abi'; import { sha256ToField } from '@aztec/foundation/crypto'; import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/types'; -import { FunctionAbiWithDebugMetadata } from '../index.js'; +import { FunctionArtifactWithDebugMetadata } from '../index.js'; /** * Test utility function to craft an L1 to L2 message. @@ -42,14 +42,17 @@ export const buildL1ToL2Message = async ( ); }; -export const getFunctionAbi = (abi: ContractAbi, functionName: string): FunctionAbiWithDebugMetadata => { - const functionIndex = abi.functions.findIndex(f => f.name === functionName); +export const getFunctionArtifact = ( + artifact: ContractArtifact, + functionName: string, +): FunctionArtifactWithDebugMetadata => { + const functionIndex = artifact.functions.findIndex(f => f.name === functionName); if (functionIndex < 0) { throw new Error(`Unknown function ${functionName}`); } - const functionAbi = abi.functions[functionIndex]; + const functionArtifact = artifact.functions[functionIndex]; - const debug = getFunctionDebugMetadata(abi, functionName); + const debug = getFunctionDebugMetadata(artifact, functionName); - return { ...functionAbi, debug }; + return { ...functionArtifact, debug }; }; diff --git a/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts b/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts index 1617c170a08..8b71aa22f99 100644 --- a/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts +++ b/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts @@ -25,7 +25,7 @@ const SECONDARY_AMOUNT = 33n; /** * Deploys the Private Token contract. * @param owner - The address that the initial balance will belong to. - * @returns An Aztec Contract object with the private token's ABI. + * @returns An Aztec Contract object with the private token's artifact. */ async function deployZKContract(owner: AztecAddress) { logger('Deploying L2 contract...'); diff --git a/yarn-project/aztec.js/README.md b/yarn-project/aztec.js/README.md index d031fb53bb0..e1041cab73f 100644 --- a/yarn-project/aztec.js/README.md +++ b/yarn-project/aztec.js/README.md @@ -21,7 +21,7 @@ console.log(`New account deployed at ${wallet.getAddress()}`); ```typescript import { Contract } from '@aztec/aztec.js'; -const contract = await Contract.deploy(wallet, MyContractAbi, [...constructorArgs]).send().deployed(); +const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed(); console.log(`Contract deployed at ${contract.address}`); ``` @@ -30,7 +30,7 @@ console.log(`Contract deployed at ${contract.address}`); ```typescript import { Contract } from '@aztec/aztec.js'; -const contract = await Contract.at(contractAddress, MyContractAbi, wallet); +const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); const tx = await contract.methods.transfer(amount, recipientAddress).send().wait(); console.log(`Transferred ${amount} to ${recipientAddress} on block ${tx.blockNumber}`); ``` @@ -40,7 +40,7 @@ console.log(`Transferred ${amount} to ${recipientAddress} on block ${tx.blockNum ```typescript import { Contract } from '@aztec/aztec.js'; -const contract = await Contract.at(contractAddress, MyContractAbi, wallet); +const contract = await Contract.at(contractAddress, MyContractArtifact, wallet); const balance = await contract.methods.getBalance(wallet.getAddress()).view(); console.log(`Account balance is ${balance}`); ``` diff --git a/yarn-project/aztec.js/src/account/contract/base_account_contract.ts b/yarn-project/aztec.js/src/account/contract/base_account_contract.ts index 42c76f1380a..d749a767fe8 100644 --- a/yarn-project/aztec.js/src/account/contract/base_account_contract.ts +++ b/yarn-project/aztec.js/src/account/contract/base_account_contract.ts @@ -1,4 +1,4 @@ -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { CompleteAddress, NodeInfo } from '@aztec/types'; import { DefaultAccountInterface } from '../defaults/default_interface.js'; @@ -13,10 +13,10 @@ export abstract class BaseAccountContract implements AccountContract { abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider; abstract getDeploymentArgs(): Promise; - constructor(private abi: ContractAbi) {} + constructor(private artifact: ContractArtifact) {} - getContractAbi(): ContractAbi { - return this.abi; + getContractArtifact(): ContractArtifact { + return this.artifact; } getInterface(address: CompleteAddress, nodeInfo: NodeInfo): Promise { diff --git a/yarn-project/aztec.js/src/account/contract/ecdsa_account_contract.ts b/yarn-project/aztec.js/src/account/contract/ecdsa_account_contract.ts index 3d057db434f..d238b8c417f 100644 --- a/yarn-project/aztec.js/src/account/contract/ecdsa_account_contract.ts +++ b/yarn-project/aztec.js/src/account/contract/ecdsa_account_contract.ts @@ -1,9 +1,9 @@ import { Ecdsa } from '@aztec/circuits.js/barretenberg'; -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress } from '@aztec/types'; -import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' }; +import EcdsaAccountContractArtifact from '../../artifacts/ecdsa_account_contract.json' assert { type: 'json' }; import { AuthWitnessProvider } from '../interface.js'; import { BaseAccountContract } from './base_account_contract.js'; @@ -13,7 +13,7 @@ import { BaseAccountContract } from './base_account_contract.js'; */ export class EcdsaAccountContract extends BaseAccountContract { constructor(private signingPrivateKey: Buffer) { - super(EcdsaAccountContractAbi as ContractAbi); + super(EcdsaAccountContractArtifact as ContractArtifact); } async getDeploymentArgs() { diff --git a/yarn-project/aztec.js/src/account/contract/index.ts b/yarn-project/aztec.js/src/account/contract/index.ts index 730acfda80b..611721b64c8 100644 --- a/yarn-project/aztec.js/src/account/contract/index.ts +++ b/yarn-project/aztec.js/src/account/contract/index.ts @@ -1,4 +1,4 @@ -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { CompleteAddress, NodeInfo } from '@aztec/types'; import { AccountInterface } from '../interface.js'; @@ -10,14 +10,14 @@ export * from './base_account_contract.js'; // docs:start:account-contract-interface /** - * An account contract instance. Knows its ABI, deployment arguments, how to create + * An account contract instance. Knows its artifact, deployment arguments, how to create * transaction execution requests out of function calls, and how to authorize actions. */ export interface AccountContract { /** - * Returns the ABI of this account contract. + * Returns the artifact of this account contract. */ - getContractAbi(): ContractAbi; + getContractArtifact(): ContractArtifact; /** * Returns the deployment arguments for this instance. diff --git a/yarn-project/aztec.js/src/account/contract/schnorr_account_contract.ts b/yarn-project/aztec.js/src/account/contract/schnorr_account_contract.ts index d185a5a70c4..2f963a468de 100644 --- a/yarn-project/aztec.js/src/account/contract/schnorr_account_contract.ts +++ b/yarn-project/aztec.js/src/account/contract/schnorr_account_contract.ts @@ -1,9 +1,9 @@ import { Schnorr } from '@aztec/circuits.js/barretenberg'; -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types'; -import SchnorrAccountContractAbi from '../../abis/schnorr_account_contract.json' assert { type: 'json' }; +import SchnorrAccountContractArtifact from '../../artifacts/schnorr_account_contract.json' assert { type: 'json' }; import { AuthWitnessProvider } from '../interface.js'; import { BaseAccountContract } from './base_account_contract.js'; @@ -13,7 +13,7 @@ import { BaseAccountContract } from './base_account_contract.js'; */ export class SchnorrAccountContract extends BaseAccountContract { constructor(private signingPrivateKey: GrumpkinPrivateKey) { - super(SchnorrAccountContractAbi as ContractAbi); + super(SchnorrAccountContractArtifact as ContractArtifact); } async getDeploymentArgs() { diff --git a/yarn-project/aztec.js/src/account/contract/single_key_account_contract.ts b/yarn-project/aztec.js/src/account/contract/single_key_account_contract.ts index 5b8f8c9c199..63cfc44524e 100644 --- a/yarn-project/aztec.js/src/account/contract/single_key_account_contract.ts +++ b/yarn-project/aztec.js/src/account/contract/single_key_account_contract.ts @@ -1,10 +1,10 @@ import { PartialAddress } from '@aztec/circuits.js'; import { Schnorr } from '@aztec/circuits.js/barretenberg'; -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types'; -import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_account_contract.json' assert { type: 'json' }; +import SchnorrSingleKeyAccountContractArtifact from '../../artifacts/schnorr_single_key_account_contract.json' assert { type: 'json' }; import { generatePublicKey } from '../../index.js'; import { AuthWitnessProvider } from '../interface.js'; import { BaseAccountContract } from './base_account_contract.js'; @@ -15,7 +15,7 @@ import { BaseAccountContract } from './base_account_contract.js'; */ export class SingleKeyAccountContract extends BaseAccountContract { constructor(private encryptionPrivateKey: GrumpkinPrivateKey) { - super(SchnorrSingleKeyAccountContractAbi as ContractAbi); + super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact); } getDeploymentArgs(): Promise { diff --git a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts index d036f1fbade..974d0fa6bde 100644 --- a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts @@ -1,5 +1,5 @@ import { AztecAddress, Fr, FunctionData, TxContext } from '@aztec/circuits.js'; -import { FunctionAbiHeader, encodeArguments } from '@aztec/foundation/abi'; +import { FunctionAbi, encodeArguments } from '@aztec/foundation/abi'; import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js'; @@ -97,6 +97,6 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { }, ], returnTypes: [], - } as FunctionAbiHeader; + } as FunctionAbi; } } diff --git a/yarn-project/aztec.js/src/account/manager/index.ts b/yarn-project/aztec.js/src/account/manager/index.ts index 3e8248d935b..69f73ebea8d 100644 --- a/yarn-project/aztec.js/src/account/manager/index.ts +++ b/yarn-project/aztec.js/src/account/manager/index.ts @@ -64,7 +64,7 @@ export class AccountManager { if (!this.completeAddress) { const encryptionPublicKey = await generatePublicKey(this.encryptionPrivateKey); const contractDeploymentInfo = await getContractDeploymentInfo( - this.accountContract.getContractAbi(), + this.accountContract.getContractArtifact(), await this.accountContract.getDeploymentArgs(), this.salt!, encryptionPublicKey, @@ -107,7 +107,7 @@ export class AccountManager { if (!this.salt) throw new Error(`Cannot deploy account contract without known salt.`); await this.register(); const encryptionPublicKey = await this.getEncryptionPublicKey(); - const deployer = new ContractDeployer(this.accountContract.getContractAbi(), this.pxe, encryptionPublicKey); + const deployer = new ContractDeployer(this.accountContract.getContractArtifact(), this.pxe, encryptionPublicKey); const args = await this.accountContract.getDeploymentArgs(); this.deployMethod = deployer.deploy(...args); } diff --git a/yarn-project/aztec.js/src/abis/ecdsa_account_contract.json b/yarn-project/aztec.js/src/artifacts/ecdsa_account_contract.json similarity index 100% rename from yarn-project/aztec.js/src/abis/ecdsa_account_contract.json rename to yarn-project/aztec.js/src/artifacts/ecdsa_account_contract.json diff --git a/yarn-project/aztec.js/src/abis/schnorr_account_contract.json b/yarn-project/aztec.js/src/artifacts/schnorr_account_contract.json similarity index 100% rename from yarn-project/aztec.js/src/abis/schnorr_account_contract.json rename to yarn-project/aztec.js/src/artifacts/schnorr_account_contract.json diff --git a/yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json b/yarn-project/aztec.js/src/artifacts/schnorr_single_key_account_contract.json similarity index 100% rename from yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json rename to yarn-project/aztec.js/src/artifacts/schnorr_single_key_account_contract.json diff --git a/yarn-project/aztec.js/src/contract/checker.test.ts b/yarn-project/aztec.js/src/contract/checker.test.ts index b4ae515188c..7214f924f86 100644 --- a/yarn-project/aztec.js/src/contract/checker.test.ts +++ b/yarn-project/aztec.js/src/contract/checker.test.ts @@ -7,12 +7,12 @@ describe('abiChecker', () => { abi = { name: 'TEST_ABI', }; - expect(() => abiChecker(abi)).toThrowError('ABI has no functions'); + expect(() => abiChecker(abi)).toThrowError('artifact has no functions'); abi = { name: 'TEST_ABI', functions: [], }; - expect(() => abiChecker(abi)).toThrowError('ABI has no functions'); + expect(() => abiChecker(abi)).toThrowError('artifact has no functions'); }); it('should error if ABI has no names', () => { diff --git a/yarn-project/aztec.js/src/contract/checker.ts b/yarn-project/aztec.js/src/contract/checker.ts index b90c3845845..616b4840ae7 100644 --- a/yarn-project/aztec.js/src/contract/checker.ts +++ b/yarn-project/aztec.js/src/contract/checker.ts @@ -1,4 +1,4 @@ -import { ABIType, BasicType, ContractAbi, StructType } from '@aztec/foundation/abi'; +import { ABIType, BasicType, ContractArtifact, StructType } from '@aztec/foundation/abi'; /** * Represents a type derived from input type T with the 'kind' property removed. @@ -7,19 +7,19 @@ import { ABIType, BasicType, ContractAbi, StructType } from '@aztec/foundation/a type TypeWithoutKind = Omit<{ [key in keyof T]: any }, 'kind'>; /** - * Validates the given ContractAbi object by checking its functions and their parameters. + * Validates the given ContractArtifact object by checking its functions and their parameters. * Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types. * Throws an error if any inconsistency is detected during the validation process. * - * @param abi - The ContractAbi object to be validated. - * @returns A boolean value indicating whether the ABI is valid or not. + * @param artifact - The ContractArtifact object to be validated. + * @returns A boolean value indicating whether the artifact is valid or not. */ -export function abiChecker(abi: ContractAbi) { - if (!abi.functions || abi.functions.length === 0) { - throw new Error('ABI has no functions'); +export function abiChecker(artifact: ContractArtifact) { + if (!artifact.functions || artifact.functions.length === 0) { + throw new Error('artifact has no functions'); } - abi.functions.forEach(func => { + artifact.functions.forEach(func => { if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) { throw new Error('ABI function has no name'); } @@ -39,7 +39,7 @@ export function abiChecker(abi: ContractAbi) { }); // TODO: implement a better check for constructor (right now only checks if it has it or not) - if (!abi.functions.find(func => func.name === 'constructor')) { + if (!artifact.functions.find(func => func.name === 'constructor')) { throw new Error('ABI has no constructor'); } diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 541a9c588b7..4434afb1e74 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -1,6 +1,6 @@ import { AztecAddress, CompleteAddress, EthAddress } from '@aztec/circuits.js'; import { L1ContractAddresses } from '@aztec/ethereum'; -import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi'; +import { ABIParameterVisibility, ContractArtifact, FunctionType } from '@aztec/foundation/abi'; import { ExtendedContractData, NodeInfo, Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/types'; import { MockProxy, mock } from 'jest-mock-extended'; @@ -35,7 +35,7 @@ describe('Contract Class', () => { l1ContractAddresses: l1Addresses, }; - const defaultAbi: ContractAbi = { + const defaultArtifact: ContractArtifact = { name: 'FooContract', functions: [ { @@ -111,7 +111,7 @@ describe('Contract Class', () => { }); it('should create and send a contract method tx', async () => { - const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); + const fooContract = await Contract.at(contractAddress, defaultArtifact, wallet); const param0 = 12; const param1 = 345n; const sentTx = fooContract.methods.bar(param0, param1).send(); @@ -126,7 +126,7 @@ describe('Contract Class', () => { }); it('should call view on an unconstrained function', async () => { - const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); + const fooContract = await Contract.at(contractAddress, defaultArtifact, wallet); const result = await fooContract.methods.qux(123n).view({ from: account.address, }); @@ -136,12 +136,12 @@ describe('Contract Class', () => { }); it('should not call create on an unconstrained function', async () => { - const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); + const fooContract = await Contract.at(contractAddress, defaultArtifact, wallet); await expect(fooContract.methods.qux().create()).rejects.toThrow(); }); it('should not call view on a secret or open function', async () => { - const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); + const fooContract = await Contract.at(contractAddress, defaultArtifact, wallet); expect(() => fooContract.methods.bar().view()).toThrow(); expect(() => fooContract.methods.baz().view()).toThrow(); }); diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 9249184c491..47dc389c7eb 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,4 +1,4 @@ -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { PublicKey } from '@aztec/types'; @@ -17,19 +17,19 @@ export class Contract extends ContractBase { /** * Creates a contract instance. * @param address - The deployed contract's address. - * @param abi - The Application Binary Interface for the contract. + * @param artifact - Build artifact of the contract. * @param wallet - The wallet to use when interacting with the contract. * @param portalContract - The portal contract address on L1, if any. * @returns A promise that resolves to a new Contract instance. */ - public static async at(address: AztecAddress, abi: ContractAbi, wallet: Wallet): Promise { + public static async at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Promise { const extendedContractData = await wallet.getExtendedContractData(address); if (extendedContractData === undefined) { throw new Error('Contract ' + address.toString() + ' is not deployed'); } return new Contract( extendedContractData.getCompleteAddress(), - abi, + artifact, wallet, extendedContractData.contractData.portalContractAddress, ); @@ -38,21 +38,21 @@ export class Contract extends ContractBase { /** * Creates a tx to deploy a new instance of a contract. * @param wallet - The wallet for executing the deployment. - * @param abi - ABI of the contract to deploy. + * @param artifact - Build artifact of the contract to deploy * @param args - Arguments for the constructor. */ - public static deploy(wallet: Wallet, abi: ContractAbi, args: any[]) { - return new DeployMethod(Point.ZERO, wallet, abi, args); + public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[]) { + return new DeployMethod(Point.ZERO, wallet, artifact, args); } /** * Creates a tx to deploy a new instance of a contract using the specified public key to derive the address. * @param publicKey - Public key for deriving the address. * @param wallet - The wallet for executing the deployment. - * @param abi - ABI of the contract to deploy. + * @param artifact - Build artifact of the contract. * @param args - Arguments for the constructor. */ - public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, abi: ContractAbi, args: any[]) { - return new DeployMethod(publicKey, wallet, abi, args); + public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, artifact: ContractArtifact, args: any[]) { + return new DeployMethod(publicKey, wallet, artifact, args); } } diff --git a/yarn-project/aztec.js/src/contract/contract_base.ts b/yarn-project/aztec.js/src/contract/contract_base.ts index 4ac143fc47a..584529573d8 100644 --- a/yarn-project/aztec.js/src/contract/contract_base.ts +++ b/yarn-project/aztec.js/src/contract/contract_base.ts @@ -1,4 +1,4 @@ -import { ContractAbi, FunctionAbi, FunctionSelector } from '@aztec/foundation/abi'; +import { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi'; import { EthAddress } from '@aztec/foundation/eth-address'; import { CompleteAddress, DeployedContract } from '@aztec/types'; @@ -29,13 +29,13 @@ export class ContractBase implements DeployedContract { /** The deployed contract's complete address. */ public readonly completeAddress: CompleteAddress, /** The Application Binary Interface for the contract. */ - public readonly abi: ContractAbi, + public readonly artifact: ContractArtifact, /** The wallet used for interacting with this contract. */ protected wallet: Wallet, /** The portal contract address on L1, if any. */ public readonly portalContract: EthAddress, ) { - abi.functions.forEach((f: FunctionAbi) => { + artifact.functions.forEach((f: FunctionArtifact) => { const interactionFunction = (...args: any[]) => { return new ContractFunctionInteraction(this.wallet, this.completeAddress.address!, f, args); }; @@ -65,6 +65,6 @@ export class ContractBase implements DeployedContract { * @returns A new contract instance. */ public withWallet(wallet: Wallet): this { - return new ContractBase(this.completeAddress, this.abi, wallet, this.portalContract) as this; + return new ContractBase(this.completeAddress, this.artifact, wallet, this.portalContract) as this; } } diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index e8a58728fe4..da6932b1b91 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -1,5 +1,5 @@ import { AztecAddress, FunctionData } from '@aztec/circuits.js'; -import { FunctionAbiHeader, FunctionType, encodeArguments } from '@aztec/foundation/abi'; +import { FunctionAbi, FunctionType, encodeArguments } from '@aztec/foundation/abi'; import { FunctionCall, TxExecutionRequest } from '@aztec/types'; import { Wallet } from '../wallet/index.js'; @@ -26,7 +26,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { constructor( protected wallet: Wallet, protected contractAddress: AztecAddress, - protected functionDao: FunctionAbiHeader, + protected functionDao: FunctionAbi, protected args: any[], ) { super(wallet); diff --git a/yarn-project/aztec.js/src/contract/index.ts b/yarn-project/aztec.js/src/contract/index.ts index 620c4d1e968..55c7329a978 100644 --- a/yarn-project/aztec.js/src/contract/index.ts +++ b/yarn-project/aztec.js/src/contract/index.ts @@ -10,12 +10,12 @@ * or can be queried via `view()`. * * ```ts - * const contract = await Contract.deploy(wallet, MyContractAbi, [...constructorArgs]).send().deployed(); + * const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed(); * console.log(`Contract deployed at ${contract.address}`); * ``` * * ```ts - * const contract = await Contract.at(address, MyContractAbi, wallet); + * const contract = await Contract.at(address, MyContractArtifact, wallet); * await contract.methods.mint(1000, owner).send().wait(); * console.log(`Total supply is now ${await contract.methods.totalSupply().view()}`); * ``` diff --git a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts index a95e6c45b97..e657b01ca58 100644 --- a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts +++ b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts @@ -1,5 +1,5 @@ import { EthAddress, Fr, Point } from '@aztec/circuits.js'; -import { ContractAbi, FunctionType } from '@aztec/foundation/abi'; +import { ContractArtifact, FunctionType } from '@aztec/foundation/abi'; import { PXE, PublicKey, Tx, TxHash, TxReceipt } from '@aztec/types'; import { MockProxy, mock } from 'jest-mock-extended'; @@ -9,7 +9,7 @@ import { ContractDeployer } from './contract_deployer.js'; describe.skip('Contract Deployer', () => { let pxe: MockProxy; - const abi: ContractAbi = { + const artifact: ContractArtifact = { name: 'MyContract', functions: [ { @@ -39,7 +39,7 @@ describe.skip('Contract Deployer', () => { }); it('should create and send a contract deployment tx', async () => { - const deployer = new ContractDeployer(abi, pxe, publicKey); + const deployer = new ContractDeployer(artifact, pxe, publicKey); const sentTx = deployer.deploy(args[0], args[1]).send({ portalContract, contractAddressSalt, diff --git a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts index bd7f7c34aef..3bc720d72be 100644 --- a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts +++ b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts @@ -1,4 +1,4 @@ -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { Point } from '@aztec/foundation/fields'; import { PXE, PublicKey } from '@aztec/types'; @@ -9,7 +9,7 @@ import { DeployMethod } from './deploy_method.js'; * @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users. */ export class ContractDeployer { - constructor(private abi: ContractAbi, private pxe: PXE, private publicKey?: PublicKey) {} + constructor(private artifact: ContractArtifact, private pxe: PXE, private publicKey?: PublicKey) {} /** * Deploy a contract using the provided ABI and constructor arguments. @@ -21,6 +21,6 @@ export class ContractDeployer { * @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments. */ public deploy(...args: any[]) { - return new DeployMethod(this.publicKey ?? Point.ZERO, this.pxe, this.abi, args); + return new DeployMethod(this.publicKey ?? Point.ZERO, this.pxe, this.artifact, args); } } diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts index 2cf6dbd9ad6..f6e1991e632 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts @@ -5,7 +5,7 @@ import { TxContext, getContractDeploymentInfo, } from '@aztec/circuits.js'; -import { ContractAbi, FunctionAbi, encodeArguments } from '@aztec/foundation/abi'; +import { ContractArtifact, FunctionArtifact, encodeArguments } from '@aztec/foundation/abi'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { PXE, PackedArguments, PublicKey, Tx, TxExecutionRequest } from '@aztec/types'; @@ -38,13 +38,18 @@ export class DeployMethod extends Bas public completeAddress?: CompleteAddress = undefined; /** Constructor function to call. */ - private constructorAbi: FunctionAbi; - - constructor(private publicKey: PublicKey, protected pxe: PXE, private abi: ContractAbi, private args: any[] = []) { + private constructorArtifact: FunctionArtifact; + + constructor( + private publicKey: PublicKey, + protected pxe: PXE, + private artifact: ContractArtifact, + private args: any[] = [], + ) { super(pxe); - const constructorAbi = abi.functions.find(f => f.name === 'constructor'); - if (!constructorAbi) throw new Error('Cannot find constructor in the ABI.'); - this.constructorAbi = constructorAbi; + const constructorArtifact = artifact.functions.find(f => f.name === 'constructor'); + if (!constructorArtifact) throw new Error('Cannot find constructor in the artifact.'); + this.constructorArtifact = constructorArtifact; } /** @@ -63,7 +68,7 @@ export class DeployMethod extends Bas const { chainId, protocolVersion } = await this.pxe.getNodeInfo(); const { completeAddress, constructorHash, functionTreeRoot } = await getContractDeploymentInfo( - this.abi, + this.artifact, this.args, contractAddressSalt, this.publicKey, @@ -85,8 +90,8 @@ export class DeployMethod extends Bas new Fr(chainId), new Fr(protocolVersion), ); - const args = encodeArguments(this.constructorAbi, this.args); - const functionData = FunctionData.fromAbi(this.constructorAbi); + const args = encodeArguments(this.constructorArtifact, this.args); + const functionData = FunctionData.fromAbi(this.constructorArtifact); const execution = { args, functionData, to: completeAddress.address }; const packedArguments = await PackedArguments.fromArgs(execution.args); @@ -103,7 +108,7 @@ export class DeployMethod extends Bas this.completeAddress = completeAddress; // TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined? - await this.pxe.addContracts([{ abi: this.abi, completeAddress, portalContract }]); + await this.pxe.addContracts([{ artifact: this.artifact, completeAddress, portalContract }]); return this.txRequest; } @@ -118,7 +123,7 @@ export class DeployMethod extends Bas */ public send(options: DeployOptions = {}): DeploySentTx { const txHashPromise = super.send(options).getTxHash(); - return new DeploySentTx(this.abi, this.pxe, txHashPromise); + return new DeploySentTx(this.artifact, this.pxe, txHashPromise); } /** diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts index 8b0fc0a2a0f..4441c831bed 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts @@ -1,5 +1,5 @@ import { FieldsOf } from '@aztec/circuits.js'; -import { ContractAbi } from '@aztec/foundation/abi'; +import { ContractArtifact } from '@aztec/foundation/abi'; import { TxHash, TxReceipt } from '@aztec/types'; import { AztecAddress, Contract, ContractBase, PXE, SentTx, WaitOpts, Wallet } from '../index.js'; @@ -20,7 +20,7 @@ export type DeployTxReceipt = FieldsO * A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance. */ export class DeploySentTx extends SentTx { - constructor(private abi: ContractAbi, wallet: PXE | Wallet, txHashPromise: Promise) { + constructor(private artifact: ContractArtifact, wallet: PXE | Wallet, txHashPromise: Promise) { super(wallet, txHashPromise); } @@ -50,6 +50,6 @@ export class DeploySentTx extends SentTx const contractWallet = wallet ?? (isWallet(this.pxe) && this.pxe); if (!contractWallet) throw new Error(`A wallet is required for creating a contract instance`); if (!address) throw new Error(`Contract address is missing from transaction receipt`); - return Contract.at(address, this.abi, contractWallet) as Promise; + return Contract.at(address, this.artifact, contractWallet) as Promise; } } diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts index 89470f7ea96..23d0b438a0f 100644 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ b/yarn-project/aztec.js/src/sandbox/index.ts @@ -3,7 +3,7 @@ import { sleep } from '@aztec/foundation/sleep'; import zip from 'lodash.zip'; -import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' }; +import SchnorrAccountContractArtifact from '../artifacts/schnorr_account_contract.json' assert { type: 'json' }; import { AccountWalletWithPrivateKey, PXE, createPXEClient, getSchnorrAccount } from '../index.js'; export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ @@ -16,7 +16,7 @@ export const INITIAL_SANDBOX_SIGNING_KEYS = INITIAL_SANDBOX_ENCRYPTION_KEYS; export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; -export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi; +export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractArtifact; export const { PXE_URL = 'http://localhost:8080' } = process.env; diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 829f7e16bc4..9df782b76df 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -1,5 +1,5 @@ import { Fr, GrumpkinPrivateKey } from '@aztec/circuits.js'; -import { ABIParameterVisibility, FunctionAbiHeader, FunctionType } from '@aztec/foundation/abi'; +import { ABIParameterVisibility, FunctionAbi, FunctionType } from '@aztec/foundation/abi'; import { AuthWitness, FunctionCall, PXE, TxExecutionRequest } from '@aztec/types'; import { AccountInterface } from '../account/interface.js'; @@ -47,7 +47,7 @@ export class AccountWallet extends BaseWallet { return this.getCompleteAddress().address; } - private getSetIsValidStorageAbi(): FunctionAbiHeader { + private getSetIsValidStorageAbi(): FunctionAbi { return { name: 'set_is_valid_storage', functionType: 'open' as FunctionType, diff --git a/yarn-project/boxes/blank-react/README.md b/yarn-project/boxes/blank-react/README.md index f6d7be7983f..3a1035d8a79 100644 --- a/yarn-project/boxes/blank-react/README.md +++ b/yarn-project/boxes/blank-react/README.md @@ -62,12 +62,12 @@ This will generate a [Contract ABI](src/artifacts/test_contract.json) and TypeSc Note: the `compile` command seems to generate a Typescript file which needs a single change - ``` -import TestContractAbiJson from 'text_contract.json' assert { type: 'json' }; +import TestContractArtifactJson from 'text_contract.json' assert { type: 'json' }; // need to update the relative import to -import TestContractAbiJson from './test_contract.json' assert { type: 'json' }; +import TestContractArtifactJson from './test_contract.json' assert { type: 'json' }; ``` -After compiling, you can re-deploy the upated noir smart contract from the web UI. The function interaction forms are generated from parsing the ContractABI, so they should update automatically after you recompile. +After compiling, you can re-deploy the updated noir smart contract from the web UI. The function interaction forms are generated from parsing the contract artifacts, so they should update automatically after you recompile. ## Learn More diff --git a/yarn-project/boxes/blank-react/src/app/components/contract_function_form.tsx b/yarn-project/boxes/blank-react/src/app/components/contract_function_form.tsx index 6c4e6b1d5ff..484a7b10207 100644 --- a/yarn-project/boxes/blank-react/src/app/components/contract_function_form.tsx +++ b/yarn-project/boxes/blank-react/src/app/components/contract_function_form.tsx @@ -1,12 +1,12 @@ -import { Button, Loader } from '@aztec/aztec-ui'; -import { AztecAddress, CompleteAddress, Fr } from '@aztec/aztec.js'; -import { ContractAbi, FunctionAbi } from '@aztec/foundation/abi'; -import { useFormik } from 'formik'; -import * as Yup from 'yup'; import { CONTRACT_ADDRESS_PARAM_NAMES, pxe } from '../../config.js'; import { callContractFunction, deployContract, viewContractFunction } from '../../scripts/index.js'; import { convertArgs } from '../../scripts/util.js'; import styles from './contract_function_form.module.scss'; +import { Button, Loader } from '@aztec/aztec-ui'; +import { AztecAddress, CompleteAddress, Fr } from '@aztec/aztec.js'; +import { ContractArtifact, FunctionArtifact } from '@aztec/foundation/abi'; +import { useFormik } from 'formik'; +import * as Yup from 'yup'; type NoirFunctionYupSchema = { // hack: add `any` at the end to get the array schema to typecheck @@ -18,7 +18,7 @@ type NoirFunctionFormValues = { [key: string]: string | number | number[] | boolean; }; -function generateYupSchema(functionAbi: FunctionAbi, defaultAddress: string) { +function generateYupSchema(functionAbi: FunctionArtifact, defaultAddress: string) { const parameterSchema: NoirFunctionYupSchema = {}; const initialValues: NoirFunctionFormValues = {}; for (const param of functionAbi.parameters) { @@ -62,12 +62,12 @@ function generateYupSchema(functionAbi: FunctionAbi, defaultAddress: string) { async function handleFunctionCall( contractAddress: AztecAddress | undefined, - contractAbi: ContractAbi, + contractArtifact: ContractArtifact, functionName: string, args: any, wallet: CompleteAddress, ) { - const functionAbi = contractAbi.functions.find(f => f.name === functionName)!; + const functionAbi = contractArtifact.functions.find(f => f.name === functionName)!; const typedArgs: any[] = convertArgs(functionAbi, args); if (functionName === 'constructor' && !!wallet) { @@ -80,13 +80,20 @@ async function handleFunctionCall( // for now, dont let user change the salt. requires some change to the form generation if we want to let user choose one // since everything is currently based on parsing the contractABI, and the salt parameter is not present there const salt = Fr.random(); - return await deployContract(wallet, contractAbi, typedArgs, salt, pxe); + return await deployContract(wallet, contractArtifact, typedArgs, salt, pxe); } if (functionAbi.functionType === 'unconstrained') { - return await viewContractFunction(contractAddress!, contractAbi, functionName, typedArgs, pxe, wallet); + return await viewContractFunction(contractAddress!, contractArtifact, functionName, typedArgs, pxe, wallet); } else { - const txnReceipt = await callContractFunction(contractAddress!, contractAbi, functionName, typedArgs, pxe, wallet); + const txnReceipt = await callContractFunction( + contractAddress!, + contractArtifact, + functionName, + typedArgs, + pxe, + wallet, + ); return `Transaction ${txnReceipt.status} on block number ${txnReceipt.blockNumber}`; } } @@ -94,8 +101,8 @@ async function handleFunctionCall( interface ContractFunctionFormProps { wallet: CompleteAddress; contractAddress?: AztecAddress; - contractAbi: ContractAbi; - functionAbi: FunctionAbi; + contractArtifact: ContractArtifact; + functionArtifact: FunctionArtifact; defaultAddress: string; title?: string; buttonText?: string; @@ -109,8 +116,8 @@ interface ContractFunctionFormProps { export function ContractFunctionForm({ wallet, contractAddress, - contractAbi, - functionAbi, + contractArtifact, + functionArtifact, defaultAddress, buttonText = 'Submit', isLoading, @@ -119,14 +126,20 @@ export function ContractFunctionForm({ onSuccess, onError, }: ContractFunctionFormProps) { - const { validationSchema, initialValues } = generateYupSchema(functionAbi, defaultAddress); + const { validationSchema, initialValues } = generateYupSchema(functionArtifact, defaultAddress); const formik = useFormik({ initialValues: initialValues, validationSchema: validationSchema, onSubmit: async (values: any) => { onSubmit(); try { - const result = await handleFunctionCall(contractAddress, contractAbi, functionAbi.name, values, wallet); + const result = await handleFunctionCall( + contractAddress, + contractArtifact, + functionArtifact.name, + values, + wallet, + ); onSuccess(result); } catch (e: any) { onError(e.message); @@ -136,7 +149,7 @@ export function ContractFunctionForm({ return (
- {functionAbi.parameters.map(input => ( + {functionArtifact.parameters.map(input => (