You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/developers/docs/concepts/call_types.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,7 @@ While Ethereum contracts are defined by bytecode that runs on the EVM, Aztec con
97
97
98
98
### Private Execution
99
99
100
-
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.
100
+
Contract functions marked with `#[external("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.
101
101
102
102
#### Private Calls
103
103
@@ -153,7 +153,7 @@ For this reason it is encouraged to try to avoid public function calls and inste
153
153
154
154
### Public Execution
155
155
156
-
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.).
156
+
Contract functions marked with `#[external("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.).
157
157
158
158
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.
159
159
@@ -167,7 +167,7 @@ This is the same function that was called by privately enqueuing a call to it! P
167
167
168
168
### Utility
169
169
170
-
Contract functions marked with `#[utility]` cannot be called as part of a transaction, and are only invoked by applications that interact with contracts to perform state queries from an offchain client (from both private and public state!) or to modify local contract-related PXE state (e.g. when processing logs in Aztec.nr). No guarantees are made on the correctness of the result since the entire execution is unconstrained and heavily reliant on oracle calls. It is possible however to verify that the bytecode being executed is the correct one, since a contract's address includes a commitment to all of its utility functions.
170
+
Contract functions marked with `#[external("utility")]` cannot be called as part of a transaction, and are only invoked by applications that interact with contracts to perform state queries from an offchain client (from both private and public state!) or to modify local contract-related PXE state (e.g. when processing logs in Aztec.nr). No guarantees are made on the correctness of the result since the entire execution is unconstrained and heavily reliant on oracle calls. It is possible however to verify that the bytecode being executed is the correct one, since a contract's address includes a commitment to all of its utility functions.
The `update` function in the registry is a public function, so you can enqueue it from a private function like the example or call it from a public function directly.
44
44
45
45
:::note
46
-
Recall that `#[private]` means calling this function preserves privacy, and it still CAN be called externally by anyone.
46
+
Recall that `#[external("private")]` means calling this function preserves privacy, and it still CAN be called externally by anyone.
47
47
So the `update_to` function above allows anyone to update the contract that implements it. A more complete implementation should have a proper authorization systems to secure contracts from malicious upgrades.
48
48
:::
49
49
@@ -54,7 +54,7 @@ This means that they have a delay before entering into effect. The default delay
Copy file name to clipboardExpand all lines: docs/docs/developers/docs/concepts/smart_contracts/functions/attributes.md
+14-8Lines changed: 14 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,17 @@ On this page you will learn about function attributes and macros.
9
9
10
10
If you are looking for a reference of function macros, go [here](../../../reference/smart_contract_reference/macros.md).
11
11
12
-
## Private functions #[private]
12
+
#External functions #[external("...")]
13
13
14
-
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.
14
+
Like in Solidity, external functions can be called from outside the contract.
15
+
There are 3 types of external functions differing in the execution environment they are executed in: private, public, and utility.
16
+
We will describe each type in the following sections.
15
17
16
-
`#[private]` is just syntactic sugar. At compile time, the Aztec.nr framework inserts code that allows the function to interact with the [kernel](../../advanced/circuits/kernels/private_kernel.md).
18
+
## Private functions #[external("private")]
19
+
20
+
A private function operates on private information, and is executed by the user on their device. Annotate the function with the `#[external("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.
21
+
22
+
`#[external("private")]` is just syntactic sugar. At compile time, the Aztec.nr framework inserts code that allows the function to interact with the [kernel](../../advanced/circuits/kernels/private_kernel.md).
17
23
18
24
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.
19
25
@@ -76,9 +82,9 @@ Any state variables declared in the `Storage` struct can now be accessed as norm
76
82
77
83
This function takes the application context, and converts it into the `PrivateCircuitPublicInputs` structure. This structure is then passed to the kernel circuit.
78
84
79
-
## Utility functions #[utility]
85
+
## Utility functions #[external("utility")]
80
86
81
-
Contract functions marked with `#[utility]` are used to perform state queries from an offchain client (from both private and public state!) or to modify local contract-related PXE state (e.g. when processing logs in Aztec.nr), and are never included in any transaction. No guarantees are made on the correctness of the result since the entire execution is unconstrained and heavily reliant on [oracle calls](https://noir-lang.org/docs/explainers/explainer-oracle).
87
+
Contract functions marked with `#[external("utility")]` are used to perform state queries from an offchain client (from both private and public state!) or to modify local contract-related PXE state (e.g. when processing logs in Aztec.nr), and are never included in any transaction. No guarantees are made on the correctness of the result since the entire execution is unconstrained and heavily reliant on [oracle calls](https://noir-lang.org/docs/explainers/explainer-oracle).
82
88
83
89
Any programming language could be used to construct these queries, since all they do is perform arbitrary computation on data that is either publicly available from any node, or locally available from the PXE. Utility functions exist as Noir contract code because they let developers utilize the rest of the contract code directly by being part of the same Noir crate, and e.g. use the same libraries, structs, etc. instead of having to rely on manual computation of storage slots, struct layout and padding, and so on.
84
90
@@ -110,15 +116,15 @@ Beyond using them inside your other functions, they are convenient for providing
110
116
Note, that utility functions can have access to both private and (historical) public data when executed on the user's device. This is possible since these functions are not invoked as part of transactions, so we don't need to worry about preventing a contract from e.g. accidentally using stale or unverified public state.
111
117
:::
112
118
113
-
## Public functions #[public]
119
+
## Public functions #[external("public")]
114
120
115
121
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.
116
122
117
123
:::note
118
124
All data inserted into private storage from a public function will be publicly viewable (not private).
119
125
:::
120
126
121
-
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.
127
+
To create a public function you can annotate it with the `#[external("public")]` attribute. This will make the public context available within the function's execution scope.
@@ -144,7 +150,7 @@ let storage = Storage::init(&mut context);
144
150
145
151
## Constrained `view` Functions #[view]
146
152
147
-
The `#[view]` attribute can be applied to a `#[private]` or a `#[public]` function and it guarantees that the function cannot modify any contract state (just like `view` functions in Solidity).
153
+
The `#[view]` attribute can be applied to a `#[external("private")]` or a `#[external("public")]` function and it guarantees that the function cannot modify any contract state (just like `view` functions in Solidity).
0 commit comments