diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 770d861ce7..d8f3d1159c 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -12,6 +12,7 @@ default = [] halo2 = ["dep:halo2_proofs", "dep:halo2_curves", "dep:snark-verifier", "dep:halo2_solidity_verifier"] estark-polygon = ["dep:pil-stark-prover"] plonky3 = ["dep:powdr-plonky3"] +stwo = ["dep:stwo-prover"] [dependencies] powdr-ast.workspace = true @@ -36,6 +37,9 @@ halo2_curves = { version = "0.6.1", package = "halo2curves", optional = true} snark-verifier = { git = "https://github.com/powdr-labs/snark-verifier", branch = "powdr-halo2", optional = true } halo2_solidity_verifier = { git = "https://github.com/powdr-labs/halo2-solidity-verifier", branch = "main", features = ["evm"], optional = true } +# TODO: Change this to main branch when the `andrew/dev/update-toolchain` branch is merged,the main branch is using "nightly-2024-01-04", not compatiable with plonky3 +stwo-prover = { git= "https://github.com/starkware-libs/stwo.git",optional=true, rev="52d050c18b5dbc74af40214b3b441a6f60a20d41" } + strum = { version = "0.24.1", features = ["derive"] } log = "0.4.17" serde = "1.0" diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 97878163b7..4f579ab28d 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -8,6 +8,7 @@ mod plonky3; mod composite; mod field_filter; +mod stwo; use powdr_ast::analyzed::Analyzed; use powdr_executor::{constant_evaluator::VariablySizedColumn, witgen::WitgenCallback}; @@ -46,6 +47,9 @@ pub enum BackendType { #[cfg(feature = "plonky3")] #[strum(serialize = "plonky3")] Plonky3, + #[cfg(feature = "stwo")] + #[strum(serialize = "stwo")] + Stwo, } pub type BackendOptions = String; @@ -84,6 +88,8 @@ impl BackendType { } #[cfg(feature = "plonky3")] BackendType::Plonky3 => Box::new(plonky3::Factory), + #[cfg(feature = "stwo")] + BackendType::Stwo => Box::new(stwo::StwoProverFactory), } } } diff --git a/backend/src/stwo/mod.rs b/backend/src/stwo/mod.rs new file mode 100644 index 0000000000..4aa1e5a6de --- /dev/null +++ b/backend/src/stwo/mod.rs @@ -0,0 +1,64 @@ +use std::io; +use std::path::PathBuf; +use std::sync::Arc; + +use crate::{Backend, BackendFactory, BackendOptions, Error, Proof}; +use powdr_ast::analyzed::Analyzed; +use powdr_executor::constant_evaluator::{get_uniquely_sized_cloned, VariablySizedColumn}; +use powdr_executor::witgen::WitgenCallback; +use powdr_number::FieldElement; +use prover::StwoProver; + +mod prover; + +#[allow(dead_code)] +pub(crate) struct StwoProverFactory; + +impl BackendFactory for StwoProverFactory { + #[allow(unreachable_code)] + #[allow(unused_variables)] + fn create( + &self, + pil: Arc>, + fixed: Arc)>>, + _output_dir: Option, + setup: Option<&mut dyn io::Read>, + verification_key: Option<&mut dyn io::Read>, + verification_app_key: Option<&mut dyn io::Read>, + options: BackendOptions, + ) -> Result>, Error> { + if pil.degrees().len() > 1 { + return Err(Error::NoVariableDegreeAvailable); + } + let fixed = Arc::new( + get_uniquely_sized_cloned(&fixed).map_err(|_| Error::NoVariableDegreeAvailable)?, + ); + let stwo = Box::new(StwoProver::new(pil, fixed, setup)?); + Ok(stwo) + } +} + +impl Backend for StwoProver { + #[allow(unused_variables)] + fn verify(&self, proof: &[u8], instances: &[Vec]) -> Result<(), Error> { + assert!(instances.len() == 1); + unimplemented!() + } + #[allow(unreachable_code)] + #[allow(unused_variables)] + fn prove( + &self, + witness: &[(String, Vec)], + prev_proof: Option, + witgen_callback: WitgenCallback, + ) -> Result { + if prev_proof.is_some() { + return Err(Error::NoAggregationAvailable); + } + unimplemented!() + } + #[allow(unused_variables)] + fn export_verification_key(&self, output: &mut dyn io::Write) -> Result<(), Error> { + unimplemented!() + } +} diff --git a/backend/src/stwo/prover.rs b/backend/src/stwo/prover.rs new file mode 100644 index 0000000000..35f66e0ca9 --- /dev/null +++ b/backend/src/stwo/prover.rs @@ -0,0 +1,32 @@ +use powdr_ast::analyzed::Analyzed; +use std::io; +use std::sync::Arc; + +use powdr_number::FieldElement; + +#[allow(unused_variables)] +pub struct StwoProver { + _analyzed: Arc>, + _fixed: Arc)>>, + /// Proving key placeholder + _proving_key: Option<()>, + /// Verifying key placeholder + _verifying_key: Option<()>, +} + +impl StwoProver { + #[allow(dead_code)] + #[allow(unused_variables)] + pub fn new( + _analyzed: Arc>, + _fixed: Arc)>>, + setup: Option<&mut dyn io::Read>, + ) -> Result { + Ok(Self { + _analyzed, + _fixed, + _proving_key: None, + _verifying_key: None, + }) + } +} diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 6471d52fdb..7d84d1add6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -16,6 +16,7 @@ estark-polygon = [ "powdr-backend/estark-polygon", "powdr-pipeline/estark-polygon", ] +stwo=["powdr-backend/stwo","powdr-pipeline/stwo"] [dependencies] powdr-backend.workspace = true diff --git a/pipeline/Cargo.toml b/pipeline/Cargo.toml index 9e29aa376b..68b15d9e51 100644 --- a/pipeline/Cargo.toml +++ b/pipeline/Cargo.toml @@ -12,6 +12,7 @@ default = [] # halo2 is disabled by default halo2 = ["powdr-backend/halo2"] plonky3 = ["powdr-backend/plonky3"] estark-polygon = ["powdr-backend/estark-polygon"] +stwo = ["powdr-backend/stwo"] [dependencies] powdr-airgen.workspace = true