Skip to content
Closed
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
207 changes: 203 additions & 4 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ members = [
"midenc-log",
"midenc-session",
"sdk/field-repr/*",
"sdk/field",
"sdk/alloc",
"sdk/base",
"sdk/base-macros",
Expand Down Expand Up @@ -157,6 +156,9 @@ miden-integration-tests = { path = "tests/integration" }
midenc-expect-test = { path = "tools/expect-test" }
miden-test-harness = { path = "test-harness/test-harness-lib" }
miden-test-harness-macros = { path = "test-harness/test-harness-macros" }
# TODO: switch to version after miden-crypto release
# miden-field = { path = "../../unified-felt/crypto/miden-field", version = "0.22" }
miden-field = { git = "https://github.com/0xMiden/crypto", rev = "7e5a2cbc1de2c0b289590d6c25ac476b319dd148", version = "0.22" }

[patch.crates-io]
#miden-assembly = { git = "https://github.com/0xMiden/miden-vm", rev = "614cd7f9b52f45238b0ab59c71ebb49325051e5d" }
Expand Down
4 changes: 2 additions & 2 deletions examples/basic-wallet-tx-script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const ASSET_END: usize = 10;
#[tx_script]
fn run(arg: Word, account: &mut Account) {
let num_felts = adv_push_mapvaln(arg.clone());
let num_felts_u64 = num_felts.as_u64();
let num_felts_u64 = num_felts.as_canonical_u64();
assert_eq(Felt::from_u32((num_felts_u64 % 4) as u32), felt!(0));
let num_words = Felt::from_u64_unchecked(num_felts_u64 / 4);
let num_words = Felt::new(num_felts_u64 / 4);
let commitment = arg;
let input = adv_load_preimage(num_words, commitment);
let tag = input[TAG_INDEX];
Expand Down
14 changes: 8 additions & 6 deletions examples/counter-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ struct CounterContract {
impl CounterContract {
/// Returns the current counter value stored in the contract's storage map.
pub fn get_count(&self) -> Felt {
let key = Word::from_u64_unchecked(0, 0, 0, 1);
self.count_map.get(&key)
let key = Word::new([Felt::ZERO, Felt::ZERO, Felt::ZERO, felt!(1)]);
let word: Word = self.count_map.get(&key);
word[3]
}

/// Increments the counter value stored in the contract's storage map by one.
pub fn increment_count(&mut self) -> Felt {
let key = Word::from_u64_unchecked(0, 0, 0, 1);
let current_value: Felt = self.count_map.get(&key);
let new_value = current_value + felt!(1);
self.count_map.set(key, new_value);
let key = Word::new([Felt::ZERO, Felt::ZERO, Felt::ZERO, felt!(1)]);
let current_value_word: Word = self.count_map.get(&key);
let new_value = current_value_word[3] + felt!(1);
let new_value_word = Word::new([Felt::ZERO, Felt::ZERO, Felt::ZERO, new_value]);
self.count_map.set(key, new_value_word);
new_value
}
}
2 changes: 1 addition & 1 deletion examples/counter-note/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl CounterNote {
pub fn run(self, _arg: Word) {
let initial_value = counter_contract::get_count();
counter_contract::increment_count();
let expected_value = initial_value + Felt::from_u32(1);
let expected_value = initial_value + felt!(1);
let final_value = counter_contract::get_count();
assert_eq(final_value, expected_value);
}
Expand Down
6 changes: 4 additions & 2 deletions examples/storage-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ impl foo::Guest for MyAccount {
let mut my_account = MyAccount::default();
let owner_key: Word = my_account.owner_public_key.read();
if pub_key == owner_key {
my_account.asset_qty_map.set(asset, qty);
let new_value_word = Word::new([qty, Felt::ZERO, Felt::ZERO, Felt::ZERO]);
my_account.asset_qty_map.set(asset.into(), new_value_word);
}
}

/// Returns the stored quantity for `asset`, or 0 if not present.
fn get_asset_qty(asset: Asset) -> Felt {
let my_account = MyAccount::default();
my_account.asset_qty_map.get(&asset)
let word: Word = my_account.asset_qty_map.get(&asset);
word[3]
}
}
4 changes: 2 additions & 2 deletions sdk/base-macros/src/component_macro/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ fn slot_id_tokens(id: miden_protocol::account::StorageSlotId) -> proc_macro2::To
let prefix = id.prefix().as_int();
quote! {
::miden::StorageSlotId::new(
::miden::Felt::from_u64_unchecked(#suffix),
::miden::Felt::from_u64_unchecked(#prefix),
::miden::Felt::new(#suffix),
::miden::Felt::new(#prefix),
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/base-macros/wit/miden.wit
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ interface core-types {


/// A group of four field elements in the Miden base field.
// type word = tuple<felt, felt, felt, felt>;
record word {
inner: tuple<felt, felt, felt, felt>
a: felt,
b: felt,
c: felt,
d: felt,
}

/// A cryptographic digest representing a 256-bit hash value.
Expand Down
Loading
Loading