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
17 changes: 7 additions & 10 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
7 changes: 5 additions & 2 deletions circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
poly_commit = { path = "../poly_commit" }

[features]
proving = ["gkr_engine/proving", "transcript/proving", "mpi"]
5 changes: 3 additions & 2 deletions circuit/src/layered/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -168,6 +168,7 @@ impl<C: FieldEngine> Circuit<C> {
Self::verifier_load_circuit::<Cfg>(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
Expand All @@ -176,7 +177,7 @@ impl<C: FieldEngine> Circuit<C> {
pub fn prover_load_circuit<Cfg: GKREngine<FieldConfig = C>>(
filename: &str,
mpi_config: &MPIConfig,
) -> (Self, *mut ompi_win_t) {
) -> (Self, MPI_Win) {
let circuit = if mpi_config.is_root() {
let rc = RecursiveCircuit::<C>::load(filename).unwrap();
let circuit = rc.flatten::<Cfg>();
Expand Down
1 change: 1 addition & 0 deletions circuit/tests/circuit_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare_gkr_config!(
GKRScheme::Vanilla,
);

#[cfg(feature = "proving")]
#[test]
fn test_circuit_serde() {
let mpi_config = MPIConfig::prover_new();
Expand Down
2 changes: 2 additions & 0 deletions circuit/tests/shared_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn load_circuit<Cfg: GKREngine>(mpi_config: &MPIConfig) -> Option<Circuit<Cfg::F
}
}

#[cfg(feature = "proving")]
#[test]
fn test_shared_mem() {
let mpi_config = MPIConfig::prover_new();
Expand All @@ -74,6 +75,7 @@ fn test_shared_mem() {
MPIConfig::finalize();
}

#[cfg(feature = "proving")]
#[allow(unreachable_patterns)]
fn test_shared_mem_helper<T: SharedMemory + ExpSerde + std::fmt::Debug>(
mpi_config: &MPIConfig,
Expand Down
7 changes: 5 additions & 2 deletions gkr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -60,11 +62,12 @@ 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" ]

[[bench]]
name = "gkr-hashes"
harness = false
path = "benches/gkr_hashes.rs"

required-features = ["proving"]
10 changes: 9 additions & 1 deletion gkr/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -37,6 +40,7 @@ pub struct ExpanderExecArgs {

#[derive(Debug, Subcommand, Clone)]
pub enum ExpanderExecSubCommand {
#[cfg(feature = "proving")]
Prove {
/// Circuit File Path
#[arg(short, long)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -119,6 +124,7 @@ pub fn detect_field_type_from_circuit_file(circuit_file: &str) -> FieldType {
}
}

#[cfg(feature = "proving")]
pub fn prove<Cfg: GKREngine>(
circuit: &mut Circuit<Cfg::FieldConfig>,
mpi_config: MPIConfig,
Expand Down Expand Up @@ -170,6 +176,7 @@ pub async fn run_command<Cfg: GKREngine + 'static>(
let subcommands = command.subcommands.clone();

match subcommands {
#[cfg(feature = "proving")]
ExpanderExecSubCommand::Prove {
circuit_file,
witness_file,
Expand Down Expand Up @@ -236,6 +243,7 @@ pub async fn run_command<Cfg: GKREngine + 'static>(

println!("success");
}
#[cfg(feature = "proving")]
ExpanderExecSubCommand::Serve {
circuit_file,
host_ip,
Expand Down
2 changes: 2 additions & 0 deletions gkr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
132 changes: 73 additions & 59 deletions gkr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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::<M31ExtConfigSha2RawVanilla>(&args, mpi_config.clone()),
"poseidon" => run_benchmark::<M31ExtConfigSha2RawSquare>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<M31ExtConfigSha2OrionVanilla>(&args, mpi_config.clone())
}
"poseidon" => {
run_benchmark::<M31ExtConfigSha2OrionSquare>(&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::<BN254ConfigSha2Raw>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::Hyrax => match args.circuit.as_str() {
"keccak" => run_benchmark::<BN254ConfigSha2Hyrax>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::KZG => match args.circuit.as_str() {
"keccak" => run_benchmark::<BN254ConfigMIMC5KZG>(&args, mpi_config.clone()),
_ => unreachable!(),
match args.field.as_str() {
"m31ext3" => match pcs_type {
PolynomialCommitmentType::Raw => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<M31ExtConfigSha2RawVanilla>(&args, mpi_config.clone())
}
"poseidon" => {
run_benchmark::<M31ExtConfigSha2RawSquare>(&args, mpi_config.clone())
}
_ => unreachable!(),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<M31ExtConfigSha2OrionVanilla>(&args, mpi_config.clone())
}
"poseidon" => {
run_benchmark::<M31ExtConfigSha2OrionSquare>(&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::<GF2ExtConfigSha2Raw>(&args, mpi_config.clone()),
_ => unreachable!(),
"fr" => match pcs_type {
PolynomialCommitmentType::Raw => match args.circuit.as_str() {
"keccak" => run_benchmark::<BN254ConfigSha2Raw>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::Hyrax => match args.circuit.as_str() {
"keccak" => run_benchmark::<BN254ConfigSha2Hyrax>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::KZG => match args.circuit.as_str() {
"keccak" => run_benchmark::<BN254ConfigMIMC5KZG>(&args, mpi_config.clone()),
_ => unreachable!(),
},
_ => unreachable!("Unsupported PCS type for BN254"),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => run_benchmark::<GF2ExtConfigSha2Orion>(&args, mpi_config.clone()),
_ => unreachable!(),
"gf2ext128" => match pcs_type {
PolynomialCommitmentType::Raw => match args.circuit.as_str() {
"keccak" => run_benchmark::<GF2ExtConfigSha2Raw>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => run_benchmark::<GF2ExtConfigSha2Orion>(&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::<GoldilocksExtConfigSha2Raw>(&args, mpi_config.clone()),
_ => unreachable!(),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<GoldilocksExtConfigSha2Orion>(&args, mpi_config.clone())
}
_ => unreachable!(),
"goldilocks" => match pcs_type {
PolynomialCommitmentType::Raw => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<GoldilocksExtConfigSha2Raw>(&args, mpi_config.clone())
}
_ => unreachable!(),
},
PolynomialCommitmentType::Orion => match args.circuit.as_str() {
"keccak" => {
run_benchmark::<GoldilocksExtConfigSha2Orion>(&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
<Cfg::PCSConfig as ExpanderPCS<Cfg::FieldConfig>>::ScratchPad: 'a,
Expand Down
Loading
Loading