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

triage(AztecNr): Investigate gate usage for the library #7071

Closed
Tracked by #2783
LHerskind opened this issue Jun 17, 2024 · 3 comments
Closed
Tracked by #2783

triage(AztecNr): Investigate gate usage for the library #7071

LHerskind opened this issue Jun 17, 2024 · 3 comments
Assignees

Comments

@LHerskind
Copy link
Contributor

LHerskind commented Jun 17, 2024

Investigate the "gate usage" of the aztec nr library. Create issues under optimisations in #7071 for heavy library functions such that it can be properly investigated how to optimise it.

Example output from the task:

  • BalancesMap.sub is expensive, since it is nullifying a lot of many notes
@benesjan
Copy link
Contributor

benesjan commented Jun 19, 2024

Note: I am starting profiling transfer function of Token and I'll be posting insights in individual comments.

1) compute_note_hash_for_read_request costs 148k gates because there is an ugly if else which results in us having gates there from both compute_unique_note_hash and compute_inner_note_hash functions. Both of these do multiple rounds of hashing (currently pedersen).

This function is called whenever we are fetching any notes (which is very common) so trying to optimize that seems to make sense.

Because of the if else we have there gates for compute_inner_note_hash twice:
image

The compute_unique_note_hash branch is triggered when nonce is non-zero.

Could we get rid of the if-else and always hash with nonce (even when zero)?

@benesjan
Copy link
Contributor

benesjan commented Jun 19, 2024

Note: The optimization proposed below was tackled in this PR.

2) destroy_note costs 557k gates (33% of total current cost).

There is one obvious optimization to be done which was spotted a long time ago and is tracked in this issue - we compute note hash twice: once in compute_nullifier and once in the function itself when.

image

The solutions proposed in #1718 seems too complex to me (maybe because they were assessed a long time ago). A more obvious way to do it would be to expose both values from compute_nullifier function. It would make the API uglier but generally the function is not really called directly by devs in the majority of usecases (we call that directly only in the Claim contract):
image

So the ugliness might be fine.

compute_note_hash_for_consumption costs 235k gates so not calling that twice would be significant.

Update: Lasse and Nico pointed out in scrum that the gate count of the function is so large because in the transfer function it's summed over 32 notes (which are iterated over). So the gain will be much smaller in cases working with individual notes.

@benesjan
Copy link
Contributor

benesjan commented Aug 9, 2024

Outdated so closing

@benesjan benesjan closed this as completed Aug 9, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in A3 Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants