Skip to content

Commit

Permalink
Additional debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 16, 2024
1 parent bd2d9f3 commit a78857d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use ibc_types::{
State as ConnectionState,
},
};
use penumbra_proto::DomainType;
use sha2::Digest;

use crate::component::{
client::StateReadExt as _,
Expand Down Expand Up @@ -99,6 +101,63 @@ impl MsgHandler for MsgConnectionOpenTry {
// PROOF VERIFICATION
// 1. verify that the counterparty chain committed the expected_conn to its state
let proof_conn_end_on_a = self.proof_conn_end_on_a.clone();

let existence_proofs: Vec<(Vec<u8>, Vec<u8>)> = proof_conn_end_on_a
.proofs
.iter()
.map(|proof| {
let p = proof.proof.clone().unwrap();
match p {
ics23::commitment_proof::Proof::Exist(p) => (p.key, p.value),
_ => (vec![], vec![]),
}
})
.inspect(|(k, v)| {
println!(
"proof_conn_end_on_a: k {} v {}",
hex::encode(k),
hex::encode(v)
);
})
.collect();

{
// TODO: change this into a different test after the bug is understood
assert_eq!(
hex::encode(&existence_proofs[0].0),
"636f6e6e656374696f6e732f636f6e6e656374696f6e2d30"
);
assert_eq!(hex::encode(&existence_proofs[0].1), "0a0f30372d74656e6465726d696e742d3012230a0131120d4f524445525f4f524445524544120f4f524445525f554e4f5244455245441801221d0a0f30372d74656e6465726d696e742d301a0a0a086962632d64617461288094ebdc03");
assert_eq!(hex::encode(&existence_proofs[1].0), "6962632d64617461");
assert_eq!(
hex::encode(&existence_proofs[1].1),
"e421a1ef4acacb331f598197adb7d3250f2b4f84a3e30721190fd00bfe914de3"
);
}

println!("trusted_client_state: {:?}", trusted_client_state);
println!("proofs_height_on_a: {:?}", self.proofs_height_on_a);
println!(
"counterparty.prefix: {}",
hex::encode(self.counterparty.prefix.key_prefix.clone())
);
println!(
"trusted_consensus_state.root.hash: {}",
hex::encode(trusted_consensus_state.root.hash.clone())
);
assert_eq!(
hex::encode(trusted_consensus_state.root.hash.clone()),
"d01e8818de18fb050c7aff28a59d430db07802f91c14c4370cf8be785381d4c7".to_string()
);
println!("expected_conn: {:?}", expected_conn);

let hashed_client_state = sha2::Sha256::digest(trusted_client_state.encode_to_vec());
println!("hashed_client_state: {}", hex::encode(hashed_client_state));
assert_eq!(
hex::encode(hashed_client_state),
"41e997cf572ca0d333e9a35d571d34cc2e67939dda4bd1a8a356aa35fa17dbb2"
);

proof_verification::verify_connection_state(
&trusted_client_state,
self.proofs_height_on_a,
Expand Down
44 changes: 44 additions & 0 deletions crates/core/component/ibc/src/component/proof_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use ibc_types::{
use async_trait::async_trait;
use cnidarium::StateRead;
use num_traits::float::FloatCore;
use prost::Message as _;
use sha2::{Digest, Sha256};

use super::HostInterface;
Expand Down Expand Up @@ -103,8 +104,51 @@ fn verify_merkle_proof(
?merkle_path,
value = ?hex::encode(&value),
);
println!(
"root: {}, merkle_path: {}, value: {}",
hex::encode(root.hash.clone()),
hex::encode(sha2::Sha256::digest(merkle_path.encode_to_vec())),
hex::encode(sha2::Sha256::digest(value.clone()))
);
for proof in proof.proofs.iter() {
println!(
"commitment proof: {}",
hex::encode(sha2::Sha256::digest(proof.encode_to_vec()))
);
}
assert_eq!(
hex::encode(sha2::Sha256::digest(proof.proofs[0].encode_to_vec())),
"fd5a592d393101820ccee81d589357917cb45a694b865cb9417e78c83f423ce7"
);
assert_eq!(
hex::encode(sha2::Sha256::digest(proof.proofs[1].encode_to_vec())),
"d98c5618b67345670fc5b6c0327e173b1e8bc4aa40d8bb74bad0ed2676bdf2c1"
);
assert_eq!(
hex::encode(root.hash.clone()),
"d01e8818de18fb050c7aff28a59d430db07802f91c14c4370cf8be785381d4c7"
);
assert_eq!(
hex::encode(sha2::Sha256::digest(merkle_path.encode_to_vec())),
"fddd7422e198fc9b30d2234f294049bf3f628e0eac3a4e161f0fde8187856500"
);
assert_eq!(
hex::encode(sha2::Sha256::digest(value.encode_to_vec())),
"39a4637d6e977d892cecdc16d0b392f1a985f261926b99402bfc4bedefeeceac"
);
assert_eq!(
hex::encode(sha2::Sha256::digest(proof_specs[0].encode_to_vec())),
"6037a57b21e649bde4b8bd2c6187a56ee432fb53ba8290cd77c408a5af5cab03"
);
assert_eq!(
hex::encode(sha2::Sha256::digest(proof_specs[1].encode_to_vec())),
"6037a57b21e649bde4b8bd2c6187a56ee432fb53ba8290cd77c408a5af5cab03"
);
proof.verify_membership(proof_specs, root.clone(), merkle_path, value, 0)?;

// fail here to prevent macOS from continuing. linux should have failed on the last call.
assert!(false, "EXPECTED FAILURE ON MACOS");

Ok(())
}

Expand Down

0 comments on commit a78857d

Please sign in to comment.