-
Notifications
You must be signed in to change notification settings - Fork 599
feat: 64 bit log type id, 64 bit log metadata #12956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benesjan
merged 14 commits into
master
from
03-22-feat_64_bit_log_type_id_64_bit_log_metadata
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
911dd38
feat: 64 bit log type id, 64 bit log metadata
benesjan 4d7c837
making it less ugly
benesjan 07f94a7
WIP
benesjan be737f4
fixes
benesjan 7a8ea2b
Update noir-projects/aztec-nr/aztec/src/discovery/private_logs.nr
benesjan 10d9407
Update noir-projects/aztec-nr/aztec/src/discovery/private_logs.nr
benesjan b1e9229
Update noir-projects/aztec-nr/aztec/src/encrypted_logs/log_type.nr
benesjan 9100c17
fix
benesjan c86959b
stale comment update
benesjan b480842
subvec in spellcheck
benesjan 4442837
u64s_packing utils
benesjan fb445a3
swapping metadata and log type id
benesjan 470b5ca
making u64s packing metadata specific
benesjan 4724c0c
roundtrip_metadata fuzz test
benesjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pub global PRIVATE_NOTE_LOG_TYPE_ID: u64 = 0; | ||
| pub global PARTIAL_NOTE_PRIVATE_LOG_TYPE_ID: u64 = 1; | ||
| pub global PRIVATE_EVENT_LOG_TYPE_ID: u64 = 2; |
89 changes: 89 additions & 0 deletions
89
noir-projects/aztec-nr/aztec/src/encrypted_logs/metadata_packing.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| global U64_SHIFT_MULTIPLIER: Field = 2.pow_32(64); | ||
|
|
||
| pub fn to_expanded_metadata(log_metadata: u64, log_type: u64) -> Field { | ||
| let metadata_field = log_metadata as Field; | ||
| // We use multiplication instead of bit shifting operations to shift the type bits as bit shift operations are | ||
| // expensive in circuits. | ||
| let type_field: Field = (log_type as Field) * U64_SHIFT_MULTIPLIER; | ||
| type_field + metadata_field | ||
| } | ||
|
|
||
| pub fn from_expanded_metadata(input: Field) -> (u64, u64) { | ||
| input.assert_max_bit_size::<128>(); | ||
| let metadata = (input as u64); | ||
| // Use division instead of bit shift since bit shifts are expensive in circuits | ||
| let log_type = ((input - (metadata as Field)) / U64_SHIFT_MULTIPLIER) as u64; | ||
| (metadata, log_type) | ||
| } | ||
|
|
||
| mod tests { | ||
| use super::{from_expanded_metadata, to_expanded_metadata}; | ||
|
|
||
| global U64_MAX: Field = 2.pow_32(64) - 1; | ||
| global U128_MAX: Field = 2.pow_32(128) - 1; | ||
|
|
||
| #[test] | ||
| fn packing_metadata() { | ||
| // Test case 1: All bits set | ||
| let packed = to_expanded_metadata(U64_MAX as u64, U64_MAX as u64); | ||
| let (metadata, log_type) = from_expanded_metadata(packed); | ||
| assert(metadata == U64_MAX as u64, "Metadata bits should be all 1s"); | ||
| assert(log_type == U64_MAX as u64, "Log type bits should be all 1s"); | ||
|
|
||
| // Test case 2: Only log type bits set | ||
| let packed = to_expanded_metadata(0, U64_MAX as u64); | ||
| let (metadata, log_type) = from_expanded_metadata(packed); | ||
| assert(metadata == 0, "Metadata bits should be 0"); | ||
| assert(log_type == U64_MAX as u64, "Log type bits should be all 1s"); | ||
|
|
||
| // Test case 3: Only metadata bits set | ||
| let packed = to_expanded_metadata(U64_MAX as u64, 0); | ||
| let (metadata, log_type) = from_expanded_metadata(packed); | ||
| assert(metadata == U64_MAX as u64, "Metadata bits should be all 1s"); | ||
| assert(log_type == 0, "Log type bits should be 0"); | ||
|
|
||
| // Test case 4: Zero | ||
| let packed = to_expanded_metadata(0, 0); | ||
| let (metadata, log_type) = from_expanded_metadata(packed); | ||
| assert(metadata == 0, "Metadata bits should be 0"); | ||
| assert(log_type == 0, "Log type bits should be 0"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn unpacking_metadata() { | ||
| // Test case 1: All bits set | ||
| let input = U128_MAX; | ||
| let (metadata, log_type) = from_expanded_metadata(input); | ||
| assert(metadata == U64_MAX as u64, "Metadata bits should be all 1s"); | ||
| assert(log_type == U64_MAX as u64, "Log type bits should be all 1s"); | ||
|
|
||
| // Test case 2: Only log type bits set | ||
| let input = U128_MAX - U64_MAX; | ||
| let (metadata, log_type) = from_expanded_metadata(input); | ||
| assert(metadata == 0, "Metadata bits should be 0"); | ||
| assert(log_type == U64_MAX as u64, "Log type bits should be all 1s"); | ||
|
|
||
| // Test case 3: Only metadata bits set | ||
| let input = U64_MAX; | ||
| let (metadata, log_type) = from_expanded_metadata(input); | ||
| assert(metadata == U64_MAX as u64, "Metadata bits should be all 1s"); | ||
| assert(log_type == 0, "Log type bits should be 0"); | ||
|
|
||
| // Test case 4: Zero | ||
| let input = 0; | ||
| let (metadata, log_type) = from_expanded_metadata(input); | ||
| assert(metadata == 0, "Metadata bits should be 0"); | ||
| assert(log_type == 0, "Log type bits should be 0"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn roundtrip_metadata(original_metadata: u64, original_type: u64) { | ||
| let packed = to_expanded_metadata(original_metadata, original_type); | ||
| let (unpacked_metadata, unpacked_type) = from_expanded_metadata(packed); | ||
| assert(original_type == unpacked_type, "Log type bits should match after roundtrip"); | ||
| assert( | ||
| original_metadata == unpacked_metadata, | ||
| "Metadata bits should match after roundtrip", | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| pub mod encrypt; | ||
| pub mod log_assembly_strategies; | ||
| pub mod log_encryption; | ||
| pub mod log_type; | ||
| pub mod metadata_packing; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.