Skip to content

feat: reduce NoteType to a 1 bit encoding and add metadata version#2691

Merged
PhilippGackstatter merged 5 commits intonextfrom
pgackst-1-bit-note-type
Mar 30, 2026
Merged

feat: reduce NoteType to a 1 bit encoding and add metadata version#2691
PhilippGackstatter merged 5 commits intonextfrom
pgackst-1-bit-note-type

Conversation

@PhilippGackstatter
Copy link
Copy Markdown
Contributor

Summary

Reduces NoteType encoding from 2 bits to 1 bit and adds a 4-bit version field to the note metadata header, as a prerequisite for #2555 (multiple attachments per note). This frees up bits in the metadata header for future attachment metadata.

Breaking change: The note metadata encoding (both Rust serialization and MASM Word layout) has changed.

This PR also implements Default for NoteType by making NoteType::Private the default - and we could do the same for AccountStorageMode::Private when we get rid of the Network variant. This makes deriving bon::builder for notes (see #2283) even easier since we don't have to make the decision on what the default note type is for every note.

New metadata layout

Old: [sender_id_suffix (56 bits) | 6 zero bits | note_type (2 bits)]
New: [sender_id_suffix (56 bits) | reserved (3 bits) | note_type (1 bit) | version (4 bits)]
  • NoteType::Private changed from 2 to 0 (new default)
  • NoteType::Public remains 1
  • Version is hardcoded to 0 for forward compatibility
  • Reserved bits are validated to be zero on decode

@PhilippGackstatter PhilippGackstatter added the pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority label Mar 26, 2026
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left a couple of small questions/comments inline.

Comment on lines +405 to +406
let sender_suffix =
Felt::try_from(raw & 0xffff_ffff_ffff_ff00).expect("felt should still be valid");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to switch away from using SENDER_SUFFIX_MASK constant here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we had:

const NOTE_TYPE_MASK: u8 = 0b11;
const SENDER_SUFFIX_MASK: u64 = !(NOTE_TYPE_MASK as u64);

If we update the note type mask it would still technically work, but would be semantically incorrect because we'd also be extracting the version from the metadata (which happens to be 0 for now). So it seems better to explicitly mask out the least significant byte.

I brought back the constant for explicitness:

const SENDER_SUFFIX_MASK: u64 = 0xffff_ffff_ffff_ff00;

@PhilippGackstatter PhilippGackstatter merged commit 5402852 into next Mar 30, 2026
17 checks passed
@PhilippGackstatter PhilippGackstatter deleted the pgackst-1-bit-note-type branch March 30, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants