Skip to content

Commit b8cc5e9

Browse files
authored
feat: merge-train/fairies (#23447)
BEGIN_COMMIT_OVERRIDE refactor(aztec-nr)!: remove array-based emit log unsafe APIs, rename BoundedVec variants (#23438) END_COMMIT_OVERRIDE
2 parents e47d306 + 83c6b27 commit b8cc5e9

10 files changed

Lines changed: 47 additions & 61 deletions

File tree

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ Aztec is in active development. Each version may introduce breaking changes that
99

1010
## TBD
1111

12+
### [Aztec.nr] `emit_private_log_unsafe` / `emit_raw_note_log_unsafe` now take `BoundedVec`
13+
14+
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.
15+
16+
```diff
17+
- context.emit_private_log_unsafe(tag, log_array, length);
18+
+ context.emit_private_log_unsafe(tag, bounded_vec_log);
19+
20+
- context.emit_raw_note_log_unsafe(tag, log_array, length, note_hash_counter);
21+
+ context.emit_raw_note_log_unsafe(tag, bounded_vec_log, note_hash_counter);
22+
```
23+
24+
If you were already using `emit_private_log_vec_unsafe` / `emit_raw_note_log_vec_unsafe`, simply drop the `_vec` from the function name:
25+
26+
```diff
27+
- context.emit_private_log_vec_unsafe(tag, log);
28+
+ context.emit_private_log_unsafe(tag, log);
29+
30+
- context.emit_raw_note_log_vec_unsafe(tag, log, note_hash_counter);
31+
+ context.emit_raw_note_log_unsafe(tag, log, note_hash_counter);
32+
```
33+
1234
### [bb.js / accounts / aztec.nr] Schnorr signatures switched to Poseidon2
1335

1436
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).

noir-projects/aztec-nr/aztec/src/context/private_context.nr

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -894,13 +894,10 @@ impl PrivateContext {
894894
/// filter for relevant logs without scanning all of them.
895895
/// * `log` - The log data that will be publicly broadcast (so make sure it's already been encrypted before you
896896
/// call this function). Private logs are bounded in size (`PRIVATE_LOG_CIPHERTEXT_LEN`), to encourage all logs
897-
/// from all smart contracts look identical.
898-
/// * `length` - The actual length of `log` (measured in number of Fields). Although the input log has a max
899-
/// size of `PRIVATE_LOG_CIPHERTEXT_LEN`, the latter values of the array might all be 0's for small logs. This
900-
/// `length` should reflect the trimmed length of the array. The protocol's kernel circuits can then append
901-
/// random fields as "padding" after the `length`, so that the logs of this smart contract look
902-
/// indistinguishable from (the same length as) the logs of all other applications. It's up to wallets how much
903-
/// padding to apply, so ideally all wallets should agree on standards for this.
897+
/// from all smart contracts look identical. The protocol's kernel circuits can then append random fields as
898+
/// "padding" after the log's length, so that the logs of this smart contract look indistinguishable from (the
899+
/// same length as) the logs of all other applications. It's up to wallets how much padding to apply, so
900+
/// ideally all wallets should agree on standards for this.
904901
///
905902
/// ## Safety
906903
///
@@ -909,67 +906,34 @@ impl PrivateContext {
909906
/// happen to share a raw tag value become indistinguishable. Prefer the higher-level APIs
910907
/// ([`crate::messages::message_delivery::MessageDelivery`] for messages, `self.emit(event)` for events) which
911908
/// handle tagging automatically.
912-
// TODO(F-555): remove this function in favor of `emit_private_log_vec_unsafe`
913-
#[deprecated("use `emit_private_log_vec_unsafe` instead")]
914-
pub fn emit_private_log_unsafe(&mut self, tag: Field, log: [Field; PRIVATE_LOG_CIPHERTEXT_LEN], length: u32) {
915-
let counter = self.next_counter();
916-
let full_log = [tag].concat(log);
917-
self.private_logs.push(PrivateLogData { log: PrivateLog::new(full_log, length + 1), note_hash_counter: 0 }
918-
.count(counter));
919-
}
920-
921-
/// `BoundedVec`-based variant of [`emit_private_log_unsafe`](PrivateContext::emit_private_log_unsafe).
922-
///
923-
/// See [`emit_private_log_unsafe`](PrivateContext::emit_private_log_unsafe) for the full description of private
924-
/// log semantics.
925-
// TODO(F-555): once `emit_private_log_unsafe` is removed, rename this function to drop the `_vec` suffix.
926-
pub fn emit_private_log_vec_unsafe(&mut self, tag: Field, log: BoundedVec<Field, PRIVATE_LOG_CIPHERTEXT_LEN>) {
927-
self.emit_raw_note_log_vec_unsafe(tag, log, 0);
909+
pub fn emit_private_log_unsafe(&mut self, tag: Field, log: BoundedVec<Field, PRIVATE_LOG_CIPHERTEXT_LEN>) {
910+
self.emit_raw_note_log_unsafe(tag, log, 0);
928911
}
929912

930-
// TODO: rename.
931913
/// Emits a private log that is explicitly tied to a newly-emitted note_hash, to convey to the kernel: "this log
932914
/// relates to this note".
933915
///
934916
/// This linkage is important in case the note gets squashed (due to being read later in this same tx), since we
935917
/// can then squash the log as well.
936918
///
937-
/// See `emit_private_log_unsafe` for more info about private log emission.
919+
/// See [`emit_private_log_unsafe`](PrivateContext::emit_private_log_unsafe) for more info about private log
920+
/// emission.
938921
///
939922
/// # Arguments
940-
/// * `tag` - A tag placed at `fields[0]`. See `emit_private_log_unsafe`.
941-
/// * `log` - The log data as an array of Field elements
942-
/// * `length` - The actual length of the `log` (measured in number of Fields).
923+
/// * `tag` - A tag placed at `fields[0]`. See
924+
/// [`emit_private_log_unsafe`](PrivateContext::emit_private_log_unsafe).
925+
/// * `log` - The log data as a `BoundedVec` of Field elements.
943926
/// * `note_hash_counter` - The side-effect counter that was assigned to the new note_hash when it was pushed to
944927
/// this `PrivateContext`.
945928
///
946929
/// Important: If your application logic requires the log to always be emitted regardless of note squashing,
947-
/// consider using `emit_private_log_unsafe` instead, or emitting additional events.
930+
/// consider using [`emit_private_log_unsafe`](PrivateContext::emit_private_log_unsafe) instead, or emitting
931+
/// additional events.
948932
///
949933
/// ## Safety
950934
///
951935
/// Same as [`PrivateContext::emit_private_log_unsafe`]: the `tag` should be domain-separated.
952-
// TODO(F-555): remove this function in favor of `emit_raw_note_log_vec_unsafe`
953-
#[deprecated("use `emit_raw_note_log_vec_unsafe` instead")]
954936
pub fn emit_raw_note_log_unsafe(
955-
&mut self,
956-
tag: Field,
957-
log: [Field; PRIVATE_LOG_CIPHERTEXT_LEN],
958-
length: u32,
959-
note_hash_counter: u32,
960-
) {
961-
let counter = self.next_counter();
962-
let full_log = [tag].concat(log);
963-
let private_log = PrivateLogData { log: PrivateLog::new(full_log, length + 1), note_hash_counter };
964-
self.private_logs.push(private_log.count(counter));
965-
}
966-
967-
/// `BoundedVec`-based variant of [`emit_raw_note_log_unsafe`](PrivateContext::emit_raw_note_log_unsafe).
968-
///
969-
/// See [`emit_raw_note_log_unsafe`](PrivateContext::emit_raw_note_log_unsafe) for the full description of
970-
/// note-tied private log semantics.
971-
// TODO(F-555): once `emit_raw_note_log_unsafe` is removed, rename this function to drop the `_vec` suffix.
972-
pub fn emit_raw_note_log_vec_unsafe(
973937
&mut self,
974938
tag: Field,
975939
log: BoundedVec<Field, PRIVATE_LOG_CIPHERTEXT_LEN>,

noir-projects/aztec-nr/aztec/src/messages/message_delivery.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ pub fn do_private_message_delivery<Env, let MESSAGE_PLAINTEXT_LEN: u32>(
241241
if maybe_note_hash_counter.is_some() {
242242
// We associate the log with the note's side effect counter, so that if the note ends up being squashed in
243243
// the current transaction, the log will be removed as well.
244-
context.emit_raw_note_log_vec_unsafe(log_tag, log, maybe_note_hash_counter.unwrap());
244+
context.emit_raw_note_log_unsafe(log_tag, log, maybe_note_hash_counter.unwrap());
245245
} else {
246-
context.emit_private_log_vec_unsafe(log_tag, log);
246+
context.emit_private_log_unsafe(log_tag, log);
247247
}
248248
}
249249
}

noir-projects/aztec-nr/uint-note/src/uint_note.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl PartialUintNote {
228228
// inserted in public as the public values are provided and the note hash computed.
229229
let log_tag = compute_log_tag(self.commitment, DOM_SEP__NOTE_COMPLETION_LOG_TAG);
230230
let payload = BoundedVec::from_array([storage_slot, value.to_field()]);
231-
context.emit_private_log_vec_unsafe(log_tag, payload);
231+
context.emit_private_log_unsafe(log_tag, payload);
232232
context.push_note_hash(self.compute_complete_note_hash(storage_slot, value));
233233
}
234234

noir-projects/noir-contracts/contracts/account/simulated_ecdsa_account_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub contract SimulatedEcdsaAccount {
5151
// and is therefore never nullified, so in practice the log will never be squashed. We
5252
// pass the note hash counter anyway for correctness.
5353
let dummy_log: [Field; MESSAGE_CIPHERTEXT_LEN] = [seed + 2; MESSAGE_CIPHERTEXT_LEN];
54-
self.context.emit_raw_note_log_vec_unsafe(
54+
self.context.emit_raw_note_log_unsafe(
5555
seed + 3,
5656
BoundedVec::from_array(dummy_log),
5757
self.context.side_effect_counter,

noir-projects/noir-contracts/contracts/account/simulated_schnorr_account_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub contract SimulatedSchnorrAccount {
5353
// and is therefore never nullified, so in practice the log will never be squashed. We
5454
// pass the note hash counter anyway for correctness.
5555
let dummy_log: [Field; MESSAGE_CIPHERTEXT_LEN] = [seed + 2; MESSAGE_CIPHERTEXT_LEN];
56-
self.context.emit_raw_note_log_vec_unsafe(
56+
self.context.emit_raw_note_log_unsafe(
5757
seed + 3,
5858
BoundedVec::from_array(dummy_log),
5959
self.context.side_effect_counter,

noir-projects/noir-contracts/contracts/message_discovery/handshake_registry_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub contract HandshakeRegistry {
8383
);
8484

8585
// TODO(F-653): Encrypt `eph_pk.x` to keep the log private
86-
self.context.emit_private_log_vec_unsafe(log_tag, BoundedVec::from_array([eph_pk.x]));
86+
self.context.emit_private_log_unsafe(log_tag, BoundedVec::from_array([eph_pk.x]));
8787

8888
note.siloed_for(self.msg_sender())
8989
}

noir-projects/noir-contracts/contracts/test/benchmarking_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub contract Benchmarking {
113113
for j in 0..PRIVATE_LOG_CIPHERTEXT_LEN {
114114
log.push(random_seed + (i * MAX_PRIVATE_LOGS_PER_CALL + j) as Field);
115115
}
116-
self.context.emit_private_log_vec_unsafe(0, log);
116+
self.context.emit_private_log_unsafe(0, log);
117117
}
118118
}
119119

noir-projects/noir-contracts/contracts/test/test_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ pub contract Test {
316316

317317
// Emit a log with non-encrypted content for testing purpose.
318318
let leaky_log = BoundedVec::from_array(event.serialize());
319-
self.context.emit_private_log_vec_unsafe(tag, leaky_log);
319+
self.context.emit_private_log_unsafe(tag, leaky_log);
320320
}
321321
}
322322

noir-projects/noir-contracts/contracts/test/test_log_contract/src/main.nr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub contract TestLog {
4747
/// Emits a single private log with the given raw tag and a one-field payload.
4848
#[external("private")]
4949
fn emit_raw_private_log(tag: Field, payload: Field) {
50-
self.context.emit_private_log_vec_unsafe(tag, BoundedVec::from_array([payload]));
50+
self.context.emit_private_log_unsafe(tag, BoundedVec::from_array([payload]));
5151
}
5252

5353
/// Emits three private logs with payloads of different lengths (1, 3, and 5 fields). Used to
@@ -61,9 +61,9 @@ pub contract TestLog {
6161
tag3: Field,
6262
payload3: [Field; 5],
6363
) {
64-
self.context.emit_private_log_vec_unsafe(tag1, BoundedVec::from_array([payload1]));
65-
self.context.emit_private_log_vec_unsafe(tag2, BoundedVec::from_array(payload2));
66-
self.context.emit_private_log_vec_unsafe(tag3, BoundedVec::from_array(payload3));
64+
self.context.emit_private_log_unsafe(tag1, BoundedVec::from_array([payload1]));
65+
self.context.emit_private_log_unsafe(tag2, BoundedVec::from_array(payload2));
66+
self.context.emit_private_log_unsafe(tag3, BoundedVec::from_array(payload3));
6767
}
6868

6969
#[external("private")]

0 commit comments

Comments
 (0)