Skip to content

Commit

Permalink
chore: enable rlp encode for axon proof (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuralyk authored Dec 16, 2023
2 parents 1e0a1d8 + fbf5288 commit c7bb87c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
53 changes: 44 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tree_hash_derive = { git = "https://github.com/synapseweb3/lighthouse", rev = "2
thiserror = "1.0"
ethereum-types = "0.14.1"
hex = "0.4"
axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "dd35f500", version = "0.1.1", features = [
axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "01704ec0", version = "0.1.1", features = [
"impl-serde",
"proof",
"std",
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tree_hash = { git = "https://github.com/synapseweb3/lighthouse", rev = "2c246d6"

eth_light_client_in_ckb-verification = { version = "0.2.3", git = "https://github.com/synapseweb3/eth-light-client-in-ckb", tag = "v0.2.3" }
eth_light_client_in_ckb-prover = { version = "0.2.3", git = "https://github.com/synapseweb3/eth-light-client-in-ckb", tag = "v0.2.3" }
axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "dd35f500", version = "0.1.1", features = [
axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "01704ec0", version = "0.1.1", features = [
"impl-serde",
"proof",
"std",
Expand Down Expand Up @@ -105,7 +105,7 @@ jsonrpc-core = "18.0"
strum = { version = "0.24.1", features = ["derive"] }
lazy_static = "1.4.0"

ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "adb8bcfb033d111174f06b88609aded5b9f2a181" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "942389081039cca0361b7fb9bfb25e646a9cdfb3" }
cstr_core = "0.2.6"
rlp = "0.5.2"

Expand Down
17 changes: 12 additions & 5 deletions crates/relayer/src/chain/ckb4ibc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use ckb_types::packed::{Byte32, Bytes, BytesOpt, OutPoint, Script, Transaction};
use ckb_types::prelude::{Builder, Entity, Pack, Unpack};
use ckb_types::utilities::{merkle_root, MerkleProof};
use ckb_types::{h256, H256};
use ethers::abi::AbiEncode;
use ethers::contract::{EthAbiCodec, EthAbiType};
use ibc_relayer_types::core::ics02_client::client_type::ClientType;
use ibc_relayer_types::core::ics03_connection::events::Attributes as ConnectionAttributes;
use ibc_relayer_types::core::ics04_channel::events::{
Expand All @@ -41,6 +39,7 @@ use ibc_relayer_types::proofs::{ConsensusProof, Proofs};
use ibc_relayer_types::timestamp::Timestamp;
use ibc_relayer_types::Height;
use itertools::Itertools;
use rlp::Encodable;
use tiny_keccak::{Hasher, Keccak};

use super::extractor::{
Expand All @@ -66,7 +65,7 @@ pub struct EncodedObject {
pub data: Bytes,
}

pub fn get_encoded_object<T: rlp::Encodable>(obj: &T) -> EncodedObject {
pub fn get_encoded_object<T: Encodable>(obj: &T) -> EncodedObject {
let content = rlp::encode(obj);
let slice = content.as_ref();
let hash = keccak256(slice);
Expand Down Expand Up @@ -540,13 +539,21 @@ pub fn parse_transaction(tx: ResponseFormat<TransactionView>) -> TransactionView
}
}

#[derive(EthAbiCodec, EthAbiType)]
struct AxonObjectProof {
pub ckb_transaction: Vec<u8>,
pub block_hash: [u8; 32],
pub proof_payload: VerifyProofPayload,
}

impl Encodable for AxonObjectProof {
fn rlp_append(&self, s: &mut rlp::RlpStream) {
s.begin_list(3)
.append(&self.ckb_transaction)
.append(&self.block_hash.as_slice())
.append(&self.proof_payload);
}
}

pub async fn generate_tx_proof_from_block(
rpc_client: &impl CkbReader,
tx_hash: &H256,
Expand Down Expand Up @@ -617,7 +624,7 @@ pub async fn generate_tx_proof_from_block(

// assemble ibc-compatible proof
let block_number = Height::from_noncosmos_height(header.inner.number.into());
let proofs = get_ibc_merkle_proof(block_number, object_proof.encode())?;
let proofs = get_ibc_merkle_proof(block_number, object_proof.rlp_bytes().to_vec())?;
Ok(Some(proofs))
}

Expand Down
2 changes: 1 addition & 1 deletion tools/ibc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonrpc-core = "18.0"
futures = "0.3.27"
serde_json = { version = "1", default-features = false }
serde = { version = "1.0", default-features = false }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "adb8bcfb033d111174f06b88609aded5b9f2a181" }
ckb-ics-axon = { git = "https://github.com/synapseweb3/ckb-ics.git", rev = "942389081039cca0361b7fb9bfb25e646a9cdfb3" }
rlp = "0.5.2"
secp256k1 = "0.24"
ckb-hash = "0.106"
Expand Down

0 comments on commit c7bb87c

Please sign in to comment.