Skip to content
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

Support private Maps of different note types in the same contract in compute_hash_and_nullifier #2820

Closed
Tracked by #4126
spalladino opened this issue Oct 12, 2023 · 3 comments · Fixed by #4500
Closed
Tracked by #4126
Assignees
Labels
T-feedback Type: recording user feedback

Comments

@spalladino
Copy link
Collaborator

Today we usually implement compute_hash_and_nullifier as a switch on the storage slot: depending on the slot, we delegate this computation to a different note implementation. But how does this work if we have two Maps of different note types? A Map basically hashes its slot with the key (same as in Solidity). So, for a note stored in a map, the compute_note_hash_and_nullifier would get a random slot that the function cannot know to which map it belongs, so it cannot know to which note implementation delegate the computation. This means we cannot have two maps of different note types in the same contract.

@spalladino
Copy link
Collaborator Author

A faint memory from a few months ago was if we can encode note structs to have unique ids, then providing the storage slot & the note struct id might suffice.

From @iAmMichaelConnor

@LeilaWang
Copy link
Collaborator

There was a discussion to always include an id, or a function selector which can process the specific note type, to the encrypted data. But there are some creative ways to figure this out before we add another field to it.

If it's hard to tell by looking at the storage slot, we can:

  • check the size of the preimage, assuming the field of the "larger" note at index n (where n >= smaller_note.size) won't be zero. (Or maybe we can pass the size of the preimage to the function?)
  • check the value of a field (e.g., the 2nd field of one of the note type should be the caller's address)(should unconstrained functions also have some sort of context?).
  • emit an extra identifier for a note type if there's no way to distinguish it from others.

@spalladino
Copy link
Collaborator Author

Requested by @30mb1 on Discord

@spalladino spalladino added the T-feedback Type: recording user feedback label Oct 19, 2023
@LHerskind LHerskind added this to the Execution Environment milestone Jan 22, 2024
LHerskind pushed a commit that referenced this issue Feb 12, 2024
Closes #2820.
Additional context and design discussion can be found [here](https://hackmd.io/@57cqwgSpQY23bzke_Ch2ig/rJsw1tS9T).
@github-project-automation github-project-automation bot moved this from Todo to Done in A3 Feb 12, 2024
michaelelliot pushed a commit to Swoir/noir_rs that referenced this issue Feb 28, 2024
Closes AztecProtocol#2820.
Additional context and design discussion can be found [here](https://hackmd.io/@57cqwgSpQY23bzke_Ch2ig/rJsw1tS9T).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feedback Type: recording user feedback
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants