Skip to content

Commit e1e9c15

Browse files
committed
ibc-go compatible packet commitment
1 parent 46931e2 commit e1e9c15

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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
}

0 commit comments

Comments
 (0)