Skip to content

refactor!: new note emission API#16091

Merged
benesjan merged 1 commit into
nextfrom
07-30-refactor_siplifying_note_emission_api
Sep 9, 2025
Merged

refactor!: new note emission API#16091
benesjan merged 1 commit into
nextfrom
07-30-refactor_siplifying_note_emission_api

Conversation

@benesjan

@benesjan benesjan commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Refactoring note emission API to use the recently introduced MessageDelivery global var.

- note_emission.emit(encode_and_encrypt_note(&mut context, from));
+ note_emission.emit(&mut context, from, MessageDelivery.CONSTRAINED_ONCHAIN);
- note_emission.emit(encode_and_encrypt_note_unconstrained(&mut context, from));
+ note_emission.emit(&mut context, from, MessageDelivery.UNCONSTRAINED_ONCHAIN);
- note_emission.emit(encode_and_encrypt_note_and_emit_as_offchain_message(&mut context, context.msg_sender());
+ note_emission.emit(&mut context, context.msg_sender(), MessageDelivery.UNCONSTRAINED_OFFCHAIN);

Followup work

Achieving final imports

Would give the highest priority to tackling this issue because the import of MessageDelivery affects contract code and we don't want to force devs to do 2 annoying migrations. Plan on tackling that right after this PR is merged.

Random thoughts that came to my mind while implementing this

Consider renaming OuterNoteEmission

I would consider renaming OuterNoteEmission to MaybeNoteEmission because OuterNoteEmission is not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much.

noteEmission.discard(...)

I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense.

Emitting partial notes as offchain message

None of our partial notes implementations support emission via an offchain message.

On using AI

In this PR there was a lot of repetitive changes in the contracts and I realized that if I write nice migration notes first then I can use that as an input to the prompt. This made the AI output flawless.

@benesjan benesjan changed the title refactor: siplifying note emission API refactor!: simplifying note emission API Jul 30, 2025

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@benesjan benesjan requested review from nventuro and removed request for nventuro July 30, 2025 07:47
Comment thread noir-projects/aztec-nr/aztec/src/note/note_emission.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/event/event_interface.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr Outdated
@benesjan benesjan force-pushed the 07-30-refactor_siplifying_note_emission_api branch 3 times, most recently from 1932957 to 03ddf58 Compare September 5, 2025 06:27
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr
Comment thread noir-projects/aztec-nr/value-note/src/utils.nr
@benesjan benesjan marked this pull request as ready for review September 5, 2025 07:23
Comment thread boxes/boxes/react/src/contracts/src/main.nr
@benesjan benesjan changed the title refactor!: simplifying note emission API refactor!: new note emission API Sep 5, 2025
@benesjan benesjan requested a review from nventuro September 5, 2025 07:54
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr

@nventuro nventuro left a comment

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.

I would consider renaming OuterNoteEmission to MaybeNoteEmission because OuterNoteEmission is not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much.

OptionNoteEmission would be ok, yes. It only exists because none of the Option methods are a good fit - we'd want something like and_then but with no chaining.

noteEmission.discard(...)

I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense.

We could add a discard example I guess. It'd come up in transiento reads, e.g.

let note = priv_mut.get_note().discard(); // discard as it's about to get deleted so no point in emitting anything
priv_mut.replace(Note::new(note + 1)).emit(...);

Emitting partial notes as offchain message
None of our partial notes implementations support emission via an offchain message.

Would be good to address this, yes.

Comment thread docs/docs/migration_notes.md Outdated
Comment thread docs/docs/migration_notes.md Outdated
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr
Comment thread noir-projects/aztec-nr/aztec/src/messages/logs/note.nr
Comment thread noir-projects/aztec-nr/value-note/src/utils.nr

@nventuro nventuro left a comment

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.

Lovely work!

@benesjan benesjan marked this pull request as draft September 9, 2025 07:46
@benesjan benesjan force-pushed the 07-30-refactor_siplifying_note_emission_api branch from fb7c202 to a6d2ea7 Compare September 9, 2025 07:51
@benesjan benesjan marked this pull request as ready for review September 9, 2025 08:03
@benesjan benesjan enabled auto-merge September 9, 2025 08:03
Refactoring note emission API to use the recently introduced `MessageDelivery` global var.

```diff
- note_emission.emit(encode_and_encrypt_note(&mut context, from));
+ note_emission.emit(&mut context, from, MessageDelivery.CONSTRAINED_ONCHAIN);
```

```diff
- note_emission.emit(encode_and_encrypt_note_unconstrained(&mut context, from));
+ note_emission.emit(&mut context, from, MessageDelivery.UNCONSTRAINED_ONCHAIN);
```

```diff
- note_emission.emit(encode_and_encrypt_note_and_emit_as_offchain_message(&mut context, context.msg_sender());
+ note_emission.emit(&mut context, context.msg_sender(), MessageDelivery.UNCONSTRAINED_OFFCHAIN);
```

## Followup work

### Achieving final imports
Would give the highest priority to tackling [this issue](#16771) because the import of `MessageDelivery` affects contract code and we don't want to force devs to do 2 annoying migrations. Plan on tackling that right after this PR is merged.

## Random thoughts that came to my mind while implementing this

### Consider renaming `OuterNoteEmission`
I would consider renaming `OuterNoteEmission` to `MaybeNoteEmission` because `OuterNoteEmission` is not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much.

### `noteEmission.discard(...)`
I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense.

### Emitting partial notes as offchain message
None of our partial notes implementations support emission via an offchain message.

## On using AI
In this PR there was a lot of repetitive changes in the contracts and I realized that if I write nice migration notes first then I can use that as an input to the prompt. This made the AI output flawless.
@AztecBot AztecBot force-pushed the 07-30-refactor_siplifying_note_emission_api branch from ae7a53e to 47c5ec2 Compare September 9, 2025 08:19
@benesjan benesjan added this pull request to the merge queue Sep 9, 2025
Merged via the queue into next with commit 9c8e0aa Sep 9, 2025
16 checks passed
@benesjan benesjan deleted the 07-30-refactor_siplifying_note_emission_api branch September 9, 2025 09:08
AztecBot pushed a commit that referenced this pull request Sep 9, 2025
As I mentioned [here](#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion.

Closes #8589.
github-merge-queue Bot pushed a commit that referenced this pull request Sep 9, 2025
As I mentioned
[here](#16091 (comment))
makes sense to move the `emit_note` function directly to the
`NoteEmission` struct as that was the only callsite of the function.
This allowed me to nuke the old ugly `assert_note_exists` check in [this
commit
](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as
now the API guarantees that we are emitting a real note. This makes this
change a huge win in my opinion.

Closes #8589.
github-merge-queue Bot pushed a commit that referenced this pull request Sep 10, 2025
With [my recent
PR](#16091),
location of the event and note emission related code became illogical.
In this PR i reshuffle it around.

I perceive it as quite important to have this merged relatively quickly
as that will allow devs to deal with 1 migration instead of 2.
mralj pushed a commit that referenced this pull request Oct 13, 2025
As I mentioned [here](#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion.

Closes #8589.
AztecBot pushed a commit to AztecProtocol/barretenberg that referenced this pull request Dec 3, 2025
As I mentioned
[here](AztecProtocol/aztec-packages#16091 (comment))
makes sense to move the `emit_note` function directly to the
`NoteEmission` struct as that was the only callsite of the function.
This allowed me to nuke the old ugly `assert_note_exists` check in [this
commit
](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as
now the API guarantees that we are emitting a real note. This makes this
change a huge win in my opinion.

Closes AztecProtocol/aztec-packages#8589.
ludamad pushed a commit that referenced this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants