Skip to content

Commit

Permalink
add feature in listener to skip input verification, at risk
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Nov 1, 2024
1 parent 14aa980 commit 16b7627
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
44 changes: 40 additions & 4 deletions listener/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub struct JobCreator {
max_threads: usize,
shared_latest_block: Arc<tokio::sync::Mutex<U64>>,
should_stop: Arc<AtomicBool>,
skip_input_verification: bool,
}

impl JobCreator {
Expand All @@ -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();
Expand Down Expand Up @@ -162,6 +171,7 @@ impl JobCreator {
max_threads,
shared_latest_block,
should_stop,
skip_input_verification,
}
} else {
Self {
Expand All @@ -171,6 +181,7 @@ impl JobCreator {
max_threads,
shared_latest_block,
should_stop,
skip_input_verification,
}
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand All @@ -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,
Expand Down Expand Up @@ -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)]
Expand All @@ -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,
Expand Down Expand Up @@ -348,14 +374,21 @@ 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(
generator_config_path: &str,
runtime_config_path: &str,
enable_logging_server: bool,
max_threads: usize,
skip_input_verification: bool,
) -> anyhow::Result<Self> {
let file_content = std::fs::read_to_string(generator_config_path)?;
let config: Config = serde_json::from_str(&file_content)?;
Expand All @@ -367,6 +400,7 @@ impl JobCreator {
config,
runtime_config,
enable_logging_server,
skip_input_verification,
max_threads,
))
}
Expand Down Expand Up @@ -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: {}",
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion listener/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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(())
Expand Down
15 changes: 15 additions & 0 deletions listener/src/proof_generator/confidential_provers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::prover::{post_request, Prover};
pub struct ExternalConfidentialProver {
base: ConfidentialProver,
encryption_key: Vec<u8>,
skip_input_verification: bool,
}

impl ExternalConfidentialProver {
Expand All @@ -20,6 +21,7 @@ impl ExternalConfidentialProver {
public: Bytes,
secrets: Bytes,
encryption_key: Vec<u8>,
skip_input_verification: bool,
) -> Self {
ExternalConfidentialProver {
base: ConfidentialProver::new(
Expand All @@ -30,8 +32,10 @@ impl ExternalConfidentialProver {
ask_id,
public,
secrets,
skip_input_verification,
),
encryption_key,
skip_input_verification,
}
}

Expand All @@ -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<ivs::models::CheckInputResponse, Box<dyn Error>> {
let (public, secrets, acl) = self.prepare_payload();
let payload = generator::models::InputPayload::from_encrypted_secrets(
Expand Down Expand Up @@ -123,6 +131,7 @@ pub struct ConfidentialProver {
public: Bytes,
secrets: Bytes,
client: reqwest::Client,
skip_input_verification: bool,
}

impl ConfidentialProver {
Expand All @@ -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,
Expand All @@ -144,6 +154,7 @@ impl ConfidentialProver {
public,
secrets,
client: reqwest::Client::new(),
skip_input_verification,
}
}

Expand All @@ -155,6 +166,10 @@ impl ConfidentialProver {
type BoxError = Box<dyn Error>;

impl Prover for ConfidentialProver {
fn should_skip_input_verification(&self) -> bool {
self.skip_input_verification
}

async fn check_inputs(&self) -> Result<ivs::models::CheckInputResponse, BoxError> {
let (public, secrets) = self.prepare_payload();
let payload = generator::models::InputPayload::from_plain_secrets(public, secrets.unwrap());
Expand Down
4 changes: 4 additions & 0 deletions listener/src/proof_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct GenerateProofParams<'a> {
pub end_block: &'a U64,
pub markets: &'a HashMap<String, MarketDetails>,
pub slave_ecies_private_keys: &'a Vec<ecies::SecretKey>,
pub skip_input_verification: bool,
}

//Generating proof for the input
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions listener/src/proof_generator/non_confidential_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct NonConfidentialProver {
ask_id: U256,
public: Bytes,
client: reqwest::Client,
skip_input_verification: bool,
}

impl NonConfidentialProver {
Expand All @@ -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,
Expand All @@ -30,6 +32,7 @@ impl NonConfidentialProver {
ask_id,
public,
client: reqwest::Client::new(),
skip_input_verification,
}
}

Expand All @@ -41,6 +44,9 @@ impl NonConfidentialProver {
type BoxError = Box<dyn Error>;

impl Prover for NonConfidentialProver {
fn should_skip_input_verification(&self) -> bool {
self.skip_input_verification
}
async fn check_inputs(&self) -> Result<ivs::models::CheckInputResponse, BoxError> {
let (public, _) = self.prepare_payload();
let payload = generator::models::InputPayload::only_public_inputs(public);
Expand Down
7 changes: 7 additions & 0 deletions listener/src/proof_generator/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ pub trait Prover {
proof: &[u8],
) -> Result<ivs::models::VerifyInputAndProofResponse, Box<dyn Error>>;

fn should_skip_input_verification(&self) -> bool;

async fn get_proof(&self) -> Result<Proof, Box<dyn Error>> {
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?;
Expand Down

0 comments on commit 16b7627

Please sign in to comment.