Skip to content

Commit

Permalink
feat: use gpu prover
Browse files Browse the repository at this point in the history
  • Loading branch information
zkfriendly committed Jan 6, 2025
1 parent 41fbafb commit ff43cf8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde_json = "1.0.68"
tiny_http = "0.12.0"
lettre = { version = "0.10.4", features = ["tokio1", "tokio1-native-tls"] }
ethers = { version = "2.0.10", features = ["abigen"] }
relayer-utils = { version = "0.4.60", git = "https://github.com/zkemail/relayer-utils.git" }
relayer-utils = { git = "https://github.com/zkemail/relayer-utils.git", branch = "main" }
futures = "0.3.28"
sqlx = { version = "=0.7.3", features = [
"postgres",
Expand Down Expand Up @@ -53,7 +53,7 @@ slog-term = "2.9.0"
slog-json = "2.6.1"
file-rotate = "0.7.5"
base64 = "0.21.7"
uuid = "1.8.0"
uuid = { version = "1.8.0", features = ["v4"] }
http = "1.1.0"
ic-agent = { version = "0.37.1", features = ["pem", "reqwest"] }
ic-utils = "0.37.0"
Expand Down
12 changes: 10 additions & 2 deletions packages/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ pub struct RelayerConfig {
pub db_path: String,
pub web_server_address: String,
pub regex_json_dir_path: PathBuf,
pub prover_address: String,
pub prover_url: String,
pub prover_api_key: String,
pub prover_blueprint_id: String,
pub prover_zkey_download_url: String,
pub prover_circuit_cpp_download_url: String,
pub chain_rpc_provider: String,
pub chain_rpc_explorer: String,
pub chain_id: u32,
Expand Down Expand Up @@ -49,7 +53,11 @@ impl RelayerConfig {
db_path: env::var(DATABASE_PATH_KEY).unwrap(),
web_server_address: env::var(WEB_SERVER_ADDRESS_KEY).unwrap(),
regex_json_dir_path: env::var(REGEX_JSON_DIR_PATH_KEY).unwrap().into(),
prover_address: env::var(PROVER_ADDRESS_KEY).unwrap(),
prover_url: env::var(PROVER_URL_KEY).unwrap(),
prover_api_key: env::var(PROVER_API_KEY_KEY).unwrap(),
prover_blueprint_id: env::var(PROVER_BLUEPRINT_ID_KEY).unwrap(),
prover_zkey_download_url: env::var(PROVER_ZKEY_DOWNLOAD_URL_KEY).unwrap(),
prover_circuit_cpp_download_url: env::var(PROVER_CIRCUIT_CPP_DOWNLOAD_URL_KEY).unwrap(),
chain_rpc_provider: env::var(CHAIN_RPC_PROVIDER_KEY).unwrap(),
chain_rpc_explorer: env::var(CHAIN_RPC_EXPLORER_KEY).unwrap(),
chain_id: env::var(CHAIN_ID_KEY).unwrap().parse().unwrap(),
Expand Down
15 changes: 12 additions & 3 deletions packages/relayer/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ethers::{
};
use relayer_utils::{
extract_substr_idxes, extract_template_vals_from_command, generate_email_circuit_input,
generate_proof, EmailCircuitParams, LOG,
generate_proof_gpu, EmailCircuitParams, LOG,
};

const DOMAIN_FIELDS: usize = 9;
Expand Down Expand Up @@ -404,8 +404,17 @@ async fn generate_email_proof(
)
.await?;

let (proof, public_signals) =
generate_proof(&circuit_input, "email_auth", PROVER_ADDRESS.get().unwrap()).await?;
// Generate the proof and public signals using the circuit input
let (proof, public_signals) = generate_proof_gpu(
&circuit_input,
&PROVER_BLUEPRINT_ID.get().unwrap(),
&uuid::Uuid::new_v4().to_string(),
&PROVER_ZKEY_DOWNLOAD_URL.get().unwrap(),
&PROVER_CIRCUIT_CPP_DOWNLOAD_URL.get().unwrap(),
&PROVER_API_KEY.get().unwrap(),
&PROVER_URL.get().unwrap(),
)
.await?;

info!(LOG, "Public signals: {:?}", public_signals);

Expand Down
18 changes: 16 additions & 2 deletions packages/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use tokio::time::Duration;

pub static REGEX_JSON_DIR_PATH: OnceLock<PathBuf> = OnceLock::new();
pub static WEB_SERVER_ADDRESS: OnceLock<String> = OnceLock::new();
pub static PROVER_ADDRESS: OnceLock<String> = OnceLock::new();
pub static PRIVATE_KEY: OnceLock<String> = OnceLock::new();
pub static CHAIN_ID: OnceLock<u32> = OnceLock::new();
pub static EMAIL_ACCOUNT_RECOVERY_VERSION_ID: OnceLock<u8> = OnceLock::new();
Expand All @@ -50,6 +49,12 @@ pub static WALLET_CANISTER_ID: OnceLock<String> = OnceLock::new();
pub static PEM_PATH: OnceLock<String> = OnceLock::new();
pub static IC_REPLICA_URL: OnceLock<String> = OnceLock::new();

pub static PROVER_URL: OnceLock<String> = OnceLock::new();
pub static PROVER_API_KEY: OnceLock<String> = OnceLock::new();
pub static PROVER_BLUEPRINT_ID: OnceLock<String> = OnceLock::new();
pub static PROVER_ZKEY_DOWNLOAD_URL: OnceLock<String> = OnceLock::new();
pub static PROVER_CIRCUIT_CPP_DOWNLOAD_URL: OnceLock<String> = OnceLock::new();

static DB_CELL: OnceCell<Arc<Database>> = OnceCell::const_new();

/// Wrapper struct for database access
Expand Down Expand Up @@ -111,7 +116,6 @@ pub async fn run(config: RelayerConfig) -> Result<()> {
// Initialize realyer configuration
REGEX_JSON_DIR_PATH.set(config.regex_json_dir_path).unwrap();
WEB_SERVER_ADDRESS.set(config.web_server_address).unwrap();
PROVER_ADDRESS.set(config.prover_address).unwrap();
PRIVATE_KEY.set(config.private_key).unwrap();
DATABASE_PATH.set(config.db_path).unwrap();
CHAIN_ID.set(config.chain_id).unwrap();
Expand All @@ -131,6 +135,16 @@ pub async fn run(config: RelayerConfig) -> Result<()> {
PEM_PATH.set(config.pem_path).unwrap();
IC_REPLICA_URL.set(config.ic_replica_url).unwrap();

PROVER_URL.set(config.prover_url).unwrap();
PROVER_API_KEY.set(config.prover_api_key).unwrap();
PROVER_BLUEPRINT_ID.set(config.prover_blueprint_id).unwrap();
PROVER_ZKEY_DOWNLOAD_URL
.set(config.prover_zkey_download_url)
.unwrap();
PROVER_CIRCUIT_CPP_DOWNLOAD_URL
.set(config.prover_circuit_cpp_download_url)
.unwrap();

// Spawn the API server task
let api_server_task = tokio::task::spawn(async move {
loop {
Expand Down
7 changes: 7 additions & 0 deletions packages/relayer/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ pub const CHAIN_ID_KEY: &str = "CHAIN_ID";
pub const EMAIL_ACCOUNT_RECOVERY_VERSION_ID_KEY: &str = "EMAIL_ACCOUNT_RECOVERY_VERSION_ID";
pub const EMAIL_TEMPLATES_PATH_KEY: &str = "EMAIL_TEMPLATES_PATH";
pub const REGEX_JSON_DIR_PATH_KEY: &str = "REGEX_JSON_DIR_PATH";

// Prover
pub const PROVER_URL_KEY: &str = "PROVER_URL";
pub const PROVER_API_KEY_KEY: &str = "PROVER_API_KEY";
pub const PROVER_BLUEPRINT_ID_KEY: &str = "PROVER_BLUEPRINT_ID";
pub const PROVER_ZKEY_DOWNLOAD_URL_KEY: &str = "PROVER_ZKEY_DOWNLOAD_URL";
pub const PROVER_CIRCUIT_CPP_DOWNLOAD_URL_KEY: &str = "PROVER_CIRCUIT_CPP_DOWNLOAD_URL";
pub const ERROR_EMAIL_ADDR_KEY: &str = "ERROR_EMAIL_ADDR";

// DKIM ORACLE ARGS
Expand Down

0 comments on commit ff43cf8

Please sign in to comment.