Skip to content

feat(standards): unify MINT/BURN notes for fungible and non-fungible faucets via CodeInspection#3222

Open
onurinanc wants to merge 7 commits into
nextfrom
integrate-code-inspection
Open

feat(standards): unify MINT/BURN notes for fungible and non-fungible faucets via CodeInspection#3222
onurinanc wants to merge 7 commits into
nextfrom
integrate-code-inspection

Conversation

@onurinanc

Copy link
Copy Markdown
Collaborator

Closes: #3163

@PhilippGackstatter PhilippGackstatter 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.

Looks good to me!

Comment thread crates/miden-standards/src/note/mint.rs
Comment thread crates/miden-standards/src/note/mint.rs
Comment on lines +89 to +93
impl AssetStatus {
/// Builds an [`AssetStatus`] from the raw status code held in element 0 of the registry value
/// word (0 = not issued, 1 = issued, 2 = burned).
fn from_status_code(status: Felt) -> Result<Self, NonFungibleFaucetError> {
match status.as_canonical_u64() {

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: I would change this to TryFrom<u8> impl to match most other flat enums in the codebase which encode to and from a u8.

@bobbinth bobbinth 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.

Looks good! Thank you! I left a few small comments inline.

Comment on lines 230 to 235
tag: Felt,
},
Public {
FungiblePublic {
recipient: NoteRecipient,
asset: FungibleAsset,
tag: Felt,

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.

Not from this PR, but since we use NoteTag for non-fungible assets, I think we should use NoteTag for fungible assets as well (for the tag field).

Comment on lines +298 to +300
/// For fungible variants this is derived from the embedded asset; for non-fungible variants it
/// is the explicitly provided target faucet ID.
pub fn faucet_id(&self) -> AccountId {

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.

Is this comment correct? I think in both cases we get the faucet ID from the asset.

Comment on lines +319 to +322
pub fn asset_status(
storage: &AccountStorage,
commitment: Word,
) -> Result<AssetStatus, NonFungibleFaucetError> {

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.

A couple of nits:

  • I would change commitment to asset_commitment to make things a bit more clear.
  • I would probably rename this method to get_asset_status().

Comment on lines +318 to +319
/// [`compute_asset_commitment`]: NonFungibleFaucet::compute_asset_commitment
pub fn asset_status(

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.

The comment on line 318 seems disconnected from the rest of the comment. Should it be integrated somehow into it?

Comment on lines 129 to +131
if.true
# public output note creation
# =========================================================================================
# FUNGIBLE MINT

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.

The code below is a bit difficult to follow. I would probably split this into 4 helper procedures and then use the if-statements here to select which one of the four procedures to execute.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agreed - I'd even take this a step further and have the fungible / non-fungible helpers separated out to their own files, e.g.:

  • crates/miden-standards/asm/standards/notes/mint.masm
  • crates/miden-standards/asm/standards/notes/mint_fungible.masm
  • crates/miden-standards/asm/standards/notes/mint_non_fungible.masm

Which sort of goes back to the old file structure, but IMO the separation would be clearer if the aggregating mint.masm only contained the minimal branching logic, with the per-faucet-type impl still in their own file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

plus, that would make the diff much smaller AFAICS

@mmagician mmagician left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM modulo code organization ✅

Comment on lines +41 to +55
# Determine the faucet kind
procref.fungible::receive_and_burn
# => [FUNGIBLE_RECEIVE_AND_BURN_ROOT, pad(16)]

call.code_inspection::has_procedure
# => [is_fungible, pad(19)]

movdn.4 dropw
# => [is_fungible, pad(15)]

if.true
# Fungible faucet: burn the fungible asset.
call.fungible::receive_and_burn
# => [pad(16)]
else

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

neat

Comment on lines 129 to +131
if.true
# public output note creation
# =========================================================================================
# FUNGIBLE MINT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agreed - I'd even take this a step further and have the fungible / non-fungible helpers separated out to their own files, e.g.:

  • crates/miden-standards/asm/standards/notes/mint.masm
  • crates/miden-standards/asm/standards/notes/mint_fungible.masm
  • crates/miden-standards/asm/standards/notes/mint_non_fungible.masm

Which sort of goes back to the old file structure, but IMO the separation would be clearer if the aggregating mint.masm only contained the minimal branching logic, with the per-faucet-type impl still in their own file

Comment on lines 129 to +131
if.true
# public output note creation
# =========================================================================================
# FUNGIBLE MINT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

plus, that would make the diff much smaller AFAICS

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.

Integrate CodeInspection component to MINT and BURN notes for Fungible and Non-Fungible Faucets

4 participants