Skip to content

Refactor asset handling and introduce SwapNoteStorage#2592

Merged
PhilippGackstatter merged 15 commits into0xMiden:nextfrom
PoulavBhowmick03:swap_note_storage
Mar 18, 2026
Merged

Refactor asset handling and introduce SwapNoteStorage#2592
PhilippGackstatter merged 15 commits into0xMiden:nextfrom
PoulavBhowmick03:swap_note_storage

Conversation

@PoulavBhowmick03
Copy link
Contributor

Closes #2515

@PoulavBhowmick03
Copy link
Contributor Author

I wrote it similar to P2idNoteStorage and P2ideNoteStorage and it's methods and complied to their API types.

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, thanks! I left a few comments.

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 one small comment inline.

storage.extend_from_slice(&requested_asset.as_elements());
storage.extend_from_slice(payback_recipient.digest().as_elements());
let inputs = NoteStorage::new(storage)?;
let inputs = NoteStorage::from(swap_storage);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd rename the variable here from inputs to storage.

Comment on lines +324 to +328
let attachment_content = match attachment_kind {
NoteAttachmentKind::None => NoteAttachmentContent::None,
NoteAttachmentKind::Word => NoteAttachmentContent::new_word(attachment_content_word),
NoteAttachmentKind::Array => NoteAttachmentContent::new_word(attachment_content_word),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This incorrectly maps NoteAttachmentKind::Array to NoteAttachmentContent::new_word but it should be new_array.

But the larger problem is that we cannot reconstruct the array content from the storage elements (&[Felt]), we'd need access to the advice map or pass the potential content of an array variant in some other way. So, in general, we cannot implement impl TryFrom<&[Felt]> for SwapNoteStorage.

For now, we do not need this impl, but it would be nice to have. There are some options:

  • Remove the impl for now.
  • Rethink whether a SWAP note needs to be as generic as it is: Does it need to be able to create payback P2ID notes with array attachments? Maybe it does, maybe not.
  • Encode the array attachment in swap note storage so it is available for reconstruction. Makes it convenient here, but not such a good idea for on-chain usage.
  • Implement fn try_from_parts(storage: NoteStorage, payback_note_attachment: NoteAttachment) instead, where we would need to make sure the provided attachment matches the encoded kind and scheme in storage and then use the array content from the provided attachment.

Since we don't need it currently, I'd remove the TryFrom impl. If we do need this in the future, we can come back to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that was a bug. looked into it, and it makes sense to remove the TryFrom for now. i think once #2555 is merged, we can look back at this. Should I add a NOTE here?

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, thanks!

@PhilippGackstatter PhilippGackstatter enabled auto-merge (squash) March 18, 2026 08:28
@PhilippGackstatter PhilippGackstatter merged commit f5685a3 into 0xMiden:next Mar 18, 2026
15 checks passed
JackTheGit pushed a commit to JackTheGit/protocol that referenced this pull request Mar 19, 2026
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.

Add SwapNoteStorage

3 participants