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

feat(prover): Initial powdr support #407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ members = [
"harness/macro",
"provers/sp1/driver",
"provers/sp1/builder",
"provers/powdr/driver",
"provers/powdr/builder",
"provers/risc0/driver",
"provers/risc0/builder",
"provers/sgx/prover",
Expand Down
2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
# provers
sp1-driver = { path = "../provers/sp1/driver", optional = true }
risc0-driver = { path = "../provers/risc0/driver", optional = true }
powdr-driver = { path = "../provers/powdr/driver", optional = true }
sgx-prover = { path = "../provers/sgx/prover", optional = true }

# raiko
Expand Down Expand Up @@ -69,4 +70,5 @@ ethers-core = { workspace = true }
# powdr = ["dep:powdr"]
sp1 = ["dep:sp1-driver", "sp1-driver/enable"]
risc0 = ["dep:risc0-driver", "risc0-driver/enable"]
powdr = ["dep:powdr-driver", "powdr-driver/enable"]
sgx = ["dep:sgx-prover", "sgx-prover/enable"]
34 changes: 34 additions & 0 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pub enum ProofType {
///
/// Uses the RISC0 prover to build the block.
Risc0,
/// # powdr
///
/// Uses powdrVM to build the block.
Powdr,
}

impl std::fmt::Display for ProofType {
Expand All @@ -122,6 +126,7 @@ impl std::fmt::Display for ProofType {
ProofType::Sp1 => "sp1",
ProofType::Sgx => "sgx",
ProofType::Risc0 => "risc0",
ProofType::Powdr => "powdr",
})
}
}
Expand All @@ -135,6 +140,7 @@ impl FromStr for ProofType {
"sp1" => Ok(ProofType::Sp1),
"sgx" => Ok(ProofType::Sgx),
"risc0" => Ok(ProofType::Risc0),
"powdr" => Ok(ProofType::Powdr),
_ => Err(RaikoError::InvalidProofType(s.to_string())),
}
}
Expand All @@ -149,6 +155,7 @@ impl TryFrom<u8> for ProofType {
1 => Ok(Self::Sp1),
2 => Ok(Self::Sgx),
3 => Ok(Self::Risc0),
4 => Ok(Self::Powdr),
_ => Err(RaikoError::Conversion("Invalid u8".to_owned())),
}
}
Expand All @@ -161,6 +168,7 @@ impl From<ProofType> for VerifierType {
ProofType::Sp1 => VerifierType::SP1,
ProofType::Sgx => VerifierType::SGX,
ProofType::Risc0 => VerifierType::RISC0,
ProofType::Powdr => VerifierType::Powdr,
}
}
}
Expand Down Expand Up @@ -194,6 +202,14 @@ impl ProofType {
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Powdr => {
#[cfg(feature = "powdr")]
return powdr_driver::PowdrProver::run(input.clone(), output, config, store)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "powdr"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return sgx_prover::SgxProver::run(input.clone(), output, config, store)
Expand Down Expand Up @@ -233,6 +249,14 @@ impl ProofType {
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Powdr => {
#[cfg(feature = "powdr")]
return powdr_driver::PowdrProver::aggregate(input.clone(), output, config, store)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "powdr"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return sgx_prover::SgxProver::aggregate(input.clone(), output, config, store)
Expand Down Expand Up @@ -271,6 +295,14 @@ impl ProofType {
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Powdr => {
#[cfg(feature = "powdr")]
return powdr_driver::PowdrProver::cancel(proof_key, read)
.await
.map_err(|e| e.into());
#[cfg(not(feature = "powdr"))]
Err(RaikoError::FeatureNotSupportedError(*self))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return sgx_prover::SgxProver::cancel(proof_key, read)
Expand Down Expand Up @@ -355,6 +387,8 @@ pub struct ProverSpecificOpts {
pub sp1: Option<Value>,
/// RISC0 prover specific options.
pub risc0: Option<Value>,
/// Powdr prover specific options.
pub powdr: Option<Value>,
}

impl<S: ::std::hash::BuildHasher + ::std::default::Default> From<ProverSpecificOpts>
Expand Down
8 changes: 8 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ mod tests {
}
},
);
prover_args.insert(
"powdr".to_string(),
json! {
{
"prover": "mock",
}
},
);
prover_args.insert(
"sgx".to_string(),
json! {
Expand Down
7 changes: 4 additions & 3 deletions harness/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ proc-macro = true

[dependencies]
syn = { workspace = true }
quote = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
proc-macro2 = { workspace = true }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt did this


[features]
sp1 = []
risc0 = []
risc0 = []
powdr = []
28 changes: 23 additions & 5 deletions harness/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Item, ItemFn, ItemMod};

#[cfg(any(feature = "sp1", feature = "risc0"))]
#[cfg(any(feature = "sp1", feature = "risc0", feature = "powdr"))]
use syn::{punctuated::Punctuated, Ident, Path, Token};

// Helper struct to parse input
#[cfg(any(feature = "sp1", feature = "risc0"))]
#[cfg(any(feature = "sp1", feature = "risc0", feature = "powdr"))]
struct EntryArgs {
main_entry: Ident,
test_modules: Option<Punctuated<Path, Token![,]>>,
}

#[cfg(any(feature = "sp1", feature = "risc0"))]
#[cfg(any(feature = "sp1", feature = "risc0", feature = "powdr"))]
impl syn::parse::Parse for EntryArgs {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let main_entry: Ident = input.parse()?;
Expand All @@ -33,7 +33,7 @@ impl syn::parse::Parse for EntryArgs {
}

#[proc_macro]
#[cfg(any(feature = "sp1", feature = "risc0"))]
#[cfg(any(feature = "sp1", feature = "risc0", feature = "powdr"))]
pub fn entrypoint(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as EntryArgs);
let main_entry = input.main_entry;
Expand Down Expand Up @@ -100,11 +100,29 @@ pub fn entrypoint(input: TokenStream) -> TokenStream {
}
};

#[cfg(feature = "powdr")]
let output = quote! {
#[cfg(test)]
#tests_entry

#[cfg(not(test))]
const ZKVM_ENTRY: fn() = #main_entry;
#[cfg(test)]
const ZKVM_ENTRY: fn() = run_tests;

mod zkvm_generated_main {
#[no_mangle]
fn main() {
super::ZKVM_ENTRY()
}
}
};

output.into()
}

#[proc_macro]
#[cfg(not(any(feature = "sp1", feature = "risc0")))]
#[cfg(not(any(feature = "sp1", feature = "risc0", feature = "powdr")))]
pub fn entrypoint(_input: TokenStream) -> TokenStream {
quote! {
mod generated_main {
Expand Down
2 changes: 2 additions & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ default-run = "raiko-host"
# provers
sp1-driver = { path = "../provers/sp1/driver", optional = true }
risc0-driver = { path = "../provers/risc0/driver", optional = true }
powdr-driver = { path = "../provers/powdr/driver", optional = true }
sgx-prover = { path = "../provers/sgx/prover", optional = true }

# raiko
Expand Down Expand Up @@ -86,6 +87,7 @@ ethers-core = { workspace = true }
default = []
sp1 = ["raiko-core/sp1"]
risc0 = ["raiko-core/risc0"]
powdr = ["raiko-core/powdr"]
sgx = ["raiko-core/sgx"]
integration = []

Expand Down
3 changes: 3 additions & 0 deletions host/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"prover": "mock",
"verify": false
},
"powdr": {
"prover": "mock"
},
"native" : {
"json_guest_input": null
}
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v1/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use super::ProofResponse;
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn proof_handler(
State(prover_state): State<ProverState>,
Json(req): Json<Value>,
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v2/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{interfaces::HostResult, server::api::v2::CancelStatus, Message, Prov
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn cancel_handler(
State(prover_state): State<ProverState>,
Json(req): Json<Value>,
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod report;
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn proof_handler(
State(prover_state): State<ProverState>,
Json(req): Json<Value>,
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v3/proof/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn aggregation_handler(
State(prover_state): State<ProverState>,
Json(mut aggregation_request): Json<AggregationOnlyRequest>,
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v3/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{interfaces::HostResult, server::api::v2::CancelStatus, Message, Prov
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn cancel_handler(
State(prover_state): State<ProverState>,
Json(mut aggregation_request): Json<AggregationRequest>,
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v3/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod cancel;
/// - sgx - uses the sgx environment to construct a block and produce proof of execution
/// - sp1 - uses the sp1 prover
/// - risc0 - uses the risc0 prover
/// - powdr - uses the powdr prover
async fn proof_handler(
State(prover_state): State<ProverState>,
Json(mut aggregation_request): Json<AggregationRequest>,
Expand Down
1 change: 1 addition & 0 deletions host/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub async fn make_request() -> anyhow::Result<ProofRequestOpt> {
sgx: None,
sp1: None,
risc0: None,
powdr: None,
},
})
}
4 changes: 3 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ std = [
sgx = []
sp1 = []
risc0 = []
sp1-cycle-tracker = []
powdr = []
sp1-cycle-tracker = []
proof_of_equivalence = []
2 changes: 2 additions & 0 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub enum VerifierType {
SGX,
SP1,
RISC0,
Powdr,
}

/// Specification of a specific chain.
Expand Down Expand Up @@ -397,6 +398,7 @@ mod tests {
(VerifierType::SGX, Some(Address::default())),
(VerifierType::SP1, None),
(VerifierType::RISC0, Some(Address::default())),
(VerifierType::Powdr, None),
]),
)]),
genesis_time: 0u64,
Expand Down
1 change: 1 addition & 0 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ fn get_blob_proof_type(
VerifierType::SGX => BlobProofType::KzgVersionedHash,
VerifierType::SP1 => BlobProofType::ProofOfEquivalence,
VerifierType::RISC0 => BlobProofType::ProofOfEquivalence,
VerifierType::Powdr => BlobProofType::ProofOfEquivalence,
}
}

Expand Down
2 changes: 2 additions & 0 deletions pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ sp1-sdk = { workspace = true, optional = true }
[features]
risc0 = ["dep:risc0-binfmt", "dep:pathdiff", "dep:hex"]
sp1 = ["dep:sp1-sdk"]
# TODO: make powdr feature work
powdr = []
Loading
Loading