Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stwobackend prover skeleton #1898

Merged
merged 43 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e822aaa
stwo prover function skeleton
ShuangWu121 Oct 14, 2024
245d95c
remove circuit build file, not ready yet
ShuangWu121 Oct 14, 2024
3ef47d7
print info change
ShuangWu121 Oct 14, 2024
8c5f1a1
Merge remote-tracking branch 'origin/main' into stwobackend-pr
ShuangWu121 Oct 14, 2024
83122aa
change back toolchain to be stable, but make github action to run stw…
ShuangWu121 Oct 14, 2024
11376e0
solve clippy pr test issues
ShuangWu121 Oct 14, 2024
53db07f
fix pr fail
ShuangWu121 Oct 14, 2024
d773717
fix nightly conditional build
ShuangWu121 Oct 14, 2024
6057380
fix stwo conditional build
ShuangWu121 Oct 14, 2024
3dfd6ab
remove stwo from stable build
ShuangWu121 Oct 14, 2024
6a2a3f0
remove stwo from stable build
ShuangWu121 Oct 14, 2024
c436773
make lint conditional for stwo
ShuangWu121 Oct 14, 2024
7c3b790
make sure nigtly toolchain is installed before lint step
ShuangWu121 Oct 14, 2024
00c4c6f
specify nightly version in command
ShuangWu121 Oct 14, 2024
84b2c89
make nextest archive also conditional
ShuangWu121 Oct 14, 2024
4f8401f
change to new nightly version
ShuangWu121 Oct 14, 2024
ea9e606
change back nightly version for stwo to be 9-21, exclude other featur…
ShuangWu121 Oct 14, 2024
06cfcf2
change back nightly version for stwo to be 9-21, exclude other featur…
ShuangWu121 Oct 14, 2024
8a50b27
change back nightly version for stwo to be 9-21, exclude other featur…
ShuangWu121 Oct 14, 2024
7a5d47d
feature to features
ShuangWu121 Oct 14, 2024
59a584c
solve clippy issues
ShuangWu121 Oct 14, 2024
0b55149
solve clippy issue by adding an empty line below the first line of th…
ShuangWu121 Oct 14, 2024
985d717
fix format
ShuangWu121 Oct 14, 2024
2e02b91
fix upload artifact confilic
ShuangWu121 Oct 14, 2024
0b38415
fix upload artifact confilic
ShuangWu121 Oct 14, 2024
1602dc8
fix download artifact
ShuangWu121 Oct 14, 2024
e1d613c
fix download artifact
ShuangWu121 Oct 14, 2024
df6de4a
fix download artifact
ShuangWu121 Oct 15, 2024
8cead5c
fix download artifact
ShuangWu121 Oct 15, 2024
59275b6
fix unpack issue
ShuangWu121 Oct 15, 2024
372045c
solve create test but cannot find file issue
ShuangWu121 Oct 15, 2024
9dac7dd
update CI file
ShuangWu121 Oct 17, 2024
3334500
solve conflict
ShuangWu121 Oct 17, 2024
f925601
fix comment
ShuangWu121 Oct 17, 2024
d1fc82b
Update backend/src/stwo/mod.rs
ShuangWu121 Oct 17, 2024
d508fed
add unimplemented
ShuangWu121 Oct 17, 2024
cbd00da
resolve conflict
ShuangWu121 Oct 17, 2024
4dceadb
fix format
ShuangWu121 Oct 17, 2024
873865c
Update backend/Cargo.toml
ShuangWu121 Oct 18, 2024
b34abb5
Update backend/src/stwo/mod.rs
ShuangWu121 Oct 18, 2024
b6ea465
Update backend/src/stwo/mod.rs
ShuangWu121 Oct 18, 2024
29aa619
remove not used import
ShuangWu121 Oct 18, 2024
03a43b9
Merge branch 'stwobackend-pr' of github.com:powdr-labs/powdr into stw…
ShuangWu121 Oct 18, 2024
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
4 changes: 4 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +88,8 @@ impl BackendType {
}
#[cfg(feature = "plonky3")]
BackendType::Plonky3 => Box::new(plonky3::Factory),
#[cfg(feature = "stwo")]
BackendType::Stwo => Box::new(stwo::StwoProverFactory),
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions backend/src/stwo/mod.rs
Original file line number Diff line number Diff line change
@@ -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<F: FieldElement> BackendFactory<F> for StwoProverFactory {
#[allow(unreachable_code)]
#[allow(unused_variables)]
fn create(
&self,
pil: Arc<Analyzed<F>>,
fixed: Arc<Vec<(String, VariablySizedColumn<F>)>>,
_output_dir: Option<PathBuf>,
setup: Option<&mut dyn io::Read>,
verification_key: Option<&mut dyn io::Read>,
verification_app_key: Option<&mut dyn io::Read>,
options: BackendOptions,
) -> Result<Box<dyn crate::Backend<F>>, 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<T: FieldElement> Backend<T> for StwoProver<T> {
#[allow(unused_variables)]
fn verify(&self, proof: &[u8], instances: &[Vec<T>]) -> Result<(), Error> {
assert!(instances.len() == 1);
unimplemented!()
}
#[allow(unreachable_code)]
#[allow(unused_variables)]
fn prove(
&self,
witness: &[(String, Vec<T>)],
prev_proof: Option<Proof>,
witgen_callback: WitgenCallback<T>,
) -> Result<Proof, Error> {
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!()
}
}
32 changes: 32 additions & 0 deletions backend/src/stwo/prover.rs
Original file line number Diff line number Diff line change
@@ -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<F> {
_analyzed: Arc<Analyzed<F>>,
_fixed: Arc<Vec<(String, Vec<F>)>>,
/// Proving key placeholder
_proving_key: Option<()>,
/// Verifying key placeholder
_verifying_key: Option<()>,
}

impl<F: FieldElement> StwoProver<F> {
#[allow(dead_code)]
#[allow(unused_variables)]
pub fn new(
_analyzed: Arc<Analyzed<F>>,
_fixed: Arc<Vec<(String, Vec<F>)>>,
setup: Option<&mut dyn io::Read>,
) -> Result<Self, io::Error> {
Ok(Self {
_analyzed,
_fixed,
_proving_key: None,
_verifying_key: None,
})
}
}
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down