Skip to content
Draft
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
880 changes: 667 additions & 213 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ miden-node-validator = { path = "crates/validator", version = "0.13" }
miden-remote-prover-client = { path = "crates/remote-prover-client", version = "0.13" }

# miden-base aka protocol dependencies. These should be updated in sync.
miden-block-prover = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
miden-protocol = { branch = "next", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
miden-standards = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
miden-testing = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
miden-tx = { branch = "next", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
miden-tx-batch-prover = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
miden-block-prover = { branch = "huitseeker/update-miden-deps-p3", git = "https://github.com/0xMiden/miden-base.git" }
miden-protocol = { branch = "huitseeker/update-miden-deps-p3", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
miden-standards = { branch = "huitseeker/update-miden-deps-p3", git = "https://github.com/0xMiden/miden-base.git" }
miden-testing = { branch = "huitseeker/update-miden-deps-p3", git = "https://github.com/0xMiden/miden-base.git" }
miden-tx = { branch = "huitseeker/update-miden-deps-p3", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
miden-tx-batch-prover = { branch = "huitseeker/update-miden-deps-p3", git = "https://github.com/0xMiden/miden-base.git" }

# Other miden dependencies. These should align with those expected by miden-base.
miden-air = { features = ["std", "testing"], version = "0.20" }
miden-air = { branch = "al-migrate-p3-ver2", features = [
"std",
"testing",
], git = "https://github.com/0xMiden/miden-vm.git" }
miden-core = { branch = "al-migrate-p3-ver2", git = "https://github.com/0xMiden/miden-vm.git" }
miden-crypto = { version = "0.20" }
miden-vm = { branch = "al-migrate-p3-ver2", git = "https://github.com/0xMiden/miden-vm.git" }

# External dependencies
anyhow = { version = "1.0" }
Expand Down
4 changes: 2 additions & 2 deletions bin/network-monitor/src/deploy/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use miden_protocol::account::{
StorageSlotName,
};
use miden_protocol::utils::sync::LazyLock;
use miden_protocol::{Felt, FieldElement, Word};
use miden_protocol::{Word, ZERO};
use miden_standards::code_builder::CodeBuilder;
use miden_standards::testing::account_component::IncrNonceAuthComponent;
use tracing::instrument;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn create_counter_account(owner_account_id: AccountId) -> Result<Account> {

let owner_id_slot = StorageSlot::with_value(
OWNER_SLOT_NAME.clone(),
Word::from([Felt::ZERO, Felt::ZERO, owner_account_id_suffix, owner_account_id_prefix]),
Word::from([ZERO, ZERO, owner_account_id_suffix, owner_account_id_prefix]),
);

let counter_slot = StorageSlot::with_value(COUNTER_SLOT_NAME.clone(), Word::empty());
Expand Down
48 changes: 33 additions & 15 deletions bin/remote-prover/src/api/prover.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use miden_block_prover::LocalBlockProver;
use miden_node_proto::BlockProofRequest;
use miden_node_utils::ErrorReport;
Expand Down Expand Up @@ -53,25 +55,25 @@ impl std::str::FromStr for ProofType {
/// This enum is used to store the prover for the remote prover.
/// Only one prover is enabled at a time.
enum Prover {
Transaction(Mutex<LocalTransactionProver>),
Batch(Mutex<LocalBatchProver>),
Block(Mutex<LocalBlockProver>),
Transaction(Arc<Mutex<LocalTransactionProver>>),
Batch(Arc<Mutex<LocalBatchProver>>),
Block(Arc<Mutex<LocalBlockProver>>),
}

impl Prover {
fn new(proof_type: ProofType) -> Self {
match proof_type {
ProofType::Transaction => {
info!(target: COMPONENT, proof_type = ?proof_type, "Transaction prover initialized");
Self::Transaction(Mutex::new(LocalTransactionProver::default()))
Self::Transaction(Arc::new(Mutex::new(LocalTransactionProver::default())))
},
ProofType::Batch => {
info!(target: COMPONENT, proof_type = ?proof_type, security_level = MIN_PROOF_SECURITY_LEVEL, "Batch prover initialized");
Self::Batch(Mutex::new(LocalBatchProver::new(MIN_PROOF_SECURITY_LEVEL)))
Self::Batch(Arc::new(Mutex::new(LocalBatchProver::new(MIN_PROOF_SECURITY_LEVEL))))
},
ProofType::Block => {
info!(target: COMPONENT, proof_type = ?proof_type, security_level = MIN_PROOF_SECURITY_LEVEL, "Block prover initialized");
Self::Block(Mutex::new(LocalBlockProver::new(MIN_PROOF_SECURITY_LEVEL)))
Self::Block(Arc::new(Mutex::new(LocalBlockProver::new(MIN_PROOF_SECURITY_LEVEL))))
},
}
}
Expand Down Expand Up @@ -102,19 +104,35 @@ impl ProverRpcApi {
tx_inputs: TransactionInputs,
request_id: &str,
) -> Result<Response<proto::remote_prover::Proof>, tonic::Status> {
let Prover::Transaction(prover) = &self.prover else {
return Err(Status::unimplemented("Transaction prover is not enabled"));
};

let locked_prover = prover
.try_lock()
.map_err(|_| Status::resource_exhausted("Server is busy handling another request"))?;

// Add a small delay to simulate longer proving time for testing
#[cfg(test)]
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

let proof = locked_prover.prove(tx_inputs).map_err(internal_error)?;
// Spawn the proving in a separate OS thread since prove() uses prove_sync internally
// which detects Tokio runtime and panics. We cannot use spawn_blocking because
// it still runs within the Tokio runtime context.
let proof = match &self.prover {
Prover::Transaction(prover) => {
let prover = Arc::clone(prover);
let (tx, rx) = tokio::sync::oneshot::channel();

std::thread::spawn(move || {
let result = prover
.try_lock()
.map_err(|_| {
Status::resource_exhausted("Server is busy handling another request")
})
.and_then(|locked_prover| {
locked_prover.prove(tx_inputs).map_err(internal_error)
});
let _ = tx.send(result);
});

rx.await
.map_err(|_| Status::internal("Proving thread panicked or was cancelled"))??
},
_ => return Err(Status::unimplemented("Transaction prover is not enabled")),
};

// Record the transaction_id in the current tracing span
let transaction_id = proof.id();
Expand Down
1 change: 0 additions & 1 deletion bin/stress-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ workspace = true
clap = { features = ["derive"], version = "4.5" }
fs-err = { workspace = true }
futures = { workspace = true }
miden-air = { features = ["testing"], workspace = true }
miden-block-prover = { features = ["testing"], workspace = true }
miden-node-block-producer = { workspace = true }
miden-node-proto = { workspace = true }
Expand Down
25 changes: 22 additions & 3 deletions bin/stress-test/src/seeding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

use metrics::SeedingMetrics;
use miden_air::ExecutionProof;
use miden_block_prover::LocalBlockProver;
use miden_node_block_producer::store::StoreClient;
use miden_node_proto::domain::batch::BatchInputs;
Expand Down Expand Up @@ -425,7 +424,17 @@ fn create_consume_note_tx(
block_ref.commitment(),
fee_from_block(block_ref).unwrap(),
u32::MAX.into(),
ExecutionProof::new_dummy(),
{
use miden_protocol::vm::ExecutionProof;
// Create a dummy ExecutionProof by deserializing a minimal valid proof

#[allow(clippy::missing_transmute_annotations)]
ExecutionProof {
proof: vec![],
hash_fn: unsafe { std::mem::transmute(0u8) }, // Blake3_192 = 0
pc_requests: vec![],
}
},
)
.add_input_notes(vec![input_note])
.account_update_details(details)
Expand Down Expand Up @@ -464,7 +473,17 @@ fn create_emit_note_tx(
)
.unwrap(),
u32::MAX.into(),
ExecutionProof::new_dummy(),
{
use miden_protocol::vm::ExecutionProof;
// Create a dummy ExecutionProof by deserializing a minimal valid proof

#[allow(clippy::missing_transmute_annotations)]
ExecutionProof {
proof: vec![],
hash_fn: unsafe { std::mem::transmute(0u8) }, // Blake3_192 = 0
pc_requests: vec![],
}
},
)
.add_output_notes(output_notes.into_iter().map(OutputNote::Full).collect::<Vec<OutputNote>>())
.build()
Expand Down
1 change: 1 addition & 0 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ url = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
miden-air = { features = ["testing"], workspace = true }
miden-node-store = { workspace = true }
miden-node-test-macro = { workspace = true }
miden-node-utils = { features = ["testing"], workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion crates/block-producer/src/test_utils/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ impl MockProvenTxBuilder {
Word::empty(),
self.fee,
self.expiration_block_num,
ExecutionProof::new_dummy(),
#[allow(clippy::missing_transmute_annotations)]
ExecutionProof {
proof: vec![],
hash_fn: unsafe { std::mem::transmute(0u8) }, // Blake3_192 = 0
pc_requests: vec![],
},
)
.add_input_notes(self.input_notes.unwrap_or_default())
.add_input_notes(self.nullifiers.unwrap_or_default())
Expand Down
1 change: 1 addition & 0 deletions crates/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workspace = true
anyhow = { workspace = true }
hex = { version = "0.4" }
http = { workspace = true }
miden-core = { workspace = true }
miden-node-grpc-error-macro = { workspace = true }
miden-node-utils = { workspace = true }
miden-protocol = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/domain/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl TryFrom<proto::account::AccountHeader> for AccountHeader {
let code_commitment = code_commitment
.ok_or(proto::account::AccountHeader::missing_field(stringify!(code_commitment)))?
.try_into()?;
let nonce = nonce.try_into().map_err(|_e| ConversionError::NotAValidFelt)?;
let nonce = nonce.into();

Ok(AccountHeader::new(
account_id,
Expand Down
5 changes: 3 additions & 2 deletions crates/proto/src/domain/digest.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt::{Debug, Display, Formatter};

use hex::{FromHex, ToHex};
use miden_core::PrimeField64;
use miden_protocol::note::NoteId;
use miden_protocol::{Felt, StarkField, Word};
use miden_protocol::{Felt, Word};

use crate::errors::ConversionError;
use crate::generated as proto;
Expand Down Expand Up @@ -163,7 +164,7 @@ impl TryFrom<proto::primitives::Digest> for [Felt; 4] {
fn try_from(value: proto::primitives::Digest) -> Result<Self, Self::Error> {
if [value.d0, value.d1, value.d2, value.d3]
.iter()
.any(|v| *v >= <Felt as StarkField>::MODULUS)
.any(|v| *v >= <Felt as PrimeField64>::ORDER_U64)
{
return Err(ConversionError::NotAValidFelt);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/domain/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TryFrom<proto::note::NoteMetadata> for NoteMetadata {

let execution_hint = NoteExecutionHint::try_from(value.execution_hint)?;

let aux = Felt::try_from(value.aux).map_err(|_| ConversionError::NotAValidFelt)?;
let aux = Felt::from(value.aux);

Ok(NoteMetadata::new(sender, note_type, tag, execution_hint, aux)?)
}
Expand Down
21 changes: 18 additions & 3 deletions crates/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use miden_protocol::crypto::dsa::ecdsa_k256_keccak::SecretKey;
use miden_protocol::testing::noop_auth_component::NoopAuthComponent;
use miden_protocol::transaction::ProvenTransactionBuilder;
use miden_protocol::utils::Serializable;
use miden_protocol::vm::ExecutionProof;
use miden_standards::account::wallets::BasicWallet;
use tempfile::TempDir;
use tokio::net::TcpListener;
Expand Down Expand Up @@ -262,7 +261,15 @@ async fn rpc_server_rejects_proven_transactions_with_invalid_commitment() {
Word::default(),
test_fee(),
u32::MAX.into(),
ExecutionProof::new_dummy(),
{
use miden_protocol::vm::ExecutionProof;
#[allow(clippy::missing_transmute_annotations)]
ExecutionProof {
proof: vec![],
hash_fn: unsafe { std::mem::transmute(0u8) }, // Blake3_192 = 0
pc_requests: vec![],
}
},
)
.account_update_details(AccountUpdateDetails::Delta(account_delta))
.build()
Expand Down Expand Up @@ -337,7 +344,15 @@ async fn rpc_server_rejects_tx_submissions_without_genesis() {
Word::default(),
test_fee(),
u32::MAX.into(),
ExecutionProof::new_dummy(),
{
use miden_protocol::vm::ExecutionProof;
#[allow(clippy::missing_transmute_annotations)]
ExecutionProof {
proof: vec![],
hash_fn: unsafe { std::mem::transmute(0u8) }, // Blake3_192 = 0
pc_requests: vec![],
}
},
)
.account_update_details(AccountUpdateDetails::Delta(account_delta))
.build()
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/db/models/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub(crate) fn execution_hint_to_raw_sql(hint: u64) -> i64 {

#[inline(always)]
pub(crate) fn raw_sql_to_aux(raw: i64) -> Felt {
Felt::try_from(raw as u64).unwrap()
Felt::from(raw as u64)
}
#[inline(always)]
pub(crate) fn aux_to_raw_sql(hint: Felt) -> i64 {
Expand Down
14 changes: 7 additions & 7 deletions crates/store/src/db/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use miden_protocol::transaction::{
TransactionHeader,
TransactionId,
};
use miden_protocol::{EMPTY_WORD, Felt, FieldElement, Word, ZERO};
use miden_protocol::{EMPTY_WORD, Felt, ONE, Word, ZERO};
use miden_standards::account::auth::AuthRpoFalcon512;
use miden_standards::code_builder::CodeBuilder;
use miden_standards::note::create_p2id_note;
Expand Down Expand Up @@ -1169,7 +1169,7 @@ fn sql_account_storage_map_values_insertion() {
[(slot_name.clone(), StorageSlotDelta::Map(map1))].into_iter().collect();
let storage1 = AccountStorageDelta::from_raw(delta1);
let delta1 =
AccountDelta::new(account_id, storage1, AccountVaultDelta::default(), Felt::ONE).unwrap();
AccountDelta::new(account_id, storage1, AccountVaultDelta::default(), ONE).unwrap();
insert_account_delta(conn, account_id, block1, &delta1);

let storage_map_page =
Expand Down Expand Up @@ -1315,7 +1315,7 @@ fn select_storage_map_sync_values() {
// UTILITIES
// -------------------------------------------------------------------------------------------
fn num_to_word(n: u64) -> Word {
[Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::new(n)].into()
[ZERO, ZERO, ZERO, Felt::new(n)].into()
}

fn num_to_nullifier(n: u64) -> Nullifier {
Expand Down Expand Up @@ -1474,11 +1474,11 @@ fn genesis_with_account_storage_map() {

let storage_map = StorageMap::with_entries(vec![
(
Word::from([Felt::new(1), Felt::ZERO, Felt::ZERO, Felt::ZERO]),
Word::from([Felt::new(1), ZERO, ZERO, ZERO]),
Word::from([Felt::new(10), Felt::new(20), Felt::new(30), Felt::new(40)]),
),
(
Word::from([Felt::new(2), Felt::ZERO, Felt::ZERO, Felt::ZERO]),
Word::from([Felt::new(2), ZERO, ZERO, ZERO]),
Word::from([Felt::new(50), Felt::new(60), Felt::new(70), Felt::new(80)]),
),
])
Expand Down Expand Up @@ -1525,7 +1525,7 @@ fn genesis_with_account_assets_and_storage() {
let fungible_asset = FungibleAsset::new(faucet_id, 5000).unwrap();

let storage_map = StorageMap::with_entries(vec![(
Word::from([Felt::new(100), Felt::ZERO, Felt::ZERO, Felt::ZERO]),
Word::from([Felt::new(100), ZERO, ZERO, ZERO]),
Word::from([Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]),
)])
.unwrap();
Expand Down Expand Up @@ -1604,7 +1604,7 @@ fn genesis_with_multiple_accounts() {
.unwrap();

let storage_map = StorageMap::with_entries(vec![(
Word::from([Felt::new(5), Felt::ZERO, Felt::ZERO, Felt::ZERO]),
Word::from([Felt::new(5), ZERO, ZERO, ZERO]),
Word::from([Felt::new(15), Felt::new(25), Felt::new(35), Felt::new(45)]),
)])
.unwrap();
Expand Down
4 changes: 4 additions & 0 deletions crates/store/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ pub enum DatabaseError {
AccountCommitmentsMismatch { expected: Word, calculated: Word },
#[error("account {0} not found")]
AccountNotFoundInDb(AccountId),
#[error("root mismatch (expected {expected}, but got {actual})")]
MismatchedRoot { expected: String, actual: String },
#[error("{0}")]
Other(String),
#[error("account {0} state at block height {1} not found")]
AccountAtBlockHeightNotFoundInDb(AccountId, BlockNumber),
#[error("historical block {block_num} not available: {reason}")]
Expand Down
Loading
Loading