diff --git a/listener/src/job_creator.rs b/listener/src/job_creator.rs index 957e07a..ed8f4a4 100644 --- a/listener/src/job_creator.rs +++ b/listener/src/job_creator.rs @@ -118,6 +118,7 @@ pub struct JobCreator { max_threads: usize, shared_latest_block: Arc>, should_stop: Arc, + skip_input_verification: bool, } impl JobCreator { @@ -126,14 +127,22 @@ impl JobCreator { runtime_config: RuntimeConfig, max_threads: usize, enable_logging_server: bool, + skip_input_verification: bool, ) -> Self { - Self::initialize(config, runtime_config, enable_logging_server, max_threads) + Self::initialize( + config, + runtime_config, + enable_logging_server, + skip_input_verification, + max_threads, + ) } fn initialize( config: Config, runtime_config: RuntimeConfig, enable_logging_server: bool, + skip_input_verification: bool, max_threads: usize, ) -> Self { let service_name = Uuid::new_v4().to_string(); @@ -162,6 +171,7 @@ impl JobCreator { max_threads, shared_latest_block, should_stop, + skip_input_verification, } } else { Self { @@ -171,6 +181,7 @@ impl JobCreator { max_threads, shared_latest_block, should_stop, + skip_input_verification, } } } @@ -202,6 +213,7 @@ impl JobCreator { ivs_url: String, enable_logging_server: bool, max_threads: usize, + skip_input_verification: bool, ) -> Self { let generator_config_models = vec![GeneratorConfigModel { address: generator_address, @@ -241,7 +253,13 @@ impl JobCreator { runtime_config: runtime_config_model, }; - Self::initialize(config, runtime_config, enable_logging_server, max_threads) + Self::initialize( + config, + runtime_config, + enable_logging_server, + skip_input_verification, + max_threads, + ) } #[allow(clippy::too_many_arguments)] @@ -257,6 +275,7 @@ impl JobCreator { ivs_url: String, enable_logging_server: bool, max_threads: usize, + skip_input_verification: bool, ) -> Self { let config = Config { generator_config: generator_configs, @@ -292,7 +311,13 @@ impl JobCreator { runtime_config: runtime_config_model, }; - Self::initialize(config, runtime_config, enable_logging_server, max_threads) + Self::initialize( + config, + runtime_config, + enable_logging_server, + skip_input_verification, + max_threads, + ) } #[allow(clippy::too_many_arguments)] @@ -309,6 +334,7 @@ impl JobCreator { prover_port: String, enable_logging_server: bool, max_threads: usize, + skip_input_verification: bool, ) -> Self { let generator_config_models = vec![GeneratorConfigModel { address: generator_address, @@ -348,7 +374,13 @@ impl JobCreator { runtime_config: runtime_config_model, }; - Self::initialize(config, runtime_config, enable_logging_server, max_threads) + Self::initialize( + config, + runtime_config, + enable_logging_server, + skip_input_verification, + max_threads, + ) } pub fn from_config_paths( @@ -356,6 +388,7 @@ impl JobCreator { runtime_config_path: &str, enable_logging_server: bool, max_threads: usize, + skip_input_verification: bool, ) -> anyhow::Result { let file_content = std::fs::read_to_string(generator_config_path)?; let config: Config = serde_json::from_str(&file_content)?; @@ -367,6 +400,7 @@ impl JobCreator { config, runtime_config, enable_logging_server, + skip_input_verification, max_threads, )) } @@ -594,6 +628,7 @@ impl JobCreator { let proof_semaphore = proof_semaphore.clone(); let transaction_semaphore = transaction_semaphore.clone(); + let skip_input_verification = self.skip_input_verification.clone(); tokio::spawn(async move { log::info!( "Spin up new thread from proof generation of ask: {}", @@ -609,6 +644,7 @@ impl JobCreator { end_block: &latest_block, markets: &markets_clone, slave_ecies_private_keys: binding.as_ref(), + skip_input_verification, }; let proof_permit = proof_semaphore diff --git a/listener/src/main.rs b/listener/src/main.rs index 4abf278..53c8b97 100644 --- a/listener/src/main.rs +++ b/listener/src/main.rs @@ -20,7 +20,7 @@ async fn main() -> Result<(), Box> { .or_else(|_| fs::read_to_string(&alt_runtime_config_path))?; println!("{}", &file_content); let runtime_config: job_creator::RuntimeConfig = serde_json::from_str(&file_content)?; - let _ = job_creator::JobCreator::new(config, runtime_config, 1, false) + let _ = job_creator::JobCreator::new(config, runtime_config, 1, false, false) .run() .await; Ok(()) diff --git a/listener/src/proof_generator/confidential_provers.rs b/listener/src/proof_generator/confidential_provers.rs index 250e894..f6316a5 100644 --- a/listener/src/proof_generator/confidential_provers.rs +++ b/listener/src/proof_generator/confidential_provers.rs @@ -6,6 +6,7 @@ use super::prover::{post_request, Prover}; pub struct ExternalConfidentialProver { base: ConfidentialProver, encryption_key: Vec, + skip_input_verification: bool, } impl ExternalConfidentialProver { @@ -20,6 +21,7 @@ impl ExternalConfidentialProver { public: Bytes, secrets: Bytes, encryption_key: Vec, + skip_input_verification: bool, ) -> Self { ExternalConfidentialProver { base: ConfidentialProver::new( @@ -30,8 +32,10 @@ impl ExternalConfidentialProver { ask_id, public, secrets, + skip_input_verification, ), encryption_key, + skip_input_verification, } } @@ -52,6 +56,10 @@ impl ExternalConfidentialProver { } impl Prover for ExternalConfidentialProver { + fn should_skip_input_verification(&self) -> bool { + self.skip_input_verification + } + async fn check_inputs(&self) -> Result> { let (public, secrets, acl) = self.prepare_payload(); let payload = generator::models::InputPayload::from_encrypted_secrets( @@ -123,6 +131,7 @@ pub struct ConfidentialProver { public: Bytes, secrets: Bytes, client: reqwest::Client, + skip_input_verification: bool, } impl ConfidentialProver { @@ -134,6 +143,7 @@ impl ConfidentialProver { ask_id: U256, public: Bytes, secrets: Bytes, + skip_input_verification: bool, ) -> Self { Self { input_verification_executable_check_input_url, @@ -144,6 +154,7 @@ impl ConfidentialProver { public, secrets, client: reqwest::Client::new(), + skip_input_verification, } } @@ -155,6 +166,10 @@ impl ConfidentialProver { type BoxError = Box; impl Prover for ConfidentialProver { + fn should_skip_input_verification(&self) -> bool { + self.skip_input_verification + } + async fn check_inputs(&self) -> Result { let (public, secrets) = self.prepare_payload(); let payload = generator::models::InputPayload::from_plain_secrets(public, secrets.unwrap()); diff --git a/listener/src/proof_generator/mod.rs b/listener/src/proof_generator/mod.rs index 978655d..0b58e8a 100644 --- a/listener/src/proof_generator/mod.rs +++ b/listener/src/proof_generator/mod.rs @@ -32,6 +32,7 @@ pub struct GenerateProofParams<'a> { pub end_block: &'a U64, pub markets: &'a HashMap, pub slave_ecies_private_keys: &'a Vec, + pub skip_input_verification: bool, } //Generating proof for the input @@ -75,6 +76,7 @@ pub async fn generate_proof( decoded_secret_input .expect("Unable to decode secret for confidential markets") .into(), + generate_proof_params.skip_input_verification, ); confidential_prover.get_proof().await @@ -96,6 +98,7 @@ pub async fn generate_proof( generator_url.clone().unwrap().clone(), parsed_ask_created_log.ask_id, public_inputs.into(), + generate_proof_params.skip_input_verification, ); non_confidential_prover.get_proof().await @@ -121,6 +124,7 @@ async fn fetch_decoded_secret( new_acl, markets, slave_ecies_private_keys, + skip_input_verification: _, } = generate_proof_params; let client = proof_market_place_contract_http.client(); let list_of_ask: &Ask = &proof_market_place_contract_http diff --git a/listener/src/proof_generator/non_confidential_prover.rs b/listener/src/proof_generator/non_confidential_prover.rs index 74b9c4c..c4965df 100644 --- a/listener/src/proof_generator/non_confidential_prover.rs +++ b/listener/src/proof_generator/non_confidential_prover.rs @@ -11,6 +11,7 @@ pub struct NonConfidentialProver { ask_id: U256, public: Bytes, client: reqwest::Client, + skip_input_verification: bool, } impl NonConfidentialProver { @@ -21,6 +22,7 @@ impl NonConfidentialProver { prover_executable_generate_proof_url: String, ask_id: U256, public: Bytes, + skip_input_verification: bool, ) -> Self { Self { input_verification_executable_check_input_url, @@ -30,6 +32,7 @@ impl NonConfidentialProver { ask_id, public, client: reqwest::Client::new(), + skip_input_verification, } } @@ -41,6 +44,9 @@ impl NonConfidentialProver { type BoxError = Box; impl Prover for NonConfidentialProver { + fn should_skip_input_verification(&self) -> bool { + self.skip_input_verification + } async fn check_inputs(&self) -> Result { let (public, _) = self.prepare_payload(); let payload = generator::models::InputPayload::only_public_inputs(public); diff --git a/listener/src/proof_generator/prover.rs b/listener/src/proof_generator/prover.rs index d6c4d0f..afcfeb4 100644 --- a/listener/src/proof_generator/prover.rs +++ b/listener/src/proof_generator/prover.rs @@ -22,7 +22,14 @@ pub trait Prover { proof: &[u8], ) -> Result>; + fn should_skip_input_verification(&self) -> bool; + async fn get_proof(&self) -> Result> { + if self.should_skip_input_verification() { + let proof = self.generate_proof().await?; + return Ok(Proof::ValidProof(proof.proof.into())); + } + let check_input = self.check_inputs().await?; if check_input.valid { let proof = self.generate_proof().await?;