Skip to content

Commit b281dea

Browse files
koalateectrlpartylikeits1983mmagician
authored
Tutorial Fixes (#117)
* fix create deploy tutorial * fix miden node setup * fix deploying a counter contract * fix interacting with public smart contracts * fix network transactions on Miden * fix fpi * remove all truncate stack and remove network_counter.masm * add print commitment back in * fix counter.masm * fix rebase issues * fix: CI & counter contract redeploy * Apply suggestions from code review --------- Co-authored-by: riemann <aleqvids@gmail.com> Co-authored-by: Marti <marcin.gorny.94@protonmail.com>
1 parent e2ba17c commit b281dea

15 files changed

+65
-107
lines changed

docs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![doc = include_str!("rust-client/create_deploy_tutorial.md")]
22
#![doc = include_str!("rust-client/mint_consume_create_tutorial.md")]
33
#![doc = include_str!("rust-client/counter_contract_tutorial.md")]
4-
#![doc = include_str!("rust-client/public_account_interaction_tutorial.md")]
54
#![doc = include_str!("rust-client/custom_note_how_to.md")]
65
#![doc = include_str!("rust-client/foreign_procedure_invocation_tutorial.md")]
6+
#![doc = include_str!("rust-client/public_account_interaction_tutorial.md")]
77
#![doc = include_str!("rust-client/unauthenticated_note_how_to.md")]
88
#![doc = include_str!("rust-client/mappings_in_masm_how_to.md")]
99
#![doc = include_str!("rust-client/creating_notes_in_masm_tutorial.md")]

docs/src/miden_node_setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mkdir accounts
2727

2828
miden-node bundled bootstrap \
2929
--data-directory data \
30-
--accounts-directory .
30+
--accounts-directory accounts
3131
```
3232

3333
Expected output:

docs/src/rust-client/counter_contract_tutorial.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ In the previous section, we explained how to instantiate the Miden client. We ca
5050

5151
Copy and paste the following code into your `src/main.rs` file:
5252

53-
```rust,no_run
53+
```rust
5454
use miden_lib::account::auth::NoAuth;
5555
use rand::RngCore;
5656
use std::{fs, path::Path, sync::Arc};
@@ -179,9 +179,6 @@ export.get_count
179179
180180
exec.account::get_item
181181
# => [count]
182-
183-
exec.sys::truncate_stack
184-
# => []
185182
end
186183
187184
# => []
@@ -237,7 +234,7 @@ end
237234

238235
To build the counter contract copy and paste the following code at the end of your `src/main.rs` file:
239236

240-
```rust,no_run
237+
```rust
241238
# use miden_lib::account::auth::NoAuth;
242239
# use rand::RngCore;
243240
# use std::{fs, path::Path, sync::Arc};
@@ -332,13 +329,17 @@ let (counter_contract, counter_seed) = AccountBuilder::new(seed)
332329
.build()
333330
.unwrap();
334331

332+
println!(
333+
"counter_contract commitment: {:?}",
334+
counter_contract.commitment()
335+
);
335336
println!(
336337
"counter_contract id: {:?}",
337338
Address::from(AccountIdAddress::new(
338339
counter_contract.id(),
339340
AddressInterface::Unspecified
340341
))
341-
.to_bech32(NetworkId::Devnet)
342+
.to_bech32(NetworkId::Testnet)
342343
);
343344
println!("counter_contract storage: {:?}", counter_contract.storage());
344345

@@ -372,7 +373,7 @@ Now that we built the counter contract, lets create a transaction request to inc
372373

373374
Paste the following code at the end of your `src/main.rs` file:
374375

375-
```rust,no_run
376+
```rust
376377
# use miden_lib::account::auth::NoAuth;
377378
# use rand::RngCore;
378379
# use std::{fs, path::Path, sync::Arc};
@@ -477,7 +478,7 @@ Paste the following code at the end of your `src/main.rs` file:
477478
# counter_contract.id(),
478479
# AddressInterface::Unspecified
479480
# ))
480-
# .to_bech32(NetworkId::Devnet)
481+
# .to_bech32(NetworkId::Testnet)
481482
# );
482483
# println!("counter_contract storage: {:?}", counter_contract.storage());
483484
#
@@ -501,16 +502,13 @@ let account_component_lib = create_library(
501502
&counter_code,
502503
)
503504
.unwrap();
504-
println!("here");
505505

506506
let tx_script = ScriptBuilder::new(true)
507507
.with_dynamically_linked_library(&account_component_lib)
508508
.unwrap()
509509
.compile_tx_script(script_code)
510510
.unwrap();
511511

512-
println!("here");
513-
514512
// Build a transaction request with the custom script
515513
let tx_increment_request = TransactionRequestBuilder::new()
516514
.custom_script(tx_script)
@@ -656,7 +654,7 @@ async fn main() -> Result<(), ClientError> {
656654
counter_contract.id(),
657655
AddressInterface::Unspecified
658656
))
659-
.to_bech32(NetworkId::Devnet)
657+
.to_bech32(NetworkId::Testnet)
660658
);
661659
println!("counter_contract storage: {:?}", counter_contract.storage());
662660

@@ -681,16 +679,13 @@ async fn main() -> Result<(), ClientError> {
681679
&counter_code,
682680
)
683681
.unwrap();
684-
println!("here");
685682

686683
let tx_script = ScriptBuilder::new(true)
687684
.with_dynamically_linked_library(&account_component_lib)
688685
.unwrap()
689686
.compile_tx_script(script_code)
690687
.unwrap();
691688

692-
println!("here");
693-
694689
// Build a transaction request with the custom script
695690
let tx_increment_request = TransactionRequestBuilder::new()
696691
.custom_script(tx_script)
@@ -728,15 +723,16 @@ async fn main() -> Result<(), ClientError> {
728723
The output of our program will look something like this:
729724

730725
```text
731-
Latest block: 226717
726+
Latest block: 374255
732727
733728
[STEP 1] Creating counter contract.
734-
counter_contract commitment: RpoDigest([10854804595308759734, 11034759279878416408, 15662010127375823242, 9560626040625797366])
735-
counter_contract id: "mtst1qpj0g3ke67tg5qqqqd2z4ffm9g8ezpf6"
736-
counter_contract storage: AccountStorage { slots: [Value([0, 0, 0, 0])] }
729+
one or more warnings were emitted
730+
counter_contract commitment: Word([3964727668949550262, 4265714847747507878, 5784293172192015964, 16803438753763367241])
731+
counter_contract id: "mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a"
732+
counter_contract storage: AccountStorage { slots: [Value(Word([0, 0, 0, 0]))] }
737733
738734
[STEP 2] Call Counter Contract With Script
739-
Stack state before step 2502:
735+
Stack state before step 2610:
740736
├── 0: 1
741737
├── 1: 0
742738
├── 2: 0
@@ -758,8 +754,10 @@ Stack state before step 2502:
758754
├── 18: 0
759755
└── 19: 0
760756
761-
View transaction on MidenScan: https://testnet.midenscan.com/tx/0x645b89ebf39c7baa2a4264854f793736b7370d65ecf5f1a23c0169fda6a6a395
762-
counter contract storage: Ok(RpoDigest([0, 0, 0, 1]))
757+
└── (0 more items)
758+
759+
View transaction on MidenScan: https://testnet.midenscan.com/tx/0x9767940bbed7bd3a74c24dc43f1ea8fe90a876dc7925621c217f648c63c4ab7a
760+
counter contract storage: Ok(Word([0, 0, 0, 1]))
763761
```
764762

765763
The line in the output `Stack state before step 2505` ouputs the stack state when we call "debug.stack" in the `counter.masm` file.

docs/src/rust-client/create_deploy_tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ async fn main() -> Result<(), ClientError> {
9898
let endpoint = Endpoint::testnet();
9999
let timeout_ms = 10_000;
100100
let rpc_api = Arc::new(TonicRpcClient::new(&endpoint, timeout_ms));
101-
let keystore = FilesystemKeyStore::new("./keystore".into()).unwrap().into();
101+
let keystore: FilesystemKeyStore<rand::prelude::StdRng> = FilesystemKeyStore::new("./keystore".into()).unwrap().into();
102102
103103
let mut client = ClientBuilder::new()
104104
.rpc(rpc_api)
105-
.authenticator(keystore)
105+
.authenticator(keystore.clone().into())
106106
.in_debug_mode(true.into())
107107
.build()
108108
.await?;

docs/src/rust-client/foreign_procedure_invocation_tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FPI is useful for developing smart contracts that extend the functionality of ex
1616

1717
## What We Will Build
1818

19-
![count copy FPI diagram](../assets/count_copy_fpi_diagram.png)
19+
![count copy FPI diagram](./assets/count_copy_fpi_diagram.png)
2020

2121
The diagram above depicts the "count copy" smart contract using foreign procedure invocation to read the count state of the counter contract. After reading the state via FPI, the "count copy" smart contract writes the value returned from the counter contract to storage.
2222

@@ -364,7 +364,7 @@ println!("\n[STEP 2] Building counter contract from public state");
364364

365365
// Define the Counter Contract account id from counter contract deploy
366366
let (_, counter_contract_address) =
367-
Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
367+
Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
368368
let counter_contract_id = match counter_contract_address {
369369
Address::AccountId(account_id_address) => account_id_address.id(),
370370
_ => panic!("Expected AccountId address"),
@@ -520,7 +520,7 @@ Add this snippet to the end of your file in the `main()` function:
520520
#
521521
# // Define the Counter Contract account id from counter contract deploy
522522
# let (_, counter_contract_address) =
523-
# Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
523+
# Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
524524
# let counter_contract_id = match counter_contract_address {
525525
# Address::AccountId(account_id_address) => account_id_address.id(),
526526
# _ => panic!("Expected AccountId address"),
@@ -786,7 +786,7 @@ async fn main() -> Result<(), ClientError> {
786786

787787
// Define the Counter Contract account id from counter contract deploy
788788
let (_, counter_contract_address) =
789-
Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
789+
Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
790790
let counter_contract_id = match counter_contract_address {
791791
Address::AccountId(account_id_address) => account_id_address.id(),
792792
_ => panic!("Expected AccountId address"),
@@ -1006,4 +1006,4 @@ cargo run --release --bin counter_contract_fpi
10061006

10071007
### Continue learning
10081008

1009-
Next tutorial: [How to Create Notes with Custom Logic](custom_note_how_to.md)
1009+
Next tutorial: [How to Use Unauthenticated Notes](unauthenticated_note_how_to.md)

docs/src/rust-client/network_transactions_tutorial.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ export.get_count
8484
8585
exec.account::get_item
8686
# => [count]
87-
88-
exec.sys::truncate_stack
89-
# => []
9087
end
9188
9289
# => []
@@ -928,9 +925,9 @@ Add this code to your `main()` function:
928925
# // STEP 3: Deploy Network Account with Transaction Script
929926
# // -------------------------------------------------------------------------
930927
# println!("\n[STEP 3] Deploy network counter smart contract");
931-
#
928+
932929
# let script_code = fs::read_to_string(Path::new("./masm/scripts/counter_script.masm")).unwrap();
933-
#
930+
934931
# let account_code = fs::read_to_string(Path::new("./masm/accounts/counter.masm")).unwrap();
935932
# let library_path = "external_contract::counter_contract";
936933
#
@@ -969,7 +966,7 @@ println!("\n[STEP 4] Creating a network note for network counter contract");
969966
let network_note_code =
970967
fs::read_to_string(Path::new("./masm/notes/network_increment_note.masm")).unwrap();
971968
let account_code =
972-
fs::read_to_string(Path::new("./masm/accounts/network_counter.masm")).unwrap();
969+
fs::read_to_string(Path::new("./masm/accounts/counter.masm")).unwrap();
973970
974971
let library_path = "external_contract::counter_contract";
975972
let library = create_library(account_code, library_path).unwrap();
@@ -1281,7 +1278,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
12811278
let network_note_code =
12821279
fs::read_to_string(Path::new("./masm/notes/network_increment_note.masm")).unwrap();
12831280
let account_code =
1284-
fs::read_to_string(Path::new("./masm/accounts/network_counter.masm")).unwrap();
1281+
fs::read_to_string(Path::new("./masm/accounts/counter.masm")).unwrap();
12851282

12861283
let library_path = "external_contract::counter_contract";
12871284
let library = create_library(account_code, library_path).unwrap();

docs/src/rust-client/public_account_interaction_tutorial.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,39 +70,38 @@ Inside of the `masm/accounts/` directory, create the `counter.masm` file:
7070
use.miden::account
7171
use.std::sys
7272
73+
const.COUNTER_SLOT=0
74+
# => []
7375
export.get_count
74-
# => []
75-
push.0
76-
76+
push.COUNTER_SLOT
7777
# => [index]
78-
exec.account::get_item
7978
79+
exec.account::get_item
8080
# => [count]
81-
exec.sys::truncate_stack
8281
end
8382
8483
# => []
8584
export.increment_count
86-
# => []
87-
push.0
88-
85+
push.COUNTER_SLOT
8986
# => [index]
90-
exec.account::get_item
9187
88+
exec.account::get_item
9289
# => [count]
90+
9391
push.1 add
92+
# => [count+1]
9493
9594
# debug statement with client
9695
debug.stack
9796
98-
# => [count+1]
99-
push.0
100-
97+
push.COUNTER_SLOT
10198
# [index, count+1]
102-
exec.account::set_item
10399
100+
exec.account::set_item
104101
# => []
102+
105103
exec.sys::truncate_stack
104+
# => []
106105
end
107106
```
108107

@@ -245,7 +244,7 @@ println!("\n[STEP 1] Reading data from public state");
245244
246245
// Define the Counter Contract account id from counter contract deploy
247246
let (_network_id, address) =
248-
Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
247+
Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
249248
let counter_contract_id = match address {
250249
Address::AccountId(account_id_address) => account_id_address.id(),
251250
_ => panic!("Expected AccountId address"),
@@ -347,7 +346,7 @@ Add the following code snippet to the end of your `src/main.rs` function:
347346
348347
# // Define the Counter Contract account id from counter contract deploy
349348
# let (_network_id, address) =
350-
# Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
349+
# Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
351350
# let counter_contract_id = match address {
352351
# Address::AccountId(account_id_address) => account_id_address.id(),
353352
# _ => panic!("Expected AccountId address"),
@@ -376,6 +375,7 @@ Add the following code snippet to the end of your `src/main.rs` function:
376375
// -------------------------------------------------------------------------
377376
// STEP 2: Call the Counter Contract with a script
378377
// -------------------------------------------------------------------------
378+
println!("\n[STEP 2] Call the increment_count procedure in the counter contract");
379379
380380
// Load the MASM script referencing the increment procedure
381381
let script_path = Path::new("./masm/scripts/counter_script.masm");
@@ -492,7 +492,7 @@ async fn main() -> Result<(), ClientError> {
492492

493493
// Define the Counter Contract account id from counter contract deploy
494494
let (_network_id, address) =
495-
Address::from_bech32("mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy").unwrap();
495+
Address::from_bech32("mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a").unwrap();
496496
let counter_contract_id = match address {
497497
Address::AccountId(account_id_address) => account_id_address.id(),
498498
_ => panic!("Expected AccountId address"),
@@ -637,4 +637,4 @@ cargo run --release --bin counter_contract_increment
637637

638638
### Continue learning
639639

640-
Next tutorial: [Foreign Procedure Invocation](foreign_procedure_invocation_tutorial.md)
640+
Next tutorial: [Network Transactions on Miden](network_transactions_tutorial.md)

docs/src/web-client/counter_contract_tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export async function incrementCounterContract(): Promise<void> {
174174

175175
// Counter contract account id on testnet
176176
const counterContractId = AccountId.fromBech32(
177-
"mtst1qrhk9zc2au2vxqzaynaz5ddhs4cqqghmajy",
177+
"mtst1qre73e6qcrfevqqngx8wewvveacqqjh8p2a",
178178
);
179179

180180
// Reading the public state of the counter contract from testnet,

masm/accounts/counter.masm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ use.std::sys
33

44
const.COUNTER_SLOT=0
55

6-
# => []
6+
#! Inputs: []
7+
#! Outputs: [count]
78
export.get_count
89
push.COUNTER_SLOT
910
# => [index]
1011

1112
exec.account::get_item
1213
# => [count]
1314

14-
exec.sys::truncate_stack
15-
# => []
15+
# clean up stack
16+
movdn.4 dropw
17+
# => [count]
1618
end
1719

18-
# => []
20+
#! Inputs: []
21+
#! Outputs: []
1922
export.increment_count
2023
push.COUNTER_SLOT
2124
# => [index]
@@ -32,8 +35,8 @@ export.increment_count
3235
# [index, count+1]
3336

3437
exec.account::set_item
35-
# => []
38+
# => [OLD_VALUE]
3639

37-
exec.sys::truncate_stack
40+
dropw
3841
# => []
3942
end

0 commit comments

Comments
 (0)