Skip to content

feat(AggLayer): B2AGG note consumption check#2334

Merged
mmagician merged 41 commits intoagglayer-fixed-2from
mmagician-bagg-check
Feb 4, 2026
Merged

feat(AggLayer): B2AGG note consumption check#2334
mmagician merged 41 commits intoagglayer-fixed-2from
mmagician-bagg-check

Conversation

@mmagician
Copy link
Copy Markdown
Collaborator

@mmagician mmagician commented Jan 23, 2026

As per the discussion here, the network target account ID is placed into NoteAttachment instead.

While at it, I created a helper function, similarly to the one we have for CLAIM notes: create_b2agg_note, and refactored the tests to use that utility.

TODO:

closes #2173
closes #2189

@mmagician mmagician added the agglayer PRs or issues related to AggLayer bridging integration label Jan 23, 2026
@mmagician mmagician force-pushed the mmagician-bagg-check branch from 69ed247 to bec68d1 Compare January 24, 2026 11:08
@mmagician mmagician marked this pull request as ready for review January 24, 2026 15:03
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left some comments inline. Also, I think it may make sense to merge this PR after #2338.

Copy link
Copy Markdown
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (only reviewed the note attachment parts - let me know if you want me to review everything).

@mmagician mmagician force-pushed the mmagician-bagg-check branch from 36ddfdb to 84bfa0a Compare January 28, 2026 13:12
@mmagician mmagician changed the base branch from agglayer to agglayer-fixed-2 January 28, 2026 13:12

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@partylikeits1983 partylikeits1983 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, similar to what @PhilippGackstatter mentioned above, create_b2agg_note will need to be updated as per #2283

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left a few comments inline - some of them could be done in a follow-up (but let's make sure these are captured in an issue).

Comment on lines +100 to +101
exec.get_id
# => [target_id_prefix, target_id_suffix]
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 believe this will panic if the attachment is of incorrect kind/scheme right? Is that the desired behavior? It may be better to check if the attachment is correct (e.g., via something like is_network_account_target procedure) and extract the id only then.

If panic is the intended behavior, we should mention this in the doc comments for this procedure.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up re-working network_account_target.masm a little, so that now we have:

  • is_network_account_target(scheme, kind) -> bool
  • get_id(ATTACHMENT) -> (prefix, suffix) (no validation of scheme/kind, simply a helper to extract id from attachment Word)
  • active_account_matches_target_account() -> bool (panics if scheme/kind dont match)

cc @PhilippGackstatter who originally suggested #2337

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.

If this approach works better in practice, then we should use that 👍

Comment on lines 71 to +102
#! Inputs: [account_id_prefix, account_id_suffix, exec_hint]
#! Outputs: [attachment_scheme, attachment_kind, NOTE_ATTACHMENT]
#! Outputs: [attachment_kind, attachment_scheme, NOTE_ATTACHMENT]
#!
#! Where:
#! - account_id_{prefix,suffix} are the prefix and suffix felts of an account ID.
#! - exec_hint is the execution hint for the note.
#! - attachment_kind is the attachment kind (Word = 1) for use with `output_note::set_attachment`.
#! - attachment_scheme is the attachment scheme (1) for use with `output_note::set_attachment`.
#!
#! Invocation: exec
pub proc new
movup.2
push.0
push.NETWORK_ACCOUNT_TARGET_ATTACHMENT_KIND
push.NETWORK_ACCOUNT_TARGET_ATTACHMENT_SCHEME
# => [attachment_scheme, attachment_kind, ATTACHMENT]
push.NETWORK_ACCOUNT_TARGET_ATTACHMENT_KIND
# => [attachment_kind, attachment_scheme, ATTACHMENT]
end

#! Returns a boolean indicating whether the active account matches the target account
#! encoded in the active note's attachment.
#!
#! Inputs: []
#! Outputs: [is_equal]
#!
#! Where:
#! - is_equal is a boolean indicating whether the active account matches the target account.
#!
#! Panics if:
#! - the attachment is not a valid network account target.
#!
#! Invocation: exec
pub proc active_account_matches_target_account
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.

Nit: The name suggests it returns only a bool but it also asserts things. Maybe it would make sense to call it assert_active_account_matches_target_account and take the ID as an input and do the equality assertion internally. This makes the error message worse due to less context, so not strictly an improvement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the current name is slightly misleading.
I think we could change the name to assert_active_account_matches_target_account as you suggest, but actually without modifying the signature?
Specifically the active_account part of the name makes it clear to me that we are talking about the concrete account ID, so no need to pass ID as input, WDYT?

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 considered that as well, but thought the procedure would then not actually do what it suggests it does, i.e. it does not assert that the active account matches the target account, it only returns a bool. So, slight preference to do the assertion internally if that works for the call sites, but not a strong opinion at all.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, in that case I'll leave it as-is

@mmagician mmagician merged commit a1f3b48 into agglayer-fixed-2 Feb 4, 2026
15 checks passed
@mmagician mmagician deleted the mmagician-bagg-check branch February 4, 2026 13:04
afa7789 pushed a commit to afa7789/miden-base that referenced this pull request Mar 9, 2026
* feat: put target account in attachment

* feat: extract b2agg creation to helper

* lint: regen error file

* feat: use NetworkAccountTarget for attachments

- make bridge a network account
- move the ID check to non-reclaim branch

* fix: still need LET slot

* chore: test the target mismatch logic

* chore: apply target checks to UPDATE_GER

* Apply suggestion from @mmagician

* chore: add TODOs

* chore: lint

* docs(masm): trim dangling B2AGG note description

Co-authored-by: marti <marti@hungrycats.studio>

* docs(masm): clarify B2AGG attachment layout

Co-authored-by: marti <marti@hungrycats.studio>

* feat: use network account target helper

Co-authored-by: marti <marti@hungrycats.studio>

* feat: make B2AGG notes always public

Co-authored-by: marti <marti@hungrycats.studio>

* feat: mark B2AGG notes always consumable

Co-authored-by: marti <marti@hungrycats.studio>

* style: use NoteScript import for B2AGG

Co-authored-by: marti <marti@hungrycats.studio>

* docs: add changelog entry for PR 2334

Co-authored-by: marti <marti@hungrycats.studio>

* Apply suggestions from code review

* chore: move helper to network_account_target

* chore: note script section headers

* chore: comment simplify and wrap

* lint

* fix: use `with_account_target` instead of `0` for `NoteTag`

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: add missing panic to get_id

* chore: mention active note

* docs: how active_account_matches_target_account panics

* Revert "fix: use `with_account_target` instead of `0` for `NoteTag`"

This reverts commit 0282672.

* feat: extract assert_is_network_account_target helper

* feat: change is_network_account_target to return bool, not panic

* feat: swap kind/scheme in signatures

* lint: regen errors

* feat: encapsulate note logic in structs

* chore: rename file to bagg_note

* chore: remove redundant comments

* Revert "feat: swap kind/scheme in signatures"

This reverts commit aad47e5.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer PRs or issues related to AggLayer bridging integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants