Skip to content

Commit

Permalink
Add new cli checks
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 23, 2024
1 parent c3a84a7 commit 37ffacc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
26 changes: 24 additions & 2 deletions kalypso-cli/src/common_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ pub struct UpdateEncryptionKeyInfo {
pub generator_registry: bindings::generator_registry::GeneratorRegistry<
SignerMiddleware<Provider<Http>, LocalWallet>,
>,
pub proof_marketplace: bindings::proof_marketplace::ProofMarketplace<Provider<Http>>,
pub attestation_utility: String,
pub attestation_verifier: String,
pub enclave_client_url: String,
Expand All @@ -810,6 +811,8 @@ impl CommonDeps {
get_config_ref!(config, "generator_registry", generator_registry_address);
get_config_ref!(config, "chain_id", chain_id);

get_config_ref!(config, "proof_marketplace", proof_marketplace_address);

get_config_ref!(config, "attestation_server_url", attestation_server_url);
get_config_ref!(config, "attestion_verifier_url", attestion_verifier_url);
get_config_ref!(config, "enclave_client_url", enclave_client_url);
Expand All @@ -825,13 +828,17 @@ impl CommonDeps {
let market_id = U256::from_dec_str(market_id.as_str())
.map_err(|e| format!("Invalid Market Id: {}", e))?;

let (proof_marketplace, _) =
get_proof_marketplace_instance_without_signer(proof_marketplace_address, rpc_url)?;

Ok(UpdateEncryptionKeyInfo {
private_key_signer,
generator_registry,
attestation_utility: attestation_server_url.to_string(),
attestation_verifier: attestion_verifier_url.to_string(),
enclave_client_url: enclave_client_url.to_string(),
market_id,
proof_marketplace,
})
}
}
Expand Down Expand Up @@ -1441,6 +1448,10 @@ pub struct UpdateGeneratorMetaInfo {
pub generator_registry: binding_patches::UpdateGeneratorMetadataPatch<
SignerMiddleware<Provider<Http>, LocalWallet>,
>,
pub read_generator_registry: bindings::generator_registry::GeneratorRegistry<
SignerMiddleware<Provider<Http>, LocalWallet>,
>,
pub private_key_signer: LocalWallet,
}

impl CommonDeps {
Expand All @@ -1452,14 +1463,25 @@ impl CommonDeps {
get_config_ref!(config, "chain_id", chain_id);
get_config_ref!(config, "generator_registry", generator_registry_address);

let (generator_registry, _) = update_generator_meta_instance(
let (generator_registry, private_key_signer) = update_generator_meta_instance(
private_key,
chain_id,
generator_registry_address,
rpc_url,
)?;

Ok(UpdateGeneratorMetaInfo { generator_registry })
let (read_generator_registry, _) = get_generator_registry_instance(
private_key,
chain_id,
generator_registry_address,
rpc_url,
)?;

Ok(UpdateGeneratorMetaInfo {
generator_registry,
private_key_signer,
read_generator_registry,
})
}
}

Expand Down
1 change: 1 addition & 0 deletions kalypso-cli/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
"private_key",
"rpc_url",
"chain_id",
"proof_marketplace",
"generator_registry",
"market_id",
"attestation_server_url",
Expand Down
18 changes: 17 additions & 1 deletion kalypso-cli/src/operations/join_marketplace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{common_deps::CommonDeps, operations::Operation};
use async_trait::async_trait;
use ethers::{signers::Signer, types::Address};
use ethers::{
signers::Signer,
types::{Address, H256},
};
use std::collections::HashMap;

pub struct JoinMarketplace;
Expand Down Expand Up @@ -54,6 +57,19 @@ impl Operation for JoinMarketplace {

// Print the transaction hash
println!("{}", tx_hash);

let market_data = generator_join_market
.proof_marketplace
.market_data(generator_join_market.market_id)
.call()
.await
.map_err(|e| {
format!("Failed making call to proof marketplace contract {}", e)
})?;

if H256::from_slice(&market_data.1.to_vec()) != kalypso_helper::image_id_helpers::hashed_image_id_for_non_confidential_market() {
println!("Market: {} is a confidential market. Please Update Encryption Key after doing so. Else the prover will not receive jobs", generator_join_market.market_id);
}
}
}
Err(_) => {
Expand Down
15 changes: 14 additions & 1 deletion kalypso-cli/src/operations/update_encryption_key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use async_trait::async_trait;
use ethers::signers::Signer;
use ethers::{signers::Signer, types::H256};
use futures::StreamExt;

use crate::{common_deps::CommonDeps, operations::compute_pcrs};
Expand Down Expand Up @@ -88,6 +88,19 @@ impl Operation for UpdateEncryptionKey {
async fn execute(&self, config: HashMap<String, String>) -> Result<(), String> {
let update_encryption_info = CommonDeps::update_encryption_info(&config)?;

let market_data = update_encryption_info
.proof_marketplace
.market_data(update_encryption_info.market_id)
.call()
.await
.map_err(|e| format!("Failed making call to proof marketplace contract {}", e))?;

if H256::from_slice(&market_data.1.to_vec())
== kalypso_helper::image_id_helpers::hashed_image_id_for_non_confidential_market()
{
return Err("non confidential markets don't need encryption key".to_string());
}

let attestation_stream =
compute_pcrs::build_attestation(&update_encryption_info.attestation_utility, false)
.await
Expand Down
12 changes: 12 additions & 0 deletions kalypso-cli/src/operations/update_generator_meta.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashMap, fs, io};

use async_trait::async_trait;
use ethers::{signers::Signer, types::Address};

use crate::common_deps::CommonDeps;

Expand All @@ -13,6 +14,17 @@ impl Operation for UpdateGeneratorMeta {
async fn execute(&self, config: HashMap<String, String>) -> Result<(), String> {
let generator_meta_info = CommonDeps::update_generator_meta_info(&config)?;

let generator_data = generator_meta_info
.read_generator_registry
.generator_registry(generator_meta_info.private_key_signer.address())
.call()
.await
.map_err(|e| format!("Failed Reading Generator Registry Contract {}", e))?;

if generator_data.0.eq(&Address::zero()) {
return Err(format!("Please 'Register' operator first"));
}

let generator_meta_paths = ["./generatormeta.json"];

let data = read_file_from_paths(&generator_meta_paths)
Expand Down

0 comments on commit 37ffacc

Please sign in to comment.