From 331678ca2c67e1e96e26788520f968ecf7cac71c Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 16 Aug 2023 15:14:59 +0000 Subject: [PATCH 01/11] WIP --- docs/docs/dev_docs/contracts/deploying.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index d1f57537c6d..2751f0d6ae4 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -1 +1,3 @@ -See sandbox section? \ No newline at end of file +# Deploying contracts + +Once you have [compiled](./compiled.md) your contracts you can proceed to deploying them using `aztec-cli`. \ No newline at end of file From 8b2d0ba9322234449f33549a5dbff44faa846e6c Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 10:37:46 +0000 Subject: [PATCH 02/11] typo --- yarn-project/circuits.js/src/abis/abis.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index bf4e6f1c64d..0e49a4a078d 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -183,7 +183,7 @@ export function hashConstructor( * Computes a contract address. * @param wasm - A module providing low-level wasm access. * @param deployerPubKey - The pubkey of the contract deployer. - * @param contractAddrSalt - The salt used as 1 one of the inputs of the contract address computation. + * @param contractAddrSalt - The salt used as one of the inputs of the contract address computation. * @param fnTreeRoot - The function tree root of the contract being deployed. * @param constructorHash - The hash of the constructor. * @returns The contract address. @@ -208,7 +208,7 @@ export function computeContractAddress( /** * Computes a partial address. Consists of all contract address components except the deployer public key. * @param wasm - A module providing low-level wasm access. - * @param contractAddrSalt - The salt used as 1 one of the inputs of the contract address computation. + * @param contractAddrSalt - The salt used as one of the inputs of the contract address computation. * @param fnTreeRoot - The function tree root of the contract being deployed. * @param constructorHash - The hash of the constructor. * @returns The partially constructed contract address. @@ -232,7 +232,7 @@ export function computePartialAddress( /** * Computes a contract address from its partial address and the pubkey. * @param wasm - A module providing low-level wasm access. - * @param partial - The salt used as 1 one of the inputs of the contract address computation. + * @param partial - The salt used as one of the inputs of the contract address computation. * @param fnTreeRoot - The function tree root of the contract being deployed. * @param constructorHash - The hash of the constructor. * @returns The partially constructed contract address. From f6e5b7defa48f6583b504f73bc25a13ffaa279d7 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 10:44:33 +0000 Subject: [PATCH 03/11] WIP --- docs/docs/dev_docs/contracts/deploying.md | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index 2751f0d6ae4..4afbad89aa1 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -1,3 +1,33 @@ # Deploying contracts -Once you have [compiled](./compiled.md) your contracts you can proceed to deploying them using `aztec-cli`. \ No newline at end of file +Once you have [compiled](./compiling.md) your contracts you can proceed to deploying them using `aztec-cli`. + +## Prerequisites +- aztec-cli installed +- contract artifacts ready + +## Deploy + +To deploy the contracts you can use the `aztec-cli` + +```bash +aztec-cli deploy --contract-abi /path/to/contract/abi.json +``` + +### Arguments +This command takes the following mandatory arguments: + +- `--contract-abi `: Path to the contract ABI file in JSON format (e.g. `build/contracts/PrivateToken.json`). +Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (e.g. `PrivateTokenContractAbi`). + +and the following optional arguments: +- `-args ` (default: `[]`): Arguments to pass to the contract constructor. +- `--rpc-url ` (default: `http://localhost:8080`): URL of the Aztec node to connect to. +- `--public-key ` (default: `undefined`): Optional encryption public key for this contract. Set this only if this contract is expected to receive private notes, which will be encrypted using this public key.' +- `--salt ` (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed. +By default is set to a random value. +Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode). + +```bash +aztec-cli deploy --contract-abi [-args ] [--rpc-url ] [--public-key ] [--salt ] +``` \ No newline at end of file From 33ff12bba1e90eebc8353303201a6eac5eb9ce48 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 13:05:42 +0000 Subject: [PATCH 04/11] refactor: making abi an argument --- yarn-project/aztec-cli/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn-project/aztec-cli/src/index.ts b/yarn-project/aztec-cli/src/index.ts index 6e64073d0bb..b9dda53f859 100644 --- a/yarn-project/aztec-cli/src/index.ts +++ b/yarn-project/aztec-cli/src/index.ts @@ -146,8 +146,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { program .command('deploy') .description('Deploys a compiled Noir contract to Aztec.') - .requiredOption( - '-c, --contract-abi ', + .argument( + '', "A compiled Noir contract's ABI in JSON format or name of a contract ABI exported by @aztec/noir-contracts", ) .option('-a, --args ', 'Contract constructor arguments', []) @@ -157,8 +157,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { 'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.', ) .option('-s, --salt ', 'Optional deployment salt as a hex string for generating the deployment address.') - .action(async (options: any) => { - const contractAbi = await getContractAbi(options.contractAbi, log); + .action(async (abiPath, options: any) => { + const contractAbi = await getContractAbi(abiPath, log); const constructorAbi = contractAbi.functions.find(({ name }) => name === 'constructor'); const client = createAztecRpcClient(options.rpcUrl); From 67c493caa7fb20ef5b22377f6eb849895cdf9a96 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 13:05:48 +0000 Subject: [PATCH 05/11] WIP --- docs/docs/dev_docs/contracts/deploying.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index 4afbad89aa1..6432238cb09 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -8,17 +8,23 @@ Once you have [compiled](./compiling.md) your contracts you can proceed to deplo ## Deploy -To deploy the contracts you can use the `aztec-cli` +To deploy the contracts you can use `aztec-cli`: ```bash aztec-cli deploy --contract-abi /path/to/contract/abi.json ``` +Example with all the arguments: + +```bash +aztec-cli deploy /path/to/contract/abi.json --rpc-url http://localhost:8080 --public-key 0x1234 --salt 0x1234 +``` + ### Arguments This command takes the following mandatory arguments: - `--contract-abi `: Path to the contract ABI file in JSON format (e.g. `build/contracts/PrivateToken.json`). -Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (e.g. `PrivateTokenContractAbi`). +Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). and the following optional arguments: - `-args ` (default: `[]`): Arguments to pass to the contract constructor. From 468f7737c87398cebf454b58a3856942c6da29fd Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 14:11:31 +0000 Subject: [PATCH 06/11] chore: command fix --- yarn-project/aztec-cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/aztec-cli/package.json b/yarn-project/aztec-cli/package.json index 09aa42df0a0..6f575328879 100644 --- a/yarn-project/aztec-cli/package.json +++ b/yarn-project/aztec-cli/package.json @@ -22,7 +22,7 @@ "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", - "start": "node --no-warnings ./dest/index.js" + "start": "node --no-warnings ./dest/bin/index.js" }, "inherits": [ "../package.common.json" From 07172f232a0d319d3d8eb80207b81c9353177c39 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 14:11:57 +0000 Subject: [PATCH 07/11] nicer register-recipient message --- yarn-project/aztec-cli/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/aztec-cli/src/index.ts b/yarn-project/aztec-cli/src/index.ts index b9dda53f859..0e70ac819b4 100644 --- a/yarn-project/aztec-cli/src/index.ts +++ b/yarn-project/aztec-cli/src/index.ts @@ -279,7 +279,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { const partialAddress = Fr.fromString(options.partialAddress); await client.registerRecipient(await CompleteAddress.create(address, publicKey, partialAddress)); - log(`\nRegistered details for Address: ${options.address}\n`); + log(`\nRegistered details for account with address: ${options.address}\n`); }); program From 57fd81db34f0169c83c8f518a2b6da4a6a5b146a Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 14:12:46 +0000 Subject: [PATCH 08/11] WIP --- docs/docs/dev_docs/contracts/deploying.md | 44 +++++++++++++++-------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index 6432238cb09..e481ecbe0e8 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -11,29 +11,43 @@ Once you have [compiled](./compiling.md) your contracts you can proceed to deplo To deploy the contracts you can use `aztec-cli`: ```bash -aztec-cli deploy --contract-abi /path/to/contract/abi.json -``` - -Example with all the arguments: - -```bash -aztec-cli deploy /path/to/contract/abi.json --rpc-url http://localhost:8080 --public-key 0x1234 --salt 0x1234 +aztec-cli deploy /path/to/contract/abi.json ``` ### Arguments -This command takes the following mandatory arguments: - -- `--contract-abi `: Path to the contract ABI file in JSON format (e.g. `build/contracts/PrivateToken.json`). -Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). +This command takes 1 mandatory positional argument which is the path to the contract ABI file in JSON format (e.g. `build/contracts/PrivateToken.json`). Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). -and the following optional arguments: +The command also takes the following optional arguments: - `-args ` (default: `[]`): Arguments to pass to the contract constructor. - `--rpc-url ` (default: `http://localhost:8080`): URL of the Aztec node to connect to. -- `--public-key ` (default: `undefined`): Optional encryption public key for this contract. Set this only if this contract is expected to receive private notes, which will be encrypted using this public key.' +- `--public-key ` (default: `undefined`): Optional encryption public key for this contract. +Set this only if this contract is expected to receive private notes, which will be encrypted using this public key. +(Contracts which are expected to receive notes are called account contracts.) - `--salt ` (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed. By default is set to a random value. Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode). +Bellow is a full example of deploying a private token contract. +The contract has `initial_supply` and `owner` as constructor arguments. +Because the contract send a note to the owner inside the constructor, we first need to register the owner as a recipient with the following command: + ```bash -aztec-cli deploy --contract-abi [-args ] [--rpc-url ] [--public-key ] [--salt ] -``` \ No newline at end of file +aztec-cli register-recipient --address 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --public-key 0x26e193aef4f83c70651485b5526c6d01a36d763223ab24efd1f9ff91b394ac0c20ad99d0ef669dc0dde8d5f5996c63105de8e15c2c87d8260b9e6f02f72af622 --partial-address 0x200e9a6c2d2e8352012e51c6637659713d336405c29386c7c4ac56779ab54fa7 +``` + +Once the recipient is registered we can deploy the contract: + +```bash +aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 +``` + +If everything went as expected you should see the following output (with a different address): +> Contract deployed at 0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906 + +If we pass in the salt argument: + +```bash +aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123 +``` + +the resulting address will be deterministic. \ No newline at end of file From dd98c8cba7300a991a87edc6657b059d4476c2c0 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 14:51:13 +0000 Subject: [PATCH 09/11] WIP --- docs/docs/dev_docs/contracts/deploying.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index e481ecbe0e8..cdd45e40127 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -3,8 +3,8 @@ Once you have [compiled](./compiling.md) your contracts you can proceed to deploying them using `aztec-cli`. ## Prerequisites -- aztec-cli installed -- contract artifacts ready +- aztec-cli installed (go to [main section](./main.md) for installation instructions) +- contract artifacts ready (go to [compiling section](../contracts/compiling.md) for instructions on how to compile contracts) ## Deploy From 17afe557e4c2cc2fdf24cf6f874fcacb2c123810 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 17 Aug 2023 15:38:36 +0000 Subject: [PATCH 10/11] final touches --- docs/docs/dev_docs/contracts/deploying.md | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index cdd45e40127..bcbc1e9a527 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -3,38 +3,43 @@ Once you have [compiled](./compiling.md) your contracts you can proceed to deploying them using `aztec-cli`. ## Prerequisites -- aztec-cli installed (go to [main section](./main.md) for installation instructions) -- contract artifacts ready (go to [compiling section](../contracts/compiling.md) for instructions on how to compile contracts) +- aztec-cli installed (go to [CLI main section](./main.md) for installation instructions) +- contract artifacts ready (go to [Compiling contracts section](../contracts/compiling.md) for instructions on how to compile contracts) +- aztec-sandbox running (go to [Sandbox section](../sandbox/main.md) for instructions on how to install and run the sandbox) ## Deploy -To deploy the contracts you can use `aztec-cli`: +To deploy the contracts we use the `deploy` command form `aztec-cli`: ```bash aztec-cli deploy /path/to/contract/abi.json ``` ### Arguments -This command takes 1 mandatory positional argument which is the path to the contract ABI file in JSON format (e.g. `build/contracts/PrivateToken.json`). Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). +This command takes 1 mandatory positional argument which is the path to the contract ABI file in a JSON format (e.g. `build/contracts/PrivateToken.json`). Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). The command also takes the following optional arguments: - `-args ` (default: `[]`): Arguments to pass to the contract constructor. - `--rpc-url ` (default: `http://localhost:8080`): URL of the Aztec node to connect to. - `--public-key ` (default: `undefined`): Optional encryption public key for this contract. -Set this only if this contract is expected to receive private notes, which will be encrypted using this public key. -(Contracts which are expected to receive notes are called account contracts.) +Set this only if this contract is expected to receive private notes (in such a case the public key is used during the note encryption). +> **NOTE**: Contracts which are expected to receive notes are called account contracts. - `--salt ` (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed. By default is set to a random value. Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode). -Bellow is a full example of deploying a private token contract. +To give you a more complete example we will deploy the `PrivateToken` contract whose artifacts are included in the `@aztec/noir-contracts` package. + +### Deploying private token contract The contract has `initial_supply` and `owner` as constructor arguments. -Because the contract send a note to the owner inside the constructor, we first need to register the owner as a recipient with the following command: +Because the contract sends a note to the owner specified inside the constructor, we first need to register the owner as a recipient inside the Aztec RPC with the following command: ```bash aztec-cli register-recipient --address 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --public-key 0x26e193aef4f83c70651485b5526c6d01a36d763223ab24efd1f9ff91b394ac0c20ad99d0ef669dc0dde8d5f5996c63105de8e15c2c87d8260b9e6f02f72af622 --partial-address 0x200e9a6c2d2e8352012e51c6637659713d336405c29386c7c4ac56779ab54fa7 ``` +> **NOTE**: If we didn't register owner as a recipient we could not encrypt a note for the owner and the contract deployment would fail because constructor execution would fail (we need owner's public key to encrypt a note). + Once the recipient is registered we can deploy the contract: ```bash @@ -44,10 +49,12 @@ aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f43 If everything went as expected you should see the following output (with a different address): > Contract deployed at 0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906 -If we pass in the salt argument: +If we pass the salt as an argument: ```bash aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529 --salt 0x123 ``` -the resulting address will be deterministic. \ No newline at end of file +the resulting address will be deterministic. + +> **NOTE**: You can try running the deployment with the same salt the second time in which case the transaction will fail because it will be considered a double spend. \ No newline at end of file From bd48d289b925346213062f0993371626252963fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Thu, 17 Aug 2023 18:39:57 +0200 Subject: [PATCH 11/11] Apply suggestions from code review Co-authored-by: Santiago Palladino --- docs/docs/dev_docs/contracts/deploying.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/docs/dev_docs/contracts/deploying.md b/docs/docs/dev_docs/contracts/deploying.md index bcbc1e9a527..c04029715b6 100644 --- a/docs/docs/dev_docs/contracts/deploying.md +++ b/docs/docs/dev_docs/contracts/deploying.md @@ -9,21 +9,20 @@ Once you have [compiled](./compiling.md) your contracts you can proceed to deplo ## Deploy -To deploy the contracts we use the `deploy` command form `aztec-cli`: +To deploy the contracts we use the `deploy` command from `aztec-cli`: ```bash aztec-cli deploy /path/to/contract/abi.json ``` ### Arguments -This command takes 1 mandatory positional argument which is the path to the contract ABI file in a JSON format (e.g. `build/contracts/PrivateToken.json`). Alternatively you can pass here a name of a contract ABI as exported by `@aztec/noir-contracts` (run `aztec-cli example-contracts` to get the list). +This command 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). The command also takes the following optional arguments: - `-args ` (default: `[]`): Arguments to pass to the contract constructor. - `--rpc-url ` (default: `http://localhost:8080`): URL of the Aztec node to connect to. - `--public-key ` (default: `undefined`): Optional encryption public key for this contract. Set this only if this contract is expected to receive private notes (in such a case the public key is used during the note encryption). -> **NOTE**: Contracts which are expected to receive notes are called account contracts. - `--salt ` (default: random value): Hexadecimal string used when computing the contract address of the contract being deployed. By default is set to a random value. Set it, if you need a deterministic contract address (same functionality as Ethereum's `CREATE2` opcode). @@ -57,4 +56,4 @@ aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f43 the resulting address will be deterministic. -> **NOTE**: You can try running the deployment with the same salt the second time in which case the transaction will fail because it will be considered a double spend. \ No newline at end of file +> **NOTE**: You can try running the deployment with the same salt the second time in which case the transaction will fail because the address has been already deployed to. \ No newline at end of file