Skip to content
Merged
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
25 changes: 10 additions & 15 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ repository = "https://github.com/0xPolygonMiden/miden-client"

[workspace.dependencies]
async-trait = "0.1"
miden-lib = { version = "0.8", default-features = false }
miden-objects = { version = "0.8", default-features = false }
miden-tx = { version = "0.8", default-features = false, features = ["async"] }
miden-proving-service-client = { version = "0.8", default-features = false, features = ["tx-prover"] }
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false }
miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["async"] }
miden-proving-service-client = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["tx-prover"] }
miette = { version = "7.2", features = ["fancy"] }
rand = { version = "0.9" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ WARNINGS=RUSTDOCFLAGS="-D warnings"

NODE_DIR="miden-node"
NODE_REPO="https://github.com/0xPolygonMiden/miden-node.git"
NODE_BRANCH="main"
NODE_BRANCH="next"

PROVER_DIR="miden-base"
PROVER_REPO="https://github.com/0xPolygonMiden/miden-base.git"
PROVER_BRANCH="main"
PROVER_BRANCH="next"
PROVER_FEATURES_TESTING=--features "testing"
PROVER_PORT=50051

Expand Down
2 changes: 1 addition & 1 deletion bin/miden-cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn test_mint_with_untracked_account() {
// ================================================================================================

// Only one faucet is being created on the genesis block
const GENESIS_ACCOUNTS_FILENAMES: [&str; 1] = ["account_0.mac"];
const GENESIS_ACCOUNTS_FILENAMES: [&str; 1] = ["account.mac"];

// This tests that it's possible to import the genesis accounts and interact with them. To do so it:
//
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ uuid = { version = "1.10", features = ["serde", "v4"] }
web-sys = { version = "0.3", features = ["console"]}

[build-dependencies]
miden-node-proto-build = { version = "0.8.0", default-features = false }
miden-node-proto-build = { git = "https://github.com/0xPolygonMiden/miden-node", branch = "next", default-features = false }
miden-lib = { workspace = true }
miden-objects = { workspace = true }
miette = { workspace = true }
Expand Down
78 changes: 51 additions & 27 deletions crates/rust-client/src/rpc/domain/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::fmt::{self, Debug, Display, Formatter};
use miden_objects::{
Digest, Felt,
account::{Account, AccountCode, AccountHeader, AccountId, AccountStorageHeader},
block::BlockNumber,
block::{AccountWitness, BlockNumber},
crypto::merkle::{MerklePath, SmtProof},
};
use miden_tx::utils::{Deserializable, Serializable, ToHex};
Expand All @@ -20,7 +20,10 @@ use crate::rpc::{
generated::{
account::{AccountHeader as ProtoAccountHeader, AccountId as ProtoAccountId},
requests::get_account_proofs_request,
responses::{AccountStateHeader as ProtoAccountStateHeader, StorageSlotMapProof},
responses::{
AccountStateHeader as ProtoAccountStateHeader, AccountWitness as ProtoAccountWitness,
StorageSlotMapProof,
},
},
};

Expand Down Expand Up @@ -96,7 +99,7 @@ impl Debug for ProtoAccountId {
}

// INTO PROTO ACCOUNT ID
// ------------------------------------------------------------------------------------------------
// ================================================================================================

impl From<AccountId> for ProtoAccountId {
fn from(account_id: AccountId) -> Self {
Expand All @@ -105,7 +108,7 @@ impl From<AccountId> for ProtoAccountId {
}

// FROM PROTO ACCOUNT ID
// ------------------------------------------------------------------------------------------------
// ================================================================================================

impl TryFrom<ProtoAccountId> for AccountId {
type Error = RpcConversionError;
Expand Down Expand Up @@ -148,7 +151,7 @@ impl ProtoAccountHeader {
}

// FROM PROTO ACCOUNT HEADERS
// ------------------------------------------------------------------------------------------------
// ================================================================================================

impl ProtoAccountStateHeader {
/// Converts the RPC response into `StateHeaders`.
Expand Down Expand Up @@ -229,57 +232,49 @@ impl ProtoAccountStateHeader {
pub type AccountProofs = (BlockNumber, Vec<AccountProof>);

/// Account state headers.
#[derive(Clone, Debug)]
pub struct StateHeaders {
// TODO: should this be renamed? or storage_slots moved to AccountProof
Comment on lines 234 to +237
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, naming here could be improved. Basically, we have:

  • AccountWitness which proves that an account with a given commitment is in the chain.
  • StateHeaders which contains some information about the account, but not all info.
  • AccountProof which contain AccountWitness and optional StateHeaders.

I think I'm OK with AccountWitness but the naming of StateHeaders and AccountProof is confusing.

Maybe StateHeaders should be something like PartialAccount as it contains partial information about the account.

Not sure what would be a good name for AccountProof though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created an issue to track this (#862), though I think I might be able to refactor some of this from miden-base (since it's related to 0xMiden/miden-base#1229)

pub account_header: AccountHeader,
pub storage_header: AccountStorageHeader,
pub code: AccountCode,
pub storage_slots: BTreeMap<StorageSlotIndex, Vec<SmtProof>>,
}

/// Represents a proof of existence of an account's state at a specific block number.
#[derive(Clone, Debug)]
pub struct AccountProof {
/// Account ID.
account_id: AccountId,
/// Authentication path from the `account_root` of the block header to the account.
merkle_proof: MerklePath,
/// Account commitment for the current state.
account_commitment: Digest,
/// Account witness.
account_witness: AccountWitness,
/// State headers of public accounts.
state_headers: Option<StateHeaders>,
}

impl AccountProof {
pub fn new(
account_id: AccountId,
merkle_proof: MerklePath,
account_commitment: Digest,
account_witness: AccountWitness,
state_headers: Option<StateHeaders>,
) -> Result<Self, AccountProofError> {
if let Some(StateHeaders {
account_header, storage_header: _, code, ..
}) = &state_headers
{
if account_header.commitment() != account_commitment {
if account_header.commitment() != account_witness.state_commitment() {
return Err(AccountProofError::InconsistentAccountCommitment);
}
if account_id != account_header.id() {
if account_header.id() != account_witness.id() {
return Err(AccountProofError::InconsistentAccountId);
}
if code.commitment() != account_header.code_commitment() {
return Err(AccountProofError::InconsistentCodeCommitment);
}
}

Ok(Self {
account_id,
merkle_proof,
account_commitment,
state_headers,
})
Ok(Self { account_witness, state_headers })
}

pub fn account_id(&self) -> AccountId {
self.account_id
self.account_witness.id()
}

pub fn account_header(&self) -> Option<&AccountHeader> {
Expand All @@ -303,16 +298,45 @@ impl AccountProof {
}

pub fn account_commitment(&self) -> Digest {
self.account_commitment
self.account_witness.state_commitment()
}

pub fn account_witness(&self) -> &AccountWitness {
&self.account_witness
}

pub fn merkle_proof(&self) -> &MerklePath {
&self.merkle_proof
self.account_witness.path()
}

/// Deconstructs `AccountProof` into its individual parts.
pub fn into_parts(self) -> (AccountId, MerklePath, Digest, Option<StateHeaders>) {
(self.account_id, self.merkle_proof, self.account_commitment, self.state_headers)
pub fn into_parts(self) -> (AccountWitness, Option<StateHeaders>) {
(self.account_witness, self.state_headers)
}
}

// ACCOUNT WITNESS
// ================================================================================================

impl TryFrom<ProtoAccountWitness> for AccountWitness {
type Error = RpcError;

fn try_from(account_witness: ProtoAccountWitness) -> Result<Self, Self::Error> {
let state_commitment = account_witness
.commitment
.ok_or(RpcError::ExpectedDataMissing(String::from("AccountWitness.StateCommitment")))?
.try_into()?;
let merkle_path = account_witness
.path
.ok_or(RpcError::ExpectedDataMissing(String::from("AccountWitness.MerklePath")))?
.try_into()?;
let account_id = account_witness
.witness_id
.ok_or(RpcError::ExpectedDataMissing(String::from("AccountWitness.WitnessId")))?
.try_into()?;

let witness = AccountWitness::new(account_id, state_commitment, merkle_path).unwrap();
Ok(witness)
}
}

Expand Down
46 changes: 46 additions & 0 deletions crates/rust-client/src/rpc/generated/nostd/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,49 @@ pub mod get_account_proofs_request {
pub map_keys: ::prost::alloc::vec::Vec<super::super::digest::Digest>,
}
}
/// Returns a list of unconsumed network notes using pagination.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct GetUnconsumedNetworkNotesRequest {
/// An opaque token used to paginate through the notes.
///
/// This should be null on the first call, and set to the response
/// token until the response token is null, at which point all data
/// has been fetched.
#[prost(uint64, optional, tag = "1")]
pub page_token: ::core::option::Option<u64>,
/// Number of notes to retrieve per page.
#[prost(uint64, tag = "2")]
pub page_size: u64,
}
/// Submit a list of network notes to the network transaction builder.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SubmitNetworkNotesRequest {
/// Id of the transaction that created the notes.
#[prost(message, optional, tag = "1")]
pub transaction_id: ::core::option::Option<super::digest::Digest>,
/// The network notes to submit.
#[prost(message, repeated, tag = "2")]
pub note: ::prost::alloc::vec::Vec<super::note::Note>,
}
/// Update network transaction builder with transaction status changes.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UpdateTransactionStatusRequest {
/// The list of updates for each transaction.
#[prost(message, repeated, tag = "1")]
pub updates: ::prost::alloc::vec::Vec<
update_transaction_status_request::TransactionUpdate,
>,
}
/// Nested message and enum types in `UpdateTransactionStatusRequest`.
pub mod update_transaction_status_request {
/// Represents the update for a single transaction.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct TransactionUpdate {
/// Id of the transaction to update.
#[prost(message, optional, tag = "1")]
pub transaction_id: ::core::option::Option<super::super::digest::Digest>,
/// New status of the transaction.
#[prost(enumeration = "super::super::transaction::TransactionStatus", tag = "2")]
pub status: i32,
}
}
Loading
Loading