-
Notifications
You must be signed in to change notification settings - Fork 599
feat: packing note content #11376
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
Merged
feat: packing note content #11376
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ddf9fa2
feat: packing note content
benesjan dadeb8e
naming fixes
benesjan 59d24b0
WIP
benesjan ba84394
WIP
benesjan 4a3c4f1
fix
benesjan 5d13c2d
WIP
benesjan 11bc4b7
fixes
benesjan 4915b72
WIP
benesjan 67d0251
last touches
benesjan e60770a
fixes after rebase
benesjan ed5e73e
fixes
benesjan 3cad55f
Update noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
benesjan 24094df
Merge branch 'master' into 01-21-feat_packing_note_content
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
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 |
|---|---|---|
|
|
@@ -112,10 +112,10 @@ comptime fn generate_contract_interface(m: Module) -> Quoted { | |
| } | ||
|
|
||
| comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { | ||
| let mut max_note_length: u32 = 0; | ||
| let mut max_note_content_length: u32 = 0; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file are just renamings |
||
| let notes = NOTES.entries(); | ||
| let body = if notes.len() > 0 { | ||
| max_note_length = notes.fold( | ||
| max_note_content_length = notes.fold( | ||
| 0, | ||
| |acc, (_, (_, len, _, _)): (Type, (StructDefinition, u32, Field, [(Quoted, u32, bool)]))| { | ||
| if len > acc { | ||
|
|
@@ -138,7 +138,7 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { | |
| if_statements_list = if_statements_list.push_back( | ||
| quote { | ||
| $if_or_else_if note_type_id == $typ::get_note_type_id() { | ||
| aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::deserialize_content, note_header, compute_nullifier, serialized_note) | ||
| aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::unpack_content, note_header, compute_nullifier, packed_note_content) | ||
| } | ||
| }, | ||
| ); | ||
|
|
@@ -166,7 +166,7 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { | |
| storage_slot: Field, | ||
| note_type_id: Field, | ||
| compute_nullifier: bool, | ||
| serialized_note: [Field; $max_note_length], | ||
| packed_note_content: [Field; $max_note_content_length], | ||
| ) -> pub [Field; 4] { | ||
| $body | ||
| } | ||
|
|
@@ -184,14 +184,14 @@ comptime fn generate_process_log() -> Quoted { | |
|
|
||
| // A typical implementation of the lambda looks something like this: | ||
| // ``` | ||
| // |serialized_note_content: BoundedVec<Field, MAX_NOTE_SERIALIZED_LEN>, note_header: NoteHeader, note_type_id: Field| { | ||
| // |packed_note_content: BoundedVec<Field, MAX_NOTE_SERIALIZED_LEN>, note_header: NoteHeader, note_type_id: Field| { | ||
| // let hashes = if note_type_id == MyNoteType::get_note_type_id() { | ||
| // assert(serialized_note_content.len() == MY_NOTE_TYPE_SERIALIZATION_LENGTH); | ||
| // assert(packed_note_content.len() == MY_NOTE_TYPE_SERIALIZATION_LENGTH); | ||
| // dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier( | ||
| // MyNoteType::deserialize_content, | ||
| // MyNoteType::unpack_content, | ||
| // note_header, | ||
| // true, | ||
| // serialized_note_content.storage(), | ||
| // packed_note_content.storage(), | ||
| // ) | ||
| // } else { | ||
| // panic(f"Unknown note type id {note_type_id}") | ||
|
|
@@ -213,7 +213,7 @@ comptime fn generate_process_log() -> Quoted { | |
|
|
||
| let mut if_note_type_id_match_statements_list = &[]; | ||
| for i in 0..notes.len() { | ||
| let (typ, (_, serialized_note_length, _, _)) = notes[i]; | ||
| let (typ, (_, packed_note_content_length, _, _)) = notes[i]; | ||
|
|
||
| let if_or_else_if = if i == 0 { | ||
| quote { if } | ||
|
|
@@ -224,17 +224,17 @@ comptime fn generate_process_log() -> Quoted { | |
| if_note_type_id_match_statements_list = if_note_type_id_match_statements_list.push_back( | ||
| quote { | ||
| $if_or_else_if note_type_id == $typ::get_note_type_id() { | ||
| // As an extra safety check we make sure that the serialized_note_content bounded vec has the | ||
| // As an extra safety check we make sure that the packed_note_content bounded vec has the | ||
| // expected length, to avoid scenarios in which compute_note_hash_and_optionally_a_nullifier | ||
| // silently trims the end if the log were to be longer. | ||
| let expected_len = $serialized_note_length; | ||
| let actual_len = serialized_note_content.len(); | ||
| let expected_len = $packed_note_content_length; | ||
| let actual_len = packed_note_content.len(); | ||
| assert( | ||
| actual_len == expected_len, | ||
| f"Expected note content of length {expected_len} but got {actual_len} for note type id {note_type_id}" | ||
| ); | ||
|
|
||
| aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::deserialize_content, note_header, true, serialized_note_content.storage()) | ||
| aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::unpack_content, note_header, true, packed_note_content.storage()) | ||
| } | ||
| }, | ||
| ); | ||
|
|
@@ -256,7 +256,7 @@ comptime fn generate_process_log() -> Quoted { | |
| unique_note_hashes_in_tx, | ||
| first_nullifier_in_tx, | ||
| recipient, | ||
| |serialized_note_content: BoundedVec<Field, _>, note_header, note_type_id| { | ||
| |packed_note_content: BoundedVec<Field, _>, note_header, note_type_id| { | ||
| let hashes = $if_note_type_id_match_statements | ||
| else { | ||
| panic(f"Unknown note type id {note_type_id}") | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a note to enable packing here in a followup PR.