Skip to content

Commit 4940486

Browse files
authored
fix(rust-client): use delegated (remote) proving in the delegated proving tutorial (#207)
1 parent 09d071d commit 4940486

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

docs/src/rust-client/delegated_proving_tutorial.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ The only downside of using delegated proving is that it reduces the privacy of t
3232

3333
Anyone can run their own delegated prover server. If you are building a product on Miden, it may make sense to run your own delegated prover server for your users. To run your own delegated proving server, follow the instructions here: https://crates.io/crates/miden-remote-prover.
3434

35-
To keep this tutorial runnable without external services, the code below uses a local prover. The
36-
flow is the same if you swap in `RemoteTransactionProver` and point it at your delegated prover.
35+
This tutorial performs real delegated proving against the public Miden testnet prover at
36+
`https://tx-prover.testnet.miden.io` using `RemoteTransactionProver`. To use your own delegated
37+
prover instead, point `RemoteTransactionProver` at its URL.
3738

3839
## Step 1: Initialize your repository
3940

@@ -58,7 +59,7 @@ tokio = { version = "1.46", features = ["rt-multi-thread", "net", "macros", "fs"
5859
## Step 2: Initialize the client and prover and construct transactions
5960

6061
Similarly to previous tutorials, we must instantiate the client.
61-
We construct a `LocalTransactionProver` for this walkthrough.
62+
We construct a `RemoteTransactionProver` pointed at the public Miden testnet delegated prover for this walkthrough.
6263

6364
```rust no_run
6465
use miden_client::auth::AuthSecretKey;
@@ -71,13 +72,8 @@ use miden_client::{
7172
builder::ClientBuilder,
7273
keystore::{FilesystemKeyStore, Keystore},
7374
rpc::{Endpoint, GrpcClient},
74-
transaction::{
75-
LocalTransactionProver,
76-
ProvingOptions,
77-
TransactionProver,
78-
TransactionRequestBuilder,
79-
},
80-
ClientError,
75+
transaction::{TransactionProver, TransactionRequestBuilder},
76+
ClientError, RemoteTransactionProver,
8177
};
8278
use miden_client_sqlite_store::ClientBuilderSqliteExt;
8379
use miden_client::account::{AccountBuilder, AccountType};
@@ -123,10 +119,15 @@ async fn main() -> Result<(), ClientError> {
123119
keystore.add_key(&key_pair, alice_account.id()).await.unwrap();
124120

125121
// -------------------------------------------------------------------------
126-
// Setup the local tx prover
122+
// Set up the delegated (remote) tx prover
127123
// -------------------------------------------------------------------------
128-
let local_tx_prover = LocalTransactionProver::new(ProvingOptions::default());
129-
let tx_prover: Arc<dyn TransactionProver> = Arc::new(local_tx_prover);
124+
// Delegated proving outsources ZK proof generation to a remote service. This is
125+
// the public Miden testnet prover; run your own
126+
// (https://crates.io/crates/miden-remote-prover) and swap the URL to use it.
127+
// The constant `miden_client::grpc_support::TESTNET_PROVER_ENDPOINT` holds this
128+
// same URL.
129+
let remote_tx_prover = RemoteTransactionProver::new("https://tx-prover.testnet.miden.io");
130+
let tx_prover: Arc<dyn TransactionProver> = Arc::new(remote_tx_prover);
130131

131132
// We use a dummy transaction request to showcase delegated proving.
132133
// The only effect of this tx should be increasing Alice's nonce.
@@ -148,8 +149,8 @@ async fn main() -> Result<(), ClientError> {
148149
.execute_transaction(alice_account.id(), transaction_request)
149150
.await?;
150151

151-
// Step 2: Prove the transaction using the local prover
152-
println!("Proving transaction with local prover...");
152+
// Step 2: Prove the transaction using the delegated (remote) prover
153+
println!("Proving transaction with the delegated prover...");
153154
let proven_transaction = client.prove_transaction_with(&tx_result, tx_prover).await?;
154155

155156
// Step 3: Submit the proven transaction
@@ -163,7 +164,7 @@ async fn main() -> Result<(), ClientError> {
163164
.apply_transaction(&tx_result, submission_height)
164165
.await?;
165166

166-
println!("Transaction submitted successfully using local prover!");
167+
println!("Transaction submitted successfully using the delegated prover!");
167168

168169
client.sync_state().await.unwrap();
169170

@@ -188,9 +189,13 @@ cargo run --release
188189
The output will look like this:
189190

190191
```text
191-
Latest block: 226954
192-
Alice initial account balance: Ok(1000)
193-
Alice final account balance: Ok(900)
192+
Latest block: 488706
193+
Alice nonce initial: 0
194+
Executing transaction...
195+
Proving transaction with the delegated prover...
196+
Submitting proven transaction...
197+
Transaction submitted successfully using the delegated prover!
198+
Alice nonce has increased: 1
194199
```
195200

196201
### Running the example

rust-client/src/bin/delegated_prover.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ use miden_client::{
77
builder::ClientBuilder,
88
keystore::{FilesystemKeyStore, Keystore},
99
rpc::{Endpoint, GrpcClient},
10-
transaction::{
11-
LocalTransactionProver, ProvingOptions, TransactionProver, TransactionRequestBuilder,
12-
},
13-
ClientError,
10+
transaction::{TransactionProver, TransactionRequestBuilder},
11+
ClientError, RemoteTransactionProver,
1412
};
1513
use miden_client_sqlite_store::ClientBuilderSqliteExt;
1614

@@ -55,10 +53,15 @@ async fn main() -> Result<(), ClientError> {
5553
keystore.add_key(&key_pair, alice_account.id()).await.unwrap();
5654

5755
// -------------------------------------------------------------------------
58-
// Setup the local tx prover
56+
// Set up the delegated (remote) tx prover
5957
// -------------------------------------------------------------------------
60-
let local_tx_prover = LocalTransactionProver::new(ProvingOptions::default());
61-
let tx_prover: Arc<dyn TransactionProver> = Arc::new(local_tx_prover);
58+
// Delegated proving outsources ZK proof generation to a remote service. This is
59+
// the public Miden testnet prover; run your own
60+
// (https://crates.io/crates/miden-remote-prover) and swap the URL to use it.
61+
// The constant `miden_client::grpc_support::TESTNET_PROVER_ENDPOINT` holds this
62+
// same URL.
63+
let remote_tx_prover = RemoteTransactionProver::new("https://tx-prover.testnet.miden.io");
64+
let tx_prover: Arc<dyn TransactionProver> = Arc::new(remote_tx_prover);
6265

6366
// We use a dummy transaction request to showcase delegated proving.
6467
// The only effect of this tx should be increasing Alice's nonce.
@@ -80,8 +83,8 @@ async fn main() -> Result<(), ClientError> {
8083
.execute_transaction(alice_account.id(), transaction_request)
8184
.await?;
8285

83-
// Step 2: Prove the transaction using the local prover
84-
println!("Proving transaction with local prover...");
86+
// Step 2: Prove the transaction using the delegated (remote) prover
87+
println!("Proving transaction with the delegated prover...");
8588
let proven_transaction = client.prove_transaction_with(&tx_result, tx_prover).await?;
8689

8790
// Step 3: Submit the proven transaction
@@ -95,7 +98,7 @@ async fn main() -> Result<(), ClientError> {
9598
.apply_transaction(&tx_result, submission_height)
9699
.await?;
97100

98-
println!("Transaction submitted successfully using local prover!");
101+
println!("Transaction submitted successfully using the delegated prover!");
99102

100103
client.sync_state().await.unwrap();
101104

0 commit comments

Comments
 (0)