Skip to content

Commit

Permalink
init commit in attempting integrating orion to m31, and misc changes …
Browse files Browse the repository at this point in the history
…in gkr binaries
  • Loading branch information
tonyfloatersu committed Feb 4, 2025
1 parent f756288 commit 3fc9651
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 124 deletions.
16 changes: 7 additions & 9 deletions gkr/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use mpi_config::MPIConfig;

use log::debug;

#[allow(unused_imports)] // The FiatShamirHashType import is used in the macro expansion
use config::FiatShamirHashType;
#[allow(unused_imports)] // The FieldType import is used in the macro expansion
use gkr_field_config::FieldType;

use gkr::executor::*;
use gkr::{executor::*, gkr_configs::*};

#[tokio::main]
async fn main() {
Expand Down Expand Up @@ -45,28 +43,28 @@ async fn main() {
debug!("field type: {:?}", field_type);
match field_type {
FieldType::M31 => {
run_command::<M31ExtConfigSha2>(
run_command::<M31ExtConfigPoseidonOrion>(
command,
circuit_file,
Config::<M31ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<M31ExtConfigPoseidonOrion>::new(GKRScheme::Vanilla, mpi_config.clone()),
&args,
)
.await;
}
FieldType::BN254 => {
run_command::<BN254ConfigMIMC5>(
run_command::<BN254ConfigMIMC5Raw>(
command,
circuit_file,
Config::<BN254ConfigMIMC5>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<BN254ConfigMIMC5Raw>::new(GKRScheme::Vanilla, mpi_config.clone()),
&args,
)
.await;
}
FieldType::GF2 => {
run_command::<GF2ExtConfigSha2>(
run_command::<GF2ExtConfigSha2Orion>(
command,
circuit_file,
Config::<GF2ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<GF2ExtConfigSha2Orion>::new(GKRScheme::Vanilla, mpi_config.clone()),
&args,
)
.await
Expand Down
34 changes: 3 additions & 31 deletions gkr/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ use std::{

use arith::{Field, FieldSerde, FieldSerdeError};
use circuit::Circuit;
use config::{
Config, GKRConfig, PolynomialCommitmentType, SENTINEL_BN254, SENTINEL_GF2, SENTINEL_M31,
};
use config_macros::declare_gkr_config;
use field_hashers::{MiMC5FiatShamirHasher, PoseidonFiatShamirHasher};
use gf2::GF2x128;
use gkr_field_config::{BN254Config, GF2ExtConfig, GKRFieldConfig, M31ExtConfig};
use mersenne31::M31x16;
use poly_commit::{expander_pcs_init_testing_only, raw::RawExpanderGKR, OrionPCSForGKR};
use config::{Config, GKRConfig, SENTINEL_BN254, SENTINEL_GF2, SENTINEL_M31};
use gkr_field_config::GKRFieldConfig;
use poly_commit::expander_pcs_init_testing_only;
use rand::SeedableRng;
use rand_chacha::ChaCha12Rng;
use transcript::{BytesHashTranscript, FieldHashTranscript, SHA256hasher};

use log::info;
use transcript::Proof;
use warp::{http::StatusCode, reply, Filter};

#[allow(unused_imports)] // The FiatShamirHashType import is used in the macro expansion
use config::FiatShamirHashType;
#[allow(unused_imports)] // The FieldType import is used in the macro expansion
use gkr_field_config::FieldType;

Expand Down Expand Up @@ -273,22 +264,3 @@ pub async fn run_command<'a, Cfg: GKRConfig>(
}
}
}

declare_gkr_config!(
pub M31ExtConfigSha2,
FieldType::M31,
FiatShamirHashType::Poseidon,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
pub BN254ConfigMIMC5,
FieldType::BN254,
FiatShamirHashType::MIMC5,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
pub GF2ExtConfigSha2,
FieldType::GF2,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Orion
);
44 changes: 44 additions & 0 deletions gkr/src/gkr_configs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use config::{GKRConfig, PolynomialCommitmentType};
use config_macros::declare_gkr_config;
use field_hashers::{MiMC5FiatShamirHasher, PoseidonFiatShamirHasher};
use gf2::GF2x128;
use gkr_field_config::{BN254Config, GF2ExtConfig, GKRFieldConfig, M31ExtConfig};
use mersenne31::M31x16;
use poly_commit::{raw::RawExpanderGKR, OrionPCSForGKR};
use transcript::{BytesHashTranscript, FieldHashTranscript, SHA256hasher};

#[allow(unused_imports)] // The FiatShamirHashType import is used in the macro expansion
use config::FiatShamirHashType;
#[allow(unused_imports)] // The FieldType import is used in the macro expansion
use gkr_field_config::FieldType;

declare_gkr_config!(
pub M31ExtConfigPoseidonOrion,
FieldType::M31,
FiatShamirHashType::Poseidon,
PolynomialCommitmentType::Orion
);
declare_gkr_config!(
pub M31ExtConfigPoseidonRaw,
FieldType::M31,
FiatShamirHashType::Poseidon,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
pub BN254ConfigMIMC5Raw,
FieldType::BN254,
FiatShamirHashType::MIMC5,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
pub GF2ExtConfigSha2Orion,
FieldType::GF2,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Orion
);
declare_gkr_config!(
pub GF2ExtConfigSha2Raw,
FieldType::GF2,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Raw
);
3 changes: 3 additions & 0 deletions gkr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ pub mod utils;

pub mod executor;

pub mod gkr_configs;
pub use gkr_configs::*;

#[cfg(test)]
mod tests;
55 changes: 15 additions & 40 deletions gkr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ use std::{
use circuit::Circuit;
use clap::Parser;
use config::{Config, GKRConfig, GKRScheme};
use config_macros::declare_gkr_config;
use gf2::GF2x128;
use gkr_field_config::{BN254Config, GF2ExtConfig, GKRFieldConfig, M31ExtConfig};
use gkr_field_config::GKRFieldConfig;
use mpi_config::MPIConfig;

use poly_commit::{expander_pcs_init_testing_only, raw::RawExpanderGKR, OrionPCSForGKR};
use poly_commit::expander_pcs_init_testing_only;
use rand::SeedableRng;
use rand_chacha::ChaCha12Rng;
use transcript::{BytesHashTranscript, SHA256hasher};

use gkr::{
utils::{
KECCAK_BN254_CIRCUIT, KECCAK_BN254_WITNESS, KECCAK_GF2_CIRCUIT, KECCAK_GF2_WITNESS,
KECCAK_M31_CIRCUIT, KECCAK_M31_WITNESS, POSEIDON_M31_CIRCUIT, POSEIDON_M31_WITNESS,
},
Prover,
BN254ConfigMIMC5Raw, GF2ExtConfigSha2Orion, M31ExtConfigPoseidonOrion, Prover,
};

#[allow(unused_imports)]
// The FiatShamirHashType and PolynomialCommitmentType import is used in the macro expansion
use config::{FiatShamirHashType, PolynomialCommitmentType};
#[allow(unused_imports)] // The FieldType import is used in the macro expansion
use gkr_field_config::FieldType;

Expand Down Expand Up @@ -57,56 +51,37 @@ fn main() {

let mpi_config = MPIConfig::new();

declare_gkr_config!(
M31ExtConfigSha2,
FieldType::M31,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
BN254ConfigSha2,
FieldType::BN254,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
GF2ExtConfigSha2,
FieldType::GF2,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Orion
);

match args.field.as_str() {
"m31ext3" => match args.scheme.as_str() {
"keccak" => run_benchmark::<M31ExtConfigSha2>(
"keccak" => run_benchmark::<M31ExtConfigPoseidonOrion>(
&args,
Config::<M31ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<M31ExtConfigPoseidonOrion>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<M31ExtConfigSha2>(
"poseidon" => run_benchmark::<M31ExtConfigPoseidonOrion>(
&args,
Config::<M31ExtConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<M31ExtConfigPoseidonOrion>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
"fr" => match args.scheme.as_str() {
"keccak" => run_benchmark::<BN254ConfigSha2>(
"keccak" => run_benchmark::<BN254ConfigMIMC5Raw>(
&args,
Config::<BN254ConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<BN254ConfigMIMC5Raw>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<BN254ConfigSha2>(
"poseidon" => run_benchmark::<BN254ConfigMIMC5Raw>(
&args,
Config::<BN254ConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<BN254ConfigMIMC5Raw>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
"gf2ext128" => match args.scheme.as_str() {
"keccak" => run_benchmark::<GF2ExtConfigSha2>(
"keccak" => run_benchmark::<GF2ExtConfigSha2Orion>(
&args,
Config::<GF2ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<GF2ExtConfigSha2Orion>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<GF2ExtConfigSha2>(
"poseidon" => run_benchmark::<GF2ExtConfigSha2Orion>(
&args,
Config::<GF2ExtConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<GF2ExtConfigSha2Orion>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
Expand Down
55 changes: 15 additions & 40 deletions gkr/src/main_mpi.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
use circuit::Circuit;
use clap::Parser;
use config::{Config, GKRConfig, GKRScheme};
use config_macros::declare_gkr_config;
use mpi_config::MPIConfig;

use gf2::GF2x128;
use gkr_field_config::{BN254Config, GF2ExtConfig, GKRFieldConfig, M31ExtConfig};
use poly_commit::{expander_pcs_init_testing_only, raw::RawExpanderGKR, OrionPCSForGKR};
use gkr_field_config::GKRFieldConfig;
use poly_commit::expander_pcs_init_testing_only;
use rand::SeedableRng;
use rand_chacha::ChaCha12Rng;
use transcript::{BytesHashTranscript, SHA256hasher};

use gkr::{
utils::{
KECCAK_BN254_CIRCUIT, KECCAK_BN254_WITNESS, KECCAK_GF2_CIRCUIT, KECCAK_GF2_WITNESS,
KECCAK_M31_CIRCUIT, KECCAK_M31_WITNESS, POSEIDON_M31_CIRCUIT, POSEIDON_M31_WITNESS,
},
Prover,
BN254ConfigMIMC5Raw, GF2ExtConfigSha2Orion, M31ExtConfigPoseidonOrion, Prover,
};

#[allow(unused_imports)]
// The FiatShamirHashType and PolynomialCommitmentType import is used in the macro expansion
use config::{FiatShamirHashType, PolynomialCommitmentType};
#[allow(unused_imports)] // The FieldType import is used in the macro expansion
use gkr_field_config::FieldType;

Expand All @@ -48,56 +42,37 @@ fn main() {

let mpi_config = MPIConfig::new();

declare_gkr_config!(
M31ExtConfigSha2,
FieldType::M31,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
BN254ConfigSha2,
FieldType::BN254,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Raw
);
declare_gkr_config!(
GF2ExtConfigSha2,
FieldType::GF2,
FiatShamirHashType::SHA256,
PolynomialCommitmentType::Orion
);

match args.field.as_str() {
"m31ext3" => match args.scheme.as_str() {
"keccak" => run_benchmark::<M31ExtConfigSha2>(
"keccak" => run_benchmark::<M31ExtConfigPoseidonOrion>(
&args,
Config::<M31ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<M31ExtConfigPoseidonOrion>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<M31ExtConfigSha2>(
"poseidon" => run_benchmark::<M31ExtConfigPoseidonOrion>(
&args,
Config::<M31ExtConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<M31ExtConfigPoseidonOrion>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
"fr" => match args.scheme.as_str() {
"keccak" => run_benchmark::<BN254ConfigSha2>(
"keccak" => run_benchmark::<BN254ConfigMIMC5Raw>(
&args,
Config::<BN254ConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<BN254ConfigMIMC5Raw>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<BN254ConfigSha2>(
"poseidon" => run_benchmark::<BN254ConfigMIMC5Raw>(
&args,
Config::<BN254ConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<BN254ConfigMIMC5Raw>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
"gf2ext128" => match args.scheme.as_str() {
"keccak" => run_benchmark::<GF2ExtConfigSha2>(
"keccak" => run_benchmark::<GF2ExtConfigSha2Orion>(
&args,
Config::<GF2ExtConfigSha2>::new(GKRScheme::Vanilla, mpi_config.clone()),
Config::<GF2ExtConfigSha2Orion>::new(GKRScheme::Vanilla, mpi_config.clone()),
),
"poseidon" => run_benchmark::<GF2ExtConfigSha2>(
"poseidon" => run_benchmark::<GF2ExtConfigSha2Orion>(
&args,
Config::<GF2ExtConfigSha2>::new(GKRScheme::GkrSquare, mpi_config.clone()),
Config::<GF2ExtConfigSha2Orion>::new(GKRScheme::GkrSquare, mpi_config.clone()),
),
_ => unreachable!(),
},
Expand Down
10 changes: 6 additions & 4 deletions scripts/test_recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def test_m31_gkr_to_gkr_recursion_payload():
BN254_GKR_TO_GROTH16_RECURSION_PROOF_CONFIG,
MPI_CONFIG
)
test_m31_gkr_to_gkr_recursion(
M31_GKR_TO_GKR_RECURSION_PROOF_CONFIG,
MPI_CONFIG
)

# TODO(HS) modify expander-exec to pass in pcs schemes
# test_m31_gkr_to_gkr_recursion(
# M31_GKR_TO_GKR_RECURSION_PROOF_CONFIG,
# MPI_CONFIG
# )

0 comments on commit 3fc9651

Please sign in to comment.