Aztec 백서

Aztec

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 64쪽

. })` | **New query and response shapes:** ``` // Query type TagQuery<T> = T | { tag: T; afterLog?: LogCursor }; type LogsQueryBase = { fromBlock?: BlockNumber; // inclusive toBlock?: BlockNumber; // exclusive txHash?: TxHash; // mutually exclusive with fromBlock/toBlock referenceBlock?: BlockHash; // reorg-safety anchor; throws if missing includeEffects?: boolean; // attach noteHashes + all nullifiers }; type PrivateLogsQuery = LogsQueryBase & { tags: TagQuery<SiloedTag>[] }; type PublicLogsQuery = LogsQueryBase & { contractAddress: AztecAddress; tags: TagQuery<Tag>[]; }; // Response (per log) type LogResult = { logData: Fr[]; blockNumber: BlockNumber; blockHash: BlockHash; blockTimestamp: UInt64; txHash: TxHash; logIndexWithinTx: number; noteHashes?: Fr[]; // present only when includeEffects is set nullifiers?: Fr[]; // all nullifiers of the tx, not just the first }; ``` **Public queries now require a contract address.** Tag-only / contract-less public queries are no longer supported (the public log index is keyed on `(contract, tag)`). **Per-tag `afterLog` cursors replace the global `page` argument.** Each tag advances independently — pass `{ tag, afterLog: LogCursor.fromLog(lastLog) }` to resume that tag, and omit it for tags that are already exhausted. **Aztec.js wallet — `PublicEventFilter.contractAddress` is now required, and `afterLog` is a `LogCursor`:** ``` - type PublicEventFilter = EventFilterBase & { contractAddress?: AztecAddress }; + type PublicEventFilter = EventFilterBase & { contractAddress: AztecAddress }; type EventFilterBase = { txHash?: TxHash; fromBlock?: BlockNumber; toBlock?: BlockNumber; - afterLog?: LogId; + afterLog?: LogCursor; }; ``` `LogId`, `LogFilter`, `TxScopedL2Log`, `ExtendedPublicLog`, `ExtendedContractClassLog`, `GetPublicLogsResponse`, and `GetContractClassLogsResponse` are no longer exported from `@aztec/aztec.js`. Build cursors with `LogCursor.fromLog(log)` and decode public-event payloads from `result.logData.slice(1)` (the tag is field 0). **CLI — `aztec get-logs` now requires `--contract-address` and `--tag`:** ``` - aztec get-logs [--tx-hash <tx>] [--from-block <n>] [--to-block <n>] [--after-log <id>] + aztec get-logs --contract-address <address> --tag <tag> \ + [--tx-hash <tx>] [--from-block <n>] [--to-block <n>] [--after-log <cursor>] ``` `--after-log` now takes a `LogCursor` of the form `<blockNumber>-<txIndexWithinBlock>-<logIndexWithinTx>` (formerly a `LogId`). **Mutual exclusion**: setting both `txHash` and `fromBlock`/`toBlock` is rejected (a `txHash` already pins a block). `txHash` + `afterLog` is allowed and paginates within the tx's logs for a tag. **Impact**: Any consumer of `getPublicLogs(LogFilter)`, `getContractClassLogs`, the old tag-based methods, `PublicEventFilter` without a `contractAddress`, or `EventFilterBase.afterLog: LogId` must be updated. The CLI rejects calls missing `--contract-address` or `--tag`. ### \[Aztec.js] `AccountManager.create` takes an options bag[​](#aztecjs-accountmanagercreate-takes-an-options-bag "Direct link to aztecjs-accountmanagercreate-takes-an-options-bag") `AccountManager.create` no longer takes `salt` as a positional argument. The trailing `salt?: Salt` parameter has been folded into a new `AccountManagerCreateOptions` bag alongside `immutablesHash` and `deployer`: ``` - AccountManager.create(wallet, secret, accountContract, salt) + AccountManager.create(wallet, secret, accountContract, { salt }) ``` `immutablesHash` lets callers commit a non-zero immutables hash on the resulting `ContractInstance` (folded into the salted initialization hash, so it affects the derived address). `deployer` overrides the deployer address recorded on the instance (defaults to `AztecAddress.ZERO`). The same `immutablesHash` field is now also threaded through `DeployMethod` / `DeployAccountMethod` so the address derived at deploy time matches the one on `accountManager.getInstance()`. ### \[Aztec.nr] Defining a custom `sync_state` function now requires `AztecConfig`[​](#aztecnr-defining-a-custom-sync_state-function-now-requires-aztecconfig "Direct link to aztecnr-defining-a-custom-sync_state-function-now-requires-aztecconfig") Contracts that previously overrode the default `sync_state` by defining their own function with that name will now get a compile error. Use `AztecConfig::custom_sync_state()` instead. The custom hook receives the same parameters as `do_sync_state` and is responsible for calling it if default behavior is also desired. You can perform work before and/or after the default `do_sync_state` call, or skip it entirely. ``` + unconstrained fn my_custom_sync( + contract_address: AztecAddress, + compute_note_hash: ComputeNoteHash, + compute_note_nullifier: ComputeNoteNullifier, + process_custom_message: Option<CustomMessageHandler>, + offchain_inbox_sync: Option<OffchainInboxSync>, + scope: AztecAddress, + ) { + // optional: work before default sync + do_sync_state(contract_address, compute_note_hash, compute_note_nullifier, process_custom_message, offchain_inbox_sync, scope); + // optional: work after default sync + } - #[aztec] + #[aztec(::aztec::macros::AztecConfig::new().custom_sync_state(crate::my_custom_sync))] contract MyContract { - use aztec::macros::functions::external; - - #[external("utility")] - unconstrained fn sync_state(scope: AztecAddress) { - // custom sync logic - } } ``` **Impact**: Only contracts that manually defined a `sync_state` function are affected. Contracts using the default macro-generated `sync_state` require no changes. ### \[Aztec.nr] `push_nullifier` renamed to `push_nullifier_unsafe`[​](#aztecnr-push_nullifier-renamed-to-push_nullifier_unsafe "Direct link to aztecnr-push_nullifier-renamed-to-push_nullifier_unsafe") `PrivateContext::push_nullifier` and `PublicContext::push_nullifier` have been renamed to `push_nullifier_unsafe` to make it clear that they are low-level functions that require careful domain separation. This is consistent with the `_unsafe` suffix already used by `emit_private_log_unsafe`, `emit_raw_note_log_unsafe`, and `emit_public_log_unsafe`. ``` - context.push_nullifier(nullifier); + context.push_nullifier_unsafe(nullifier); ``` Prefer higher-level abstractions like `SingleUseClaim` or `destroy_note` which handle domain separation automatically. ### \[Aztec.nr] `LogRetrievalRequest` now includes `source`, `from_block`, and `to_block` fields[​](#aztecnr-logretrievalrequest-now-includes-source-from_block-and-to_block-fields "Direct link to aztecnr-logretrievalrequest-now-includes-source-from_block-and-to_block-fields") `LogRetrievalRequest` has been extended with three new fields to support filtering logs by source and block range. The `get_logs_by_tag` oracle now also returns all matching logs per tag instead of only the first match. A `LogRetrievalRequest::new(contract_address, tag)` constructor is provided that defaults to querying both public and private logs with no block range filter: ``` LogRetrievalRequest::new(contract_address, my_tag) ``` If you need to customize source or block range, construct the struct manually with the new fields: ``` LogRetrievalRequest { tag: my_tag, + source: LogSource.PUBLIC_AND_PRIVATE, + from_block: Option::none(), + to_block: Option::none(), } ``` `source` controls which RPCs are queried: `LogSource.PRIVATE`, `LogSource.PUBLIC`, or `LogSource.PUBLIC_AND_PRIVATE`. `from_block` and `to_block` define a half-open `[from, to)` block range filter. Both are `Option<Field>` and default to `Option::none()` (no filtering). ### \[Protocol] Public-key hashes replace points in `PublicKeys`[​](#protocol-public-key-hashes-replace-points-in-publickeys "Direct link to protocol-public-key-hashes-replace-points-in-publickeys") Ships together with immutables hash changes (shown below). Per [AZIP-8](https://github.com/AztecProtocol/governance/blob/main/AZIPs/azip-8.md), `PublicKeys` no longer carries the four master public keys as elliptic curve points. Three of them (`npk_m`, `ovpk_m`, `tpk_m`) are now exposed only as their poseidon2 hash digests; only `ivpk_m` (the master incoming viewing key) remains a point because address derivation needs it as a curve point. **This is a hard fork:** every contract address and account address derived from a non-default `PublicKeys` changes. **Contract author migration.** Read the master nullifier hash directly off `PublicKeys` instead of computing it from a point: ``` - let owner_npk_m = get_public_keys(owner).npk_m; - let secret = context.request_nhk_app(owner_npk_m.hash()); + let owner_npk_m_hash = get_public_keys(owner).npk_m_hash; + let secret = context.request_nhk_app(owner_npk_m_hash); ``` The same field-rename applies to `.ovpk_m` and `.tpk_m`: these are now `.ovpk_m_hash` and `.tpk_m_hash` respectively. Code that needed those keys as points will not compile; the points are no longer accessible to contract code. **Custom account contracts.** Wallets that ship their own Noir account contracts must recompile. Macro-generated calldata extraction and the `request_nsk_app` / `request_ovsk_app` paths use the hash form natively. **TS / wallet author migration.** The `PublicKeys` constructor signature changes from four `Point`s to `(npkMHash: Fr, ivpkM: Point, ovpkMHash: Fr, tpkMHash: Fr)`. `KeyValidationRequest` carries `pkMHash: Fr` instead of `pkM: Point`. `KeyStore.getMasterSecretKey` now takes a `pkMHash: Fr` rather than a `Point`. Callers using the auto-generated TS binding pick this up automatically; callers that hand-roll the arg buffer must update. **Wallet UI.** Any panel that displayed `masterNullifierPublicKey`, `masterOutgoingViewingPublicKey`, or `masterTaggingPublicKey` as Grumpkin points will no longer compile against the new `PublicKeys` class. The points themselves are no longer in `ContractInstancePublished` and cannot be recovered from the onchain record. Switch to displaying the hashes (`npkMHash`, `ovpkMHash`, `tpkMHash`) or drop the display. **PXE storage migration.** `DatabaseVersionManager` deletes pre-v6 databases on first open: users will see registered accounts, contacts, address aliases, and synced notes wiped. Wallets should surface a "your local state was reset, please re-register accounts and re-sync" path. There is no forward migration because the address derived from a given secret changes (the new `public_keys_hash` is over four single-key digests, not four raw points). Previous addresses are not recoverable from the same secret; assets and notes attached to them are inaccessible at the protocol level. **Indexer / event-decoder migration.** The `ContractInstancePublished` private log payload is now 13 fields: ``` [ MAGIC, address, version, salt, class_id, init_hash, immutables_hash, npk_m_hash, ivpk_m.x, ivpk_m.y, ovpk_m_hash, tpk_m_hash, deployer ] ``` `version` is `2`. v1 events should be rejected. **Security note (PXE side).** The kernel circuit no longer checks that `npk_m`, `ovpk_m`, `tpk_m` are on-curve or non-infinity (those points are no longer in the witness). The PXE / key store relies on `deriveKeys`'s by-construction guarantee that derived points are on-curve and non-infinity. Account-creation flows that bypass `deriveKeys` (e.g. importing pre-derived public keys from an external source) must validate this themselves, or risk producing unspendable notes. ### \[Contracts] `ContractInstance` gains `immutablesHash`, address derivation changes[​](#contracts-contractinstance-gains-immutableshash-address-derivation-changes "Direct link to contracts-contractinstance-gains-immutableshash-address-derivation-changes") `ContractInstance` now has a new `immutablesHash: Fr` field that commits to a contract's immutable storage values. The field is folded into the salted initialization hash, so contract addresses are impacted: ``` salted_initialization_hash = poseidon2(DOM_SEP__SALTED_INITIALIZATION_HASH, [salt, initialization_hash, deployer, immutables_hash]) ``` **You may need to act if:** * You hardcode contract addresses computed from instance fields outside the SDK. Recompute them under the new derivation. * You parse the `ContractInstancePublished` private log directly. The event payload has an extra field, with `immutables_hash` inserted between `initialization_hash` and the public-keys block: ``` [tag, address, version, salt, classId, initialization_hash, immutables_hash, ...publicKeys(5), deployer] ``` * You call `ContractInstanceRegistry.publish_for_public_execution` directly. The function now takes 6 arguments instead of 5, with `immutables_hash` inserted between `initialization_hash` and `public_keys`: ``` - publish_for_public_execution(salt, contract_class_id, initialization_hash, public_keys, universal_deploy) + publish_for_public_execution(salt, contract_class_id, initialization_hash, immutables_hash, public_keys, universal_deploy) ``` * You call the `GetContractInstance` AVM opcode directly or use the per-member helpers in `aztec-nr`. A new enum value `ContractInstanceMember::IMMUTABLES_HASH = 3` selects `immutables_hash`. Use the wrapper helper from `aztec::oracle::get_contract_instance`: ``` use aztec::oracle::get_contract_instance::get_contract_instance_immutables_hash_avm; let immutables_hash: Option<Field> = get_contract_instance_immutables_hash_avm(address); ``` The `aztec.js` `publishInstance` helper handles this automatically. ### \[Aztec.nr] `emit_private_log_unsafe` / `emit_raw_note_log_unsafe` now take `BoundedVec`[​](#aztecnr-emit_private_log_unsafe--emit_raw_note_log_unsafe-now-take-boundedvec "Direct link to aztecnr-emit_private_log_unsafe--emit_raw_note_log_unsafe-now-take-boundedvec") The old array-based `emit_private_log_unsafe(tag, log: [Field; N], length)` and `emit_raw_note_log_unsafe(tag, log: [Field; N], length, note_hash_counter)` have been removed. The temporary `_vec_unsafe` variants introduced in a prior release have been renamed to take their place. ``` - context.emit_private_log_unsafe(tag, log_array, length); + context.emit_private_log_unsafe(tag, bounded_vec_log); - context.emit_raw_note_log_unsafe(tag, log_array, length, note_hash_counter); + context.emit_raw_note_log_unsafe(tag, bounded_vec_log, note_hash_counter); ``` If you were already using `emit_private_log_vec_unsafe` / `emit_raw_note_log_vec_unsafe`, simply drop the `_vec` from the function name: ``` - context.emit_private_log_vec_unsafe(tag, log); + context.emit_private_log_unsafe(tag, log); - context.emit_raw_note_log_vec_unsafe(tag, log, note_hash_counter); + context.emit_raw_note_log_unsafe(tag, log, note_hash_counter); ``` ### \[bb.js / accounts / aztec.nr] Schnorr signatures switched to Poseidon2[​](#bbjs--accounts--aztecnr-schnorr-signatures-switched-to-poseidon2 "Direct link to \[bb.js / accounts / aztec.nr] Schnorr signatures switched to Poseidon2") The Schnorr challenge hash function changed from `blake2s(pedersen(R.x, pubkey.x, pubkey.y) ‖ message)` to `Poseidon2(DST, R.x, pubkey.x, pubkey.y, message)`, where `DST = poseidon2_hash_bytes("schnorr_grumpkin_poseidon2")` is a domain separation tag binding signatures to this scheme. The change applies end-to-end across the native signer (`bb`), `@aztec/bb.js`, the noir verifier library (`noir-lang/schnorr` v0.2.0 → v0.4.0), and both standard Schnorr account contracts. The auth witness on-wire shape also changes from `[u8; 64]` (the serialized `(s, e)` bytes) to `[Field; 4]` (`[s.lo, s.hi, e.lo, e.hi]`, each scalar split into two 128-bit limbs). **Impact:** A previously-deployed Schnorr account cannot be controlled by the new TypeScript code. Both the signature scheme and the auth witness format change, so signatures produced by the new code will fail in-circuit verification against the old account contract, and old-style 64-byte auth witnesses will not decode in the new contract. Users with existing Schnorr accounts on testnet must deploy a fresh account contract and migrate funds. ECDSA accounts (`ecdsa_k`, `ecdsa_r`) are unaffected. **If you maintain a custom Schnorr account contract**, bump the `schnorr` dependency in `Nargo.toml`: ``` - schnorr = { tag = "v0.2.0", git = "https://github.com/noir-lang/schnorr" } + schnorr = { tag = "v0.4.0", git = "https://github.com/noir-lang/schnorr" } ``` and update `is_valid_impl` to consume the auth witness as four `Field` limbs and pass `outer_hash` directly: ``` - let signature: [u8; 64] = unsafe { get_auth_witness_as_bytes(outer_hash) }; - schnorr::verify_signature(pub_key, signature, outer_hash.to_be_bytes::<32>()) + let limbs: [Field; 4] = unsafe { get_auth_witness(outer_hash) }; + let signature = ( + std::embedded_curve_ops::EmbeddedCurveScalar::new(limbs[0], limbs[1]), + std::embedded_curve_ops::EmbeddedCurveScalar::new(limbs[2], limbs[3]), + ); + schnorr::verify_signature(pub_key, signature, outer_hash) ``` The `Schnorr` TypeScript API in `@aztec/foundation/crypto/schnorr` keeps the same surface (`constructSignature(msg: Uint8Array, ...)`, `verifySignature(msg, ...)`), but the `msg` parameter is now required to be exactly 32 bytes — a serialized field element (e.g. `Fr.toBuffer()` or `messageHash.toBuffer()`). Passing arbitrary-length byte strings will fail at the bb.js boundary. ### \[Aztec.nr] `attempt_note_discovery` is no longer exposed; use `process_private_note_msg`[​](#aztecnr-attempt_note_discovery-is-no-longer-exposed-use-process_private_note_msg "Direct link to aztecnr-attempt_note_discovery-is-no-longer-exposed-use-process_private_note_msg") `attempt_note_discovery` is now crate-private. Custom message handlers (implementations of `CustomMessageHandler`) that previously called it directly should call `process_private_note_msg` instead, which runs the standard private note message decoding and discovery pipeline. `process_private_note_msg` takes the raw `msg_metadata` and `msg_content` rather than already-decoded note fields, so it handles decoding (and silently discards undecodable messages) on your behalf: ``` - attempt_note_discovery( - contract_address, - tx_hash, - unique_note_hashes_in_tx, - first_nullifier_in_tx, - compute_note_hash, - compute_note_nullifier, - owner, - storage_slot, - randomness, - note_type_id, - packed_note, - ); + process_private_note_msg( + contract_address, + tx_hash, + unique_note_hashes_in_tx, + first_nullifier_in_tx, + compute_note_hash, + compute_note_nullifier, + msg_metadata, + msg_content, + ); ``` **Impact**: Custom message handlers that reused the standard note message processing pipeline must switch to `process_private_note_msg`. Contracts using only built-in private note handling are unaffected. ### \[Aztec.nr] TXE `call_public_incognito` no longer takes a `from` parameter[​](#aztecnr-txe-call_public_incognito-no-longer-takes-a-from-parameter "Direct link to aztecnr-txe-call_public_incognito-no-longer-takes-a-from-parameter") `TestEnvironment::call_public_incognito` previously accepted a `from` address that was silently ignored (the function always uses a null `msg_sender`). The `from` parameter has been removed. ``` - env.call_public_incognito(sender, SampleContract::at(addr).some_function()); + env.call_public_incognito(SampleContract::at(addr).some_function()); ``` If you need to call a public function *with* a sender, use `call_public` instead. ### \[Aztec.nr] TXE `view_public_incognito` is deprecated[​](#aztecnr-txe-view_public_incognito-is-deprecated "Direct link to aztecnr-txe-view_public_incognito-is-deprecated") `TestEnvironment::view_public_incognito` is now deprecated in favor of `view_public`, which has the same behavior (null `msg_sender`, static call). ``` - env.view_public_incognito(SampleContract::at(addr).some_view()); + env.view_public(SampleContract::at(addr).some_view()); ``` ### \[Aztec.js] `DeployMethod` address-affecting parameters move to construction time[​](#aztecjs-deploymet
프로젝트로 돌아가기