-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send/receive TEE prover inputs via pub/sub.
Need to run `zk server` and `zksync_tee_prover` with env variable GOOGLE_APPLICATION_CREDENTIALS_JSON set to credentials file.
- Loading branch information
1 parent
cf80184
commit 4de7fee
Showing
5 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[package] | ||
name = "zksync_tee_prover" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
zksync_config.workspace = true | ||
zksync_env_config.workspace = true | ||
zksync_protobuf_config.workspace = true | ||
zksync_storage.workspace = true | ||
zksync_utils.workspace = true | ||
zksync_types.workspace = true | ||
zksync_core.workspace = true | ||
zksync_object_store.workspace = true | ||
zksync_tee_verifier.workspace = true | ||
google-cloud-pubsub.workspace = true | ||
google-cloud-auth.workspace = true | ||
|
||
# Consensus dependenices | ||
zksync_consensus_crypto.workspace = true | ||
zksync_consensus_roles.workspace = true | ||
zksync_consensus_executor.workspace = true | ||
zksync_concurrency.workspace = true | ||
vlog.workspace = true | ||
|
||
anyhow.workspace = true | ||
clap = { workspace = true, features = ["derive"] } | ||
serde_json.workspace = true | ||
tokio = { workspace = true, features = ["full"] } | ||
tracing.workspace = true | ||
futures.workspace = true | ||
futures-util = "0.3" | ||
[target.'cfg(not(target_env = "msvc"))'.dependencies] | ||
tikv-jemallocator.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use anyhow::Context as _; | ||
use clap::Parser; | ||
use futures_util::StreamExt; | ||
use google_cloud_pubsub::client::{Client, ClientConfig}; | ||
use zksync_core::temp_config_store::decode_yaml_repr; | ||
use zksync_object_store::StoredObject; | ||
use zksync_tee_verifier::TeeVerifierInput; | ||
|
||
#[cfg(not(target_env = "msvc"))] | ||
#[global_allocator] | ||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | ||
#[derive(Debug, Parser)] | ||
#[command(author = "Matter Labs", version, about = "zkSync operator node", long_about = None)] | ||
struct Cli { | ||
/// Path to the yaml config. If set, it will be used instead of env vars. | ||
#[arg(long)] | ||
config_path: Option<std::path::PathBuf>, | ||
/// Path to the yaml with secrets. If set, it will be used instead of env vars. | ||
#[arg(long)] | ||
secrets_path: Option<std::path::PathBuf>, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let opt = Cli::parse(); | ||
|
||
let configs = match opt.config_path { | ||
None => panic!(), | ||
Some(path) => { | ||
let yaml = | ||
std::fs::read_to_string(&path).with_context(|| path.display().to_string())?; | ||
decode_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&yaml) | ||
.context("failed decoding general YAML config")? | ||
} | ||
}; | ||
|
||
let observability_config = configs | ||
.observability | ||
.clone() | ||
.context("observability config")?; | ||
|
||
let log_format: vlog::LogFormat = observability_config | ||
.log_format | ||
.parse() | ||
.context("Invalid log format")?; | ||
|
||
let mut builder = vlog::ObservabilityBuilder::new().with_log_format(log_format); | ||
if let Some(log_directives) = observability_config.log_directives { | ||
builder = builder.with_log_directives(log_directives); | ||
} | ||
|
||
let _guard = builder.build(); | ||
|
||
let pubsub_config = ClientConfig::default().with_auth().await?; | ||
let client = Client::new(pubsub_config).await?; | ||
|
||
let subscription_name = "sgx-prover-inputs"; | ||
let subscription = client.subscription(&subscription_name); | ||
if !subscription.exists(None).await? { | ||
return Err(anyhow::anyhow!("subscription missing")); | ||
} | ||
|
||
let mut iter: google_cloud_pubsub::subscription::MessageStream = | ||
subscription.subscribe(None).await?; | ||
|
||
while let Some(message) = iter.next().await { | ||
let _ = message.ack().await?; | ||
|
||
tracing::debug!("Received input. Generating proof ..."); | ||
|
||
if message.message.data.len() == 0 { | ||
tracing::info!("empty data field"); | ||
continue; | ||
} | ||
|
||
let input = | ||
TeeVerifierInput::deserialize(message.message.data).expect("Deserialization error"); | ||
let result = input.verify(); | ||
if result.is_ok() { | ||
tracing::info!("Successfully proved a batch!"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters