Skip to content

Commit e840fac

Browse files
committed
feat: 64 bit log type id, 64 bit log metadata
1 parent 7c20b23 commit e840fac

5 files changed

Lines changed: 21 additions & 17 deletions

File tree

noir-projects/aztec-nr/aztec/src/discovery/private_logs.nr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ pub unconstrained fn do_process_log<Env>(
105105
/// ```
106106
///
107107
/// The expanded metadata itself is (currently) interpreted as a u64, of which:
108-
/// - the upper 57 bits are the log type id
109-
/// - the remaining 7 bits are called the 'log metadata'
108+
/// - the upper 64 bits are the log type id
109+
/// - the remaining 64 bits are called the 'log metadata'
110110
///
111111
/// ```
112-
/// log_expanded_metadata: [ log_type_id | log_metadata ]
113-
/// <--- 57 bits --->|<--- 7 bits --->
112+
/// log_expanded_metadata: [ log_type_id | log_metadata ]
113+
/// <--- 64 bits --->|<--- 64 bits --->
114114
/// ```
115115
///
116116
/// The meaning of the log metadata and log content depend on the value of the log type id. Note that there is
@@ -134,8 +134,8 @@ unconstrained fn decode_log_plaintext(
134134
// See the documentation of this function for a description of the log layout
135135
let expanded_log_metadata = log_plaintext.get(0);
136136

137-
let log_type_id = ((expanded_log_metadata as u64) / 128);
138-
let log_metadata = ((expanded_log_metadata as u64) % 128);
137+
let log_type_id = ((expanded_log_metadata as u128) >> 64) as u64;
138+
let log_metadata = (expanded_log_metadata as u64);
139139

140140
let log_content = array::subbvec(log_plaintext, PRIVATE_LOG_EXPANDED_METADATA_LEN);
141141

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub global PRIVATE_NOTE_LOG_TYPE_ID: Field = 0;
2+
pub global PARTIAL_NOTE_LOG_TYPE_ID: Field = 1;
3+
pub global PRIVATE_EVENT_LOG_TYPE_ID: Field = 2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod encrypt;
22
pub mod log_assembly_strategies;
33
pub mod log_encryption;
4+
pub mod log_type;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dep::aztec::{
22
context::{PrivateContext, PublicContext},
3-
encrypted_logs::log_assembly_strategies::default_aes128,
3+
encrypted_logs::{log_assembly_strategies::default_aes128, log_type::PARTIAL_NOTE_LOG_TYPE_ID},
44
keys::getters::{get_nsk_app, get_public_keys},
55
macros::notes::custom_note,
66
note::note_interface::{NoteHash, NoteType},
@@ -188,9 +188,9 @@ struct PrivateUintPartialNotePrivateLogContent {
188188

189189
impl NoteType for PrivateUintPartialNotePrivateLogContent {
190190
fn get_id() -> Field {
191-
// We abuse the fact that note type ids are 7 bits long to use the 8th bit indicate the log corresponds to a
192-
// partial note. Ideally we'd use proper events with selectors, but those are not handled well at the moment.
193-
UintNote::get_id() + 128
191+
// The log type id is 1 to indicate this is a partial note log, and the log metadata is the note type id
192+
// TODO: Mixing the log type id and note type id here is a hack and should be separated.
193+
(PARTIAL_NOTE_LOG_TYPE_ID * 2.pow_32(64)) + UintNote::get_id()
194194
}
195195
}
196196

noir-projects/noir-contracts/contracts/nft_contract/src/types/nft_note.nr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dep::aztec::{
22
context::{PrivateContext, PublicContext},
3-
encrypted_logs::log_assembly_strategies::default_aes128,
3+
encrypted_logs::{log_assembly_strategies::default_aes128, log_type::PARTIAL_NOTE_LOG_TYPE_ID},
44
keys::getters::{get_nsk_app, get_public_keys},
55
macros::notes::custom_note,
66
note::note_interface::{NoteHash, NoteType},
@@ -113,7 +113,7 @@ impl NFTNote {
113113
/// Each partial note should only be used once, since otherwise multiple notes would be linked together and known to
114114
/// belong to the same owner.
115115
///
116-
/// As part of the partial note cration process, a log will be sent to `recipient` from `sender` so that they can
116+
/// As part of the partial note creation process, a log will be sent to `recipient` from `sender` so that they can
117117
/// discover the note. `recipient` will typically be the same as `owner`.
118118
pub fn partial(
119119
owner: AztecAddress,
@@ -189,15 +189,15 @@ struct PrivateNFTPartialNotePrivateLogContent {
189189

190190
impl NoteType for PrivateNFTPartialNotePrivateLogContent {
191191
fn get_id() -> Field {
192-
// We abuse the fact that note type ids are 7 bits long to use the 8th bit indicate the log corresponds to a
193-
// partial note. Ideally we'd use proper events with selectors, but those are not handled well at the moment.
194-
NFTNote::get_id() + 128
192+
// The log type id is 1 to indicate this is a partial note log, and the log metadata is the note type id
193+
// TODO: Mixing the log type id and note type id here is a hack and should be separated.
194+
(PARTIAL_NOTE_LOG_TYPE_ID * 2.pow_32(64)) + NFTNote::get_id()
195195
}
196196
}
197197

198198
/// A partial instance of a NFTNote. This value represents a private commitment to the owner, randomness and storage
199199
/// slot, but the token id field has not yet been set. A partial note can be completed in public with the `complete`
200-
/// function (revealing the tolken id to the public), resulting in a NFTNote that can be used like any other one (except
200+
/// function (revealing the token id to the public), resulting in a NFTNote that can be used like any other one (except
201201
/// of course that its token id is known).
202202
#[derive(Packable, Serialize, Deserialize)]
203203
pub struct PartialNFTNote {
@@ -307,7 +307,7 @@ mod test {
307307
partial_note.compute_note_completion_log(token_id)[0],
308308
);
309309

310-
// Then we exctract all fields except the first of both logs (i.e. the public log tag), and combine them to
310+
// Then we extract all fields except the first of both logs (i.e. the public log tag), and combine them to
311311
// produce the note's packed representation. This requires that the members of the intermediate structs are in
312312
// the same order as in NFTNote.
313313
let private_log_without_public_tag: [_; 2] = subarray(private_log_content.pack(), 1);

0 commit comments

Comments
 (0)