Skip to content

Commit 1f82ec1

Browse files
committed
doc: update miden in rust to v13 & some adjustment to the migration
guide
1 parent 670db95 commit 1f82ec1

File tree

13 files changed

+160
-119
lines changed

13 files changed

+160
-119
lines changed

docs/builder/migration/02-account-changes.md

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Replace numeric indices with `StorageSlotName`:
1616

1717
```rust title="src/account.rs"
1818
// Before
19-
let value = account.storage().get_slot(0)?;
19+
let value = account.storage().get_item(0)?;
2020

2121
// After
22-
let slot_name = StorageSlotName::new("my_slot")?;
23-
let value = account.storage().get_slot(&slot_name)?;
22+
let slot_name = StorageSlotName::new("my_component::my_slot")?;
23+
let value = account.storage().get_item(&slot_name)?;
2424
```
2525

2626
---
@@ -33,26 +33,27 @@ Replace index-based storage access with `StorageSlotName` identifiers.
3333

3434
```diff title="src/account.rs"
3535
- // Before: access by numeric index
36-
- let value = account.storage().get_slot(0)?;
37-
- account.storage_mut().set_slot(0, new_value)?;
36+
- let value = account.storage().get_item(0)?;
37+
- let _old_value = account.storage_mut().set_item(0, new_value)?;
3838

3939
+ // After: access by name
40-
+ let slot_name = StorageSlotName::new("my_slot")?;
41-
+ let value = account.storage().get_slot(&slot_name)?;
42-
+ account.storage_mut().set_slot(&slot_name, new_value)?;
40+
+ let slot_name = StorageSlotName::new("my_component::my_slot")?;
41+
+ let value = account.storage().get_item(&slot_name)?;
42+
+ let _old_value = account.storage_mut().set_item(&slot_name, new_value)?;
4343
```
4444

4545
### MASM Updates
4646

47-
The `set_map_item` procedure now takes slot IDs and returns only old values:
47+
The `native_account::set_map_item` procedure now takes slot IDs and returns only old values:
4848

4949
```diff title="src/contract.masm"
5050
- # Before
51-
- exec.account::set_map_item
51+
- exec.native_account::set_map_item
5252
- # Returns: [OLD_MAP_ROOT, OLD_VALUE, ...]
5353

5454
+ # After
55-
+ exec.account::set_map_item
55+
+ # Inputs: [slot_id_prefix, slot_id_suffix, KEY, NEW_VALUE]
56+
+ exec.native_account::set_map_item
5657
+ # Returns: [OLD_VALUE, ...]
5758
```
5859

@@ -80,16 +81,13 @@ Remove RNG generics from `FilesystemKeyStore`:
8081

8182
Web component compilation now requires `AccountComponentCode` from `CodeBuilder`:
8283

83-
```diff title="src/component.rs"
84+
```diff title="src/component.ts"
8485
- // Before
85-
- let component = AccountComponent::compile(source)?;
86+
- const component = AccountComponent.compile(accountCode, builder, [slot]);
8687

8788
+ // After
88-
+ use miden_protocol::code::CodeBuilder;
89-
+ let code = CodeBuilder::new()
90-
+ .with_source(source)
91-
+ .build()?;
92-
+ let component = AccountComponent::new(code)?;
89+
+ const componentCode = builder.compileAccountComponentCode(accountCode);
90+
+ const component = AccountComponent.compile(componentCode, [slot]);
9391
```
9492

9593
---
@@ -102,11 +100,22 @@ Replace `AccountComponentTemplate` with metadata-driven `StorageSchema`:
102100
- use miden_lib::AccountComponentTemplate;
103101
- let template = AccountComponentTemplate::new(slots)?;
104102

105-
+ use miden_standards::StorageSchema;
106-
+ let schema = StorageSchema::builder()
107-
+ .add_slot("balance", StorageSlotType::Value)
108-
+ .add_slot("metadata", StorageSlotType::Map)
109-
+ .build()?;
103+
+ use miden_protocol::account::component::{SchemaTypeId, StorageSchema, StorageSlotSchema};
104+
+ use miden_protocol::account::StorageSlotName;
105+
+ let schema = StorageSchema::new([
106+
+ (
107+
+ StorageSlotName::new("my_component::balance")?,
108+
+ StorageSlotSchema::value("balance", SchemaTypeId::native_word()),
109+
+ ),
110+
+ (
111+
+ StorageSlotName::new("my_component::metadata")?,
112+
+ StorageSlotSchema::map(
113+
+ "metadata",
114+
+ SchemaTypeId::native_word(),
115+
+ SchemaTypeId::native_word(),
116+
+ ),
117+
+ ),
118+
+ ])?;
110119
```
111120

112121
---
@@ -116,11 +125,11 @@ Replace `AccountComponentTemplate` with metadata-driven `StorageSchema`:
116125
Use `AccountProcedureRoot` instead of `AccountProcedureInfo`:
117126

118127
```diff title="src/procedure.rs"
119-
- use miden_objects::accounts::AccountProcedureInfo;
128+
- use miden_objects::account::AccountProcedureInfo;
120129
- let info = AccountProcedureInfo::new(digest, storage_offset)?;
121130

122-
+ use miden_protocol::accounts::AccountProcedureRoot;
123-
+ let root = AccountProcedureRoot::new(digest)?;
131+
+ use miden_protocol::account::AccountProcedureRoot;
132+
+ let root = AccountProcedureRoot::from_raw(digest);
124133
```
125134

126135
---
@@ -141,6 +150,6 @@ Use `AccountProcedureRoot` instead of `AccountProcedureInfo`:
141150

142151
| Error | Cause | Fix |
143152
|-------|-------|-----|
144-
| `no method named 'get_slot' taking u32` | API changed to names | Use `StorageSlotName` |
153+
| `expected &StorageSlotName, found u8` | API changed to names | Use `StorageSlotName` |
145154
| `FilesystemKeyStore expects 0 type parameters` | RNG generic removed | Remove type parameter |
146155
| `AccountComponentTemplate not found` | Renamed | Use `StorageSchema` |

docs/builder/migration/03-note-changes.md

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ The note system has been redesigned. `NoteMetadata` no longer stores `aux` or `N
1414

1515
```rust title="src/note.rs"
1616
// Before
17-
let metadata = NoteMetadata::new(sender, note_type, tag, aux, execution_hint)?;
17+
let metadata = NoteMetadata::new(sender, note_type, tag, execution_hint, aux)?;
1818

1919
// After
20-
let metadata = NoteMetadata::new(sender, note_type, tag)?;
21-
let attachment = NoteAttachment::new(aux_data, execution_hint)?;
22-
let note = Note::new(metadata, script, inputs, attachment)?;
20+
let attachment_word = Word::from([aux, execution_hint.into(), felt!(0), felt!(0)]);
21+
let attachment = NoteAttachment::new_word(NoteAttachmentScheme::none(), attachment_word);
22+
let metadata = NoteMetadata::new(sender, note_type)
23+
.with_tag(tag)
24+
.with_attachment(attachment);
25+
let note = Note::new(assets, metadata, recipient);
2326
```
2427

2528
---
@@ -34,14 +37,17 @@ let note = Note::new(metadata, script, inputs, attachment)?;
3437
- sender,
3538
- note_type,
3639
- tag,
37-
- aux, // No longer here
3840
- execution_hint, // No longer here
41+
- aux, // No longer here
3942
- )?;
4043

4144
+ // After: use attachments
42-
+ let metadata = NoteMetadata::new(sender, note_type, tag)?;
43-
+ let attachment = NoteAttachment::new(aux_data, execution_hint)?;
44-
+ let note = Note::new(metadata, script, inputs, attachment)?;
45+
+ let attachment_word = Word::from([aux, execution_hint.into(), felt!(0), felt!(0)]);
46+
+ let attachment = NoteAttachment::new_word(NoteAttachmentScheme::none(), attachment_word);
47+
+ let metadata = NoteMetadata::new(sender, note_type)
48+
+ .with_tag(tag)
49+
+ .with_attachment(attachment);
50+
+ let note = Note::new(assets, metadata, recipient);
4551
```
4652

4753
:::info Good to know
@@ -52,15 +58,17 @@ This separation makes note metadata more lightweight and allows attachments to b
5258

5359
## Tag Semantics
5460

55-
`NoteTag` is now a plain `u32`. Use `with_account_target()` for account targeting:
61+
`NoteTag::from_account_id` was removed. Use `NoteTag::new()` for explicit values and
62+
`NoteTag::with_account_target()` for account targeting:
5663

5764
```diff title="src/note.rs"
5865
- // Before: tag with embedded target
59-
- let tag = NoteTag::from_account_id(target_account)?;
60-
61-
+ // After: plain tag with explicit targeting
62-
+ let tag: u32 = 12345;
63-
+ let note = note.with_account_target(target_account)?;
66+
- let tag = NoteTag::from_account_id(target_account);
67+
-
68+
+ // After: use tag constructors
69+
+ let tag = NoteTag::new(12345);
70+
+ let target_tag = NoteTag::with_account_target(target_account);
71+
+ let metadata = metadata.with_tag(target_tag);
6472
```
6573

6674
---
@@ -70,34 +78,55 @@ This separation makes note metadata more lightweight and allows attachments to b
7078
Implement `NetworkAccountTarget` attachment for network-account notes:
7179

7280
```rust title="src/network_note.rs"
73-
use miden_protocol::notes::NetworkAccountTarget;
81+
use miden_protocol::note::NoteAttachment;
82+
use miden_standards::note::NetworkAccountTarget;
7483

75-
let target = NetworkAccountTarget::new(account_id, network_id)?;
76-
let note = note.with_attachment(target)?;
84+
let target = NetworkAccountTarget::new(account_id, execution_hint)?;
85+
let attachment = NoteAttachment::from(target);
86+
let metadata = metadata.with_attachment(attachment);
7787
```
7888

7989
---
8090

8191
## MINT Notes
8292

83-
New `MintNoteInputs` enum supports private and public output notes:
93+
`MintNoteStorage` supports private and public output notes:
8494

8595
```diff title="src/mint.rs"
8696
- // Before
87-
- let mint_note = MintNote::new(amount, recipient)?;
97+
- use miden_lib::note::create_mint_note;
98+
- let mint_note = create_mint_note(
99+
- faucet_id,
100+
- sender,
101+
- recipient_digest,
102+
- output_note_tag,
103+
- amount,
104+
- aux,
105+
- output_note_aux,
106+
- rng,
107+
- )?;
88108

89109
+ // After: explicit private/public choice
90-
+ use miden_standards::notes::MintNoteInputs;
110+
+ use miden_standards::note::{MintNote, MintNoteStorage};
111+
+ use miden_protocol::note::NoteAttachment;
91112
+
92-
+ // For private notes
93-
+ let inputs = MintNoteInputs::Private { amount, recipient };
113+
+ // For private output notes
114+
+ let mint_storage = MintNoteStorage::new_private(recipient_digest, amount, output_note_tag);
94115
+
95-
+ // For public notes
96-
+ let inputs = MintNoteInputs::Public { amount, recipient, metadata };
116+
+ // For public output notes
117+
+ let mint_storage = MintNoteStorage::new_public(recipient, amount, output_note_tag)?;
118+
+ let mint_note = MintNote::create(
119+
+ faucet_id,
120+
+ sender,
121+
+ mint_storage,
122+
+ NoteAttachment::default(),
123+
+ rng,
124+
+ )?;
97125
```
98126

99127
:::tip
100-
Choose `MintNoteInputs::Private` for most use cases. Use `Public` only when the note contents should be visible on-chain.
128+
Choose `MintNoteStorage::new_private` for most use cases. Use `new_public` only when the note
129+
contents should be visible on-chain.
101130
:::
102131

103132
---
@@ -108,13 +137,15 @@ Unified interface accepts full `Note` objects instead of IDs:
108137

109138
```diff title="src/transaction.rs"
110139
- // Before: separate authenticated/unauthenticated lists
111-
- let tx = TransactionRequest::new()
140+
- let tx = TransactionRequestBuilder::new()
112141
- .with_authenticated_input_notes(auth_note_ids)
113-
- .with_unauthenticated_input_notes(unauth_note_ids)?;
142+
- .with_unauthenticated_input_notes(unauth_note_ids)
143+
- .build()?;
114144

115145
+ // After: unified input notes
116-
+ let tx = TransactionRequest::new()
117-
+ .with_input_notes(notes)?; // Full Note objects
146+
+ let tx = TransactionRequestBuilder::new()
147+
+ .input_notes(notes) // Full Note objects
148+
+ .build()?;
118149
```
119150

120151
---
@@ -125,11 +156,11 @@ Private notes now carry `NoteHeader`; public notes expose `note` and `inclusionP
125156

126157
```rust title="src/fetch.rs"
127158
match fetched_note {
128-
FetchedNote::Private { header, .. } => {
159+
FetchedNote::Private(header, _) => {
129160
// Access header fields
130161
let note_id = header.id();
131162
}
132-
FetchedNote::Public { note, inclusion_proof } => {
163+
FetchedNote::Public(note, inclusion_proof) => {
133164
// Access full note and proof
134165
let inputs = note.inputs();
135166
}
@@ -142,10 +173,10 @@ match fetched_note {
142173

143174
1. Remove `aux` and `execution_hint` from `NoteMetadata` constructors
144175
2. Create `NoteAttachment` objects for aux data and hints
145-
3. Update `NoteTag` usage to plain `u32` values
176+
3. Update `NoteTag` usage to `NoteTag::new()` / `NoteTag::with_account_target()`
146177
4. Use `with_account_target()` for targeted notes
147178
5. Implement `NetworkAccountTarget` for network notes
148-
6. Update mint note creation to use `MintNoteInputs` enum
179+
6. Update mint note creation to use `MintNoteStorage`
149180
7. Refactor input notes to pass full `Note` objects
150181
8. Update `FetchedNote` handling for new structure
151182

@@ -155,6 +186,6 @@ match fetched_note {
155186

156187
| Error | Cause | Fix |
157188
|-------|-------|-----|
158-
| `NoteMetadata::new takes 3 arguments` | aux/hint removed | Use `NoteAttachment` |
189+
| `NoteMetadata::new takes 2 arguments` | aux/hint removed | Use `NoteAttachment` |
159190
| `NoteTag::from_account_id not found` | API changed | Use `with_account_target()` |
160191
| `with_authenticated_input_notes not found` | API unified | Use `with_input_notes()` |

docs/builder/smart-contracts/rust/accounts/account-operations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ let new_nonce: Felt = native_account::incr_nonce();
9898
```
9999

100100
:::warning
101-
The nonce must be incremented for any transaction that modifies account state. Without it, the same transaction could be replayed. The `#[component]` macro handles this automatically for most cases.
101+
The nonce must be incremented for any transaction that modifies account state. Without it, the same transaction could be replayed.
102102
:::
103103

104104
### Transaction tracking
@@ -139,8 +139,8 @@ impl MyAccount {
139139
| `add_asset` | `fn add_asset(&mut self, asset: Asset) -> Asset` |
140140
| `remove_asset` | `fn remove_asset(&mut self, asset: Asset) -> Asset` |
141141
| `incr_nonce` | `fn incr_nonce(&mut self) -> Felt` |
142-
| `compute_delta_commitment` | `fn compute_delta_commitment(&mut self) -> Word` |
143-
| `was_procedure_called` | `fn was_procedure_called(&mut self, proc_root: Word) -> bool` |
142+
| `compute_delta_commitment` | `fn compute_delta_commitment(&self) -> Word` |
143+
| `was_procedure_called` | `fn was_procedure_called(&self, proc_root: Word) -> bool` |
144144

145145
### ActiveAccount methods (on `&self`)
146146

docs/builder/smart-contracts/rust/accounts/components.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl CounterContract {
4141
The macro generates:
4242

4343
1. **WIT interface definition** describing the component's public API
44-
2. **Storage metadata** mapping field names to slot indices
44+
2. **Storage metadata** mapping slot names to slot IDs (derived from the component package + field name)
4545
3. **Export bindings** for the Miden runtime
4646

4747
## Struct definition
@@ -71,13 +71,15 @@ field_name: Value,
7171
field_name: StorageMap,
7272
```
7373

74-
The `description` is required and becomes part of the generated metadata. Slots are assigned sequentially starting from 0 unless explicitly specified with `slot(N)`:
74+
The `description` is optional but recommended and becomes part of the generated metadata. Slot IDs are derived from the component package name (from `[package.metadata.component]`) and the field name, so **renaming a field changes the slot ID**. Ordering does not matter, and `slot(N)` is not supported.
75+
76+
Use `#[storage(description = "...")]` on each storage field:
7577

7678
```rust
77-
#[storage(slot(0), description = "initialized flag")]
79+
#[storage(description = "initialized flag")]
7880
initialized: Value,
7981

80-
#[storage(slot(1), description = "balances map")]
82+
#[storage(description = "balances map")]
8183
balances: StorageMap,
8284
```
8385

@@ -157,7 +159,7 @@ Public methods can use these types in their signatures:
157159

158160
The `#[component]` macro automatically provides methods on `self` through the `NativeAccount` and `ActiveAccount` traits.
159161

160-
### Always available (via `NativeAccount` trait on `&mut self`)
162+
### Always available (via `NativeAccount` trait; mutating methods require `&mut self`)
161163

162164
```rust
163165
// Add an asset to the account vault
@@ -169,10 +171,10 @@ self.remove_asset(asset: Asset) -> Asset
169171
// Increment the account nonce (replay protection)
170172
self.incr_nonce() -> Felt
171173

172-
// Compute commitment of account state changes
174+
// Compute commitment of account state changes (read-only)
173175
self.compute_delta_commitment() -> Word
174176

175-
// Check if a procedure was called during this transaction
177+
// Check if a procedure was called during this transaction (read-only)
176178
self.was_procedure_called(proc_root: Word) -> bool
177179
```
178180

0 commit comments

Comments
 (0)