Skip to content

Commit

Permalink
draft of function calling the zk-prover http server
Browse files Browse the repository at this point in the history
  • Loading branch information
blasrodri committed Nov 8, 2023
1 parent 7519168 commit 2ff863d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
26 changes: 14 additions & 12 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions hyperspace/cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ ripemd = "0.1.3"
digest = "0.10.6"
quick_cache = "0.3.0"
rand = "0.8.5"
ureq = {version = "2.8.0", features = ["json"] }
base64 = "0.21.5"


# composable
ibc = { path = "../../ibc/modules", features = [] }
Expand Down
1 change: 1 addition & 0 deletions hyperspace/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ pub mod provider;
#[cfg(any(test, feature = "testing"))]
pub mod test_provider;
pub mod tx;
pub mod utils;

pub type TimeoutHeight = Option<Height>;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use base64::{engine::general_purpose, Engine as _};

use crate::error::Error;
use ics07_tendermint::client_message::Header;
use tendermint::{
block::{signed_header::SignedHeader, Commit, CommitSig},
crypto::default::signature::Verifier,
crypto::{default::signature::Verifier, signature::Verifier as _},
signature::Signature,
PublicKey,
};

use crate::client_message::Header;

use tendermint::crypto::signature::Verifier as _;

/// Utilty function that:
/// - collects {signature, pubkey, msg} from every validator that successfuly signed a block so that
/// - there's consensus (voting power > 2/3) and
Expand All @@ -20,14 +20,12 @@ pub fn collect_signatures_for_finalized_block(
) -> Option<Vec<(PublicKey, Signature, Vec<u8>)>> {
let Header {
validator_set,
signed_header: SignedHeader { header, commit: Commit { signatures, .. }, .. },
signed_header: SignedHeader { commit: Commit { signatures, .. }, .. },
..
} = header;

let total_voting_power = validator_set.total_voting_power().value();

// 1. order by voting power

// filter by valid signatures
let mut validator_info_signed_block = signatures
.iter()
Expand Down Expand Up @@ -80,6 +78,50 @@ pub fn collect_signatures_for_finalized_block(
}
}

// fn check_block_is_final() {
// TODO: this should be async
pub fn call_zk_prover(
zk_prover_url: String,
signatures: Vec<u8>,
public_keys: Vec<u8>,
messages: Vec<u8>,
) -> Result<Vec<u8>, Error> {
let body: ProverResponse = ureq::get(zk_prover_url.as_ref())
.call()
.map_err(|e| Error::Custom(e.to_string()))?
.into_json()
.map_err(|e| Error::Custom(e.to_string()))?;

if body.message.as_str() != "prover is busy" {
let resp: ProverResponse = ureq::post(zk_prover_url.as_ref())
.send_json(ureq::json!({
"public_keys": public_keys,
"signatures": signatures,
"messages": messages,
}))
.map_err(|e| Error::Custom(e.to_string()))?
.into_json()
.map_err(|e| Error::Custom(e.to_string()))?;

// }
if &resp.message == "proof submitted" {
let body: ProverResponse = ureq::get(zk_prover_url.as_ref())
.call()
.map_err(|e| Error::Custom(e.to_string()))?
.into_json()
.map_err(|e| Error::Custom(e.to_string()))?;

// assume here that we got the proof
// TODO: do proper re-check as the proof takes 5 minutes to be build
return Ok(general_purpose::STANDARD_NO_PAD
.decode(body.proof)
.map_err(|e| Error::Custom(e.to_string()))?)
}
}
Err(Error::Custom("could not get a proof".to_string()))
}

// note that we know the circuit size
#[derive(Debug, serde::Deserialize)]
struct ProverResponse {
message: String,
proof: String,
}
2 changes: 0 additions & 2 deletions light-clients/ics07-tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ pub mod merkle;
pub mod mock;
#[cfg(any(test, feature = "mocks"))]
mod query;
pub mod utils;

/// Host functions that allow the light client verify cryptographic proofs in native.
pub trait HostFunctionsProvider:
ics23::HostFunctionsProvider
Expand Down

0 comments on commit 2ff863d

Please sign in to comment.