Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions sdk/stdlib-sys/src/intrinsics/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ impl Word {
}
}

/// Creates a new `Word` with all four field elements set to zero.
pub fn empty() -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's implement this via the Default trait instead, which makes it more generally useful anyway.

Self {
inner: (felt!(0), felt!(0), felt!(0), felt!(0)),
}
}

pub fn reverse(&self) -> Word {
// This is workaround for the https://github.com/0xMiden/compiler/issues/596 to avoid
// i64.rotl op in the compiled Wasm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn rust_sdk_account_has_procedure_binding() {
run_account_binding_test(
"rust_sdk_account_has_procedure_binding",
"pub fn binding(&self) -> Felt {
let proc_root = Word::from([Felt::from_u32(0); 4]);
let proc_root = Word::empty();
if self.has_procedure(proc_root) {
Felt::from_u32(1)
} else {
Expand All @@ -207,7 +207,7 @@ fn rust_sdk_account_was_procedure_called_binding() {
run_account_binding_test(
"rust_sdk_account_was_procedure_called_binding",
"pub fn binding(&self) -> Felt {
let proc_root = Word::from([Felt::from_u32(0); 4]);
let proc_root = Word::empty();
if self.was_procedure_called(proc_root) {
Felt::from_u32(1)
} else {
Expand All @@ -232,7 +232,7 @@ fn rust_sdk_account_storage_get_initial_map_item_binding() {
run_account_binding_test(
"rust_sdk_account_storage_get_initial_map_item_binding",
"pub fn binding(&self) -> Word {
let key = Word::from([Felt::from_u32(0); 4]);
let key = Word::empty();
storage::get_initial_map_item(0, &key)
}",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn rust_sdk_account_asset_build_non_fungible_asset_binding() {
"rust_sdk_account_asset_build_non_fungible_asset_binding",
"pub fn binding(&self) -> Asset {
let faucet = AccountId { prefix: Felt::from_u32(1), suffix: Felt::from_u32(0) };
let hash = Word::from([Felt::from_u32(0); 4]);
let hash = Word::empty();
asset::build_non_fungible_asset(faucet, hash)
}",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn rust_sdk_account_faucet_create_non_fungible_asset_binding() {
run_faucet_binding_test(
"rust_sdk_account_faucet_create_non_fungible_asset_binding",
"pub fn binding(&self) -> Asset {
let hash = Word::from([Felt::from_u32(0); 4]);
let hash = Word::empty();
faucet::create_non_fungible_asset(hash)
}",
);
Expand Down