Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
1,051 changes: 876 additions & 175 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ miden-tx = { default-features = false, version = "=0.14.0-alpha.1" }
miden-node-block-producer = { version = "=0.14.0-alpha.4" }
miden-node-ntx-builder = { version = "=0.14.0-alpha.4" }
miden-node-proto = { version = "=0.14.0-alpha.4" }
miden-node-proto-build = { default-features = false, version = "=0.14.0-alpha.4" }
miden-node-proto-build = { default-features = false, path = "../node/proto", version = "=0.14.0-alpha.1" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to be fixed.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, sure. I should have marked this as a draft.

miden-node-rpc = { version = "=0.14.0-alpha.4" }
miden-node-store = { version = "=0.14.0-alpha.4" }
miden-node-utils = { version = "=0.14.0-alpha.4" }
miden-node-validator = { version = "=0.14.0-alpha.4" }
miden-note-transport-proto-build = { default-features = false, version = "0.2" }
miden-remote-prover-client = { default-features = false, features = ["tx-prover"], version = "=0.14.0-alpha.4" }

# Miden debug dependency
miden-debug = { default-features = false, features = ["dap", "std"], path = "../miden-debug" }

# External dependencies
anyhow = { default-features = false, version = "1.0" }
async-trait = { version = "0.1" }
Expand All @@ -76,3 +79,9 @@ module_name_repetitions = "allow" # Many triggers, and is a stylistic choice
must_use_candidate = "allow" # This marks many fn's which isn't helpful.
should_panic_without_expect = "allow" # We don't care about the specific panic message.
# End of pedantic lints.

[patch.crates-io]
miden-protocol = { path = "../protocol/crates/miden-protocol" }
miden-standards = { path = "../protocol/crates/miden-standards" }
miden-testing = { path = "../protocol/crates/miden-testing" }
miden-tx = { path = "../protocol/crates/miden-tx" }
Comment on lines +83 to +87
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be removed

4 changes: 4 additions & 0 deletions bin/miden-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ version.workspace = true
name = "miden-client"
path = "src/main.rs"

[features]
dap = ["miden-client/dap", "dep:miden-debug"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we gate behind a feature? Or have connection depend on an Optional argument?


[dependencies]
# Workspace dependencies
miden-client = { features = ["tonic"], workspace = true }
miden-client-sqlite-store = { workspace = true }
miden-debug = { optional = true, workspace = true }

# External dependencies
clap = { features = ["derive"], version = "4.5" }
Expand Down
9 changes: 6 additions & 3 deletions bin/miden-cli/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async fn list_accounts<AUTH>(client: Client<AUTH>) -> Result<(), CliError> {
acc.id().to_hex(),
account_type_display_name(&acc.id())?,
acc.id().storage_mode().to_string(),
acc.nonce().as_int().to_string(),
acc.nonce().as_canonical_u64().to_string(),
status,
]);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ pub async fn show_account<AUTH>(
// TODO: Display non-fungible assets more clearly.
(
"Non Fungible Asset",
non_fungible_asset.faucet_id_prefix().to_hex(),
non_fungible_asset.faucet_id().to_hex(),
1.0.to_string(),
)
},
Expand Down Expand Up @@ -263,7 +263,10 @@ async fn print_summary_table<AUTH>(
Cell::new("Storage Root"),
Cell::new(account.storage().to_commitment().to_string()),
]);
table.add_row(vec![Cell::new("Nonce"), Cell::new(account.nonce().as_int().to_string())]);
table.add_row(vec![
Cell::new("Nonce"),
Cell::new(account.nonce().as_canonical_u64().to_string()),
]);

println!("{table}\n");
Ok(())
Expand Down
21 changes: 21 additions & 0 deletions bin/miden-cli/src/commands/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub struct ExecCmd {
/// Print the output stack grouped into words
#[arg(long, default_value_t = false)]
hex_words: bool,

/// Start a DAP debug adapter server on the given address (e.g. "127.0.0.1:4711")
/// and wait for a DAP client to connect before executing.
#[cfg(feature = "dap")]
#[arg(long = "start-debug-adapter")]
start_debug_adapter: Option<String>,
}

impl ExecCmd {
Expand Down Expand Up @@ -87,6 +93,21 @@ impl ExecCmd {

let tx_script = client.code_builder().compile_tx_script(&program)?;

#[cfg(feature = "dap")]
let result = if let Some(ref addr) = self.start_debug_adapter {
miden_debug::DapConfig::set_global(miden_debug::DapConfig {
listen_addr: addr.clone(),
});
client
.execute_program_with_dap(account_id, tx_script, advice_inputs, BTreeSet::new())
.await
} else {
client
.execute_program(account_id, tx_script, advice_inputs, BTreeSet::new())
.await
};

#[cfg(not(feature = "dap"))]
let result = client
.execute_program(account_id, tx_script, advice_inputs, BTreeSet::new())
.await;
Comment on lines +105 to 113
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is duplicated code. Maybe the best approach is not to split between feature = "dap" or not.

Expand Down
24 changes: 22 additions & 2 deletions bin/miden-cli/src/commands/new_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub struct NewWalletCmd {
/// authentication transaction.
#[arg(long, default_value_t = false)]
pub deploy: bool,
/// Seed local-only state so the wallet can be created and used for execution without a node.
#[arg(long, default_value_t = false)]
pub offline: bool,
}

impl NewWalletCmd {
Expand Down Expand Up @@ -124,6 +127,7 @@ impl NewWalletCmd {
&package_paths,
self.init_storage_data_path.clone(),
self.deploy,
self.offline,
)
.await?;

Expand Down Expand Up @@ -191,6 +195,9 @@ pub struct NewAccountCmd {
/// authentication transaction.
#[arg(long, default_value_t = false)]
pub deploy: bool,
/// Seed local-only state so the account can be created and used for execution without a node.
#[arg(long, default_value_t = false)]
pub offline: bool,
}

impl NewAccountCmd {
Expand All @@ -207,6 +214,7 @@ impl NewAccountCmd {
&self.packages,
self.init_storage_data_path.clone(),
self.deploy,
self.offline,
)
.await?;

Expand Down Expand Up @@ -354,6 +362,7 @@ async fn create_client_account<AUTH: Keystore + Sync + 'static>(
package_paths: &[PathBuf],
init_storage_data_path: Option<PathBuf>,
deploy: bool,
offline: bool,
) -> Result<Account, CliError> {
if package_paths.is_empty() {
return Err(CliError::InvalidArgument(format!(
Expand All @@ -362,6 +371,12 @@ async fn create_client_account<AUTH: Keystore + Sync + 'static>(
", client_binary_name().display())));
}

if deploy && offline {
return Err(CliError::InvalidArgument(
"`--offline` cannot be combined with `--deploy`".to_string(),
));
}

// Load the component templates and initialization storage data.

let cli_config = CliConfig::load()?;
Expand Down Expand Up @@ -390,10 +405,10 @@ async fn create_client_account<AUTH: Keystore + Sync + 'static>(
None
} else {
debug!("Adding default Falcon auth component");
let kp = AuthSecretKey::new_falcon512_rpo_with_rng(client.rng());
let kp = AuthSecretKey::new_falcon512_poseidon2_with_rng(client.rng());
builder = builder.with_auth_component(AuthSingleSig::new(
kp.public_key().to_commitment(),
AuthSchemeId::Falcon512Rpo,
AuthSchemeId::Falcon512Poseidon2,
));
Some(kp)
};
Expand All @@ -416,6 +431,11 @@ async fn create_client_account<AUTH: Keystore + Sync + 'static>(
println!("Using custom authentication component from package (no key generated).");
}

if offline {
client.prepare_offline_bootstrap().await?;
println!("Offline mode seeded default RPC limits and a synthetic genesis header.");
}

client.add_account(&account, false).await?;

if deploy {
Expand Down
4 changes: 2 additions & 2 deletions bin/miden-cli/src/commands/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ fn print_transaction_details(executed_tx: &ExecutedTransaction) -> Result<(), Cl
NonFungibleDeltaAction::Add => {
table.add_row(vec![
"Non Fungible Asset",
&asset.faucet_id_prefix().to_hex(),
&asset.faucet_id().to_hex(),
"1",
]);
},
NonFungibleDeltaAction::Remove => {
table.add_row(vec![
"Non Fungible Asset",
&asset.faucet_id_prefix().to_hex(),
&asset.faucet_id().to_hex(),
"-1",
]);
},
Expand Down
2 changes: 1 addition & 1 deletion bin/miden-cli/src/commands/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async fn show_note<AUTH: Keystore + Sync>(
},
Asset::NonFungible(non_fungible_asset) => (
"Non Fungible Asset",
non_fungible_asset.faucet_id_prefix().to_hex(),
non_fungible_asset.faucet_id().to_hex(),
1.0.to_string(),
),
};
Expand Down
3 changes: 2 additions & 1 deletion crates/rust-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ std = [
"tonic/transport",
]
testing = ["dep:miden-testing", "dep:uuid", "miden-protocol/testing", "miden-standards/testing", "miden-tx/testing"]
dap = ["dep:miden-debug"]
tonic = []

[dependencies]
# Miden dependencies
miden-mast-package = { default-features = false, version = "0.20" }
miden-debug = { optional = true, workspace = true }
miden-protocol = { workspace = true }
miden-remote-prover-client = { default-features = false, features = ["tx-prover"], workspace = true }
miden-standards = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/account/account_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl AccountReader {
/// To load the entire vault, use
/// [`Client::get_account_vault`](crate::Client::get_account_vault).
pub async fn get_balance(&self, faucet_id: AccountId) -> Result<u64, ClientError> {
if let Some(vault_key) = AssetVaultKey::from_account_id(faucet_id)
if let Some(vault_key) = AssetVaultKey::new_fungible(faucet_id)
&& let Some((Asset::Fungible(fungible_asset), _)) =
self.store.get_account_asset(self.account_id, vault_key).await?
{
Expand Down
9 changes: 6 additions & 3 deletions crates/rust-client/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ impl<AUTH> Client<AUTH> {
return Err(ClientError::AccountAlreadyTracked(account.id()));
}

if tracked_account.nonce().as_int() > account.nonce().as_int() {
if tracked_account.nonce().as_canonical_u64()
> account.nonce().as_canonical_u64()
{
// If the new account is older than the one being tracked, return an error
return Err(ClientError::AccountNonceTooLow);
}
Expand Down Expand Up @@ -422,9 +424,10 @@ pub fn build_wallet_id(

let auth_scheme = public_key.auth_scheme();
let auth_component = match auth_scheme {
AuthSchemeId::Falcon512Rpo => {
AuthSchemeId::Falcon512Poseidon2 => {
let auth_component: AccountComponent =
AuthSingleSig::new(public_key.to_commitment(), AuthSchemeId::Falcon512Rpo).into();
AuthSingleSig::new(public_key.to_commitment(), AuthSchemeId::Falcon512Poseidon2)
.into();
auth_component
},
AuthSchemeId::EcdsaK256Keccak => {
Expand Down
1 change: 1 addition & 0 deletions crates/rust-client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ where
exec_options: ExecutionOptions::new(
Some(MAX_TX_EXECUTION_CYCLES),
MIN_TX_EXECUTION_CYCLES,
ExecutionOptions::DEFAULT_CORE_TRACE_FRAGMENT_SIZE,
false,
self.in_debug_mode.into(),
)
Expand Down
17 changes: 10 additions & 7 deletions crates/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod test_utils;

pub mod errors;

pub use miden_protocol::utils::{Deserializable, Serializable, SliceReader};
pub use miden_protocol::utils::serde::{Deserializable, Serializable, SliceReader};

// RE-EXPORTS
// ================================================================================================
Expand Down Expand Up @@ -212,7 +212,7 @@ pub mod auth {

pub use crate::account::component::AuthScheme;

pub const RPO_FALCON_SCHEME_ID: AuthSchemeId = AuthSchemeId::Falcon512Rpo;
pub const RPO_FALCON_SCHEME_ID: AuthSchemeId = AuthSchemeId::Falcon512Poseidon2;
pub const ECDSA_K256_KECCAK_SCHEME_ID: AuthSchemeId = AuthSchemeId::EcdsaK256Keccak;
}

Expand All @@ -226,9 +226,13 @@ pub mod block {
/// the `miden_standards` crate.
pub mod crypto {
pub mod rpo_falcon512 {
pub use miden_protocol::crypto::dsa::falcon512_rpo::{PublicKey, SecretKey, Signature};
pub use miden_protocol::crypto::dsa::falcon512_poseidon2::{
PublicKey,
SecretKey,
Signature,
};
}
pub use miden_protocol::crypto::hash::blake::{Blake3_160, Blake3Digest};
pub use miden_protocol::crypto::hash::blake::{Blake3_192, Blake3Digest};
pub use miden_protocol::crypto::hash::rpo::Rpo256;
pub use miden_protocol::crypto::merkle::mmr::{
Forest,
Expand Down Expand Up @@ -272,17 +276,17 @@ pub mod address {

/// Provides types for working with the virtual machine within the Miden network.
pub mod vm {
// TODO: Remove this re-export once miden-protocol exposes PackageKind/ProcedureExport.
pub use miden_mast_package::{PackageKind, ProcedureExport};
pub use miden_protocol::vm::{
AdviceInputs,
AdviceMap,
AttributeSet,
MastArtifact,
Package,
PackageExport,
PackageKind,
PackageManifest,
Program,
ProcedureExport,
QualifiedProcedureName,
Section,
SectionId,
Expand All @@ -299,7 +303,6 @@ pub use miden_protocol::{
MIN_TX_EXECUTION_CYCLES,
ONE,
PrettyPrint,
StarkField,
Word,
ZERO,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/note_transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::boxed::Box;
use alloc::string::String;
use core::error::Error;

use miden_protocol::utils::DeserializationError;
use miden_protocol::utils::serde::DeserializationError;
use thiserror::Error;

#[derive(Debug, Error)]
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/note_transport/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::task::{Context, Poll};

use futures::Stream;
use miden_protocol::note::{NoteHeader, NoteTag};
use miden_protocol::utils::{Deserializable, Serializable};
use miden_protocol::utils::serde::{Deserializable, Serializable};
use miden_tx::utils::sync::RwLock;
use tonic::{Request, Streaming};
use tonic_health::pb::HealthCheckRequest;
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-client/src/note_transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use alloc::vec::Vec;
use futures::Stream;
use miden_protocol::address::Address;
use miden_protocol::note::{Note, NoteDetails, NoteFile, NoteHeader, NoteTag};
use miden_protocol::utils::Serializable;
use miden_protocol::utils::serde::Serializable;
use miden_tx::auth::TransactionAuthenticator;
use miden_tx::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, SliceReader};
use miden_tx::utils::serde::{ByteReader, ByteWriter, Deserializable, DeserializationError, SliceReader};

pub use self::errors::NoteTransportError;
use crate::{Client, ClientError};
Expand Down
14 changes: 3 additions & 11 deletions crates/rust-client/src/rpc/domain/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,7 @@ impl TryFrom<proto::rpc::AccountVaultDetails> for AccountVaultDetails {
let assets = value
.assets
.into_iter()
.map(|asset| {
let native_digest: Word = asset
.asset
.ok_or(proto::rpc::AccountVaultDetails::missing_field(stringify!(assets)))?
.try_into()?;
native_digest
.try_into()
.map_err(|_| RpcError::DeserializationError("asset".to_string()))
})
.map(TryInto::try_into)
.collect::<Result<Vec<Asset>, RpcError>>()?;

Ok(Self { too_many_assets, assets })
Expand Down Expand Up @@ -686,13 +678,13 @@ impl From<AccountStorageRequirements> for Vec<account_detail_request::StorageMap
}

impl Serializable for AccountStorageRequirements {
fn write_into<W: miden_tx::utils::ByteWriter>(&self, target: &mut W) {
fn write_into<W: miden_tx::utils::serde::ByteWriter>(&self, target: &mut W) {
target.write(&self.0);
}
}

impl Deserializable for AccountStorageRequirements {
fn read_from<R: miden_tx::utils::ByteReader>(
fn read_from<R: miden_tx::utils::serde::ByteReader>(
source: &mut R,
) -> Result<Self, miden_tx::utils::DeserializationError> {
Ok(AccountStorageRequirements(source.read()?))
Expand Down
Loading
Loading