From ad2efb4d0d13fcbd6669b542653207095c4fa090 Mon Sep 17 00:00:00 2001 From: liyukun Date: Fri, 1 Dec 2023 22:17:50 +0800 Subject: [PATCH] feat: verify proof_payload through axon-tools --- Cargo.lock | 44 ++++--------------- crates/relayer-types/Cargo.toml | 2 +- crates/relayer/Cargo.toml | 2 +- crates/relayer/src/chain/ckb4ibc/utils.rs | 29 +++++++----- tools/ibc-test/Cargo.toml | 2 +- tools/ibc-test/src/tests/ckb/packet/utils.rs | 2 +- .../src/tests/ibc/sudt_erc20_transfer.rs | 4 +- 7 files changed, 32 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 542f442b..41f56153 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,7 +362,7 @@ dependencies = [ [[package]] name = "axon-tools" version = "0.1.1" -source = "git+https://github.com/axonweb3/axon.git?rev=06340ba4#06340ba42a752f9f31d38dab2dd40fa50ab2e239" +source = "git+https://github.com/axonweb3/axon.git?rev=e6eee4a#e6eee4ab5ecea52d5e618d112d4674f25c3752d4" dependencies = [ "bit-vec", "blst", @@ -371,6 +371,8 @@ dependencies = [ "ckb-blst", "derive_more", "ethereum-types", + "ethers-contract", + "ethers-core", "faster-hex 0.8.1", "log", "rlp", @@ -388,18 +390,10 @@ dependencies = [ "bit-vec", "blst", "bytes", - "cita_trie", "ckb-blst", - "derive_more", "ethereum-types", - "ethers-contract", - "ethers-core", - "faster-hex 0.8.1", - "log", "rlp", "rlp-derive", - "serde", - "serde_json", "tiny-keccak", ] @@ -1100,26 +1094,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "ckb-ics-axon" -version = "0.1.0" -source = "git+https://github.com/synapseweb3/ckb-ics.git?rev=8c4b958#8c4b958ac7d89d247390a791d6807567a59416ea" -dependencies = [ - "axon-tools 0.1.1 (git+https://github.com/axonweb3/axon.git?rev=f889d38)", - "axon-types", - "bytes", - "ethereum-types", - "hex", - "molecule", - "prost 0.12.1", - "prost-build", - "protobuf-src", - "rlp", - "rlp-derive", - "sha2 0.10.8", - "tiny-keccak", -] - [[package]] name = "ckb-jsonrpc-types" version = "0.111.0" @@ -2952,13 +2926,13 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "forcerelay-ckb-sdk" version = "0.1.0" -source = "git+https://github.com/synapseweb3/forcerelay-ckb-sdk?rev=5a4c605b6#5a4c605b65a8985269801c0d93885c70f30818fd" +source = "git+https://github.com/synapseweb3/forcerelay-ckb-sdk?rev=1c4b361b8#1c4b361b8e1eb6dd2835f434a9b263e4dc3c1b6f" dependencies = [ "anyhow", "async-stream", "bytes", "ckb-fixed-hash", - "ckb-ics-axon 0.1.0 (git+https://github.com/synapseweb3/ckb-ics.git?rev=8c4b958)", + "ckb-ics-axon", "ckb-jsonrpc-types", "ckb-sdk", "ckb-types", @@ -3740,13 +3714,13 @@ dependencies = [ "anyhow", "async-stream", "async-trait", - "axon-tools 0.1.1 (git+https://github.com/axonweb3/axon.git?rev=f889d38)", + "axon-tools 0.1.1 (git+https://github.com/axonweb3/axon.git?rev=e6eee4a)", "bech32 0.9.1", "bitcoin", "bs58 0.4.0", "bytes", "ckb-hash 0.111.0", - "ckb-ics-axon 0.1.0 (git+https://github.com/synapseweb3/ckb-ics.git?rev=4ca20ad)", + "ckb-ics-axon", "ckb-jsonrpc-types", "ckb-sdk", "ckb-types", @@ -3890,7 +3864,7 @@ dependencies = [ name = "ibc-relayer-types" version = "0.23.0" dependencies = [ - "axon-tools 0.1.1 (git+https://github.com/axonweb3/axon.git?rev=06340ba4)", + "axon-tools 0.1.1 (git+https://github.com/axonweb3/axon.git?rev=e6eee4a)", "bls", "bytes", "derive_more", @@ -3954,7 +3928,7 @@ dependencies = [ "bytes", "ckb-chain-spec", "ckb-hash 0.106.0", - "ckb-ics-axon 0.1.0 (git+https://github.com/synapseweb3/ckb-ics.git?rev=4ca20ad)", + "ckb-ics-axon", "ckb-jsonrpc-types", "ckb-sdk", "ckb-types", diff --git a/crates/relayer-types/Cargo.toml b/crates/relayer-types/Cargo.toml index 682fc56a..d6289ee7 100644 --- a/crates/relayer-types/Cargo.toml +++ b/crates/relayer-types/Cargo.toml @@ -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 = "06340ba4", version = "0.1.1", features = [ +axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "e6eee4a", version = "0.1.1", features = [ "impl-serde", "proof", "std", diff --git a/crates/relayer/Cargo.toml b/crates/relayer/Cargo.toml index 2d373003..361082d5 100644 --- a/crates/relayer/Cargo.toml +++ b/crates/relayer/Cargo.toml @@ -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 = "f889d38", version = "0.1.1", features = [ +axon-tools = { git = "https://github.com/axonweb3/axon.git", package = "axon-tools", rev = "e6eee4a", version = "0.1.1", features = [ "impl-serde", "proof", "std", diff --git a/crates/relayer/src/chain/ckb4ibc/utils.rs b/crates/relayer/src/chain/ckb4ibc/utils.rs index b5f970dc..05b7f7a3 100644 --- a/crates/relayer/src/chain/ckb4ibc/utils.rs +++ b/crates/relayer/src/chain/ckb4ibc/utils.rs @@ -6,7 +6,7 @@ use crate::chain::SEC_TO_NANO; use crate::config::ckb4ibc::ChainConfig; use crate::error::Error; use crate::event::IbcEventWithHeight; -use axon_tools::precompile::{Proof, VerifyProofPayload}; +use axon_tools::precompile::{verify_proof, Proof, VerifyProofPayload}; use ckb_ics_axon::consts::CHANNEL_ID_PREFIX; use ckb_ics_axon::handler::IbcPacket; use ckb_ics_axon::message::MsgType; @@ -583,20 +583,25 @@ pub async fn generate_tx_proof_from_block( let raw_transaction_root = merkle_root(&tx_hashes.iter().map(Pack::pack).collect_vec()); let witnesses_root = merkle_root(&witness_hashes.iter().map(Pack::pack).collect_vec()); + let proof_payload = VerifyProofPayload { + verify_type: 1, // to verify witness + transactions_root: block.header.inner.transactions_root.into(), + witnesses_root: witnesses_root.unpack().into(), + raw_transactions_root: raw_transaction_root.unpack().into(), + proof: Proof { + indices: proof.indices.into_iter().map(Into::into).collect(), + lemmas: proof.lemmas.into_iter().map(Into::into).collect(), + leaves: witness_hashes.into_iter().map(Into::into).collect(), + }, + }; + + verify_proof(proof_payload.clone()) + .map_err(|err| Error::other_error(format!("proof payload verify failed: {err}")))?; + let object_proof = AxonObjectProof { ckb_transaction: transaction.as_slice().to_owned(), block_hash: block_hash.into(), - proof_payload: VerifyProofPayload { - verify_type: 1, // to verify witness - transactions_root: block.header.inner.transactions_root.into(), - witnesses_root: witnesses_root.unpack().into(), - raw_transactions_root: raw_transaction_root.unpack().into(), - proof: Proof { - indices: proof.indices.into_iter().map(Into::into).collect(), - lemmas: proof.lemmas.into_iter().map(Into::into).collect(), - leaves: witness_hashes.into_iter().map(Into::into).collect(), - }, - }, + proof_payload, }; // assemble ibc-compatible proof diff --git a/tools/ibc-test/Cargo.toml b/tools/ibc-test/Cargo.toml index 6adf743f..789c4e17 100644 --- a/tools/ibc-test/Cargo.toml +++ b/tools/ibc-test/Cargo.toml @@ -45,7 +45,7 @@ toml_edit = "0.19.14" lazy_static = "1.4.0" ethers = { version = "2.0.2", features = ["rustls", "ws"] } -forcerelay-ckb-sdk = { git = "https://github.com/synapseweb3/forcerelay-ckb-sdk", rev = "5a4c605b6" } +forcerelay-ckb-sdk = { git = "https://github.com/synapseweb3/forcerelay-ckb-sdk", rev = "1c4b361b8" } [dependencies] bytes = "1.5.0" diff --git a/tools/ibc-test/src/tests/ckb/packet/utils.rs b/tools/ibc-test/src/tests/ckb/packet/utils.rs index f72c8661..f3434bdb 100644 --- a/tools/ibc-test/src/tests/ckb/packet/utils.rs +++ b/tools/ibc-test/src/tests/ckb/packet/utils.rs @@ -255,7 +255,7 @@ pub fn prepare_artificials( .hash_type(ScriptHashType::Type.into()) .args(CLIENT_TYPE_ARGS.as_bytes().pack()) .build(); - let channel_number = u16::from_str( + let channel_number = u64::from_str( channel_id .to_string() .split('-') diff --git a/tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs b/tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs index 2d07718c..e698650b 100644 --- a/tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs +++ b/tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs @@ -483,7 +483,7 @@ fn sighash_placeholder_witness() -> packed::WitnessArgs { pub struct Args<'a> { pub client_id: &'a [u8; 32], - pub channel_id: u16, + pub channel_id: u64, pub channel_contract_code_hash: &'a [u8; 32], pub packet_contract_code_hash: &'a [u8; 32], } @@ -492,7 +492,7 @@ impl<'a> Args<'a> { pub fn encode(&self) -> Vec { [ self.client_id, - &u16::to_be_bytes(self.channel_id)[..], + &u64::to_be_bytes(self.channel_id)[..], self.channel_contract_code_hash, self.packet_contract_code_hash, ]