Skip to content

Commit

Permalink
refactor: remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Dec 6, 2024
1 parent 2ca3273 commit d7f75b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 64 deletions.
32 changes: 4 additions & 28 deletions packages/relayer-lib/src/tx_builder/eth_eureka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ use sp1_ics07_tendermint_prover::{
programs::UpdateClientAndMembershipProgram, prover::SP1ICS07TendermintProver,
};

use sp1_ics07_tendermint_utils::{
light_block::LightBlockExt, merkle::convert_tm_to_ics_merkle_proof, rpc::TendermintRpcExt,
};
use sp1_ics07_tendermint_utils::{light_block::LightBlockExt, rpc::TendermintRpcExt};
use sp1_sdk::HashableKey;
use tendermint_rpc::{Client, HttpClient};
use tendermint_rpc::HttpClient;

use crate::{
chain::{CosmosSdk, EthEureka},
Expand Down Expand Up @@ -197,30 +195,8 @@ where

let kv_proofs: Vec<(Vec<Vec<u8>>, Vec<u8>, _)> =
future::try_join_all(ibc_paths.into_iter().map(|path| async {
let res = self
.tm_client
.abci_query(
Some(format!("store/{}/key", std::str::from_utf8(&path[0])?)),
path[1].as_slice(),
// Proof height should be the block before the target block.
Some((revision_height - 1).into()),
true,
)
.await?;

if u32::try_from(res.height.value())? + 1 != revision_height {
anyhow::bail!("Proof height mismatch");
}

if res.key.as_slice() != path[1].as_slice() {
anyhow::bail!("Key mismatch");
}
let vm_proof = convert_tm_to_ics_merkle_proof(&res.proof.unwrap())?;
if vm_proof.proofs.is_empty() {
anyhow::bail!("Empty proof");
}

anyhow::Ok((path, res.value, vm_proof))
let (value, proof) = self.tm_client.prove_path(&path, revision_height).await?;
anyhow::Ok((path, value, proof))
}))
.await?;

Expand Down
23 changes: 5 additions & 18 deletions programs/operator/src/runners/fixtures/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use sp1_ics07_tendermint_prover::{
programs::MembershipProgram,
prover::{SP1ICS07TendermintProver, SupportedProofType},
};
use sp1_ics07_tendermint_utils::{merkle::convert_tm_to_ics_merkle_proof, rpc::TendermintRpcExt};
use sp1_ics07_tendermint_utils::rpc::TendermintRpcExt;
use sp1_sdk::HashableKey;
use std::path::PathBuf;
use tendermint_rpc::{Client, HttpClient};
use tendermint_rpc::HttpClient;

/// The fixture data to be used in [`MembershipProgram`] tests.
#[serde_with::serde_as]
Expand Down Expand Up @@ -122,22 +122,9 @@ pub async fn run_sp1_membership(
};
assert_eq!(path.len(), 2);

let res = tm_rpc_client
.abci_query(
Some(format!("store/{}/key", str::from_utf8(&path[0])?)),
path[1].as_slice(),
// Proof height should be the block before the target block.
Some((trusted_block - 1).into()),
true,
)
.await?;

assert_eq!(u32::try_from(res.height.value())? + 1, trusted_block);
assert_eq!(res.key.as_slice(), path[1].as_slice());
let vm_proof = convert_tm_to_ics_merkle_proof(&res.proof.unwrap())?;
assert!(!vm_proof.proofs.is_empty());

anyhow::Ok((path, res.value, vm_proof))
let (value, proof) = tm_rpc_client.prove_path(&path, trusted_block).await?;

anyhow::Ok((path, value, proof))
}))
.await?;

Expand Down
21 changes: 3 additions & 18 deletions programs/operator/src/runners/fixtures/uc_and_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
},
};
use alloy_sol_types::SolValue;
use core::str;
use ibc_client_tendermint_types::ConsensusState;
use ibc_core_commitment_types::merkle::MerkleProof;
use ibc_eureka_solidity_types::sp1_ics07::{
Expand All @@ -19,11 +18,10 @@ use ibc_eureka_solidity_types::sp1_ics07::{
use sp1_ics07_tendermint_prover::{
programs::UpdateClientAndMembershipProgram, prover::SP1ICS07TendermintProver,
};
use sp1_ics07_tendermint_utils::merkle::convert_tm_to_ics_merkle_proof;
use sp1_ics07_tendermint_utils::{light_block::LightBlockExt, rpc::TendermintRpcExt};
use sp1_sdk::HashableKey;
use std::path::PathBuf;
use tendermint_rpc::{Client, HttpClient};
use tendermint_rpc::HttpClient;

/// Writes the proof data for the given trusted and target blocks to the given fixture path.
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
Expand Down Expand Up @@ -71,22 +69,9 @@ pub async fn run(args: UpdateClientAndMembershipCmd) -> anyhow::Result<()> {
};
assert_eq!(path.len(), 2);

let res = tm_rpc_client
.abci_query(
Some(format!("store/{}/key", str::from_utf8(&path[0])?)),
path[1].as_slice(),
// Proof height should be the block before the target block.
Some((args.target_block - 1).into()),
true,
)
.await?;
let (value, proof) = tm_rpc_client.prove_path(&path, args.target_block).await?;

assert_eq!(u32::try_from(res.height.value())? + 1, args.target_block);
assert_eq!(res.key.as_slice(), path[1].as_slice());
let vm_proof = convert_tm_to_ics_merkle_proof(&res.proof.unwrap())?;
assert!(!vm_proof.proofs.is_empty());

anyhow::Ok((path, res.value, vm_proof))
anyhow::Ok((path, value, proof))
}))
.await?;

Expand Down

0 comments on commit d7f75b1

Please sign in to comment.