bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 72쪽
sg_sender`
* `self.enqueue_view_incognito(...)` - Enqueue a static call to an external function but hides the `msg_sender`
* `self.set_as_teardown(...)` - Enqueue a call to an external public function and sets the call as teardown
* `self.set_as_teardown_incognito(...)` - Enqueue a call to an external public function and sets the call as teardown and hides the `msg_sender`
* `self.internal.my_internal_fn(...)` - Call an internal function
`self` also provides you with convenience API to call and enqueue calls to external functions from within the same contract (this is just a convenience API as `self.call(MyContract::at(self.address).my_external_fn(...))` would also work):
* `self.call_self.my_external_fn(...)` - Call external function from within the same contract
* `self.enqueue_self.my_public_external_fn(...)`
* `self.call_self_static.my_static_external_fn(...)`
* `self.enqueue_self_static.my_static_external_public_fn(...)`
##### How it works[](#how-it-works "Direct link to How it works")
The `#[external(...)]` macro automatically injects `self` into your function. When you write:
```
#[external("private")]
fn transfer(amount: u128, recipient: AztecAddress) {
let sender = self.msg_sender().unwrap();
self.storage.balances.at(sender).sub(amount);
self.storage.balances.at(recipient).add(amount);
}
```
The macro transforms it to initialize `self` with the context and storage before your code executes.
##### Migration guide[](#migration-guide "Direct link to Migration guide")
**Before:** Access context and storage as separate parameters
```
#[external("private")]
fn old_transfer(amount: u128, recipient: AztecAddress) {
let storage = Storage::init(context);
let sender = context.msg_sender().unwrap();
storage.balances.at(sender).sub(amount);
}
```
**After:** Use `self` to access everything
```
#[external("private")]
fn new_transfer(amount: u128, recipient: AztecAddress) {
let sender = self.msg_sender().unwrap();
self.storage.balances.at(sender).sub(amount);
}
```
##### Key changes[](#key-changes "Direct link to Key changes")
1. **Storage and context access:**
Storage and context are no longer injected into the function as standalone variables and instead you need to access them via `self`:
```
- let balance = storage.balances.at(owner).read();
+ let balance = self.storage.balances.at(owner).read();
```
```
- context.push_nullifier(nullifier);
+ self.context.push_nullifier(nullifier);
```
Note that `context` is expected to be use only when needing to access a low-level API (like directly emitting a nullifier).
2. **Getting caller address:** Use `self.msg_sender()` instead of `context.msg_sender()`
```
- let caller = context.msg_sender().unwrap();
+ let caller = self.msg_sender().unwrap();
```
3. **Getting contract address:** Use `self.address` instead of `context.this_address()`
```
- let this_contract = context.this_address();
+ let this_contract = self.address;
```
4. **Emitting events:**
In private functions:
```
- emit_event_in_private(event, context, recipient, delivery_mode);
+ self.emit(event, recipient, delivery_mode);
```
In public functions:
```
- emit_event_in_public(event, context);
+ self.emit(event);
```
5. **Calling functions:**
In private functions:
```
- Token::at(stable_coin).mint_to_public(to, amount).call(&mut context);
+ self.call(Token::at(stable_coin).mint_to_public(to, amount));
```
##### Example: Full contract migration[](#example-full-contract-migration "Direct link to Example: Full contract migration")
**Before:**
```
#[external("private")]
fn withdraw(amount: u128, recipient: AztecAddress) {
let storage = Storage::init(context);
let sender = context.msg_sender().unwrap();
let token = storage.donation_token.get_note().get_address();
// ... withdrawal logic
emit_event_in_private(Withdraw { withdrawer, amount }, context, withdrawer, MessageDelivery.UNCONSTRAINED_ONCHAIN);
}
```
**After:**
```
#[external("private")]
fn withdraw(amount: u128, recipient: AztecAddress) {
let sender = self.msg_sender().unwrap();
let token = self.storage.donation_token.get_note().get_address();
// ... withdrawal logic
self.emit(Withdraw { withdrawer, amount }, withdrawer, MessageDelivery.UNCONSTRAINED_ONCHAIN);
}
```
#### No-longer allowing calling of non-view function statically via the old higher-level API[](#no-longer-allowing-calling-of-non-view-function-statically-via-the-old-higher-level-api "Direct link to No-longer allowing calling of non-view function statically via the old higher-level API")
We used to allow calling of non-view function statically as follows:
```
MyContract::at(address).my_non_view_function(...).view(context);
MyContract::at(address).my_non_view_function(...).enqueue_view(context);
```
This is no-longer allowed and if you will want to call a function statically you will need to mark the function with `#[view]`.
### Phase checks[](#phase-checks "Direct link to Phase checks")
Now private external functions check by default that no phase change from non revertible to revertible happens during the execution of the function or any of its nested calls. If you're developing a function that handles phase change (you call `context.end_setup()` or call a function that you expect will change phase) you need to opt out of the phase check using the `#[nophasecheck]` macro. Also, now it's possible to know if you're in the revertible phase of the transaction at any point using `self.context.in_revertible_phase()`.
### \[`aztec` command] Moving functionality of `aztec-nargo` to `aztec` command[](#aztec-command-moving-functionality-of-aztec-nargo-to-aztec-command "Direct link to aztec-command-moving-functionality-of-aztec-nargo-to-aztec-command")
`aztec-nargo` has been deprecated and all workflows should now migrate to the `aztec` command that fully replaces `aztec-nargo`:
* **For contract initialization:**
```
aztec init
```
(Behaves like `nargo init`, but defaults to a contract project.)
* **For testing:**
```
aztec test
```
(Starts the Aztec TXE and runs your tests.)
* **For compiling contracts:**
```
aztec compile
```
(Transpiles your contracts and generates verification keys.)
## 3.0.0-devnet.4[](#300-devnet4 "Direct link to 3.0.0-devnet.4")
## \[aztec.js] Removal of barrel export[](#aztecjs-removal-of-barrel-export "Direct link to \[aztec.js] Removal of barrel export")
`aztec.js` is now divided into granular exports, which improves loading performance in node.js and also makes the job of web bundlers easier:
```
-import { AztecAddress, Fr, getContractInstanceFromInstantiationParams, type Wallet } from '@aztec/aztec.js';
+import { AztecAddress } from '@aztec/aztec.js/addresses';
+import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
+import { Fr } from '@aztec/aztec.js/fields';
+import type { Wallet } from '@aztec/aztec.js/wallet';
```
Additionally, some general utilities reexported from `foundation` have been removed:
```
-export { toBigIntBE } from '@aztec/foundation/bigint-buffer';
-export { sha256, Grumpkin, Schnorr } from '@aztec/foundation/crypto';
-export { makeFetch } from '@aztec/foundation/json-rpc/client';
-export { retry, retryUntil } from '@aztec/foundation/retry';
-export { to2Fields, toBigInt } from '@aztec/foundation/serialize';
-export { sleep } from '@aztec/foundation/sleep';
-export { elapsed } from '@aztec/foundation/timer';
-export { type FieldsOf } from '@aztec/foundation/types';
-export { fileURLToPath } from '@aztec/foundation/url';
```
### `getSenders` renamed to `getAddressBook` in wallet interface[](#getsenders-renamed-to-getaddressbook-in-wallet-interface "Direct link to getsenders-renamed-to-getaddressbook-in-wallet-interface")
An app could request "contacts" from the wallet, which don't necessarily have to be senders in the wallet's PXE. This method has been renamed to reflect that fact:
```
-wallet.getSenders();
+wallet.getAddressBook();
```
### Removal of `proveTx` from `Wallet` interface[](#removal-of-provetx-from-wallet-interface "Direct link to removal-of-provetx-from-wallet-interface")
Exposing this method on the interface opened the door for certain types of attacks, were an app could route proven transactions through malicious nodes (that stored them for later decryption, or collected user IPs for example). It also made transactions difficult to track for the wallet, since they could be sent without their knowledge at any time. This change also affects `ContractFunctionInteraction` and `DeployMethod`, which no longer expose a `prove()` method.
### `msg_sender` is now an `Option<AztecAddress>` type.[](#msg_sender-is-now-an-optionaztecaddress-type "Direct link to msg_sender-is-now-an-optionaztecaddress-type")
Because Aztec has native account abstraction, the very first function call of a tx has no `msg_sender`. (Recall, the first function call of an Aztec transaction is always a *private* function call).
Previously (before this change) we'd been silently setting this first `msg_sender` to be `AztecAddress::from_field(-1);`, and enforcing this value in the protocol's kernel circuits. Now we're passing explicitness to smart contract developers by wrapping `msg_sender` in an `Option` type. We'll explain the syntax shortly.
We've also added a new protocol feature. Previously (before this change) whenever a public function call was enqueued by a private function (a so-called private->public call), the called public function (and hence the whole world) would be able to see `msg_sender`. For some use cases, visibility of `msg_sender` is important, to ensure the caller executed certain checks in private-land. For `#[only_self]` public functions, visibility of `msg_sender` is unavoidable (the caller of an `#[only_self]` function must be the same contract address by definition). But for *some* use cases, a visible `msg_sender` is an unnecessary privacy leakage. We therefore have added a feature where `msg_sender` can be optionally set to `Option<AztecAddress>::none()` for enqueued public function calls (aka private->public calls). We've been colloquially referring to this as "setting msg\_sender to null".
#### Aztec.nr diffs[](#aztecnr-diffs "Direct link to Aztec.nr diffs")
> Note: we'll be doing another pass at this aztec.nr syntax in the near future.
Given the above, the syntax for accessing `msg_sender` in Aztec.nr is slightly different:
For most public and private functions, to adjust to this change, you can make this change to your code:
```
- let sender: AztecAddress = context.msg_sender();
+ let sender: AztecAddress = context.msg_sender().unwrap();
```
Recall that `Option::unwrap()` will throw if the Option is "none".
Indeed, most smart contract functions will require access to a proper contract address (instead of a "null" value), in order to do bookkeeping (allocation of state variables against user addresses), and so in such cases throwing is sensible behaviour.
If you want to output a useful error message when unwrapping fails, you can use `Option::expect`:
```
- let sender: AztecAddress = context.msg_sender();
+ let sender: AztecAddress = context.msg_sender().expect(f"Sender must not be none!");
```
For a minority of functions, a "null" msg\_sender will be acceptable:
* A private entrypoint function.
* A public function which doesn't seek to do bookkeeping against `msg_sender`.
Some apps might even want to *assert* that the `msg_sender` is "null" to force their users into strong privacy practices:
```
let sender: Option<AztecAddress> = context.msg_sender();
assert(sender.is_none());
```
##### Enqueueing public function calls[](#enqueueing-public-function-calls "Direct link to Enqueueing public function calls")
###### Auto-generated contract interfaces[](#auto-generated-contract-interfaces "Direct link to Auto-generated contract interfaces")
When you use the `#[aztec]` macro, it will generate a noir contract interface for your contract, behind the scenes.
This provides pretty syntax when you come to call functions of that contract. E.g.:
```
Token::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context);
```
In keeping with this new feature of being able to enqueue public function calls with a hidden `msg_sender`, there are some new methods that can be chained instead of `.enqueue(...)`:
* `enqueue_incognito` -- akin to `enqueue`, but `msg_sender` is set "null".
* `enqueue_view_incognito` -- akin to `enqueue_view`, but `msg_sender` is "null".
* `set_as_teardown_incognito` -- akin to `set_as_teardown`, but `msg_sender` is "null".
> The name "incognito" has been chosen to imply "msg\_sender will not be visible to observers".
These new functions enable the *calling* contract to specify that it wants its address to not be visible to the called public function. This is worth re-iterating: it is the *caller's* choice. A smart contract developer who uses these functions must be sure that the target public function will accept a "null" `msg_sender`. It would not be good (for example) if the called public function did `context.msg_sender().unwrap()`, because then a public function that is called via `enqueue_incognito` would *always fail*! Hopefully smart contract developers will write sufficient tests to catch such problems during development!
###### Making lower-level public function calls from the private context[](#making-lower-level-public-function-calls-from-the-private-context "Direct link to Making lower-level public function calls from the private context")
This is discouraged vs using the auto-generated contract interfaces described directly above.
If you do use any of these low-level methods of the `PrivateContext` in your contract:
* `call_public_function`
* `static_call_public_function`
* `call_public_function_no_args`
* `static_call_public_function_no_args`
* `call_public_function_with_calldata_hash`
* `set_public_teardown_function`
* `set_public_teardown_function_with_calldata_hash`
... there is a new `hide_msg_sender: bool` parameter that you will need to specify.
#### Aztec.js diffs[](#aztecjs-diffs "Direct link to Aztec.js diffs")
> Note: we'll be doing another pass at this aztec.js syntax in the near future.
When lining up a new tx, the `FunctionCall` struct has been extended to include a `hide_msg_sender: bool` field.
* `is_public & hide_msg_sender` -- will make a public call with `msg_sender` set to "null".
* `is_public & !hide_msg_sender` -- will make a public call with a visible `msg_sender`, as was the case before this new feature.
* `!is_public & hide_msg_sender` -- Incompatible flags.
* `!is_public & !hide_msg_sender` -- will make a private call with a visible `msg_sender` (noting that since it's a private function call, the `msg_sender` will only be visible to the called private function, but not to the rest of the world).
## \[cli-wallet][](#cli-wallet "Direct link to \[cli-wallet]")
The `deploy-account` command now requires the address (or alias) of the account to deploy as an argument, not a parameter
```
+aztec-wallet deploy-account main
-aztec-wallet deploy-account -f main
```
This release includes a major architectural change to the system. The PXE JSON RPC Server has been removed, and PXE is now available only as a library to be used by wallets.
## \[Aztec node][](#aztec-node "Direct link to \[Aztec node]")
Network config. The node now pulls default configuration from the public repository [AztecProtocol/networks](https://github.com/AztecProtocol/networks) after it applies the configuration it takes from the running environment and the configuration values baked into the source code. See associated [Design document](https://github.com/AztecProtocol/engineering-designs/blob/15415a62a7c8e901acb8e523625e91fc6f71dce4/docs/network-config/dd.md)
## \[Aztec.js][](#aztecjs "Direct link to \[Aztec.js]")
### Removing Aztec cheatcodes[](#removing-aztec-cheatcodes "Direct link to Removing Aztec cheatcodes")
The Aztec cheatcodes class has been removed. Its functionality can be replaced by using the `getNotes(...)` function directly available on our `TestWallet`, along with the relevant functions available on the Aztec Node interface (note that the cheatcodes were generally just a thin wrapper around the Aztec Node interface).
### CLI Wallet commands dropped from `aztec` command[](#cli-wallet-commands-dropped-from-aztec-command "Direct link to cli-wallet-commands-dropped-from-aztec-command")
The following commands used to be exposed by both the `aztec` and the `aztec-wallet` commands:
* import-test-accounts
* create-account
* deploy-account
* deploy
* send
* simulate
* profile
* bridge-fee-juice
* create-authwit
* authorize-action
* get-tx
* cancel-tx
* register-sender
* register-contract
These were dropped from `aztec` and now are exposed only by the `cli-wallet` command exposed by the `@aztec/cli-wallet` package.
### PXE commands dropped from `aztec` command[](#pxe-commands-dropped-from-aztec-command "Direct link to pxe-commands-dropped-from-aztec-command")
The following commands were dropped from the `aztec` command:
* `add-contract`: use can be replaced with `register-contract` on our `cli-wallet`
* `get-contract-data`: debug-only and not considered important enough to need a replacement
* `get-accounts`: debug-only and can be replaced by loading aliases from `cli-wallet`
* `get-account`: debug-only and can be replaced by loading aliases from `cli-wallet`
* `get-pxe-info`: debug-only and not considered important enough to need a replacement
## \[Aztec.nr][](#aztecnr "Direct link to \[Aztec.nr]")
### Replacing #\[private], #\[public], #\[utility] with #\[external(...)] macro[](#replacing-private-public-utility-with-external-macro "Direct link to Replacing #\[private], #\[public], #\[utility] with #\[external(...)] macro")
The original naming was not great in that it did not sufficiently communicate what the given macro did. We decided to rename `#[private]` as `#[external("private")]`, `#[public]` as `#[external("public")]`, and `#[utility]` as `#[external("utility")]` to better communicate that these functions are externally callable and to specify their execution context. In this sense, `external` now means the exact same thing as in Solidity, i.e. a function that can be called from other contracts, and that can only be invoked via a contract call (i.e. the `CALL` opcode in the EVM, and a kernel call/AVM `CALL` opcode in Aztec).
You have to do the following changes in your contracts:
Update import:
```
- use aztec::macros::functions::private;
- use aztec::macros::functions::public;
- use aztec::macros::functions::utility;
+ use aztec::macros::functions::external;
```
Update attributes of your functions:
```
- #[private]
+ #[external("private")]
fn my_private_func() {
```
```
- #[public]
+ #[external("public")]
fn my_public_func() {
```
```
- #[utility]
+ #[external("utility")]
fn my_utility_func() {
```
### Dropping remote mutable references to public context[](#dropping-remote-mutable-references-to-public-context "Direct link to Dropping remote mutable references to public context")
`PrivateContext` generally needs to be passed as a mutable reference to functions because it does actually hold state we're mutating. This is not the case for `PublicContext`, or `UtilityContext` - these are just marker objects that indicate the current execution mode and make available the correct subset of the API. For this reason we have dropped the mutable reference from the API.
If you've passed the context as an argument to custom functions you will need to do the following migration (example from our token contract):
```
#[contract_library_method]
fn _finalize_transfer_to_private(
from_and_completer: AztecAddress,
amount: u128,
partial_note: PartialUintNote,
- context: &mut PublicContext,
- storage: Storage<&mut PublicContext>,
프로젝트로 돌아가기