-
Notifications
You must be signed in to change notification settings - Fork 47
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
Enable transaction-specified inputs for notes #338
Comments
I can give it a try |
I have started with this, but there are some implementation details that we might need to discuss.
If so, we might need to provide a
At the moment, any note script has the note script root on top of the stack. We can put the |
I think so. We could modify the
I'm actually not sure we need to "unhash" not args to memory. Another option is to just move them from the advice provider onto the stack before a note is executed. Though, to avoid potential attacks, it may be good to put a hash of note args into memory during transaction prologue. |
Currently, note scripts have access to the following properties of a note:
get_assets
kernel procedure.get_inputs
kernel procedure.get_sender
note procedure.The script can also read global transaction variables (e.g., block number) and we can add procedures to the kernel to enable access to global account state, chain MMR etc.
The above is already pretty powerful, but we can make note scripts even more powerful if we enable per-transaction note inputs (I'll call these note args to distinguish them from the current note inputs). These args can be placed on the stack by the kernel runtime right before a note's script is called, and then the script will have access to these args.
One use case for these are orders in an order-book DEX (see #330 (comment)). There, a note can represent an order, and if we can't find a perfect matching order, we may want to "consume" a part of the note.
To consume a part of the note, the note script would need to know how to "split" itself. For example, we could have a script which roughly does the following:
In the above, if
rem == 0
, the whole note is consumed in the trade. But ifrem
is greater than 0, then we consume a part of the note in a trade, and send the remainder of the note's assets into a new note (which can then be again consumed by the DEX account).In the above,
rem
would be this per-transaction note argument and whoever generates this transaction (e.g., a DEX operator), would be able to specify the value ofrem
based on the current state of the order book.The text was updated successfully, but these errors were encountered: