Skip to content

Commit

Permalink
feat: verify proof_payload through axon-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Dec 1, 2023
1 parent 08d10d4 commit ad2efb4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 53 deletions.
44 changes: 9 additions & 35 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 = "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",
Expand Down
2 changes: 1 addition & 1 deletion 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 = "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",
Expand Down
29 changes: 17 additions & 12 deletions crates/relayer/src/chain/ckb4ibc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
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 @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/ibc-test/src/tests/ckb/packet/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('-')
Expand Down
4 changes: 2 additions & 2 deletions tools/ibc-test/src/tests/ibc/sudt_erc20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
Expand All @@ -492,7 +492,7 @@ impl<'a> Args<'a> {
pub fn encode(&self) -> Vec<u8> {
[
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,
]
Expand Down

0 comments on commit ad2efb4

Please sign in to comment.