diff --git a/README.md b/README.md index cc6b62484a8..c26aa2f49fe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Aztec Monorepo -All the packages that make up [Aztec](https://docs.aztec.network). +All the packages that make up [Aztec](https://docs.aztec.network). - [**`l1-contracts`**](/l1-contracts): Solidity code for the Ethereum contracts that process rollups - [**`yarn-project`**](/yarn-project): Typescript code for client and backend @@ -17,7 +17,7 @@ All the packages that make up [Aztec](https://docs.aztec.network). ## Issues Board -All issues being worked on are tracked on the [Aztec Github Project](https://github.com/orgs/AztecProtocol/projects/22). For a higher-level roadmap, check the [milestones overview](https://docs.aztec.network/aztec/roadmap) section of our docs. +All issues being worked on are tracked on the [Aztec Github Project](https://github.com/orgs/AztecProtocol/projects/22). For a higher-level roadmap, check the [milestones overview](https://aztec.network/roadmap) section of our website. ## Development Setup diff --git a/docs/docs/aztec/concepts/accounts/keys.md b/docs/docs/aztec/concepts/accounts/keys.md index b20ae224227..30f2e8610e1 100644 --- a/docs/docs/aztec/concepts/accounts/keys.md +++ b/docs/docs/aztec/concepts/accounts/keys.md @@ -6,6 +6,8 @@ tags: [accounts, keys] The goal of this section is to give app developer a good idea what keys there are used in the system. For a detailed description head over to the [protocol specification](../../../protocol-specs/addresses-and-keys/index.md). +In short, there is a **nullifier key** (to spend your notes), an **incoming viewing key** (to view any notes or logs that were sent to you), an **outgoing viewing key** (to view any logs or notes you sent to another entity), a **tagging key** (to quickly find notes relevant to you) and oftentimes a signing key. A signing key is not strictly required by the protocol, but are often used with specific account contracts for authorization purposes. + Each account in Aztec is backed by 4 key pairs: - A **nullifier key pair** used for note nullifier computation, comprising the master nullifier secret key (`nsk_m`) and master nullifier public key (`Npk_m`). diff --git a/docs/docs/aztec/concepts/storage/partial_notes.md b/docs/docs/aztec/concepts/storage/partial_notes.md index 06d3e2ff0a4..82489fcfdd6 100644 --- a/docs/docs/aztec/concepts/storage/partial_notes.md +++ b/docs/docs/aztec/concepts/storage/partial_notes.md @@ -104,7 +104,7 @@ $$ We also need to create a point for the owner of the FPC (whom we call Bob) to receive the transaction fee, which will also need randomness. -So in the contract we compute $\text{rand}_b := h(\text{rand}_a, \text{msg_sender})$. +So in the contract we compute $\text{rand}_b := h(\text{rand}_a, \text{msg sender})$. :::warning We need to use different randomness for Bob's note here to avoid potential privacy leak (see [description](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-contracts/contracts/token_contract/src/main.nr#L491) of `setup_refund` function) @@ -116,7 +116,7 @@ $$ Here, the $P'$s "partially encode" the notes that we are _going to create_ for Alice and Bob. So we can use points as "Partial Notes". -We pass these points and the funded amount to public, and at the end of public execution, we compute tx fee point $P_{fee} := (\text{transaction fee}) * G_{amount}$ and refund point $P_{refund} := (\text{funded_amount - transaction_fee}) * G_{amount}$ +We pass these points and the funded amount to public, and at the end of public execution, we compute tx fee point $P_{fee} := (\text{transaction fee}) * G_{amount}$ and refund point $P_{refund} := (\text{funded amount} - \text{transaction fee}) * G_{amount}$ Then, we arrive at the point that corresponds to the complete note by diff --git a/docs/docs/aztec/glossary/call_types.md b/docs/docs/aztec/glossary/call_types.md index 0e080b38335..efdbd2bd26b 100644 --- a/docs/docs/aztec/glossary/call_types.md +++ b/docs/docs/aztec/glossary/call_types.md @@ -94,7 +94,7 @@ While Ethereum contracts are defined by bytecode that runs on the EVM, Aztec con ### Private Execution -Contract functions marked with `#[aztec(private)]` can only be called privately, and as such 'run' in the user's device. Since they're circuits, their 'execution' is actually the generation of a zk-SNARK proof that'll later be sent to the sequencer for verification. +Contract functions marked with `#[private]` can only be called privately, and as such 'run' in the user's device. Since they're circuits, their 'execution' is actually the generation of a zk-SNARK proof that'll later be sent to the sequencer for verification. #### Private Calls @@ -112,7 +112,7 @@ Since the public call is made asynchronously, any return values or side effects #include_code enqueue_public /noir-projects/noir-contracts/contracts/lending_contract/src/main.nr rust -It is also possible to create public functions that can _only_ be invoked by privately enqueueing a call from the same contract, which can very useful to update public state after private execution (e.g. update a token's supply after privately minting). This is achieved by annotating functions with `#[aztec(internal)]`. +It is also possible to create public functions that can _only_ be invoked by privately enqueueing a call from the same contract, which can very useful to update public state after private execution (e.g. update a token's supply after privately minting). This is achieved by annotating functions with `#[internal]`. A common pattern is to enqueue public calls to check some validity condition on public state, e.g. that a deadline has not expired or that some public value is set. @@ -148,7 +148,7 @@ For this reason it is encouraged to try to avoid public function calls and inste ### Public Execution -Contract functions marked with `#[aztec(public)]` can only be called publicly, and are executed by the sequencer. The computation model is very similar to the EVM: all state, parameters, etc. are known to the entire network, and no data is private. Static execution like the EVM's `STATICCALL` is possible too, with similar semantics (state can be accessed but not modified, etc.). +Contract functions marked with `#[public]` can only be called publicly, and are executed by the sequencer. The computation model is very similar to the EVM: all state, parameters, etc. are known to the entire network, and no data is private. Static execution like the EVM's `STATICCALL` is possible too, with similar semantics (state can be accessed but not modified, etc.). Since private calls are always run in a user's device, it is not possible to perform any private execution from a public context. A reasonably good mental model for public execution is that of an EVM in which some work has already been done privately, and all that is know about it is its correctness and side-effects (new notes and nullifiers, enqueued public calls, etc.). A reverted public execution will also revert the private side-effects. diff --git a/docs/docs/aztec/smart_contracts/functions/inner_workings.md b/docs/docs/aztec/smart_contracts/functions/inner_workings.md index dc72805ea2c..25598471293 100644 --- a/docs/docs/aztec/smart_contracts/functions/inner_workings.md +++ b/docs/docs/aztec/smart_contracts/functions/inner_workings.md @@ -8,11 +8,11 @@ Below, we go more into depth of what is happening under the hood when you create If you are looking for a reference of function macros, go [here](../../../reference/developer_references/smart_contract_reference/macros.md). -## Private functions #[aztec(private)] +## Private functions #[private] -A private function operates on private information, and is executed by the user on their device. Annotate the function with the `#[aztec(private)]` attribute to tell the compiler it's a private function. This will make the [private context](./context.md#the-private-context) available within the function's execution scope. The compiler will create a circuit to define this function. +A private function operates on private information, and is executed by the user on their device. Annotate the function with the `#[private]` attribute to tell the compiler it's a private function. This will make the [private context](./context.md#the-private-context) available within the function's execution scope. The compiler will create a circuit to define this function. -`#aztec(private)` is just syntactic sugar. At compile time, the Aztec.nr framework inserts code that allows the function to interact with the [kernel](../../../aztec/concepts/circuits/kernels/private_kernel.md). +`#[private]` is just syntactic sugar. At compile time, the Aztec.nr framework inserts code that allows the function to interact with the [kernel](../../../aztec/concepts/circuits/kernels/private_kernel.md). To help illustrate how this interacts with the internals of Aztec and its kernel circuits, we can take an example private function, and explore what it looks like after Aztec.nr's macro expansion. @@ -107,7 +107,7 @@ Beyond using them inside your other functions, they are convenient for providing Note, that unconstrained functions can have access to both public and private data when executed on the user's device. This is possible since it is not actually part of the circuits that are executed in contract execution. ::: -## `Public` Functions #[aztec(public)] +## `Public` Functions #[public] A public function is executed by the sequencer and has access to a state model that is very similar to that of the EVM and Ethereum. Even though they work in an EVM-like model for public transactions, they are able to write data into private storage that can be consumed later by a private function. @@ -115,7 +115,7 @@ A public function is executed by the sequencer and has access to a state model t All data inserted into private storage from a public function will be publicly viewable (not private). ::: -To create a public function you can annotate it with the `#[aztec(public)]` attribute. This will make the public context available within the function's execution scope. +To create a public function you can annotate it with the `#[public]` attribute. This will make the public context available within the function's execution scope. #include_code set_minter /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust @@ -139,17 +139,17 @@ let storage = Storage::init(&mut context); - Visibility Control: The function is marked as pub, making it accessible from outside the contract. - Unconstrained Execution: Public functions are marked as unconstrained, meaning they don't generate proofs and are executed directly by the sequencer. -## Constrained `view` Functions #[aztec(view)] +## Constrained `view` Functions #[view] -The `#[aztec(view)]` attribute is used to define constrained view functions in Aztec contracts. These functions are similar to view functions in Solidity, in that they are read-only and do not modify the contract's state. They are similar to the [`unconstrained`](#unconstrained-functions-aztecunconstrained) keyword but are executed in a constrained environment. It is not possible to update state within an `#[aztec(view)]` function. +The `#[view]` attribute is used to define constrained view functions in Aztec contracts. These functions are similar to view functions in Solidity, in that they are read-only and do not modify the contract's state. They are similar to the [`unconstrained`](#unconstrained-functions-aztecunconstrained) keyword but are executed in a constrained environment. It is not possible to update state within an `#[view]` function. This means the results of these functions are verifiable and can be trusted, as they are part of the proof generation and verification process. This is unlike unconstrained functions, where results are provided by the PXE and are not verified. -This makes `#[aztec(view)]` functions suitable for critical read-only operations where the integrity of the result is crucial. Unconstrained functions, on the other hand, are executed entirely client-side without generating any proofs. It is better to use `#[aztec(view)]` if the result of the function will be used in another function that will affect state, and they can be used for cross-contract calls. +This makes `#[view]` functions suitable for critical read-only operations where the integrity of the result is crucial. Unconstrained functions, on the other hand, are executed entirely client-side without generating any proofs. It is better to use `#[view]` if the result of the function will be used in another function that will affect state, and they can be used for cross-contract calls. -`#[aztec(view)]` functions can be combined with other Aztec attributes like `#[aztec(private)]` or `#[aztec(public)]`. +`#[view]` functions can be combined with other Aztec attributes like `#[private]` or `#[public]`. -## `Initializer` Functions #[aztec(initializer)] +## `Initializer` Functions #[initializer] This is used to designate functions as initializers (or constructors) for an Aztec contract. These functions are responsible for setting up the initial state of the contract when it is first deployed. The macro does two important things: @@ -159,18 +159,18 @@ This is used to designate functions as initializers (or constructors) for an Azt Key things to keep in mind: - A contract can have multiple initializer functions defined, but only one initializer function should be called for the lifetime of a contract instance -- Other functions in the contract will have an initialization check inserted, ie they cannot be called until the contract is initialized, unless they are marked with [`#[aztec(noinitcheck)]`](#aztecnoinitcheck) +- Other functions in the contract will have an initialization check inserted, ie they cannot be called until the contract is initialized, unless they are marked with [`#[noinitcheck]`](#aztecnoinitcheck) -## #[aztec(noinitcheck)] +## #[noinitcheck] -In normal circumstances, all functions in an Aztec contract (except initializers) have an initialization check inserted at the beginning of the function body. This check ensures that the contract has been initialized before any other function can be called. However, there may be scenarios where you want a function to be callable regardless of the contract's initialization state. This is when you would use `#[aztec(noinitcheck)]`. +In normal circumstances, all functions in an Aztec contract (except initializers) have an initialization check inserted at the beginning of the function body. This check ensures that the contract has been initialized before any other function can be called. However, there may be scenarios where you want a function to be callable regardless of the contract's initialization state. This is when you would use `#[noinitcheck]`. -When a function is annotated with `#[aztec(noinitcheck)]`: +When a function is annotated with `#[noinitcheck]`: - The Aztec macro processor skips the [insertion of the initialization check](#initializer-functions-aztecinitializer) for this specific function - The function can be called at any time, even if the contract hasn't been initialized yet -## `Internal` functions #[aztec(internal)] +## `Internal` functions #[internal] This macro inserts a check at the beginning of the function to ensure that the caller is the contract itself. This is done by adding the following assertion: @@ -178,11 +178,11 @@ This macro inserts a check at the beginning of the function to ensure that the c assert(context.msg_sender() == context.this_address(), "Function can only be called internally"); ``` -## Custom notes #[aztec(note)] +## Custom notes #[note] -The `#[aztec(note)]` attribute is used to define custom note types in Aztec contracts. Learn more about notes [here](../../concepts/storage/index.md). +The `#[note]` attribute is used to define custom note types in Aztec contracts. Learn more about notes [here](../../concepts/storage/index.md). -When a struct is annotated with `#[aztec(note)]`, the Aztec macro applies a series of transformations and generates implementations to turn it into a note that can be used in contracts to store private data. +When a struct is annotated with `#[note]`, the Aztec macro applies a series of transformations and generates implementations to turn it into a note that can be used in contracts to store private data. 1. **NoteInterface Implementation**: The macro automatically implements most methods of the `NoteInterface` trait for the annotated struct. This includes: @@ -208,7 +208,7 @@ When a struct is annotated with `#[aztec(note)]`, the Aztec macro applies a seri Here is how you could define a custom note: ```rust -#[aztec(note)] +#[note] struct CustomNote { data: Field, owner: Address, @@ -293,11 +293,11 @@ Key things to keep in mind: - Developers can override any of the auto-generated methods by specifying a note interface - The note's fields are automatically serialized and deserialized in the order they are defined in the struct -## Storage struct #[aztec(storage)] +## Storage struct #[storage] -The `#[aztec(storage)]` attribute is used to define the storage structure for an Aztec contract. +The `#[storage]` attribute is used to define the storage structure for an Aztec contract. -When a struct is annotated with `#[aztec(storage)]`, the macro does this under the hood: +When a struct is annotated with `#[storage]`, the macro does this under the hood: 1. **Context Injection**: injects a `Context` generic parameter into the storage struct and all its fields. This allows the storage to interact with the Aztec context, eg when using `context.msg_sender()` @@ -310,7 +310,7 @@ When a struct is annotated with `#[aztec(storage)]`, the macro does this under t ### Before expansion ```rust -#[aztec(storage)] +#[storage] struct Storage { balance: PublicMutable, owner: PublicMutable
, diff --git a/docs/docs/guides/developer_guides/getting_started.md b/docs/docs/guides/developer_guides/getting_started.md index 5fa6e910b26..8ea5f341bdd 100644 --- a/docs/docs/guides/developer_guides/getting_started.md +++ b/docs/docs/guides/developer_guides/getting_started.md @@ -10,9 +10,10 @@ The Sandbox is an Aztec network running fully on your machine, and interacting w ## Prerequisites -You need two global dependencies iyour machine: +You need two global dependencies on your machine: -- Node.js >= v18 (recommend installing with [nvm](https://github.com/nvm-sh/nvm)) +- Node.js {'>='} v18.xx.x and {'<='} v20.17.x (lts/iron) (later versions, eg v22.9, gives an error around 'assert') + - Recommend installing with [nvm](https://github.com/nvm-sh/nvm) - Docker (visit [this page of the Docker docs](https://docs.docker.com/get-docker/) on how to install it) ## Install and run the sandbox diff --git a/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md b/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md index e2b4fa891f0..b66308412d0 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md +++ b/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md @@ -243,14 +243,14 @@ contract FPC { ... - #[aztec(private)] + #[private] fn fee_entrypoint_private(amount: Field, asset: AztecAddress, secret_hash: Field, nonce: Field) { assert(asset == storage.other_asset.read_private()); Token::at(asset).unshield(context.msg_sender(), context.this_address(), amount, nonce).call(&mut context); FPC::at(context.this_address()).pay_fee_with_shielded_rebate(amount, asset, secret_hash).enqueue(&mut context); } - #[aztec(private)] + #[private] fn fee_entrypoint_public(amount: Field, asset: AztecAddress, nonce: Field) { FPC::at(context.this_address()).prepare_fee(context.msg_sender(), amount, asset, nonce).enqueue(&mut context); FPC::at(context.this_address()).pay_fee(context.msg_sender(), amount, asset).enqueue(&mut context); diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md index dbcfd7e8a05..71c085f3ca6 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md @@ -74,7 +74,7 @@ Note in particular that the request for a witness is done by the token contract, As part of `AuthWit` we are assuming that the `on_behalf_of` implements the private function: ```rust -#[aztec(private)] +#[private] fn verify_private_authwit(inner_hash: Field) -> Field; ``` diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md index f99deb83cbd..fdcc1af2b19 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md @@ -46,14 +46,14 @@ You can't read public storage in private domain. But nevertheless reading public 1. You pass the data as a parameter to your private method and later assert in public that the data is correct. E.g.: ```rust -#[aztec(storage)] +#[storage] struct Storage { token: PublicMutable, } contract Bridge { - #[aztec(private)] + #[private] fn burn_token_private( token: AztecAddress, // pass token here since this is a private method but can't access public storage amount: Field, diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/initializers.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/initializers.md index d350301d4f7..19b525524f7 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/initializers.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/initializers.md @@ -8,12 +8,12 @@ This page explains how to write an initializer function, also known as a constru Initializers are regular functions that set an "initialized" flag (a nullifier) for the contract. A contract can only be initialized once, and contract functions can only be called after the contract has been initialized, much like a constructor. However, if a contract defines no initializers, it can be called at any time. Additionally, you can define as many initializer functions in a contract as you want, both private and public. -## Annotate with `#[aztec(initializer)]` +## Annotate with `#[initializer]` Define your initializer like so: ```rust -#[aztec(initializer)] +#[initializer] fn constructor(){ // function logic here } @@ -24,8 +24,8 @@ fn constructor(){ Aztec supports both public and private initializers. Use the appropriate macro, for example for a private initializer: ```rust -#[aztec(private)] -#[aztec(initializer)] +#[private] +#[initializer] fn constructor(){ // function logic here } @@ -41,9 +41,9 @@ Here, the initializer is writing to storage. It can also call another function. ## Multiple initializers -You can set multiple functions as an initializer function simply by annotating each of them with `#[aztec(initializer)]`. You can then decide which one to call when you are deploying the contract. +You can set multiple functions as an initializer function simply by annotating each of them with `#[initializer]`. You can then decide which one to call when you are deploying the contract. -Calling any one of the functions annotated with `#[aztec(initializer)]` will mark the contract as initialized. +Calling any one of the functions annotated with `#[initializer]` will mark the contract as initialized. See [this page of the protocol specs](../../../../protocol-specs/contract-deployment/instances.md#initialization) for more info about what marking a function as initialized means. diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/notes/custom_note.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/notes/custom_note.md index c3efb4b6844..4ca5dbfd881 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/notes/custom_note.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/notes/custom_note.md @@ -14,7 +14,7 @@ If you want to work with values or addresses, you can check out [ValueNote](./va You will likely want to define your note in a new file and import it into your contract. -A custom note type can be defined with the macro `#[aztec(note)]` used on a struct: +A custom note type can be defined with the macro `#[note]` used on a struct: #include_code state_vars-CardNote noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr rust @@ -26,7 +26,7 @@ In this example, we are implementing a card note that holds a number of `points` ## Implement NoteInterface -You will need to implement a note interface for your note. Most of this is automatically generated by the `#[aztec(note)]` macro but can be overwritten. For your reference, this is what a note interface looks like: +You will need to implement a note interface for your note. Most of this is automatically generated by the `#[note]` macro but can be overwritten. For your reference, this is what a note interface looks like: #include_code note_interface noir-projects/aztec-nr/aztec/src/note/note_interface.nr rust @@ -48,6 +48,6 @@ If you are also planning to be able to access the data with a note in public sta ## Further reading -- [What is `#[aztec(note)]` actually doing? + functions such as serialize() and deserialize()](../../../../../aztec/smart_contracts/functions/inner_workings.md#custom-notes-aztecnote) +- [What is `#[note]` actually doing? + functions such as serialize() and deserialize()](../../../../../aztec/smart_contracts/functions/inner_workings.md#custom-notes-aztecnote) - [Macros reference](../../../../../reference/developer_references/smart_contract_reference/macros.md) - [Keys, including npk_m_hash (nullifier public key master)](../../../../../aztec/concepts/accounts/keys.md) diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/storage/index.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/storage/index.md index 022c0bbbe0d..60ceb2a374a 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/storage/index.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/storage/index.md @@ -10,11 +10,11 @@ To learn more about how storage works in Aztec, read [the concepts](./storage_sl [See the storage reference](../../../../../reference/developer_references/smart_contract_reference/storage/index.md). ```rust -#[aztec(storage)] +#[storage] struct Storage { // public state variables // private state variables } ``` -If you have defined a struct and annotated it as `#[aztec(storage)]`, then it will be made available to you through the reserved `storage` keyword within your contract functions. +If you have defined a struct and annotated it as `#[storage]`, then it will be made available to you through the reserved `storage` keyword within your contract functions. diff --git a/docs/docs/reference/developer_references/debugging.md b/docs/docs/reference/developer_references/debugging.md index 1946ec9f5c1..59bd3436f6a 100644 --- a/docs/docs/reference/developer_references/debugging.md +++ b/docs/docs/reference/developer_references/debugging.md @@ -9,6 +9,12 @@ On this section you can learn how to debug your Aztec.nr smart contracts and com You can log statements from Aztec.nr contracts that will show ups in the Sandbox. +:::info + +The Noir standard library `std::println` function will not work in Aztec contracts. You must use the `debug_log` and `debug_log_format` defined below. + +::: + ### Import `debug_log` Import the `debug_log` dependency from Aztec oracles: diff --git a/docs/docs/reference/developer_references/sandbox_reference/cheat_codes.md b/docs/docs/reference/developer_references/sandbox_reference/cheat_codes.md index ccf52eddb82..0cbbcf69ccb 100644 --- a/docs/docs/reference/developer_references/sandbox_reference/cheat_codes.md +++ b/docs/docs/reference/developer_references/sandbox_reference/cheat_codes.md @@ -463,7 +463,7 @@ The baseSlot is specified in the Aztec.nr contract. #### Example ```rust -#[aztec(storage)] +#[storage] struct Storage { balances: Map>, } @@ -494,7 +494,7 @@ Note: One Field element occupies a storage slot. Hence, structs with multiple fi #### Example ```rust -#[aztec(storage)] +#[storage] struct Storage { balances: Map>, } @@ -526,7 +526,7 @@ Note: One Field element occupies a storage slot. Hence, structs with multiple fi #### Example ```rust -#[aztec(storage)] +#[storage] struct Storage { ... pending_shields: PrivateSet, diff --git a/docs/docs/reference/developer_references/smart_contract_reference/macros.md b/docs/docs/reference/developer_references/smart_contract_reference/macros.md index a68b305ddc0..533bcff73b5 100644 --- a/docs/docs/reference/developer_references/smart_contract_reference/macros.md +++ b/docs/docs/reference/developer_references/smart_contract_reference/macros.md @@ -9,12 +9,14 @@ tags: [contracts, functions] In addition to the function macros in Noir, Aztec also has its own macros for specific functions. An Aztec contract function can be annotated with more than 1 macro. It is also worth mentioning Noir's `unconstrained` function type [here (Noir docs page)](https://noir-lang.org/docs/noir/concepts/unconstrained/). -- `#[aztec(public)]` or `#[aztec(private)]` - Whether the function is to be executed from a public or private context (see Further Reading) -- `#[aztec(initializer)]` - If one or more functions are marked as an initializer, then one of them must be called before any non-initilizer functions -- `#[aztec(noinitcheck)]` - The function is able to be called before an initializer (if one exists) -- `#[aztec(view)]` - Makes calls to the function static (see also [Static calls in the protocol spec](../../../protocol-specs/calls/static-calls.md)) -- `#[aztec(internal)]` - Function can only be called from within the contract -- `#[aztec(note)]` - Creates a custom note +- `#[aztec]` - Defines a contract, placed above `contract ContractName{}` +- `#[public]` or `#[private]` - Whether the function is to be executed from a public or private context (see Further Reading) +- `#[initializer]` - If one or more functions are marked as an initializer, then one of them must be called before any non-initilizer functions +- `#[noinitcheck]` - The function is able to be called before an initializer (if one exists) +- `#[view]` - Makes calls to the function static (see also [Static calls in the protocol spec](../../../protocol-specs/calls/static-calls.md)) +- `#[internal]` - Function can only be called from within the contract +- `#[note]` - Creates a custom note +- `#[storage]` - Defines contract storage ## Further reading [How do Aztec macros work? (Concepts)](../../../aztec/smart_contracts/functions/inner_workings.md) diff --git a/docs/docs/reference/developer_references/smart_contract_reference/storage/index.md b/docs/docs/reference/developer_references/smart_contract_reference/storage/index.md index 7d3730efc64..02f38916a48 100644 --- a/docs/docs/reference/developer_references/smart_contract_reference/storage/index.md +++ b/docs/docs/reference/developer_references/smart_contract_reference/storage/index.md @@ -7,7 +7,7 @@ Smart contracts rely on storage, acting as the persistent memory on the blockcha To learn how to define a storage struct, read [this guide](../../../../guides/developer_guides/smart_contracts/writing_contracts/storage/index.md). To learn more about storage slots, read [this explainer in the Concepts section](../../../../aztec/concepts/storage/index.md). -You control this storage in Aztec using a struct annotated with `#[aztec(storage)]`. This struct serves as the housing unit for all your smart contract's state variables - the data it needs to keep track of and maintain. +You control this storage in Aztec using a struct annotated with `#[storage]`. This struct serves as the housing unit for all your smart contract's state variables - the data it needs to keep track of and maintain. These state variables come in two forms: [public](./public_state.md) and [private](./private_state.md). Public variables are visible to anyone, and private variables remain hidden within the contract. A state variable with both public and private components is said to be [shared](./shared_state.md). @@ -35,19 +35,19 @@ Aztec.nr prevents developers from calling functions unavailable in the current e All state variables are generic over this `Context` type, and expose different methods in each execution mode. In the example above, `PublicImmutable`'s `initialize` function is only available with a public execution context, and so the following code results in a compilation error: ```rust -#[aztec(storage)] +#[storage] struct Storage { variable: PublicImmutable, } -#[aztec(private)] +#[private] fn some_private_function() { storage.variable.initialize(0); // ^ ERROR: Expected type PublicImmutable<_, &mut PublicContext>, found type PublicImmutable } ``` -The `Context` generic type parameter is not visible in the code above as it is automatically injected by the `#[aztec(storage)]` macro, in order to reduce boilerplate. Similarly, all state variables in that struct (e.g. `PublicImmutable`) similarly have that same type parameter automatically passed to them. +The `Context` generic type parameter is not visible in the code above as it is automatically injected by the `#[storage]` macro, in order to reduce boilerplate. Similarly, all state variables in that struct (e.g. `PublicImmutable`) similarly have that same type parameter automatically passed to them. ## Map diff --git a/docs/docs/tutorials/codealong/contract_tutorials/counter_contract.md b/docs/docs/tutorials/codealong/contract_tutorials/counter_contract.md index 3cada7c837f..227695fa135 100644 --- a/docs/docs/tutorials/codealong/contract_tutorials/counter_contract.md +++ b/docs/docs/tutorials/codealong/contract_tutorials/counter_contract.md @@ -99,13 +99,13 @@ Add this below the imports. It declares the storage variables for our contract. Now we’ve got a mechanism for storing our private state, we can start using it to ensure the privacy of balances. -Let’s create a constructor method to run on deployment that assigns an initial supply of tokens to a specified owner. This function is called `initialize`, but behaves like a constructor. It is the `#[aztec(initializer)]` decorator that specifies that this function behaves like a constructor. Write this: +Let’s create a constructor method to run on deployment that assigns an initial supply of tokens to a specified owner. This function is called `initialize`, but behaves like a constructor. It is the `#[initializer]` decorator that specifies that this function behaves like a constructor. Write this: #include_code constructor /noir-projects/noir-contracts/contracts/counter_contract/src/main.nr rust This function accesses the counts from storage. Then it assigns the passed initial counter to the `owner`'s counter privately using `at().add()`. -We have annotated this and other functions with `#[aztec(private)]` which are ABI macros so the compiler understands it will handle private inputs. +We have annotated this and other functions with `#[private]` which are ABI macros so the compiler understands it will handle private inputs. ## Incrementing our counter @@ -159,4 +159,4 @@ Follow the private voting contract tutorial on the [next page](./private_voting_ ### Optional: Learn more about concepts mentioned here -- [Functions and annotations like `#[aztec(private)]`](../../../aztec/smart_contracts/functions/inner_workings.md) + - [Functions and annotations like `#[private]`](../../../aztec/smart_contracts/functions/inner_workings.md) diff --git a/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md b/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md index 3c57628df9a..66dece82714 100644 --- a/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md +++ b/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md @@ -176,7 +176,7 @@ This function sets the creator of the contract (passed as `msg_sender` from the ### Public function implementations -Public functions are declared with the `#[aztec(public)]` macro above the function name. +Public functions are declared with the `#[public]` macro above the function name. As described in the [execution contexts section above](#execution-contexts), public function logic and transaction information is transparent to the world. Public functions update public state, but can be used to prepare data to be used in a private context, as we will go over below (e.g. see the [shield](#shield) function). @@ -244,10 +244,10 @@ After storage is initialized, the [authorization flow specified above](#authoriz ### Private function implementations -Private functions are declared with the `#[aztec(private)]` macro above the function name like so: +Private functions are declared with the `#[private]` macro above the function name like so: ```rust - #[aztec(private)] + #[private] fn redeem_shield( ```