Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/auth-component-no-auth/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/auth-component-rpo-falcon512/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/basic-wallet-tx-script/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions examples/basic-wallet-tx-script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use miden::{intrinsics::advice::adv_push_mapvaln, *};

use crate::bindings::miden::basic_wallet::basic_wallet;
use crate::bindings::Account;

// Input layout constants
const TAG_INDEX: usize = 0;
Expand All @@ -23,7 +23,7 @@ const ASSET_START: usize = 8;
const ASSET_END: usize = 12;

#[tx_script]
fn run(arg: Word) {
fn run(arg: Word, account: Account) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a good reason to pass account by value, rather than by reference (either immutable or mutable, depending on the needs of the script)?

One reason why I think that might be important, is that it would provide us enough information to be able to determine how a given script/note interacts with an account, as well as allow Rust to enforce at compile-time that you cannot call certain methods on the account because you don't have an appropriate reference type.

The bigger question I guess, is whether there is any value in non-mutable references as argument to a transaction script/note script. In theory, that would enforce read-only access - but I'm not clear on whether read-only scripts would be useful; and even if we had them, how other parts of our tooling would leverage that (i.e. depending on what type of reference your script entrypoint uses (e.g. & vs &mut), we'd encode in the resulting package metadata that the script is read-only or can mutate an account. That could make it easier to notify users that they are about to perform an action with mutable access to an account - but I don't know the exact mechanism by which that would work.

Anyhow, by passing the account parameter by-value, we don't even have the option of using reference mutability to encode that information, so it might be worth getting ahead of it a bit, by always passing a mutable reference for now (or if it's possible, we could look at the reference type of the method, and then have the proc macro machinery emit code to pass a reference of the appropriate type).

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I addressed this in #801 but forgot to mention it in this PR.
Also, I'm linking here for account methods self mutability issue: #802.

let num_felts = adv_push_mapvaln(arg.clone());
let num_felts_u64 = num_felts.as_u64();
assert_eq(Felt::from_u32((num_felts_u64 % 4) as u32), felt!(0));
Expand All @@ -35,7 +35,8 @@ fn run(arg: Word) {
let note_type = input[NOTE_TYPE_INDEX];
let execution_hint = input[EXECUTION_HINT_INDEX];
let recipient: [Felt; 4] = input[RECIPIENT_START..RECIPIENT_END].try_into().unwrap();
let note_idx = output_note::create(tag.into(), aux, note_type.into(), execution_hint, recipient.into());
let note_idx =
output_note::create(tag.into(), aux, note_type.into(), execution_hint, recipient.into());
let asset: [Felt; 4] = input[ASSET_START..ASSET_END].try_into().unwrap();
basic_wallet::move_asset_to_note(asset.into(), note_idx);
account.move_asset_to_note(asset.into(), note_idx);
}
2 changes: 2 additions & 0 deletions examples/basic-wallet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/counter-contract/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/counter-note/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/p2id-note/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/p2id-note/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

use miden::*;

use crate::bindings::miden::basic_wallet::basic_wallet::receive_asset;
use crate::bindings::Account;

#[note_script]
fn run(_arg: Word) {
fn run(_arg: Word, account: Account) {
let inputs = active_note::get_inputs();
let target_account_id_prefix = inputs[0];
let target_account_id_suffix = inputs[1];
Expand All @@ -23,6 +23,6 @@ fn run(_arg: Word) {

let assets = active_note::get_assets();
for asset in assets {
receive_asset(asset);
account.receive_asset(asset);
}
}
2 changes: 2 additions & 0 deletions examples/p2ide-note/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/storage-example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/base-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ semver.workspace = true
toml.workspace = true
syn.workspace = true
heck.workspace = true
wit-bindgen-core = "0.46"
wit-bindgen-rust = { version = "0.46", default-features = false }

[dev-dependencies]
# Use local paths for dev-only dependency to avoid relying on crates.io during packaging
Expand Down
Loading