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
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
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
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
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
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
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
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
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
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
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
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
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
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