-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from 0xPolygonMiden/dominik_restructure_asm_c…
…ompile_note_scripts refactor: change asm structure and compile note scripts
- Loading branch information
Showing
29 changed files
with
217 additions
and
105 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use.miden::sat::account | ||
use.miden::sat::note | ||
use.miden::sat::tx | ||
use.miden::wallets::basic->wallet | ||
|
||
#! Helper procedure to add all assets of a note to an account. | ||
#! | ||
#! Inputs: [] | ||
#! Outputs: [] | ||
#! | ||
proc.add_note_assets_to_account | ||
push.0 exec.note::get_assets | ||
# => [num_of_assets, 0 = ptr, ...] | ||
|
||
# compute the pointer at which we should stop iterating | ||
dup.1 add | ||
# => [end_ptr, ptr, ...] | ||
|
||
# pad the stack and move the pointer to the top | ||
padw movup.5 | ||
# => [ptr, 0, 0, 0, 0, end_ptr, ...] | ||
|
||
# compute the loop latch | ||
dup dup.6 neq | ||
# => [latch, ptr, 0, 0, 0, 0, end_ptr, ...] | ||
|
||
while.true | ||
# => [ptr, 0, 0, 0, 0, end_ptr, ...] | ||
|
||
# save the pointer so that we can use it later | ||
dup movdn.5 | ||
# => [ptr, 0, 0, 0, 0, ptr, end_ptr, ...] | ||
|
||
# load the asset and add it to the account | ||
mem_loadw call.wallet::receive_asset | ||
# => [ASSET, ptr, end_ptr, ...] | ||
|
||
# increment the pointer and compare it to the end_ptr | ||
movup.4 add.1 dup dup.6 neq | ||
# => [latch, ptr+1, ASSET, end_ptr, ...] | ||
end | ||
|
||
# clear the stack | ||
drop dropw drop | ||
end | ||
|
||
# Pay-to-ID script: adds all assets from the note to the account, assuming ID of the account | ||
# matches target account ID specified by the note inputs. | ||
# | ||
# Requires that the account exposes: miden::wallets::basic::receive_asset procedure. | ||
# | ||
# Inputs: [] | ||
# Outputs: [] | ||
# | ||
# Note inputs are assumed to be as follows: | ||
# - target_account_id is the ID of the account for which the note is intended. | ||
# | ||
# FAILS if: | ||
# - Account does not expose miden::wallets::basic::receive_asset procedure. | ||
# - Account ID of executing account is not equal to the Account ID specified via note inputs. | ||
# - The same non-fungible asset already exists in the account. | ||
# - Adding a fungible asset would result in amount overflow, i.e., the total amount would be | ||
# greater than 2^63. | ||
begin | ||
# drop the transaction script root | ||
dropw | ||
# => [] | ||
|
||
# load the note inputs to memory starting at address 0 | ||
push.0 exec.note::get_inputs | ||
# => [inputs_ptr] | ||
|
||
# read the target account id from the note inputs | ||
mem_load | ||
# => [target_account_id] | ||
|
||
exec.account::get_id | ||
# => [account_id, target_account_id, ...] | ||
|
||
# ensure account_id = target_account_id, fails otherwise | ||
assert_eq | ||
# => [...] | ||
|
||
exec.add_note_assets_to_account | ||
# => [...] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.