From a2b61db12bcc20bd92478af886c30e181aa8dcfd Mon Sep 17 00:00:00 2001 From: weikengchen Date: Wed, 23 Apr 2025 17:49:54 +0800 Subject: [PATCH] proving feature --- Cargo.lock | 17 ++- Cargo.toml | 3 + circuit/Cargo.toml | 7 +- circuit/src/layered/circuit.rs | 5 +- circuit/tests/circuit_serde.rs | 1 + circuit/tests/shared_mem.rs | 2 + gkr/Cargo.toml | 7 +- gkr/src/executor.rs | 10 +- gkr/src/lib.rs | 2 + gkr/src/main.rs | 132 ++++++++++++---------- gkr/src/prover/gkr_par_verifier.rs | 39 +------ gkr/src/tests/gkr_correctness.rs | 7 +- gkr/src/verifier.rs | 2 +- gkr/src/verifier/gkr_par_verifier.rs | 39 ++++++- gkr_engine/Cargo.toml | 3 +- gkr_engine/src/field_engine/definition.rs | 1 + gkr_engine/src/mpi_engine/definition.rs | 30 +++-- gkr_engine/src/mpi_engine/engine.rs | 70 +++++++++--- gkr_engine/src/mpi_engine/tests.rs | 4 + gkr_engine/src/poly_commit/definition.rs | 2 + poly_commit/Cargo.toml | 3 + poly_commit/src/hyrax/expander_api.rs | 2 + poly_commit/src/kzg/expander_api.rs | 2 + poly_commit/src/kzg/hyper_bikzg.rs | 6 +- poly_commit/src/orion.rs | 2 + poly_commit/src/orion/expander_api.rs | 12 +- poly_commit/src/orion/mpi_utils.rs | 4 +- poly_commit/src/raw.rs | 2 + poly_commit/tests/common.rs | 1 + poly_commit/tests/test_hyrax.rs | 2 + poly_commit/tests/test_kzg.rs | 2 + poly_commit/tests/test_orion.rs | 2 + poly_commit/tests/test_raw.rs | 2 + sumcheck/Cargo.toml | 1 + sumcheck/src/lib.rs | 1 + sumcheck/src/sumcheck.rs | 6 +- sumcheck/src/utils.rs | 1 + transcript/Cargo.toml | 3 +- transcript/src/lib.rs | 4 +- transcript/src/transcript_utils.rs | 1 + 40 files changed, 289 insertions(+), 153 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbe819b59..8234f3a9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -246,8 +246,7 @@ dependencies = [ [[package]] name = "build-probe-mpi" version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3234fa6de2f6e0e338c7183ba09ae68c8f2bd6919d8763362597627362b7f8fe" +source = "git+https://github.com/0pendansor/rsmpi/?branch=patch-2#bbb572024e460e99e4ee1cfda0e382640b1e32ca" dependencies = [ "pkg-config", "shell-words", @@ -1362,9 +1361,9 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libffi" -version = "3.2.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce826c243048e3d5cec441799724de52e2d42f820468431fc3fceee2341871e2" +checksum = "4a9434b6fc77375fb624698d5f8c49d7e80b10d59eb1219afda27d1f824d4074" dependencies = [ "libc", "libffi-sys", @@ -1372,9 +1371,9 @@ dependencies = [ [[package]] name = "libffi-sys" -version = "2.3.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36115160c57e8529781b4183c2bb51fdc1f6d6d1ed345591d84be7703befb3c" +checksum = "ead36a2496acfc8edd6cc32352110e9478ac5b9b5f5b9856ebd3d28019addb84" dependencies = [ "cc", ] @@ -1487,8 +1486,7 @@ dependencies = [ [[package]] name = "mpi" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677762a4bde2c81158fc566a69b97d11b0c3358694e64f4f922ac5189be311cc" +source = "git+https://github.com/0pendansor/rsmpi/?branch=patch-2#bbb572024e460e99e4ee1cfda0e382640b1e32ca" dependencies = [ "build-probe-mpi", "conv", @@ -1502,8 +1500,7 @@ dependencies = [ [[package]] name = "mpi-sys" version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f35fdd7bdb38959515f008d12598065631de9624f6d42c11caef19e8e0d10de" +source = "git+https://github.com/0pendansor/rsmpi/?branch=patch-2#bbb572024e460e99e4ee1cfda0e382640b1e32ca" dependencies = [ "bindgen", "build-probe-mpi", diff --git a/Cargo.toml b/Cargo.toml index 0fa47ee0f..e45910b11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,3 +55,6 @@ ethnum = "1.5.0" rand_chacha = "0.3.1" derivative = "2.2.0" transpose = "0.2.3" + +[patch.crates-io] +mpi = { git = "https://github.com/0pendansor/rsmpi/", branch = "patch-2" } \ No newline at end of file diff --git a/circuit/Cargo.toml b/circuit/Cargo.toml index b8cbd83d3..40b3c1ae3 100644 --- a/circuit/Cargo.toml +++ b/circuit/Cargo.toml @@ -14,10 +14,13 @@ ark-std.workspace = true bytes.workspace = true ethnum.workspace = true log.workspace = true -mpi.workspace = true +mpi = { workspace = true, optional = true } rand.workspace = true thiserror.workspace = true [dev-dependencies] config_macros = { path = "../config_macros" } -poly_commit = { path = "../poly_commit" } \ No newline at end of file +poly_commit = { path = "../poly_commit" } + +[features] +proving = ["gkr_engine/proving", "transcript/proving", "mpi"] \ No newline at end of file diff --git a/circuit/src/layered/circuit.rs b/circuit/src/layered/circuit.rs index 3c9509a33..a9a4bb187 100644 --- a/circuit/src/layered/circuit.rs +++ b/circuit/src/layered/circuit.rs @@ -7,7 +7,7 @@ use gkr_engine::{ root_println, ExpanderPCS, FieldEngine, GKREngine, MPIConfig, MPIEngine, PolynomialCommitmentType, Transcript, }; -use mpi::ffi::ompi_win_t; +use mpi::ffi::MPI_Win; use serdes::ExpSerde; use crate::*; @@ -168,6 +168,7 @@ impl Circuit { Self::verifier_load_circuit::(filename) } + #[cfg(feature = "proving")] // The root process loads a circuit from a file and shares it with other processes // with shared memory // Used in the mpi case, ok if mpi_size = 1, but @@ -176,7 +177,7 @@ impl Circuit { pub fn prover_load_circuit>( filename: &str, mpi_config: &MPIConfig, - ) -> (Self, *mut ompi_win_t) { + ) -> (Self, MPI_Win) { let circuit = if mpi_config.is_root() { let rc = RecursiveCircuit::::load(filename).unwrap(); let circuit = rc.flatten::(); diff --git a/circuit/tests/circuit_serde.rs b/circuit/tests/circuit_serde.rs index f3d6918fb..e9df73077 100644 --- a/circuit/tests/circuit_serde.rs +++ b/circuit/tests/circuit_serde.rs @@ -38,6 +38,7 @@ declare_gkr_config!( GKRScheme::Vanilla, ); +#[cfg(feature = "proving")] #[test] fn test_circuit_serde() { let mpi_config = MPIConfig::prover_new(); diff --git a/circuit/tests/shared_mem.rs b/circuit/tests/shared_mem.rs index c09d6b668..fa052d14b 100644 --- a/circuit/tests/shared_mem.rs +++ b/circuit/tests/shared_mem.rs @@ -54,6 +54,7 @@ fn load_circuit(mpi_config: &MPIConfig) -> Option( mpi_config: &MPIConfig, diff --git a/gkr/Cargo.toml b/gkr/Cargo.toml index 8a93a6b48..42b64d84a 100644 --- a/gkr/Cargo.toml +++ b/gkr/Cargo.toml @@ -27,7 +27,7 @@ env_logger.workspace = true ethnum.workspace = true halo2curves.workspace = true log.workspace = true -mpi.workspace = true +mpi = {workspace = true, optional = true } rand.workspace = true rayon.workspace = true sha2.workspace = true @@ -47,10 +47,12 @@ criterion.workspace = true [[bin]] name = "gkr-mpi" path = "src/main_mpi.rs" +required-features = ["proving"] [[bin]] name = "expander-exec" path = "src/exec.rs" +required-features = ["proving"] [[bin]] name = "dev-setup" @@ -60,6 +62,7 @@ path = "src/utils.rs" default = [] # default = [ "grinding" ] grinding = [ ] +proving = ["transcript/proving", "gkr_engine/proving", "poly_commit/proving", "circuit/proving", "sumcheck/proving", "mpi"] recursion = [ "transcript/recursion" ] profile = [ "utils/profile", "sumcheck/profile" ] @@ -67,4 +70,4 @@ profile = [ "utils/profile", "sumcheck/profile" ] name = "gkr-hashes" harness = false path = "benches/gkr_hashes.rs" - +required-features = ["proving"] diff --git a/gkr/src/executor.rs b/gkr/src/executor.rs index 6168509cd..56064caad 100644 --- a/gkr/src/executor.rs +++ b/gkr/src/executor.rs @@ -17,7 +17,10 @@ use poly_commit::expander_pcs_init_testing_only; use serdes::{ExpSerde, SerdeError}; use warp::{http::StatusCode, reply, Filter}; -use crate::{Prover, Verifier}; +#[cfg(feature = "proving")] +use crate::Prover; + +use crate::Verifier; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] @@ -37,6 +40,7 @@ pub struct ExpanderExecArgs { #[derive(Debug, Subcommand, Clone)] pub enum ExpanderExecSubCommand { + #[cfg(feature = "proving")] Prove { /// Circuit File Path #[arg(short, long)] @@ -67,6 +71,7 @@ pub enum ExpanderExecSubCommand { #[arg(short, long, default_value_t = 1)] mpi_size: u32, }, + #[cfg(feature = "proving")] Serve { /// Circuit File Path #[arg(short, long)] @@ -119,6 +124,7 @@ pub fn detect_field_type_from_circuit_file(circuit_file: &str) -> FieldType { } } +#[cfg(feature = "proving")] pub fn prove( circuit: &mut Circuit, mpi_config: MPIConfig, @@ -170,6 +176,7 @@ pub async fn run_command( let subcommands = command.subcommands.clone(); match subcommands { + #[cfg(feature = "proving")] ExpanderExecSubCommand::Prove { circuit_file, witness_file, @@ -236,6 +243,7 @@ pub async fn run_command( println!("success"); } + #[cfg(feature = "proving")] ExpanderExecSubCommand::Serve { circuit_file, host_ip, diff --git a/gkr/src/lib.rs b/gkr/src/lib.rs index ec936c8f7..054a77cd4 100644 --- a/gkr/src/lib.rs +++ b/gkr/src/lib.rs @@ -1,6 +1,8 @@ #![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512))] +#[cfg(feature = "proving")] pub mod prover; +#[cfg(feature = "proving")] pub use prover::*; pub mod verifier; diff --git a/gkr/src/main.rs b/gkr/src/main.rs index b6ffc63fc..ab35d229f 100644 --- a/gkr/src/main.rs +++ b/gkr/src/main.rs @@ -16,8 +16,12 @@ use gkr::{ BN254ConfigMIMC5KZG, BN254ConfigSha2Hyrax, BN254ConfigSha2Raw, GF2ExtConfigSha2Orion, GF2ExtConfigSha2Raw, GoldilocksExtConfigSha2Orion, GoldilocksExtConfigSha2Raw, M31ExtConfigSha2OrionSquare, M31ExtConfigSha2OrionVanilla, M31ExtConfigSha2RawSquare, - M31ExtConfigSha2RawVanilla, Prover, + M31ExtConfigSha2RawVanilla, }; + +#[cfg(feature = "proving")] +use gkr::Prover; + use gkr_engine::{ ExpanderPCS, FieldEngine, FieldType, GKREngine, MPIConfig, MPIEngine, PolynomialCommitmentType, }; @@ -53,72 +57,82 @@ fn main() { let args = Args::parse(); print_info(&args); - let mpi_config = MPIConfig::prover_new(); - let pcs_type = PolynomialCommitmentType::from_str(&args.pcs).unwrap(); + #[cfg(feature = "proving")] + { + let mpi_config = MPIConfig::prover_new(); + let pcs_type = PolynomialCommitmentType::from_str(&args.pcs).unwrap(); - match args.field.as_str() { - "m31ext3" => match pcs_type { - PolynomialCommitmentType::Raw => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - "poseidon" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), - }, - PolynomialCommitmentType::Orion => match args.circuit.as_str() { - "keccak" => { - run_benchmark::(&args, mpi_config.clone()) - } - "poseidon" => { - run_benchmark::(&args, mpi_config.clone()) - } - _ => unreachable!(""), - }, - _ => unreachable!("Unsupported PCS type for M31"), - }, - "fr" => match pcs_type { - PolynomialCommitmentType::Raw => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), - }, - PolynomialCommitmentType::Hyrax => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), - }, - PolynomialCommitmentType::KZG => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), + match args.field.as_str() { + "m31ext3" => match pcs_type { + PolynomialCommitmentType::Raw => match args.circuit.as_str() { + "keccak" => { + run_benchmark::(&args, mpi_config.clone()) + } + "poseidon" => { + run_benchmark::(&args, mpi_config.clone()) + } + _ => unreachable!(), + }, + PolynomialCommitmentType::Orion => match args.circuit.as_str() { + "keccak" => { + run_benchmark::(&args, mpi_config.clone()) + } + "poseidon" => { + run_benchmark::(&args, mpi_config.clone()) + } + _ => unreachable!(""), + }, + _ => unreachable!("Unsupported PCS type for M31"), }, - _ => unreachable!("Unsupported PCS type for BN254"), - }, - "gf2ext128" => match pcs_type { - PolynomialCommitmentType::Raw => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), + "fr" => match pcs_type { + PolynomialCommitmentType::Raw => match args.circuit.as_str() { + "keccak" => run_benchmark::(&args, mpi_config.clone()), + _ => unreachable!(), + }, + PolynomialCommitmentType::Hyrax => match args.circuit.as_str() { + "keccak" => run_benchmark::(&args, mpi_config.clone()), + _ => unreachable!(), + }, + PolynomialCommitmentType::KZG => match args.circuit.as_str() { + "keccak" => run_benchmark::(&args, mpi_config.clone()), + _ => unreachable!(), + }, + _ => unreachable!("Unsupported PCS type for BN254"), }, - PolynomialCommitmentType::Orion => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), + "gf2ext128" => match pcs_type { + PolynomialCommitmentType::Raw => match args.circuit.as_str() { + "keccak" => run_benchmark::(&args, mpi_config.clone()), + _ => unreachable!(), + }, + PolynomialCommitmentType::Orion => match args.circuit.as_str() { + "keccak" => run_benchmark::(&args, mpi_config.clone()), + _ => unreachable!(), + }, + _ => unreachable!("Unsupported PCS type for GF2"), }, - _ => unreachable!("Unsupported PCS type for GF2"), - }, - "goldilocks" => match pcs_type { - PolynomialCommitmentType::Raw => match args.circuit.as_str() { - "keccak" => run_benchmark::(&args, mpi_config.clone()), - _ => unreachable!(), - }, - PolynomialCommitmentType::Orion => match args.circuit.as_str() { - "keccak" => { - run_benchmark::(&args, mpi_config.clone()) - } - _ => unreachable!(), + "goldilocks" => match pcs_type { + PolynomialCommitmentType::Raw => match args.circuit.as_str() { + "keccak" => { + run_benchmark::(&args, mpi_config.clone()) + } + _ => unreachable!(), + }, + PolynomialCommitmentType::Orion => match args.circuit.as_str() { + "keccak" => { + run_benchmark::(&args, mpi_config.clone()) + } + _ => unreachable!(), + }, + _ => unreachable!("Unsupported PCS type for Goldilocks"), }, - _ => unreachable!("Unsupported PCS type for Goldilocks"), - }, - _ => unreachable!(), - }; + _ => unreachable!(), + }; - MPIConfig::finalize(); + MPIConfig::finalize(); + } } +#[cfg(feature = "proving")] fn run_benchmark<'a, Cfg: GKREngine>(args: &'a Args, mpi_config: MPIConfig) where >::ScratchPad: 'a, diff --git a/gkr/src/prover/gkr_par_verifier.rs b/gkr/src/prover/gkr_par_verifier.rs index b3f910346..a7e0d395a 100644 --- a/gkr/src/prover/gkr_par_verifier.rs +++ b/gkr/src/prover/gkr_par_verifier.rs @@ -1,3 +1,4 @@ +use crate::verifier::SumcheckLayerState; use circuit::Circuit; use gkr_engine::{ ExpanderDualVarChallenge, ExpanderSingleVarChallenge, FieldEngine, MPIEngine, Transcript, @@ -6,44 +7,6 @@ use serdes::ExpSerde; use sumcheck::{sumcheck_prove_gkr_layer, ProverScratchPad}; use utils::timer::Timer; -#[derive(Debug, Clone, PartialEq)] -pub struct SumcheckLayerState { - pub transcript_state: Vec, - pub challenge: ExpanderDualVarChallenge, - pub alpha: Option, - pub claimed_v0: F::ChallengeField, - pub claimed_v1: Option, -} - -impl ExpSerde for SumcheckLayerState { - const SERIALIZED_SIZE: usize = unimplemented!(); - - fn serialize_into(&self, mut writer: W) -> serdes::SerdeResult<()> { - self.transcript_state.serialize_into(&mut writer)?; - self.challenge.serialize_into(&mut writer)?; - self.alpha.serialize_into(&mut writer)?; - self.claimed_v0.serialize_into(&mut writer)?; - self.claimed_v1.serialize_into(&mut writer)?; - Ok(()) - } - - fn deserialize_from(mut reader: R) -> serdes::SerdeResult { - let transcript_state = Vec::deserialize_from(&mut reader)?; - let challenge = ExpanderDualVarChallenge::::deserialize_from(&mut reader)?; - let alpha = Option::::deserialize_from(&mut reader)?; - let claimed_v0 = F::ChallengeField::deserialize_from(&mut reader)?; - let claimed_v1 = Option::::deserialize_from(&mut reader)?; - - Ok(Self { - transcript_state, - challenge, - alpha, - claimed_v0, - claimed_v1, - }) - } -} - #[allow(clippy::too_many_arguments)] pub fn checkpoint_sumcheck_layer_state( challenge: &ExpanderDualVarChallenge, diff --git a/gkr/src/tests/gkr_correctness.rs b/gkr/src/tests/gkr_correctness.rs index e9e1fb2be..d4471d2b2 100644 --- a/gkr/src/tests/gkr_correctness.rs +++ b/gkr/src/tests/gkr_correctness.rs @@ -23,8 +23,12 @@ use serdes::ExpSerde; use sha2::Digest; use transcript::{BytesHashTranscript, FieldHashTranscript}; -use crate::{utils::*, Prover, Verifier}; +use crate::{utils::*, Verifier}; +#[cfg(feature = "proving")] +use crate::Prover; + +#[cfg(feature = "proving")] #[test] fn test_gkr_correctness() { // Initialize logger @@ -171,6 +175,7 @@ fn test_gkr_correctness() { MPIConfig::finalize(); } +#[cfg(feature = "proving")] #[allow(unreachable_patterns)] fn test_gkr_correctness_helper(write_proof_to: Option<&str>) { let mpi_config = MPIConfig::prover_new(); diff --git a/gkr/src/verifier.rs b/gkr/src/verifier.rs index 16106568e..8ff4b1297 100644 --- a/gkr/src/verifier.rs +++ b/gkr/src/verifier.rs @@ -27,7 +27,7 @@ mod gkr_square; pub use gkr_square::gkr_square_verify; mod gkr_par_verifier; -pub use gkr_par_verifier::gkr_par_verifier_verify; +pub use gkr_par_verifier::{gkr_par_verifier_verify, SumcheckLayerState}; #[derive(Default)] pub struct Verifier { diff --git a/gkr/src/verifier/gkr_par_verifier.rs b/gkr/src/verifier/gkr_par_verifier.rs index c3c48dc0b..d7a30904d 100644 --- a/gkr/src/verifier/gkr_par_verifier.rs +++ b/gkr/src/verifier/gkr_par_verifier.rs @@ -14,7 +14,44 @@ use sumcheck::{VerifierScratchPad, SUMCHECK_GKR_DEGREE, SUMCHECK_GKR_SIMD_MPI_DE use utils::timer::Timer; use super::common::sumcheck_verify_gkr_layer; -use crate::prover::gkr_par_verifier::SumcheckLayerState; + +#[derive(Debug, Clone, PartialEq)] +pub struct SumcheckLayerState { + pub transcript_state: Vec, + pub challenge: ExpanderDualVarChallenge, + pub alpha: Option, + pub claimed_v0: F::ChallengeField, + pub claimed_v1: Option, +} + +impl ExpSerde for SumcheckLayerState { + const SERIALIZED_SIZE: usize = unimplemented!(); + + fn serialize_into(&self, mut writer: W) -> serdes::SerdeResult<()> { + self.transcript_state.serialize_into(&mut writer)?; + self.challenge.serialize_into(&mut writer)?; + self.alpha.serialize_into(&mut writer)?; + self.claimed_v0.serialize_into(&mut writer)?; + self.claimed_v1.serialize_into(&mut writer)?; + Ok(()) + } + + fn deserialize_from(mut reader: R) -> serdes::SerdeResult { + let transcript_state = Vec::deserialize_from(&mut reader)?; + let challenge = ExpanderDualVarChallenge::::deserialize_from(&mut reader)?; + let alpha = Option::::deserialize_from(&mut reader)?; + let claimed_v0 = F::ChallengeField::deserialize_from(&mut reader)?; + let claimed_v1 = Option::::deserialize_from(&mut reader)?; + + Ok(Self { + transcript_state, + challenge, + alpha, + claimed_v0, + claimed_v1, + }) + } +} pub fn parse_proof( circuit: &Circuit, diff --git a/gkr_engine/Cargo.toml b/gkr_engine/Cargo.toml index 6faea60ba..962df1567 100644 --- a/gkr_engine/Cargo.toml +++ b/gkr_engine/Cargo.toml @@ -14,7 +14,7 @@ polynomials = { path = "../arith/polynomials"} serdes = { path = "../serdes" } thiserror.workspace = true -mpi.workspace = true +mpi = { workspace = true, optional = true } rand.workspace = true itertools.workspace = true @@ -23,4 +23,5 @@ ark-std.workspace = true [features] default = [] +proving = ["mpi"] # grinding = [ "grinding" ] \ No newline at end of file diff --git a/gkr_engine/src/field_engine/definition.rs b/gkr_engine/src/field_engine/definition.rs index 06901b90c..ed8fc913b 100644 --- a/gkr_engine/src/field_engine/definition.rs +++ b/gkr_engine/src/field_engine/definition.rs @@ -123,6 +123,7 @@ pub trait FieldEngine: Default + Debug + Clone + Send + Sync + PartialEq + 'stat } } + #[cfg(feature = "proving")] /// This assumes each mpi core hold their own evals, and collectively /// compute the global evaluation. /// Mostly used by the prover run with `mpiexec` diff --git a/gkr_engine/src/mpi_engine/definition.rs b/gkr_engine/src/mpi_engine/definition.rs index d0e44dc9d..da2c57d4e 100644 --- a/gkr_engine/src/mpi_engine/definition.rs +++ b/gkr_engine/src/mpi_engine/definition.rs @@ -1,4 +1,7 @@ use arith::Field; +#[cfg(feature = "proving")] +use mpi::ffi::MPI_Win; +#[cfg(feature = "proving")] use mpi::{ ffi::{ompi_win_t, MPI_Win_free}, topology::Process, @@ -15,13 +18,16 @@ pub trait MPIEngine { /// The maximum chunk size for MPI communications const CHUNK_SIZE: usize; + #[cfg(feature = "proving")] /// Initialize the MPI environment. /// Safe to call multiple times as `mpi::initialize()` will return None if already initialized. fn init(); + #[cfg(feature = "proving")] /// Finalize the MPI environment fn finalize(); + #[cfg(feature = "proving")] /// Create a new MPI engine for the prover fn prover_new() -> Self; @@ -31,6 +37,7 @@ pub trait MPIEngine { /// * `world_size` - The total number of processes in the MPI world fn verifier_new(world_size: i32) -> Self; + #[cfg(feature = "proving")] /// Gather vectors from all processes into the root process /// /// # Arguments @@ -42,6 +49,7 @@ pub trait MPIEngine { /// - Non-root processes send their vectors but don't modify global_vec fn gather_vec(&self, local_vec: &[F], global_vec: &mut Vec); + #[cfg(feature = "proving")] /// Broadcast a field element from root process to all processes /// /// # Arguments @@ -52,6 +60,7 @@ pub trait MPIEngine { /// - All other processes receive the value fn root_broadcast_f(&self, f: &mut F); + #[cfg(feature = "proving")] /// Broadcast a vector of bytes from root process to all processes /// /// # Arguments @@ -62,6 +71,7 @@ pub trait MPIEngine { /// - All other processes receive the bytes fn root_broadcast_bytes(&self, bytes: &mut Vec); + #[cfg(feature = "proving")] /// Sum up field elements across all processes /// /// # Arguments @@ -71,6 +81,7 @@ pub trait MPIEngine { /// A vector containing the sum of corresponding elements from all processes fn sum_vec(&self, local_vec: &[F]) -> Vec; + #[cfg(feature = "proving")] /// Combines vectors from all MPI processes using weighted coefficients /// /// # Arguments @@ -87,6 +98,7 @@ pub trait MPIEngine { /// Non-root processes participate in gathering but return zero vectors. fn coef_combine_vec(&self, local_vec: &[F], coef: &[F]) -> Vec; + #[cfg(feature = "proving")] /// Perform matrix transpose with other MPI processes through MPI all-to-all transpose /// /// # Arguments @@ -98,6 +110,7 @@ pub trait MPIEngine { /// (e.g., rows to columns in a distributed matrix) fn all_to_all_transpose(&self, row: &mut [F]); + #[cfg(feature = "proving")] /// Gather *variable length* vectors from all processes into the root process /// /// # Arguments @@ -125,6 +138,7 @@ pub trait MPIEngine { #[allow(clippy::ptr_arg)] fn gather_varlen_vec(&self, local_vec: &Vec, global_vec: &mut Vec>); + #[cfg(feature = "proving")] /// Check if there is only one process in the MPI world fn is_single_process(&self) -> bool; @@ -140,20 +154,21 @@ pub trait MPIEngine { self.world_rank() == Self::ROOT_RANK as usize } + #[cfg(feature = "proving")] /// Get the root process handle fn root_process(&self) -> Process; + #[cfg(feature = "proving")] /// Synchronize all processes at this point fn barrier(&self); /// Create a shared memory segment for inter-process communication - fn create_shared_mem(&self, n_bytes: usize) -> (*mut u8, *mut ompi_win_t); + #[cfg(feature = "proving")] + fn create_shared_mem(&self, n_bytes: usize) -> (*mut u8, MPI_Win); /// Consume the shared memory segment and create a new shared memory object - fn consume_obj_and_create_shared( - &self, - obj: Option, - ) -> (T, *mut ompi_win_t) { + #[cfg(feature = "proving")] + fn consume_obj_and_create_shared(&self, obj: Option) -> (T, MPI_Win) { assert!(!self.is_root() || obj.is_some()); if self.is_root() { @@ -171,10 +186,11 @@ pub trait MPIEngine { } } + #[cfg(feature = "proving")] /// Discard the control of shared memory segment - fn free_shared_mem(&self, window: &mut *mut ompi_win_t) { + fn free_shared_mem(&self, window: *mut MPI_Win) { unsafe { - MPI_Win_free(window as *mut *mut ompi_win_t); + MPI_Win_free(window); } } } diff --git a/gkr_engine/src/mpi_engine/engine.rs b/gkr_engine/src/mpi_engine/engine.rs index 3c5c2723a..241be64cc 100644 --- a/gkr_engine/src/mpi_engine/engine.rs +++ b/gkr_engine/src/mpi_engine/engine.rs @@ -3,6 +3,7 @@ use std::{cmp, fmt::Debug}; use arith::Field; use itertools::izip; +#[cfg(feature = "proving")] use mpi::{ datatype::PartitionMut, environment::Universe, @@ -24,12 +25,16 @@ macro_rules! root_println { }; } +#[cfg(feature = "proving")] static mut UNIVERSE: Option = None; +#[cfg(feature = "proving")] static mut WORLD: Option = None; #[derive(Clone)] pub struct MPIConfig { + #[cfg(feature = "proving")] pub universe: Option<&'static mpi::environment::Universe>, + #[cfg(feature = "proving")] pub world: Option<&'static SimpleCommunicator>, pub world_size: i32, pub world_rank: i32, @@ -38,7 +43,9 @@ pub struct MPIConfig { impl Default for MPIConfig { fn default() -> Self { Self { + #[cfg(feature = "proving")] universe: None, + #[cfg(feature = "proving")] world: None, world_size: 1, world_rank: 0, @@ -48,24 +55,35 @@ impl Default for MPIConfig { impl Debug for MPIConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let universe_fmt = if self.universe.is_none() { - Option::::None - } else { - Some(self.universe.unwrap().buffer_size()) - }; + #[cfg(feature = "proving")] + { + let universe_fmt = if self.universe.is_none() { + Option::::None + } else { + Some(self.universe.unwrap().buffer_size()) + }; - let world_fmt = if self.world.is_none() { - Option::::None - } else { - Some(0usize) - }; + let world_fmt = if self.world.is_none() { + Option::::None + } else { + Some(0usize) + }; + + f.debug_struct("MPIConfig") + .field("universe", &universe_fmt) + .field("world", &world_fmt) + .field("world_size", &self.world_size) + .field("world_rank", &self.world_rank) + .finish() + } - f.debug_struct("MPIConfig") - .field("universe", &universe_fmt) - .field("world", &world_fmt) - .field("world_size", &self.world_size) - .field("world_rank", &self.world_rank) - .finish() + #[cfg(not(feature = "proving"))] + { + f.debug_struct("MPIConfig") + .field("world_size", &self.world_size) + .field("world_rank", &self.world_rank) + .finish() + } } } @@ -85,6 +103,7 @@ impl MPIEngine for MPIConfig { // OK if already initialized, mpi::initialize() will return None #[allow(static_mut_refs)] + #[cfg(feature = "proving")] fn init() { unsafe { let universe = mpi::initialize(); @@ -96,10 +115,12 @@ impl MPIEngine for MPIConfig { } #[inline] + #[cfg(feature = "proving")] fn finalize() { unsafe { ffi::MPI_Finalize() }; } + #[cfg(feature = "proving")] #[allow(static_mut_refs)] fn prover_new() -> Self { Self::init(); @@ -126,13 +147,16 @@ impl MPIEngine for MPIConfig { #[inline] fn verifier_new(world_size: i32) -> Self { Self { + #[cfg(feature = "proving")] universe: None, + #[cfg(feature = "proving")] world: None, world_size, world_rank: 0, } } + #[cfg(feature = "proving")] #[allow(clippy::collapsible_else_if)] fn gather_vec(&self, local_vec: &[F], global_vec: &mut Vec) { unsafe { @@ -196,6 +220,7 @@ impl MPIEngine for MPIConfig { } /// Root process broadcast a value f into all the processes + #[cfg(feature = "proving")] #[inline] fn root_broadcast_f(&self, f: &mut F) { unsafe { @@ -208,12 +233,14 @@ impl MPIEngine for MPIConfig { } } + #[cfg(feature = "proving")] #[inline] fn root_broadcast_bytes(&self, bytes: &mut Vec) { self.root_process().broadcast_into(bytes); } /// sum up all local values + #[cfg(feature = "proving")] #[inline] fn sum_vec(&self, local_vec: &[F]) -> Vec { if self.world_size == 1 { @@ -235,6 +262,7 @@ impl MPIEngine for MPIConfig { } /// coef has a length of mpi_world_size + #[cfg(feature = "proving")] #[inline] fn coef_combine_vec(&self, local_vec: &[F], coef: &[F]) -> Vec { if self.world_size == 1 { @@ -259,6 +287,7 @@ impl MPIEngine for MPIConfig { /// perform an all to all transpose, /// supposing the current party holds a row in a matrix with row number being MPI parties. + #[cfg(feature = "proving")] #[inline(always)] fn all_to_all_transpose(&self, row: &mut [F]) { assert_eq!(row.len() % self.world_size(), 0); @@ -311,6 +340,7 @@ impl MPIEngine for MPIConfig { }); } + #[cfg(feature = "proving")] #[inline(always)] fn gather_varlen_vec(&self, elems: &Vec, global_elems: &mut Vec>) { let mut elems_bytes: Vec = Vec::new(); @@ -346,6 +376,7 @@ impl MPIEngine for MPIConfig { } } + #[cfg(feature = "proving")] #[inline(always)] fn is_single_process(&self) -> bool { self.world_size == 1 @@ -361,6 +392,7 @@ impl MPIEngine for MPIConfig { self.world_rank as usize } + #[cfg(feature = "proving")] #[inline(always)] fn root_process(&self) -> Process { self.world.unwrap().process_at_rank(Self::ROOT_RANK) @@ -368,6 +400,7 @@ impl MPIEngine for MPIConfig { // Barrier is designed for mpi use only // There might be some issues if used with multi-threading + #[cfg(feature = "proving")] #[inline(always)] fn barrier(&self) { if self.world_size > 1 { @@ -375,11 +408,12 @@ impl MPIEngine for MPIConfig { } } + #[cfg(feature = "proving")] #[inline] - fn create_shared_mem(&self, n_bytes: usize) -> (*mut u8, *mut ompi_win_t) { + fn create_shared_mem(&self, n_bytes: usize) -> (*mut u8, MPI_Win) { let window_size = if self.is_root() { n_bytes } else { 0 }; let mut baseptr: *mut c_void = std::ptr::null_mut(); - let mut window = std::ptr::null_mut(); + let mut window = MPI_Win(std::ptr::null_mut()); unsafe { MPI_Win_allocate_shared( window_size as isize, diff --git a/gkr_engine/src/mpi_engine/tests.rs b/gkr_engine/src/mpi_engine/tests.rs index 2e10dd265..ea47d4863 100644 --- a/gkr_engine/src/mpi_engine/tests.rs +++ b/gkr_engine/src/mpi_engine/tests.rs @@ -6,6 +6,7 @@ use mersenne31::{M31Ext3, M31x16, M31}; use crate::{MPIConfig, MPIEngine}; +#[cfg(feature = "proving")] fn test_gather_vec_helper(mpi_config: &MPIConfig) { const TEST_SIZE: usize = (1 << 10) + 1; @@ -28,6 +29,7 @@ fn test_gather_vec_helper(mpi_config: &MPIConfig) { } } +#[cfg(feature = "proving")] fn test_varlen_gather_vec_helper(mpi_config: &MPIConfig) { let msg: Vec<_> = (0..=mpi_config.world_rank()).collect(); let mut global_elems: Vec> = Vec::new(); @@ -43,6 +45,7 @@ fn test_varlen_gather_vec_helper(mpi_config: &MPIConfig) { }); } +#[cfg(feature = "proving")] fn test_all_to_all_transpose_helper(mpi_config: &MPIConfig) { const TEST_MATRIX_LEN: usize = 1 << 23; @@ -80,6 +83,7 @@ fn test_all_to_all_transpose_helper(mpi_config: &MPIConfig) { }); } +#[cfg(feature = "proving")] #[test] fn test_mpi_engine() { let mpi_config = MPIConfig::prover_new(); diff --git a/gkr_engine/src/poly_commit/definition.rs b/gkr_engine/src/poly_commit/definition.rs index 3f0a80fa9..aa7386861 100644 --- a/gkr_engine/src/poly_commit/definition.rs +++ b/gkr_engine/src/poly_commit/definition.rs @@ -59,6 +59,7 @@ pub trait ExpanderPCS { /// Each process returns its own scratch pad. fn init_scratch_pad(params: &Self::Params, mpi_engine: &impl MPIEngine) -> Self::ScratchPad; + #[cfg(feature = "proving")] /// Commit to a polynomial. Root process returns the commitment, other processes can return /// arbitrary value. fn commit( @@ -69,6 +70,7 @@ pub trait ExpanderPCS { scratch_pad: &mut Self::ScratchPad, ) -> Option; + #[cfg(feature = "proving")] /// Open the polynomial at a point. /// Root process returns the opening, other processes can return arbitrary value. /// diff --git a/poly_commit/Cargo.toml b/poly_commit/Cargo.toml index 431beb4c2..82b561200 100644 --- a/poly_commit/Cargo.toml +++ b/poly_commit/Cargo.toml @@ -41,3 +41,6 @@ harness = false [[bench]] name = "kzg" harness = false + +[features] +proving = ["gkr_engine/proving", "transcript/proving"] \ No newline at end of file diff --git a/poly_commit/src/hyrax/expander_api.rs b/poly_commit/src/hyrax/expander_api.rs index 6a03da408..eeea84d85 100644 --- a/poly_commit/src/hyrax/expander_api.rs +++ b/poly_commit/src/hyrax/expander_api.rs @@ -50,6 +50,7 @@ where (hyrax_setup(*params, rng), *params) } + #[cfg(feature = "proving")] fn commit( _params: &Self::Params, mpi_engine: &impl MPIEngine, @@ -77,6 +78,7 @@ where HyraxCommitment(global_commit).into() } + #[cfg(feature = "proving")] fn open( _params: &Self::Params, mpi_engine: &impl MPIEngine, diff --git a/poly_commit/src/kzg/expander_api.rs b/poly_commit/src/kzg/expander_api.rs index 4427f02a2..acd6c154c 100644 --- a/poly_commit/src/kzg/expander_api.rs +++ b/poly_commit/src/kzg/expander_api.rs @@ -53,6 +53,7 @@ where (srs, local_num_vars) } + #[cfg(feature = "proving")] fn commit( _params: &Self::Params, mpi_engine: &impl MPIEngine, @@ -80,6 +81,7 @@ where KZGCommitment(final_commit).into() } + #[cfg(feature = "proving")] fn open( _params: &Self::Params, mpi_engine: &impl MPIEngine, diff --git a/poly_commit/src/kzg/hyper_bikzg.rs b/poly_commit/src/kzg/hyper_bikzg.rs index f1fe789f2..0f486d39e 100644 --- a/poly_commit/src/kzg/hyper_bikzg.rs +++ b/poly_commit/src/kzg/hyper_bikzg.rs @@ -14,10 +14,14 @@ use halo2curves::{ use itertools::{chain, izip}; use polynomials::MultilinearExtension; use serdes::ExpSerde; -use transcript::{transcript_root_broadcast, transcript_verifier_sync}; +use transcript::transcript_verifier_sync; + +#[cfg(feature = "proving")] +use transcript::transcript_root_broadcast; use crate::*; +#[cfg(feature = "proving")] pub fn coeff_form_hyper_bikzg_open( srs: &CoefFormBiKZGLocalSRS, mpi_engine: &impl MPIEngine, diff --git a/poly_commit/src/orion.rs b/poly_commit/src/orion.rs index 911bc1646..fa8fb485b 100644 --- a/poly_commit/src/orion.rs +++ b/poly_commit/src/orion.rs @@ -15,7 +15,9 @@ pub use simd_field_impl::{orion_commit_simd_field, orion_open_simd_field}; mod mpi_utils; +#[cfg(feature = "proving")] mod simd_field_mpi_impl; +#[cfg(feature = "proving")] pub use simd_field_mpi_impl::{orion_mpi_commit_simd_field, orion_mpi_open_simd_field}; mod verify; diff --git a/poly_commit/src/orion/expander_api.rs b/poly_commit/src/orion/expander_api.rs index e60fea882..e80caccfe 100644 --- a/poly_commit/src/orion/expander_api.rs +++ b/poly_commit/src/orion/expander_api.rs @@ -5,12 +5,15 @@ use gkr_engine::{ }; use polynomials::MultilinearExtension; +use crate::orion::{ + verify::orion_verify, OrionCommitment, OrionProof, OrionSIMDFieldPCS, OrionSRS, + OrionScratchPad, ORION_CODE_PARAMETER_INSTANCE, +}; + +#[cfg(feature = "proving")] use crate::orion::{ simd_field_impl::{orion_commit_simd_field, orion_open_simd_field}, simd_field_mpi_impl::{orion_mpi_commit_simd_field, orion_mpi_open_simd_field}, - verify::orion_verify, - OrionCommitment, OrionProof, OrionSIMDFieldPCS, OrionSRS, OrionScratchPad, - ORION_CODE_PARAMETER_INSTANCE, }; impl ExpanderPCS @@ -57,7 +60,7 @@ where fn init_scratch_pad(_params: &Self::Params, _mpi_engine: &impl MPIEngine) -> Self::ScratchPad { Self::ScratchPad::default() } - + #[cfg(feature = "proving")] fn commit( params: &Self::Params, mpi_engine: &impl MPIEngine, @@ -86,6 +89,7 @@ where .ok() } + #[cfg(feature = "proving")] fn open( params: &Self::Params, mpi_engine: &impl MPIEngine, diff --git a/poly_commit/src/orion/mpi_utils.rs b/poly_commit/src/orion/mpi_utils.rs index 4c69bdfa3..5b8723768 100644 --- a/poly_commit/src/orion/mpi_utils.rs +++ b/poly_commit/src/orion/mpi_utils.rs @@ -102,7 +102,7 @@ eventually, a final transpose each row lead to results of ordering by *WHOLE* in After all these, we can go onwards to MT commitment, and later open alphabets lies in one of the parties. */ - +#[cfg(feature = "proving")] #[inline(always)] pub(crate) fn mpi_commit_encoded( mpi_engine: &impl MPIEngine, @@ -199,7 +199,7 @@ where Ok(root) } - +#[cfg(feature = "proving")] #[inline(always)] pub(crate) fn orion_mpi_mt_openings( mpi_engine: &impl MPIEngine, diff --git a/poly_commit/src/raw.rs b/poly_commit/src/raw.rs index 4c3b92454..830fbad6c 100644 --- a/poly_commit/src/raw.rs +++ b/poly_commit/src/raw.rs @@ -148,6 +148,7 @@ impl ExpanderPCS for RawExpanderGKR { fn init_scratch_pad(_params: &Self::Params, _mpi_engine: &impl MPIEngine) -> Self::ScratchPad {} + #[cfg(feature = "proving")] fn commit( params: &Self::Params, mpi_engine: &impl MPIEngine, @@ -179,6 +180,7 @@ impl ExpanderPCS for RawExpanderGKR { Self::Commitment { evals: buffer }.into() } + #[cfg(feature = "proving")] fn open( _params: &Self::Params, _mpi_engine: &impl MPIEngine, diff --git a/poly_commit/tests/common.rs b/poly_commit/tests/common.rs index ff636f7fb..b4098b3ae 100644 --- a/poly_commit/tests/common.rs +++ b/poly_commit/tests/common.rs @@ -44,6 +44,7 @@ pub fn test_pcs, P: PolynomialCommitmentSche } } +#[cfg(feature = "proving")] pub fn test_pcs_for_expander_gkr< C: FieldEngine, T: Transcript, diff --git a/poly_commit/tests/test_hyrax.rs b/poly_commit/tests/test_hyrax.rs index 0f53dd649..84b4f1091 100644 --- a/poly_commit/tests/test_hyrax.rs +++ b/poly_commit/tests/test_hyrax.rs @@ -31,6 +31,7 @@ fn test_hyrax_pcs_e2e() { test_hyrax_pcs_generics(3, 17) } +#[cfg(feature = "proving")] fn test_hyrax_for_expander_gkr_generics(mpi_config_ref: &MPIConfig, total_num_vars: usize) { let mut rng = test_rng(); @@ -73,6 +74,7 @@ fn test_hyrax_for_expander_gkr_generics(mpi_config_ref: &MPIConfig, total_num_va ); } +#[cfg(feature = "proving")] #[test] fn test_hyrax_for_expander_gkr() { let mpi_config = MPIConfig::prover_new(); diff --git a/poly_commit/tests/test_kzg.rs b/poly_commit/tests/test_kzg.rs index 823aa2bc2..37bf747b4 100644 --- a/poly_commit/tests/test_kzg.rs +++ b/poly_commit/tests/test_kzg.rs @@ -31,6 +31,7 @@ fn test_hyperkzg_pcs_full_e2e() { test_hyperkzg_pcs_generics(2, 15) } +#[cfg(feature = "proving")] fn test_hyper_bikzg_for_expander_gkr_generics(mpi_config_ref: &MPIConfig, total_num_vars: usize) { let mut rng = test_rng(); @@ -73,6 +74,7 @@ fn test_hyper_bikzg_for_expander_gkr_generics(mpi_config_ref: &MPIConfig, total_ ); } +#[cfg(feature = "proving")] #[test] fn test_hyper_bikzg_for_expander_gkr() { let mpi_config = MPIConfig::prover_new(); diff --git a/poly_commit/tests/test_orion.rs b/poly_commit/tests/test_orion.rs index a5c7538cd..b4fb658fb 100644 --- a/poly_commit/tests/test_orion.rs +++ b/poly_commit/tests/test_orion.rs @@ -55,6 +55,7 @@ fn test_orion_simd_pcs_full_e2e() { test_orion_simd_pcs_generics::(16, 22) } +#[cfg(feature = "proving")] fn test_orion_for_expander_gkr_generics( mpi_config_ref: &MPIConfig, total_num_vars: usize, @@ -115,6 +116,7 @@ fn test_orion_for_expander_gkr_generics( ); } +#[cfg(feature = "proving")] #[test] fn test_orion_for_expander_gkr() { let mpi_config = MPIConfig::prover_new(); diff --git a/poly_commit/tests/test_raw.rs b/poly_commit/tests/test_raw.rs index 65c29d80e..9013e4a21 100644 --- a/poly_commit/tests/test_raw.rs +++ b/poly_commit/tests/test_raw.rs @@ -30,6 +30,7 @@ fn test_raw() { ); } +#[cfg(feature = "proving")] fn test_raw_gkr_helper>( mpi_config: &MPIConfig, transcript: &mut T, @@ -59,6 +60,7 @@ fn test_raw_gkr_helper>( ); } +#[cfg(feature = "proving")] #[test] fn test_raw_gkr() { let mpi_config = MPIConfig::prover_new(); diff --git a/sumcheck/Cargo.toml b/sumcheck/Cargo.toml index 4fa75da6e..0b374c2f5 100644 --- a/sumcheck/Cargo.toml +++ b/sumcheck/Cargo.toml @@ -16,3 +16,4 @@ log.workspace = true [features] profile = [ "utils/profile" ] +proving = ["gkr_engine/proving"] \ No newline at end of file diff --git a/sumcheck/src/lib.rs b/sumcheck/src/lib.rs index 18d61b7fc..ccee38351 100644 --- a/sumcheck/src/lib.rs +++ b/sumcheck/src/lib.rs @@ -1,6 +1,7 @@ mod sumcheck; pub use sumcheck::*; +#[cfg(feature = "proving")] mod prover_helper; mod verifier_helper; diff --git a/sumcheck/src/sumcheck.rs b/sumcheck/src/sumcheck.rs index de14dd3eb..d76f4dc1b 100644 --- a/sumcheck/src/sumcheck.rs +++ b/sumcheck/src/sumcheck.rs @@ -4,12 +4,14 @@ use gkr_engine::{ Transcript, }; +#[cfg(feature = "proving")] use crate::{ prover_helper::{SumcheckGkrSquareHelper, SumcheckGkrVanillaHelper}, utils::transcript_io, - ProverScratchPad, }; +use crate::ProverScratchPad; + /// The degree of the polynomial for sumcheck, which is 2 for non-SIMD/MPI variables /// and 3 for SIMD/MPI variables. pub const SUMCHECK_GKR_DEGREE: usize = 2; @@ -19,6 +21,7 @@ pub const SUMCHECK_GKR_SIMD_MPI_DEGREE: usize = 3; /// It is 6 for both SIMD/MPI and non-SIMD/MPI variables. pub const SUMCHECK_GKR_SQUARE_DEGREE: usize = 6; +#[cfg(feature = "proving")] // FIXME #[allow(clippy::too_many_arguments)] #[allow(clippy::type_complexity)] @@ -91,6 +94,7 @@ pub fn sumcheck_prove_gkr_layer (vx_claim, vy_claim) } +#[cfg(feature = "proving")] // FIXME #[allow(clippy::needless_range_loop)] // todo: remove #[allow(clippy::type_complexity)] diff --git a/sumcheck/src/utils.rs b/sumcheck/src/utils.rs index 23589f6ba..71ef837ab 100644 --- a/sumcheck/src/utils.rs +++ b/sumcheck/src/utils.rs @@ -22,6 +22,7 @@ pub fn unpack_and_combine(p: &F, coef: &[F::Scalar]) -> F::Scalar .sum() } +#[cfg(feature = "proving")] /// Transcript IO between sumcheck steps #[inline] pub fn transcript_io(mpi_config: &impl MPIEngine, ps: &[F], transcript: &mut T) -> F diff --git a/transcript/Cargo.toml b/transcript/Cargo.toml index a0e699738..986e779fd 100644 --- a/transcript/Cargo.toml +++ b/transcript/Cargo.toml @@ -16,4 +16,5 @@ tiny-keccak.workspace = true mersenne31 = { path = "../arith/mersenne31/" } [features] -recursion = [] \ No newline at end of file +recursion = [] +proving = ["gkr_engine/proving"] \ No newline at end of file diff --git a/transcript/src/lib.rs b/transcript/src/lib.rs index 832931c56..939c2474d 100644 --- a/transcript/src/lib.rs +++ b/transcript/src/lib.rs @@ -7,7 +7,9 @@ mod byte_hash_transcript; pub use byte_hash_transcript::BytesHashTranscript; mod transcript_utils; -pub use transcript_utils::{transcript_root_broadcast, transcript_verifier_sync}; +#[cfg(feature = "proving")] +pub use transcript_utils::transcript_root_broadcast; +pub use transcript_utils::transcript_verifier_sync; #[cfg(test)] mod tests; diff --git a/transcript/src/transcript_utils.rs b/transcript/src/transcript_utils.rs index 17e0459f3..17fc976a9 100644 --- a/transcript/src/transcript_utils.rs +++ b/transcript/src/transcript_utils.rs @@ -1,6 +1,7 @@ use arith::ExtensionField; use gkr_engine::{MPIEngine, Transcript}; +#[cfg(feature = "proving")] /// broadcast root transcript state. incurs an additional hash if self.world_size > 1 pub fn transcript_root_broadcast( transcript: &mut impl Transcript,