Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Note Consumption: Skip Invalid Notes and Consume Valid Ones from the List #679

Open
iamyeasin opened this issue Jan 19, 2025 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@iamyeasin
Copy link

iamyeasin commented Jan 19, 2025

Feature description

Story

I was trying to create multiple notes using an invalid (almost an empty) masm script. My balance was deducted & it created the note scripts. But note was not valid or it was failing to consume in the target account. After importing the notes, I found out I already had few other imported note but not consumed yet. I prepared a noteList and tried to use this method webClient.new_consume_transaction(targetAccount,noteList). And it was failing to consume the notes. Since it had that invalid note. But If I provided valid note ids, it was working fine.

Requesting Feature

A better way to handle that note consumption will be nice. For an example, If I have 5 notes & 1 of them is invalid, it should consume 4 of them & throw an error for the invalid one.

Why is this feature needed?

In my case, I was having trouble to consume valid notes because of invalid one. I didn't know if it was an invalid note. It created the notes & deducted the balance from my account & it failed on target account note consumption level. This is also a bit concerning if an invalid note is generated and can't be consumed by target account that fund might be lost.

@iamyeasin iamyeasin added the enhancement New feature or request label Jan 19, 2025
@igamigo
Copy link
Collaborator

igamigo commented Jan 19, 2025

This is also a bit concerning if an invalid note is generated and can't be consumed by target account that fund might be lost.

For this scenario where an asset is placed on a note which cannot be consumed as expected for whatever reason (wrong target account, etc.), you can always encode conditions in the script that could let you recall assets after a certain amount of time has passed. For example, you could make it so that only a target account ID can consume the note, but if the reference block is, say, 1000 or higher, you (the sender account ID) can consume the note again. The P2IDR note script is provided for scenarios similar to these.

Regarding not failing if a single note errors, I think it could potentially be done although I'm not sure about all the implications (cc @bobbinth) nor whether it's always desirable. A simple workaround that you could use now for knowing whether a note is consumable is to test with a simple execution transaction, but disregarding proving/submitting to the node.

@bobbinth
Copy link
Contributor

I think there are a few things here:

  1. As @igamigo pointed out, sometimes it may be good to add "recall conditions" to notes to make sure the sender can get the note back if the main note script is malformed in some way. We should probably have an example of how to do this. cc @partylikeits1983.
  2. It would be good to detect if a note can be consumed against some account. This could involve checks on multiple levels:
    a. For well-known notes (e.g., P2ID), we can very easily check if a note is consumable w/o looking at the actual note script. The tricky thing would be to figure out how to do this "generically".
    b. We could also do some simple MASM analysis to figure out if a note calls any of the account's interface methods. This would not be a precise test - i.e., we'll know "the note is definitely not consumable" or "the note may be consumable". We already have an issue for this in miden-base.
    c. We could execute the note script against the account in a "dry-run" fashion and see if it succeeds. This would require picking a specific set of conditions (e.g., a specific state of account, specific block height etc.) - but will give us a precise answer that a note can be executed under these conditions.
  3. We should provide an ability to mark notes as "poisoned" in the client. Basically, if we imported a note, and this note cannot be applied to any of the accounts, the user should be able to specify that this not should be excluded from future attempts to consume it.

For points 2 and 3, we should think through the UX - i.e., specifically how do we let the user know that a given note may not be executable (e.g., does it happen at transaction building time? or maybe earlier?)

@bobbinth bobbinth added this to the v0.8.0 milestone Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants