Skip to content

Commit

Permalink
ibc-go compatible packet commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Feb 4, 2025
1 parent 46931e2 commit e1e9c15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cairo-contracts/packages/core/src/commitment/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub fn compute_packet_commitment(
json_packet_data: @ByteArray, timeout_height: Height, timeout_timestamp: Timestamp
) -> Commitment {
let mut coll = U32CollectorImpl::init();
coll.extend(timeout_timestamp);
// ibc-go uses nanosecs
// https://github.com/cosmos/ibc-go/blob/98d7e7550a23ecf8d96ce042ab11ef857b184f2a/proto/ibc/core/channel/v1/channel.proto#L179-L180
coll.extend(timeout_timestamp.timestamp * 1_000_000_000);
coll.extend(timeout_height);
coll.extend_from_chunk(compute_sha256_byte_array(json_packet_data));
compute_sha256_u32_array(coll.value(), 0, 0).into()
Expand Down
2 changes: 1 addition & 1 deletion cairo-contracts/packages/core/src/tests/commitment.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_array_u8_into_array_u32() {
fn test_compute_packet_commitment() {
let commitment = PACKET_COMMITMENT_ON_SN(ERC20());
let expected: [u32; 8] = [
3458244073, 1576048754, 4210798310, 1002247062, 2365181318, 2763927782, 545147151, 944653547
1561496803, 591083406, 1958596266, 2480824962, 846563094, 2634790765, 145282158, 2139799705
];
assert_eq!(commitment, expected.into());
}
Expand Down

0 comments on commit e1e9c15

Please sign in to comment.