Skip to content

Commit

Permalink
feat: make prover conditionally asynchronous (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth authored Nov 3, 2024
1 parent 1ea1e1e commit a82a174
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
23 changes: 12 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
#### Changes

- [BREAKING] Wrapped `MastForest`s in `Program` and `Library` structs in `Arc` (#1465).
- `MastForestBuilder`: use `MastNodeId` instead of MAST root to uniquely identify procedures (#1473)
- `MastForestBuilder`: use `MastNodeId` instead of MAST root to uniquely identify procedures (#1473).
- Added `miden_core::utils::sync::racy_lock` module (#1463).
- Updated `miden_core::utils` to re-export `std::sync::LazyLock` and `racy_lock::RacyLock as LazyLock` for std and no_std environments, respectively (#1463).
- Made the undocumented behavior of the VM with regard to undefined behavior of u32 operations, stricter (#1480)
- Introduced the `Emit` instruction (#1496)
- Debug instructions can be enabled in the cli `run` command using `--debug` flag (#1502)
- [BREAKING] ExecutionOptions::new constructor requires a boolean to explicitly set debug mode (#1502)
- [BREAKING] The `run` and the `prove` commands in the cli will accept `--trace` flag instead of `--tracing` (#1502)
- Made the undocumented behavior of the VM with regard to undefined behavior of u32 operations, stricter (#1480).
- Introduced the `Emit` instruction (#1496).
- Debug instructions can be enabled in the cli `run` command using `--debug` flag (#1502).
- [BREAKING] ExecutionOptions::new constructor requires a boolean to explicitly set debug mode (#1502).
- [BREAKING] The `run` and the `prove` commands in the cli will accept `--trace` flag instead of `--tracing` (#1502).
- Migrated to new padding rule for RPO (#1343).
- Migrated to `miden-crypto` v0.11.0 (#1343).
- Implemented `MastForest` merging (#1534)
- Rename `EqHash` to `MastNodeFingerprint` and make it `pub` (#1539)
- Implemented `MastForest` merging (#1534).
- Rename `EqHash` to `MastNodeFingerprint` and make it `pub` (#1539).
- Updated Winterfell dependency to v0.10 (#1533).
- [BREAKING] `DYN` operation now expects a memory address pointing to the procedure hash (#1535)
- [BREAKING] `DYNCALL` operation fixed, and now expects a memory address pointing to the procedure hash (#1535)
- Permit child `MastNodeId`s to exceed the `MastNodeId`s of their parents (#1542)
- [BREAKING] `DYN` operation now expects a memory address pointing to the procedure hash (#1535).
- [BREAKING] `DYNCALL` operation fixed, and now expects a memory address pointing to the procedure hash (#1535).
- Permit child `MastNodeId`s to exceed the `MastNodeId`s of their parents (#1542).
- Make `miden-prover::prove()` method conditionally asynchronous (#1563).

#### Fixes

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ DEBUG_ASSERTIONS=RUSTFLAGS="-C debug-assertions"
FEATURES_CONCURRENT_EXEC=--features concurrent,executable
FEATURES_LOG_TREE=--features concurrent,executable,tracing-forest
FEATURES_METAL_EXEC=--features concurrent,executable,metal
ALL_FEATURES_BUT_ASYNC=--features concurrent,executable,metal,testing,with-debug-info

# -- linting --------------------------------------------------------------------------------------

.PHONY: clippy
clippy: ## Runs Clippy with configs
cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings
cargo +nightly clippy --workspace --all-targets ${ALL_FEATURES_BUT_ASYNC} -- -D warnings


.PHONY: fix
fix: ## Runs Fix with configs
cargo +nightly fix --allow-staged --allow-dirty --all-targets --all-features
cargo +nightly fix --allow-staged --allow-dirty --all-targets ${ALL_FEATURES_BUT_ASYNC}


.PHONY: format
Expand All @@ -41,7 +42,7 @@ lint: format fix clippy ## Runs all linting tasks at once (Clippy, fixing, forma

.PHONY: doc
doc: ## Generates & checks documentation
$(WARNINGS) cargo doc --all-features --keep-going --release
$(WARNINGS) cargo doc ${ALL_FEATURES_BUT_ASYNC} --keep-going --release

.PHONY: mdbook
mdbook: ## Generates mdbook documentation
Expand Down Expand Up @@ -73,7 +74,7 @@ test-package: ## Tests specific package: make test-package package=miden-vm

.PHONY: check
check: ## Checks all targets and features for errors without code generation
cargo check --all-targets --all-features
cargo check --all-targets ${ALL_FEATURES_BUT_ASYNC}

# --- building ------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ doctest = false
[features]
concurrent = ["std", "winter-prover/concurrent"]
default = ["std"]
testing = ["miden-air/testing"]
std = ["vm-core/std", "winter-prover/std"]
testing = ["miden-air/testing"]

[dependencies]
miden-air = { package = "miden-air", path = "../air", version = "0.10", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version.workspace = true
edition.workspace = true

[features]
async = ["winter-maybe-async/async"]
concurrent = ["processor/concurrent", "std", "winter-prover/concurrent"]
default = ["std"]
metal = ["dep:miden-gpu", "dep:elsa", "dep:pollster", "concurrent", "std"]
Expand All @@ -23,6 +24,7 @@ std = ["air/std", "processor/std", "winter-prover/std"]
air = { package = "miden-air", path = "../air", version = "0.10", default-features = false }
processor = { package = "miden-processor", path = "../processor", version = "0.10", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes"] }
winter-maybe-async = { package = "winter-maybe-async", version = "0.10", default-features = false }
winter-prover = { package = "winter-prover", version = "0.10", default-features = false }

[target.'cfg(all(target_arch = "aarch64", target_os = "macos"))'.dependencies]
Expand Down
44 changes: 27 additions & 17 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use processor::{
ExecutionTrace, Program,
};
use tracing::instrument;
use winter_maybe_async::{maybe_async, maybe_await};
use winter_prover::{
matrix::ColMatrix, ConstraintCompositionCoefficients, DefaultConstraintEvaluator,
DefaultTraceLde, ProofOptions as WinterProofOptions, Prover, StarkDomain, TraceInfo,
Expand All @@ -45,13 +46,15 @@ pub use winter_prover::{crypto::MerkleTree as MerkleTreeVC, Proof};
/// Executes and proves the specified `program` and returns the result together with a STARK-based
/// proof of the program's execution.
///
/// * `inputs` specifies the initial state of the stack as well as non-deterministic (secret) inputs
/// for the VM.
/// * `options` defines parameters for STARK proof generation.
/// - `stack_inputs` specifies the initial state of the stack for the VM.
/// - `host` specifies the host environment which contain non-deterministic (secret) inputs for the
/// prover
/// - `options` defines parameters for STARK proof generation.
///
/// # Errors
/// Returns an error if program execution or STARK proof generation fails for any reason.
#[instrument("prove_program", skip_all)]
#[maybe_async]
pub fn prove<H>(
program: &Program,
stack_inputs: StackInputs,
Expand Down Expand Up @@ -81,18 +84,22 @@ where

// generate STARK proof
let proof = match hash_fn {
HashFunction::Blake3_192 => ExecutionProver::<Blake3_192, WinterRandomCoin<_>>::new(
options,
stack_inputs,
stack_outputs.clone(),
)
.prove(trace),
HashFunction::Blake3_256 => ExecutionProver::<Blake3_256, WinterRandomCoin<_>>::new(
options,
stack_inputs,
stack_outputs.clone(),
)
.prove(trace),
HashFunction::Blake3_192 => {
let prover = ExecutionProver::<Blake3_192, WinterRandomCoin<_>>::new(
options,
stack_inputs,
stack_outputs.clone(),
);
maybe_await!(prover.prove(trace))
},
HashFunction::Blake3_256 => {
let prover = ExecutionProver::<Blake3_256, WinterRandomCoin<_>>::new(
options,
stack_inputs,
stack_outputs.clone(),
);
maybe_await!(prover.prove(trace))
},
HashFunction::Rpo256 => {
let prover = ExecutionProver::<Rpo256, RpoRandomCoin>::new(
options,
Expand All @@ -101,7 +108,7 @@ where
);
#[cfg(all(feature = "metal", target_arch = "aarch64", target_os = "macos"))]
let prover = gpu::metal::MetalExecutionProver::new(prover, HashFn::Rpo256);
prover.prove(trace)
maybe_await!(prover.prove(trace))
},
HashFunction::Rpx256 => {
let prover = ExecutionProver::<Rpx256, RpxRandomCoin>::new(
Expand All @@ -111,7 +118,7 @@ where
);
#[cfg(all(feature = "metal", target_arch = "aarch64", target_os = "macos"))]
let prover = gpu::metal::MetalExecutionProver::new(prover, HashFn::Rpx256);
prover.prove(trace)
maybe_await!(prover.prove(trace))
},
}
.map_err(ExecutionError::ProverError)?;
Expand Down Expand Up @@ -206,6 +213,7 @@ where
PublicInputs::new(program_info, self.stack_inputs.clone(), self.stack_outputs.clone())
}

#[maybe_async]
fn new_trace_lde<E: FieldElement<BaseField = Felt>>(
&self,
trace_info: &TraceInfo,
Expand All @@ -216,6 +224,7 @@ where
DefaultTraceLde::new(trace_info, main_trace, domain, partition_options)
}

#[maybe_async]
fn new_evaluator<'a, E: FieldElement<BaseField = Felt>>(
&self,
air: &'a ProcessorAir,
Expand All @@ -226,6 +235,7 @@ where
}

#[instrument(skip_all)]
#[maybe_async]
fn build_aux_trace<E: FieldElement<BaseField = Self::BaseField>>(
&self,
trace: &Self::Trace,
Expand Down

0 comments on commit a82a174

Please sign in to comment.