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/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,6 @@ The Private eXecution Environment (PXE) within the `aztec-wallet` will be used.
14
14
15
15
## Contributions
16
16
17
-
Example in this repo are heavily curated to showcase and explain atomic functionality of Aztec, as well as slightly larger examples for broader concepts.
17
+
Examples in this repo are heavily curated to showcase and explain atomic functionality of Aztec, as well as slightly larger examples for broader concepts.
18
18
19
-
Developers: Pull requests contining examples with code AND documentation that fit the brief will be considered.
19
+
Developers: Pull requests containing examples with code AND documentation that fit the brief will be considered.
@@ -65,7 +88,7 @@ Since private functions are executed client side and the proof of execution is u
65
88
66
89
Public functions are executed as part of the protocol, so the total cost of operations is important, which is measured in gas.
67
90
68
-
We can compile and then calculate the gates required for this private function.
91
+
We can compile and then calculate the gates required for the private function, `div_prv`. To see gas for the public function, we will deploy the contract and call `div_exe`.
69
92
70
93
## Building the project
71
94
### Compile the contract
@@ -82,12 +105,36 @@ make
82
105
The gate flamegraph of a specific function can be calculate and presented by passing the function name to:
83
106
84
107
```bash
85
-
make gate-flamegraph <function-name>
108
+
make gate-flamegraph div_prv
86
109
```
87
110
88
-
eg: `make gate-flamegraph mul_8_prv`
111
+
In the terminal you'll see: `Opcode count: 775, Total gates by opcodes: 5197, Circuit size: 5962`
112
+
113
+
Also go to the URL in the command output to see the gate count total, and of each sub-section. The exported .svg file is in the `target` directory.
114
+
115
+
### Unconstrained cost in private
89
116
90
-
Go to the URL in the command output to see the gate count total, and of each sub-section. The exported .svg file is in the `target` directory.
117
+
To assess the cost of the unconstrained function in private, lets replace its call with a result directly, eg `(2, 2)`
118
+
119
+
```rust
120
+
#[private] // use macro to wrap for private execution
In the terminal you'll see the same counts: `Opcode count: 775, Total gates by opcodes: 5197, Circuit size: 5962`
136
+
137
+
That is, the unconstrained function does NOT contribute to gate count in the private function. So the result from this unconstrained function must then be verified in the calling constrained function (via `assert`).
-`no-init` is specified because we do not have or need a constractor/`initializer` for this example
165
+
-`no-init` is specified because we do not have or need a constructor/`initializer` for this example
119
166
- The last param requests the deployed contract address be aliased to `hello`
120
167
121
168
### Command summary script
@@ -125,24 +172,75 @@ For convenience/reference, these commands are consolidated in a script. To see t
125
172
./run.sh --help
126
173
```
127
174
128
-
### Profile gate count
175
+
### Showing gas cost for a transaction
129
176
130
-
To see a breakdown of proving times and gate counts per inner-circuit:
177
+
With the sandbox running and contract deployed (see earlier section), we can now interact with the public function:
131
178
132
179
```bash
133
-
./run.sh gate-profile mul_8_prv 8
180
+
./run.sh hello-fn div_exe 8 3
134
181
```
135
182
136
-
This command expects the contract in `hello.nr` to be deployed, and the contract address aliased to `hello`.
183
+
```bash
184
+
Transaction has been mined
185
+
Tx fee: 39680550
186
+
...
187
+
```
137
188
138
-
This uses the deployed contract to provide a breakdown of time and gates for each inner function. This will become useful when comparing
189
+
Lets assess the cost of the unconstrained function in public by replacing the call with a result:
139
190
140
-
## Compare implementations
191
+
```rust
192
+
let (quotient, remainder) = (2, 2); // divide(dividend, divisor);
193
+
```
141
194
195
+
Compiling, deploying, then calling:
142
196
197
+
```bash
198
+
make
199
+
./run.sh hello-deploy
200
+
./run.sh hello-fn div_exe 8 3
201
+
```
202
+
203
+
The result will show a lower gas cost:
204
+
```bash
205
+
Transaction has been mined
206
+
Tx fee: 33770160
207
+
```
208
+
209
+
That is, the unconstrained function call from public contributes to the cost.
210
+
211
+
### Comparison
212
+
213
+
The above example highlights that coding things well in private may have unexpected costs if used in public.
214
+
215
+
Another example of this is in the use of memory. This is cheaper in private circuits (witness values) and expensive in public (operations to read across different memory locations).
216
+
217
+
## Further use
218
+
219
+
### Testing output
143
220
144
-
## Calling private functions
221
+
For a quick sneak peak into testing, see the functions after the Noir divide function: `setup()` and `test_funcs()`. Notice the more explicity way of calling a function from a private or public context.
222
+
223
+
Tests are simply run with the command: `aztec test`
- Runs nargo tests pointing to the txe as an oracle - `nargo test --silence-warnings --pedantic-solving --oracle-resolver http://127.0.0.1:8081`
228
+
229
+
We'll modify the second command to show the `println` output:
230
+
- Start TXE - `aztec start --txe --port=8081` (in a separate terminal)
231
+
- Test - `nargo test --oracle-resolver http://127.0.0.1:8081 --show-output`
232
+
233
+
### Profile gate count
234
+
235
+
To see a breakdown of proving times and gate counts per inner-circuit:
236
+
237
+
```bash
238
+
./run.sh gate-profile div_prv 8 3
239
+
```
240
+
241
+
This command expects the contract in `hello.nr` to be deployed, and the contract address aliased to `hello`.
145
242
243
+
This uses the deployed contract to provide a breakdown of time and gates for each inner function. This will become useful when comparing calls into contexts.
0 commit comments