Skip to content

Commit 7025c5a

Browse files
authored
feat(lc/starknet): verify signed commitment proofs from starknet (#242)
* update ibc-client-cw patch branch * fix cw context methods * impl cw client state execution for starknet * add membership proof signer * sign connection open try message * ignore client and consensus proof * open ack proof * todo comment * generate membership proof message at starknet payload * membership proof msg for channel end * membership proof msg for packet commitment * membership proof msg for packet ack * membership proof msg for packet receipt * rename field in StarknetCommitmentProof * rm redundant todos * sign self client and consensus state proofs * use chain_status height as proof height * add tiny-bip39 dep * proof_signer components * add proof_signer field to StarknetChain * generate secp256k1 keypair from felt signing key * sign with starknet proof signer * nits * rm redundant endpoint * use packet_receipt endpoint * ibc-go compatible packet commitment * test consistent packet commitment in cairo and rust * happy clippy * rm test steps with dummy proofs * cargo fmt * cargo clippy * update expected commitment hash after fix
1 parent 51c9b8d commit 7025c5a

File tree

42 files changed

+547
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+547
-225
lines changed

cairo-contracts/packages/core/src/channel/components/handler.cairo

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ pub mod ChannelHandlerComponent {
174174
self.read_packet_ack(@port_id, @channel_id, @sequence)
175175
}
176176

177-
fn is_packet_received(
178-
self: @ComponentState<TContractState>,
179-
port_id: PortId,
180-
channel_id: ChannelId,
181-
sequence: Sequence
182-
) -> bool {
183-
self.packet_ack_exists(@port_id, @channel_id, @sequence)
184-
}
185-
186177
fn unreceived_packet_sequences(
187178
self: @ComponentState<TContractState>,
188179
port_id: PortId,

cairo-contracts/packages/core/src/channel/interface.cairo

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub trait IChannelQuery<TContractState> {
6767
fn packet_acknowledgement(
6868
self: @TContractState, port_id: PortId, channel_id: ChannelId, sequence: Sequence
6969
) -> Commitment;
70-
fn is_packet_received(
71-
self: @TContractState, port_id: PortId, channel_id: ChannelId, sequence: Sequence
72-
) -> bool;
7370
fn unreceived_packet_sequences(
7471
self: @TContractState, port_id: PortId, channel_id: ChannelId, sequences: Array<Sequence>
7572
) -> Array<Sequence>;

cairo-contracts/packages/core/src/commitment/types.cairo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub fn compute_packet_commitment(
5252
json_packet_data: @ByteArray, timeout_height: Height, timeout_timestamp: Timestamp
5353
) -> Commitment {
5454
let mut coll = U32CollectorImpl::init();
55-
coll.extend(timeout_timestamp);
55+
// ibc-go uses nanosecs
56+
// https://github.com/cosmos/ibc-go/blob/98d7e7550a23ecf8d96ce042ab11ef857b184f2a/proto/ibc/core/channel/v1/channel.proto#L179-L180
57+
coll.extend(timeout_timestamp.timestamp * 1_000_000_000);
5658
coll.extend(timeout_height);
5759
coll.extend_from_chunk(compute_sha256_byte_array(json_packet_data));
5860
compute_sha256_u32_array(coll.value(), 0, 0).into()

cairo-contracts/packages/core/src/tests/commitment.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_array_u8_into_array_u32() {
5252
fn test_compute_packet_commitment() {
5353
let commitment = PACKET_COMMITMENT_ON_SN(ERC20());
5454
let expected: [u32; 8] = [
55-
3458244073, 1576048754, 4210798310, 1002247062, 2365181318, 2763927782, 545147151, 944653547
55+
1561496803, 591083406, 1958596266, 2480824962, 846563094, 2634790765, 145282158, 2139799705
5656
];
5757
assert_eq!(commitment, expected.into());
5858
}

light-client/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

light-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ibc-client-starknet = { path = "./ibc-client-starknet" }
6161
ibc-client-starknet-cw = { path = "./ibc-client-starknet-cw" }
6262
ibc-client-starknet-types = { path = "./ibc-client-starknet-types" }
6363

64-
ibc-client-cw = { git = "https://github.com/informalsystems/cosmwasm-ibc.git", branch = "luca_joss/add-cw-client-extension-trait" }
64+
ibc-client-cw = { git = "https://github.com/informalsystems/cosmwasm-ibc.git", branch = "starknet/demo2" }
6565

6666
ibc = { git = "https://github.com/cosmos/ibc-rs", branch = "main" }
6767
ibc-core = { git = "https://github.com/cosmos/ibc-rs", branch = "main" }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use ibc_client_cw::api::CwClientStateExecution;
2+
use ibc_client_cw::context::client_ctx::CwClientExecution;
3+
4+
use super::ClientState;
5+
use crate::ConsensusState;
6+
7+
impl<'a, E> CwClientStateExecution<'a, E> for ClientState
8+
where
9+
E: CwClientExecution<'a, ClientStateMut = ClientState, ConsensusStateRef = ConsensusState>,
10+
{
11+
fn public_key(&self) -> Option<Vec<u8>> {
12+
Some(self.0.pub_key.clone())
13+
}
14+
}

light-client/ibc-client-starknet/src/client_state/execution.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ where
6262

6363
let raw_header = signed_header.header;
6464

65-
let header_digest = ctx.generate_sha256_digest(&raw_header);
65+
let header_digest = ctx.checksum(&raw_header);
6666

67-
let deps = ctx
68-
.cosmwasm_execute_context()
69-
.ok_or_else(|| ClientError::ClientSpecific {
70-
description: "missing Deps from context".to_owned(),
71-
})?;
67+
let deps = ctx.deps_mut().ok_or_else(|| ClientError::ClientSpecific {
68+
description: "missing Deps from context".to_owned(),
69+
})?;
7270

7371
match deps.api.secp256k1_verify(
7472
header_digest.as_slice(),

light-client/ibc-client-starknet/src/client_state/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod common;
2+
pub mod cw;
23
pub mod execution;
34
pub mod validation;
45

nix/ibc-starknet-cw.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let
1212
outputHashes = {
1313
"hermes-cosmos-encoding-components-0.1.0" = "sha256-uxXpzxVc89DkAC4VqC/Au3cpBzUbxiSS2KiFKZ+rqdg=";
1414
"cgp-0.3.1" = "sha256-AOQ+WVQWPlF2ZfYYc5Eq3t7XAljd5P2qExWLYZWNnd8=";
15-
"ibc-client-cw-0.56.0" = "sha256-EkLxuJfr3vf0busmSZD7DwOS9GfgfhT+sdopi1nNiCs=";
15+
"ibc-client-cw-0.56.0" = "sha256-DA3AB8ejUrx4ksBtN/vaOznjpKE0+0F6vGA7JmWyHWA=";
1616
"ibc-0.56.0" = "sha256-7DPIqu/zs0szjmtJTfXI2eQ0HEkRyvGjArcMZsFWMT4=";
1717
};
1818
};

0 commit comments

Comments
 (0)