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
104 changes: 101 additions & 3 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ xz2 = "0.1.7"
zerocopy = "0.8.25"
zeroize = "1.8.1"
zstd = "0.13"
metal = "0.33.0"
cudarc = { version = "0.19.4", default-features = false, features = ["cuda-12000", "driver", "nvrtc", "dynamic-loading"] }

# WASM-specific dependencies
js-sys = "0.3"
Expand Down Expand Up @@ -200,4 +202,4 @@ spongefish = { git = "https://github.com/arkworks-rs/spongefish", features = [
"sha2",
], rev = "fcc277f8a857fdeeadd7cca92ab08de63b1ff1a1" }
spongefish-pow = { git = "https://github.com/arkworks-rs/spongefish", rev = "fcc277f8a857fdeeadd7cca92ab08de63b1ff1a1" }
whir = { git ="https://github.com/WizardOfMenlo/whir/", rev="0aeaa7f337c743d9ddfcb9d909628d6491e3355c", features = ["tracing", "rs_in_order"] }
whir = { git = "https://github.com/zkfriendly/whir.git", branch = "zkfr/add-metal-gpu-refactor", features = ["tracing", "rs_in_order"] }
6 changes: 6 additions & 0 deletions provekit/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ xz2.workspace = true
[package.metadata.cargo-machete]
ignored = ["keccak"] # Intentionally anchored to keep Noir beta.19-compatible RC version

[target.'cfg(target_os = "macos")'.dependencies]
metal.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
cudarc.workspace = true

[dev-dependencies]
divan.workspace = true
proptest.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion provekit/common/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Interner {
values: Vec<FieldElement>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct InternedFieldElement(usize);

impl Default for Interner {
Expand Down
64 changes: 51 additions & 13 deletions provekit/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,61 @@ pub use {
///
/// Must be called once before any prove/verify operations.
/// Idempotent — safe to call multiple times.
pub fn register_ntt() {
use std::sync::{Arc, Once};
pub fn register_whir_backends() {
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once(|| {
// Register NTT for polynomial operations
#[cfg(not(feature = "provekit_ntt"))]
let ntt: Arc<dyn whir::algebra::ntt::ReedSolomon<FieldElement>> =
Arc::new(whir::algebra::ntt::NttEngine::<FieldElement>::new_from_fftfield());

#[cfg(feature = "provekit_ntt")]
let ntt: Arc<dyn whir::algebra::ntt::ReedSolomon<FieldElement>> =
Arc::new(crate::ntt::RSFr);

whir::algebra::ntt::NTT.insert(ntt);
let irs_committer = build_irs_committer();
whir::protocols::irs_commit::IRS_COMMITTERS.insert(irs_committer);

// Register Skyscraper (ProveKit-specific); WHIR's built-in engines
// (SHA2, Keccak, Blake3, etc.) are pre-registered via whir::hash::ENGINES.
whir::hash::ENGINES.register(Arc::new(skyscraper::SkyscraperHashEngine));
whir::hash::ENGINES
.register(std::sync::Arc::new(skyscraper::SkyscraperHashEngine));
});
}

/// Build the IRS committer for BN254.
///
/// With `provekit_ntt`: uses ProveKit's optimized NTT backends (Metal on
/// macOS with CPU fallback, CPU-only on other targets).
/// Without `provekit_ntt`: uses whir's built-in `NttEngine`.
fn build_irs_committer()
-> std::sync::Arc<dyn whir::protocols::irs_commit::IrsCommitter<FieldElement>> {
use std::sync::Arc;
use whir::protocols::irs_commit::CpuIrsCommitter;

#[cfg(feature = "provekit_ntt")]
{
#[cfg(target_os = "macos")]
match crate::ntt::MetalBn254Ntt::new() {
Ok(ntt) => return Arc::new(ntt),
Err(err) => {
tracing::info!(
error = %err,
"Metal BN254 IRS backend unavailable, using ProveKit CPU fallback"
);
}
}

#[cfg(target_os = "linux")]
match crate::ntt::CudaBn254Ntt::new() {
Ok(ntt) => return Arc::new(ntt),
Err(err) => {
tracing::info!(
error = %err,
"CUDA BN254 IRS backend unavailable, using ProveKit CPU fallback"
);
}
}

Arc::new(CpuIrsCommitter::new(Arc::new(crate::ntt::RSFr)))
}

#[cfg(not(feature = "provekit_ntt"))]
{
Arc::new(CpuIrsCommitter::new(Arc::new(
whir::algebra::ntt::NttEngine::<FieldElement>::new_from_fftfield(),
)))
}
}
File renamed without changes.
Loading
Loading