Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update with latest next #667

Merged
merged 10 commits into from
Jan 15, 2025
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
296 changes: 153 additions & 143 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ WARNINGS=RUSTDOCFLAGS="-D warnings"
NODE_DIR="miden-node"
NODE_REPO="https://github.com/0xPolygonMiden/miden-node.git"
NODE_BRANCH="next"
NODE_FEATURES_TESTING=--features "testing"

PROVER_DIR="miden-base"
PROVER_REPO="https://github.com/0xPolygonMiden/miden-base.git"
Expand Down Expand Up @@ -123,7 +122,7 @@ update-node-branch: setup-miden-base ## Checkout and update the specified branch

.PHONY: build-node
build-node: update-node-branch ## Update dependencies and build the node binary with specified features
cd $(NODE_DIR) && rm -rf miden-store.sqlite3* && cargo run --locked --bin miden-node $(NODE_FEATURES_TESTING) -- make-genesis --inputs-path ../tests/config/genesis.toml --force
cd $(NODE_DIR) && rm -rf miden-store.sqlite3* && cargo run --locked --bin miden-node -- make-genesis --inputs-path ../tests/config/genesis.toml --force

.PHONY: start-node
start-node: ## Run node. This requires the node repo to be present at `miden-node`
Expand Down
6 changes: 5 additions & 1 deletion bin/miden-cli/src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ pub async fn show_account<R: FeltRng>(
},
Asset::NonFungible(non_fungible_asset) => {
// TODO: Display non-fungible assets more clearly.
("Non Fungible Asset", non_fungible_asset.faucet_id().to_hex(), 1.0.to_string())
(
"Non Fungible Asset",
non_fungible_asset.faucet_id_prefix().to_hex(),
1.0.to_string(),
)
},
};
table.add_row(vec![asset_type, &faucet, &amount.to_string()]);
Expand Down
6 changes: 2 additions & 4 deletions bin/miden-cli/src/commands/new_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ impl NewFaucetCmd {

let anchor_block = client.get_latest_epoch_block().await?;

let (new_account, seed) = AccountBuilder::new()
.init_seed(init_seed)
let (new_account, seed) = AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().expect("anchor block should be valid"))
.account_type(AccountType::FungibleFaucet)
.storage_mode(self.storage_mode.into())
Expand Down Expand Up @@ -131,8 +130,7 @@ impl NewWalletCmd {

let anchor_block = client.get_latest_epoch_block().await?;

let (new_account, seed) = AccountBuilder::new()
.init_seed(init_seed)
let (new_account, seed) = AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().expect("anchor block should be valid"))
.account_type(account_type)
.storage_mode(self.storage_mode.into())
Expand Down
12 changes: 10 additions & 2 deletions bin/miden-cli/src/commands/new_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,18 @@ fn print_transaction_details(transaction_result: &TransactionResult) -> Result<(
for (asset, action) in account_delta.vault().non_fungible().iter() {
match action {
NonFungibleDeltaAction::Add => {
table.add_row(vec!["Non Fungible Asset", &asset.faucet_id().to_hex(), "1"]);
table.add_row(vec![
"Non Fungible Asset",
&asset.faucet_id_prefix().to_hex(),
"1",
]);
},
NonFungibleDeltaAction::Remove => {
table.add_row(vec!["Non Fungible Asset", &asset.faucet_id().to_hex(), "-1"]);
table.add_row(vec![
"Non Fungible Asset",
&asset.faucet_id_prefix().to_hex(),
"-1",
]);
},
}
}
Expand Down
9 changes: 5 additions & 4 deletions bin/miden-cli/src/commands/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ async fn show_note(client: Client<impl FeltRng>, note_id: String) -> Result<(),
let (asset_type, faucet, amount) = match asset {
Asset::Fungible(fungible_asset) => {
let (faucet, amount) = faucet_details_map.format_fungible_asset(fungible_asset)?;

("Fungible Asset", faucet, amount)
},
Asset::NonFungible(non_fungible_asset) => {
("Non Fungible Asset", non_fungible_asset.faucet_id().to_hex(), 1.0.to_string())
},
Asset::NonFungible(non_fungible_asset) => (
"Non Fungible Asset",
non_fungible_asset.faucet_id_prefix().to_hex(),
1.0.to_string(),
),
};
table.add_row(vec![asset_type, &faucet, &amount.to_string()]);
}
Expand Down
3 changes: 1 addition & 2 deletions bin/miden-cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ async fn test_mint_with_untracked_account() {

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (new_account, seed) = AccountBuilder::new()
.init_seed(init_seed)
let (new_account, seed) = AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(AccountType::RegularAccountImmutableCode)
.storage_mode(AccountStorageMode::Private)
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 @@ -16,7 +16,7 @@ edition.workspace = true
crate-type = ["lib"]

[features]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"]
concurrent = ["miden-tx/concurrent", "std"]
default = []
idxdb = ["dep:base64", "dep:serde-wasm-bindgen", "dep:wasm-bindgen", "dep:wasm-bindgen-futures", "dep:serde"]
sqlite = ["dep:rusqlite", "dep:deadpool-sqlite", "std"]
Expand Down
18 changes: 14 additions & 4 deletions crates/rust-client/src/notes/note_screener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ impl NoteScreener {
"Should be able to convert the first two note inputs to an array of two Felt elements",
);

let account_id = AccountId::try_from([account_id_felts[1], account_id_felts[0]])
.map_err(|err| InvalidNoteInputsError::AccountError(note.id(), err))?;
let account_id =
AccountId::try_from([account_id_felts[1], account_id_felts[0]]).map_err(|err| {
InvalidNoteInputsError::AccountError(
note.id(),
AccountError::FinalAccountHeaderIdParsingFailed(err),
)
})?;

if !account_ids.contains(&account_id) {
return Ok(vec![]);
Expand Down Expand Up @@ -116,8 +121,13 @@ impl NoteScreener {
InvalidNoteInputsError::BlockNumberError(note.id(), recall_height_felt.as_int())
})?;

let account_id = AccountId::try_from([account_id_felts[1], account_id_felts[0]])
.map_err(|err| InvalidNoteInputsError::AccountError(note.id(), err))?;
let account_id =
AccountId::try_from([account_id_felts[1], account_id_felts[0]]).map_err(|err| {
InvalidNoteInputsError::AccountError(
note.id(),
AccountError::FinalAccountHeaderIdParsingFailed(err),
)
})?;

Ok(vec![
(account_id, NoteRelevance::Always),
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-client/src/notes/script_roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//! This file was generated by build.rs.

/// Script root of the P2ID note script.
pub const P2ID: &str = "0x1130a5be5301e6712d83ceaa37926f368703d5b3ab2fe8c2dd275dbf8cf788bf";
pub const P2ID: &str = "0xf586180b61a0fcabb7033e2bdb36ad3d00387081d19a90d32f282c8e52e31581";

/// Script root of the P2IDR note script.
pub const P2IDR: &str = "0xcbe719ff292d3e3b0abf162bc1a3d21dfaf07860b4bf71a36edeb71f777fab5c";
pub const P2IDR: &str = "0x06819748ba07cdb67a45996091eb168ff5428e83161682dc2a63338f32a12445";

/// Script root of the SWAP note script.
pub const SWAP: &str = "0xba6dc9c022ad9a988c3c8f91e40ad89f4ef736472c79f389397943a1db538bfc";
4 changes: 3 additions & 1 deletion crates/rust-client/src/store/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use miden_objects::{
accounts::AccountId,
crypto::merkle::MmrError,
utils::{DeserializationError, HexParseError},
AccountError, AssetVaultError, Digest, NoteError, TransactionScriptError,
AccountError, AccountIdError, AssetVaultError, Digest, NoteError, TransactionScriptError,
};
use miden_tx::DataStoreError;
use thiserror::Error;
Expand All @@ -26,6 +26,8 @@ pub enum StoreError {
AccountDataNotFound(AccountId),
#[error("account error")]
AccountError(#[from] AccountError),
#[error("account id error")]
AccountIdError(#[from] AccountIdError),
#[error("account hash {0} already exists")]
AccountHashAlreadyExists(Digest),
#[error("account hash mismatch for account {0}")]
Expand Down
8 changes: 6 additions & 2 deletions crates/rust-client/src/store/sqlite_store/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{collections::BTreeMap, rc::Rc};
use miden_objects::{
accounts::{Account, AccountCode, AccountHeader, AccountId, AccountStorage, AuthSecretKey},
assets::{Asset, AssetVault},
Digest, Felt, Word,
AccountError, Digest, Felt, Word,
};
use miden_tx::utils::{Deserializable, Serializable};
use rusqlite::{params, types::Value, Connection, Transaction};
Expand Down Expand Up @@ -215,7 +215,11 @@ impl SqliteStore {
result.map_err(|err| StoreError::ParsingError(err.to_string())).and_then(
|(id, code): (String, Vec<u8>)| {
Ok((
AccountId::from_hex(&id).map_err(StoreError::AccountError)?,
AccountId::from_hex(&id).map_err(|err| {
StoreError::AccountError(
AccountError::FinalAccountHeaderIdParsingFailed(err),
)
})?,
AccountCode::from_bytes(&code).map_err(StoreError::AccountError)?,
))
},
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-client/src/store/web_store/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl WebStore {
.into_iter()
.map(|idxdb_object| {
let account_id = AccountId::from_hex(&idxdb_object.account_id)
.map_err(StoreError::AccountError)?;
.map_err(StoreError::AccountIdError)?;
let code = AccountCode::from_bytes(&idxdb_object.code)
.map_err(StoreError::AccountError)?;

Expand Down
6 changes: 2 additions & 4 deletions crates/rust-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ async fn insert_new_wallet<R: FeltRng>(

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (account, seed) = AccountBuilder::new()
.init_seed(init_seed)
let (account, seed) = AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(AccountType::RegularAccountImmutableCode)
.storage_mode(storage_mode)
Expand Down Expand Up @@ -83,8 +82,7 @@ async fn insert_new_fungible_faucet<R: FeltRng>(

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (account, seed) = AccountBuilder::new()
.init_seed(init_seed)
let (account, seed) = AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(AccountType::FungibleFaucet)
.storage_mode(storage_mode)
Expand Down
20 changes: 12 additions & 8 deletions crates/rust-client/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,13 +664,17 @@ impl<R: FeltRng> Client<R> {
// Check if the non fungible asset is in the incoming assets
if !incoming_non_fungible_balance_set.contains(&non_fungible) {
return Err(ClientError::AssetError(
AssetError::NonFungibleFaucetIdTypeMismatch(non_fungible.faucet_id()),
AssetError::NonFungibleFaucetIdTypeMismatch(
non_fungible.faucet_id_prefix(),
),
));
}
},
_ => {
return Err(ClientError::AssetError(
AssetError::NonFungibleFaucetIdTypeMismatch(non_fungible.faucet_id()),
AssetError::NonFungibleFaucetIdTypeMismatch(
non_fungible.faucet_id_prefix(),
),
));
},
}
Expand Down Expand Up @@ -784,7 +788,7 @@ impl<R: FeltRng> Client<R> {
},
};

extend_advice_inputs_for_account(
extend_advice_inputs_for_foreign_account(
tx_args,
&mut self.tx_executor,
foreign_account_inputs,
Expand Down Expand Up @@ -837,7 +841,7 @@ impl<R: FeltRng> Client<R> {

/// Extends the advice inputs with account data and Merkle proofs, and loads the necessary
/// [code](AccountCode) in `tx_executor`.
fn extend_advice_inputs_for_account(
fn extend_advice_inputs_for_foreign_account(
tx_args: &mut TransactionArgs,
tx_executor: &mut TransactionExecutor,
foreign_account_inputs: ForeignAccountInputs,
Expand All @@ -848,7 +852,7 @@ fn extend_advice_inputs_for_account(

let account_id = account_header.id();
let foreign_id_root =
Digest::from([account_id.second_felt(), account_id.first_felt(), ZERO, ZERO]);
Digest::from([account_id.suffix(), account_id.prefix().as_felt(), ZERO, ZERO]);

// Extend the advice inputs with the new data
tx_args.extend_advice_map([
Expand All @@ -873,8 +877,9 @@ fn extend_advice_inputs_for_account(

// Extend the advice inputs with Merkle store data
tx_args.extend_merkle_store(
merkle_path.inner_nodes(account_id.first_felt().as_int(), account_header.hash())?,
merkle_path.inner_nodes(account_id.prefix().as_u64(), account_header.hash())?,
);

tx_executor.load_account_code(&account_code);

Ok(())
Expand Down Expand Up @@ -971,8 +976,7 @@ mod test {

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let account = AccountBuilder::new()
.init_seed(Default::default())
let account = AccountBuilder::new(Default::default())
.anchor((&anchor_block).try_into().unwrap())
.with_component(wallet_component)
.with_component(RpoFalcon512::new(secret_key.public_key()))
Expand Down
32 changes: 13 additions & 19 deletions crates/rust-client/src/transactions/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,17 @@ mod tests {

use miden_lib::{notes::create_p2id_note, transaction::TransactionKernel};
use miden_objects::{
accounts::{AccountBuilder, AccountId, AccountIdAnchor, AccountStorageMode, AccountType},
accounts::{AccountBuilder, AccountId, AccountIdAnchor, AccountType},
assets::FungibleAsset,
crypto::rand::{FeltRng, RpoRandomCoin},
notes::{NoteExecutionMode, NoteTag, NoteType},
testing::account_component::AccountMockComponent,
testing::{
account_component::AccountMockComponent,
account_id::{
ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, ACCOUNT_ID_SENDER,
},
},
transaction::OutputNote,
Digest, Felt, ZERO,
};
Expand All @@ -348,21 +354,10 @@ mod tests {

#[test]
fn transaction_request_serialization() {
let sender_id = AccountId::new_dummy(
[0u8; 15],
AccountType::RegularAccountImmutableCode,
AccountStorageMode::Private,
);
let target_id = AccountId::new_dummy(
[1u8; 15],
AccountType::RegularAccountImmutableCode,
AccountStorageMode::Public,
);
let faucet_id = AccountId::new_dummy(
[2u8; 15],
AccountType::FungibleFaucet,
AccountStorageMode::Private,
);
let sender_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap();
let target_id =
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN).unwrap();
let faucet_id = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN).unwrap();
let mut rng = RpoRandomCoin::new(Default::default());

let mut notes = vec![];
Expand All @@ -384,8 +379,7 @@ mod tests {
advice_vec.push((Digest::new(rng.draw_word()), vec![Felt::new(i)]));
}

let account = AccountBuilder::new()
.init_seed(Default::default())
let account = AccountBuilder::new(Default::default())
.anchor(AccountIdAnchor::new_unchecked(0, Default::default()))
.with_component(
AccountMockComponent::new_with_empty_slots(TransactionKernel::assembler()).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions crates/web-client/src/models/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl AccountId {
}

pub fn prefix(&self) -> Felt {
let native_felt: NativeFelt = self.0.first_felt();
let native_felt: NativeFelt = self.0.prefix().as_felt();
native_felt.into()
}

pub fn suffix(&self) -> Felt {
let native_felt: NativeFelt = self.0.second_felt();
let native_felt: NativeFelt = self.0.suffix();
native_felt.into()
}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/web-client/src/new_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ impl WebClient {

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (new_account, seed) = match AccountBuilder::new()
.init_seed(init_seed)
let (new_account, seed) = match AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(account_type)
.storage_mode(storage_mode.into())
Expand Down Expand Up @@ -95,8 +94,7 @@ impl WebClient {

let anchor_block = client.get_latest_epoch_block().await.unwrap();

let (new_account, seed) = match AccountBuilder::new()
.init_seed(init_seed)
let (new_account, seed) = match AccountBuilder::new(init_seed)
.anchor((&anchor_block).try_into().unwrap())
.account_type(AccountType::FungibleFaucet)
.storage_mode(storage_mode.into())
Expand Down
Loading
Loading