-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lc/starknet): verify signed commitment proofs from starknet #242
base: main
Are you sure you want to change the base?
Changes from 5 commits
a5f39fd
01290a9
e3080cf
de53ed2
07e36a1
59ec68f
d71ba5d
776aa81
311be49
4c465ac
cbaf6be
02d4d6b
7722d4d
cb4fa8d
c14166f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use ibc_client_cw::api::CwClientStateExecution; | ||
use ibc_client_cw::context::client_ctx::CwClientExecution; | ||
|
||
use super::ClientState; | ||
use crate::ConsensusState; | ||
|
||
impl<'a, E> CwClientStateExecution<'a, E> for ClientState | ||
where | ||
E: CwClientExecution<'a, ClientStateMut = ClientState, ConsensusStateRef = ConsensusState>, | ||
{ | ||
fn public_key(&self) -> Option<Vec<u8>> { | ||
Some(self.0.pub_key.clone()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod common; | ||
pub mod cw; | ||
pub mod execution; | ||
pub mod validation; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ use hermes_chain_components::traits::message_builders::connection_handshake::{ | |
ConnectionOpenAckMessageBuilder, ConnectionOpenConfirmMessageBuilder, | ||
ConnectionOpenInitMessageBuilder, ConnectionOpenTryMessageBuilder, | ||
}; | ||
use hermes_chain_components::traits::queries::chain_status::CanQueryChainStatus; | ||
use hermes_chain_components::traits::queries::consensus_state::CanQueryConsensusStateWithLatestHeight; | ||
use hermes_chain_components::traits::types::client_state::HasClientStateType; | ||
use hermes_chain_components::traits::types::connection::{ | ||
HasConnectionEndType, HasConnectionOpenAckPayloadType, HasConnectionOpenConfirmPayloadType, | ||
HasConnectionOpenInitPayloadType, HasConnectionOpenTryPayloadType, | ||
HasInitConnectionOptionsType, | ||
}; | ||
use hermes_chain_components::traits::types::consensus_state::HasConsensusStateType; | ||
use hermes_chain_components::traits::types::height::HasHeightType; | ||
use hermes_chain_components::traits::types::ibc::{HasClientIdType, HasConnectionIdType}; | ||
use hermes_chain_components::traits::types::message::HasMessageType; | ||
|
@@ -22,23 +25,31 @@ use hermes_chain_components::types::payloads::connection::{ | |
}; | ||
use hermes_cosmos_chain_components::traits::message::{CosmosMessage, ToCosmosMessage}; | ||
use hermes_cosmos_chain_components::types::connection::CosmosInitConnectionOptions; | ||
use hermes_cosmos_chain_components::types::key_types::secp256k1::Secp256k1KeyPair; | ||
use hermes_cosmos_chain_components::types::messages::connection::open_ack::CosmosConnectionOpenAckMessage; | ||
use hermes_cosmos_chain_components::types::messages::connection::open_confirm::CosmosConnectionOpenConfirmMessage; | ||
use hermes_cosmos_chain_components::types::messages::connection::open_init::CosmosConnectionOpenInitMessage; | ||
use hermes_cosmos_chain_components::types::messages::connection::open_try::CosmosConnectionOpenTryMessage; | ||
use hermes_cosmos_chain_components::types::status::ChainStatus; | ||
use hermes_relayer_components::transaction::traits::default_signer::HasDefaultSigner; | ||
use ibc::core::client::types::error::ClientError; | ||
use ibc::core::client::types::Height as CosmosHeight; | ||
use ibc::core::connection::types::version::Version as CosmosConnectionVersion; | ||
use ibc::core::connection::types::ConnectionEnd; | ||
use ibc::core::host::types::identifiers::{ | ||
ClientId as CosmosClientId, ConnectionId as CosmosConnectionId, | ||
}; | ||
use ibc::core::host::types::path::{ConnectionPath, Path}; | ||
use ibc::primitives::proto::Any as IbcProtoAny; | ||
use ibc_proto::Protobuf; | ||
use prost_types::Any; | ||
|
||
use crate::types::client_id::ClientId as StarknetClientId; | ||
use crate::types::commitment_proof::StarknetCommitmentProof; | ||
use crate::types::connection_id::ConnectionId as StarknetConnectionId; | ||
use crate::types::consensus_state::WasmStarknetConsensusState; | ||
use crate::types::cosmos::client_state::CometClientState; | ||
use crate::types::membership_proof_signer::MembershipVerifierContainer; | ||
pub struct BuildStarknetToCosmosConnectionHandshake; | ||
|
||
impl<Chain, Counterparty> ConnectionOpenInitMessageBuilder<Chain, Counterparty> | ||
|
@@ -83,19 +94,25 @@ where | |
+ HasHeightType<Height = CosmosHeight> | ||
+ HasClientIdType<Counterparty, ClientId = CosmosClientId> | ||
+ CanRaiseAsyncError<ClientError> | ||
+ CanQueryChainStatus<ChainStatus = ChainStatus> | ||
+ CanQueryConsensusStateWithLatestHeight<Counterparty> | ||
+ HasDefaultSigner<Signer = Secp256k1KeyPair> | ||
+ CanRaiseAsyncError<String> | ||
+ CanRaiseAsyncError<&'static str> | ||
+ HasClientStateType<Counterparty, ClientState = CometClientState>, | ||
Counterparty: HasConnectionOpenTryPayloadType< | ||
Chain, | ||
ConnectionOpenTryPayload = ConnectionOpenTryPayload<Counterparty, Chain>, | ||
> + HasClientIdType<Chain, ClientId = StarknetClientId> | ||
+ HasConnectionIdType<Chain, ConnectionId = StarknetConnectionId> | ||
+ HasHeightType<Height = u64> | ||
+ HasConnectionEndType<Chain> | ||
+ HasConsensusStateType<Chain, ConsensusState = WasmStarknetConsensusState> | ||
+ HasConnectionEndType<Chain, ConnectionEnd = ConnectionEnd> | ||
+ HasCommitmentPrefixType<CommitmentPrefix = Vec<u8>> | ||
+ HasCommitmentProofType<CommitmentProof = StarknetCommitmentProof>, | ||
{ | ||
async fn build_connection_open_try_message( | ||
_chain: &Chain, | ||
chain: &Chain, | ||
client_id: &CosmosClientId, | ||
counterparty_client_id: &StarknetClientId, | ||
counterparty_connection_id: &StarknetConnectionId, | ||
|
@@ -109,10 +126,25 @@ where | |
// TODO(rano): delay period | ||
let delay_period = Duration::from_secs(0); | ||
|
||
// TODO(rano): apparently update height is set to zero | ||
let update_height = | ||
CosmosHeight::new(0, core::cmp::max(1, counterparty_payload.update_height)) | ||
.map_err(Chain::raise_error)?; | ||
CosmosHeight::new(0, counterparty_payload.update_height).map_err(Chain::raise_error)?; | ||
|
||
let proof_init = { | ||
let data = MembershipVerifierContainer { | ||
// FIXME(hack) we are passing consensus root as proof | ||
state_root: counterparty_payload.proof_init.proof_bytes, | ||
prefix: counterparty_payload.commitment_prefix.clone(), | ||
path: Path::Connection(ConnectionPath::new(counterparty_connection_id)) | ||
.to_string() | ||
.into(), | ||
value: Some(counterparty_payload.connection_end.encode_vec()), | ||
}; | ||
|
||
chain | ||
.get_default_signer() | ||
.sign(&data.canonical_bytes()) | ||
.map_err(Chain::raise_error)? | ||
}; | ||
|
||
let message = CosmosConnectionOpenTryMessage { | ||
client_id: client_id.to_string(), | ||
|
@@ -126,7 +158,7 @@ where | |
}, | ||
delay_period, | ||
update_height, | ||
proof_init: counterparty_payload.proof_init.proof_bytes, | ||
proof_init, | ||
// TODO(rano): counterparty_payload has empty proofs? | ||
// proof_client: counterparty_payload.proof_client.proof_bytes, | ||
proof_client: vec![0x1], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like these two are skipped. Probably |
||
|
@@ -214,7 +246,8 @@ where | |
let message = CosmosConnectionOpenConfirmMessage { | ||
connection_id: connection_id.to_string(), | ||
update_height, | ||
proof_ack: counterparty_payload.proof_ack.proof_bytes, | ||
// FIXME(rano): generate the signature | ||
proof_ack: dbg!(counterparty_payload.proof_ack.proof_bytes), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the signature verification fails here. But I don't know how to create the signature at this point without access to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can query the stored counteryparty connection end (starknet) at cosmos, cosmos's own connection id to recreate the ConnectionEnd. |
||
}; | ||
|
||
Ok(message.to_cosmos_message()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[derive(Debug)] | ||
pub struct MembershipVerifierContainer { | ||
pub state_root: Vec<u8>, | ||
pub prefix: Vec<u8>, | ||
pub path: Vec<u8>, | ||
pub value: Option<Vec<u8>>, | ||
} | ||
|
||
impl MembershipVerifierContainer { | ||
pub fn canonical_bytes(self) -> Vec<u8> { | ||
let mut bytes = Vec::new(); | ||
let encode_bytes = |mut data: Vec<u8>, output: &mut Vec<u8>| { | ||
let len = data.len() as u64; | ||
output.extend(len.to_be_bytes()); | ||
output.append(&mut data); | ||
}; | ||
encode_bytes(self.state_root, &mut bytes); | ||
encode_bytes(self.prefix, &mut bytes); | ||
encode_bytes(self.path, &mut bytes); | ||
if let Some(v) = self.value { | ||
encode_bytes(v, &mut bytes); | ||
} | ||
bytes | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I successfully managed to sign the
proof_init