Skip to content

Commit 8a7e050

Browse files
authored
Movement hubble integration (#3806)
2 parents d1c24d6 + 2bc828b commit 8a7e050

File tree

19 files changed

+396
-297
lines changed

19 files changed

+396
-297
lines changed

aptos/ibc/sources/acknowledge_packet.move

+8-7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module ibc::acknowledge_packet {
7878
packet_timeout_heights: vector<u64>,
7979
packet_timeout_timestamps: vector<u64>,
8080
acknowledgements: vector<vector<u8>>,
81+
maker: address,
8182
proof: vector<u8>,
8283
proof_height: u64
8384
) {
@@ -105,23 +106,23 @@ module ibc::acknowledge_packet {
105106
assert!(l > 0, 1);
106107

107108
let first_packet = *vector::borrow(&packets, 0);
108-
let source_channel = packet::source_channel(&first_packet);
109-
let destination_channel = packet::destination_channel(&first_packet);
109+
let source_channel_id = packet::source_channel_id(&first_packet);
110+
let destination_channel_id = packet::destination_channel_id(&first_packet);
110111

111-
let channel = ibc::ensure_channel_state(source_channel);
112+
let channel = ibc::ensure_channel_state(source_channel_id);
112113
let client_id = ibc::ensure_connection_state(channel::connection_id(&channel));
113114

114115
let commitment_key;
115116
let commitment_value;
116117
if (l == 1) {
117118
commitment_key = commitment::batch_receipts_commitment_key(
118-
destination_channel,
119+
destination_channel_id,
119120
commitment::commit_packet(&first_packet)
120121
);
121122
commitment_value = commitment::commit_ack(*vector::borrow(&acknowledgements, 0));
122123
} else {
123124
commitment_key = commitment::batch_receipts_commitment_key(
124-
destination_channel,
125+
destination_channel_id,
125126
commitment::commit_packets(&packets)
126127
);
127128
commitment_value = commitment::commit_acks(acknowledgements);
@@ -145,7 +146,7 @@ module ibc::acknowledge_packet {
145146
let packet = *vector::borrow(&packets, i);
146147
let commitment_key =
147148
commitment::batch_packets_commitment_key(
148-
source_channel, commitment::commit_packet(&packet)
149+
source_channel_id, commitment::commit_packet(&packet)
149150
);
150151
ibc::remove_commitment(commitment_key);
151152

@@ -157,7 +158,7 @@ module ibc::acknowledge_packet {
157158

158159
dispatcher::delete_storage<T>();
159160

160-
ibc::emit_acknowledge_packet(packet, acknowledgement);
161+
ibc::emit_acknowledge_packet(packet, acknowledgement, maker);
161162

162163
i = i + 1;
163164
}

aptos/ibc/sources/cometbls_lc.move

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
module ibc::cometbls_lc {
6262
use std::vector;
6363
use std::bcs;
64-
use std::string::{Self};
64+
use std::string::{Self, String};
6565
use aptos_std::smart_table::{Self, SmartTable};
6666
use std::object;
6767
use std::timestamp;
@@ -113,7 +113,7 @@ module ibc::cometbls_lc {
113113
}
114114

115115
struct ClientState has copy, drop, store {
116-
chain_id: string::String,
116+
chain_id: String,
117117
trusting_period: u64,
118118
max_clock_drift: u64,
119119
frozen_height: Height,
@@ -137,7 +137,7 @@ module ibc::cometbls_lc {
137137
client_id: u32,
138138
client_state_bytes: vector<u8>,
139139
consensus_state_bytes: vector<u8>
140-
): (vector<u8>, vector<u8>) {
140+
): (vector<u8>, vector<u8>, String) {
141141
let client_state = decode_client_state(client_state_bytes);
142142
let consensus_state = decode_consensus_state(consensus_state_bytes);
143143

@@ -164,7 +164,7 @@ module ibc::cometbls_lc {
164164

165165
move_to(&client_signer, state);
166166

167-
(client_state_bytes, consensus_state_bytes)
167+
(client_state_bytes, consensus_state_bytes, client_state.chain_id)
168168
}
169169

170170
public fun latest_height(client_id: u32): u64 acquires State {
@@ -703,7 +703,7 @@ module ibc::cometbls_lc {
703703
next_validators_hash: x"0000000000000000000000000000000000000000000000000000000000000000"
704704
};
705705

706-
let (cs, cons) =
706+
let (cs, cons, _counterparty_channel_id) =
707707
create_client(
708708
ibc_signer,
709709
0,
@@ -730,7 +730,7 @@ module ibc::cometbls_lc {
730730
client_state.trusting_period = 2;
731731
consensus_state.timestamp = 20000;
732732

733-
let (cs, cons) =
733+
let (cs, cons, _counterparty_channel_id) =
734734
create_client(
735735
ibc_signer,
736736
2,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
2+
// "Business Source License" is a trademark of MariaDB Corporation Ab.
3+
4+
// Parameters
5+
6+
// Licensor: Union.fi, Labs Inc.
7+
// Licensed Work: All files under https://github.com/unionlabs/union's aptos subdirectory
8+
// The Licensed Work is (c) 2024 Union.fi, Labs Inc.
9+
// Change Date: Four years from the date the Licensed Work is published.
10+
// Change License: Apache-2.0
11+
//
12+
13+
// For information about alternative licensing arrangements for the Licensed Work,
14+
// please contact [email protected].
15+
16+
// Notice
17+
18+
// Business Source License 1.1
19+
20+
// Terms
21+
22+
// The Licensor hereby grants you the right to copy, modify, create derivative
23+
// works, redistribute, and make non-production use of the Licensed Work. The
24+
// Licensor may make an Additional Use Grant, above, permitting limited production use.
25+
26+
// Effective on the Change Date, or the fourth anniversary of the first publicly
27+
// available distribution of a specific version of the Licensed Work under this
28+
// License, whichever comes first, the Licensor hereby grants you rights under
29+
// the terms of the Change License, and the rights granted in the paragraph
30+
// above terminate.
31+
32+
// If your use of the Licensed Work does not comply with the requirements
33+
// currently in effect as described in this License, you must purchase a
34+
// commercial license from the Licensor, its affiliated entities, or authorized
35+
// resellers, or you must refrain from using the Licensed Work.
36+
37+
// All copies of the original and modified Licensed Work, and derivative works
38+
// of the Licensed Work, are subject to this License. This License applies
39+
// separately for each version of the Licensed Work and the Change Date may vary
40+
// for each version of the Licensed Work released by Licensor.
41+
42+
// You must conspicuously display this License on each original or modified copy
43+
// of the Licensed Work. If you receive the Licensed Work in original or
44+
// modified form from a third party, the terms and conditions set forth in this
45+
// License apply to your use of that work.
46+
47+
// Any use of the Licensed Work in violation of this License will automatically
48+
// terminate your rights under this License for the current and all other
49+
// versions of the Licensed Work.
50+
51+
// This License does not grant you any right in any trademark or logo of
52+
// Licensor or its affiliates (provided that you may use a trademark or logo of
53+
// Licensor as expressly required by this License).
54+
55+
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
56+
// AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
57+
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
58+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
59+
// TITLE.
60+
61+
module ibc::consensus_state_update {
62+
struct ConsensusStateUpdate {
63+
client_state_commitment: vector<u8>,
64+
consensus_state_commitment: vector<u8>,
65+
height: u64
66+
}
67+
68+
public fun new(client_state_commitment: vector<u8>, consensus_state_commitment: vector<u8>, height: u64): ConsensusStateUpdate {
69+
ConsensusStateUpdate { client_state_commitment, consensus_state_commitment, height }
70+
}
71+
72+
public fun client_state_commitment(update: &ConsensusStateUpdate): vector<u8> {
73+
update.client_state_commitment
74+
}
75+
76+
public fun consensus_state_commitment(update: &ConsensusStateUpdate): vector<u8> {
77+
update.consensus_state_commitment
78+
}
79+
80+
public fun height(update: &ConsensusStateUpdate): u64 {
81+
update.height
82+
}
83+
84+
}

aptos/ibc/sources/ibc.move

+32-27
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ module ibc::ibc {
146146
const E_PACKET_SEQUENCE_ACK_SEQUENCE_MISMATCH: u64 = 1045;
147147

148148
#[event]
149-
struct ClientCreatedEvent has copy, drop, store {
149+
struct CreateClient has copy, drop, store {
150150
client_id: u32,
151151
client_type: String,
152-
consensus_height: u64
152+
counterparty_chain_id: String
153153
}
154154

155155
#[event]
156-
struct ClientUpdated has copy, drop, store {
156+
struct UpdateClient has copy, drop, store {
157157
client_id: u32,
158158
client_type: String,
159-
height: u64
159+
counterparty_height: u64
160160
}
161161

162162
#[event]
@@ -229,16 +229,20 @@ module ibc::ibc {
229229

230230
#[event]
231231
struct RecvIntentPacket has drop, store {
232-
packet: Packet
232+
packet: Packet,
233+
maker: address,
234+
maker_msg: vector<u8>
233235
}
234236

235237
#[event]
236-
struct RecvPacket has drop, store {
237-
packet: Packet
238+
struct PacketRecv has drop, store {
239+
packet: Packet,
240+
maker: address,
241+
maker_msg: vector<u8>
238242
}
239243

240244
#[event]
241-
struct SendPacket has drop, store {
245+
struct PacketSend has drop, store {
242246
source_channel: u32,
243247
destination_channel: u32,
244248
data: vector<u8>,
@@ -252,13 +256,14 @@ module ibc::ibc {
252256
}
253257

254258
#[event]
255-
struct AcknowledgePacket has drop, store {
259+
struct PacketAck has drop, store {
256260
packet: Packet,
257-
acknowledgement: vector<u8>
261+
acknowledgement: vector<u8>,
262+
maker: address,
258263
}
259264

260265
#[event]
261-
struct WriteAcknowledgement has drop, store {
266+
struct WriteAck has drop, store {
262267
packet: Packet,
263268
acknowledgement: vector<u8>
264269
}
@@ -330,7 +335,7 @@ module ibc::ibc {
330335
let client_id = generate_client_identifier();
331336
let store = borrow_global_mut<IBCStore>(get_vault_addr());
332337

333-
let (client_state, consensus_state) =
338+
let (client_state, consensus_state, counterparty_chain_id) =
334339
light_client::create_client(
335340
client_type,
336341
&get_ibc_signer(),
@@ -360,7 +365,7 @@ module ibc::ibc {
360365
);
361366

362367
event::emit(
363-
ClientCreatedEvent { client_id, client_type, consensus_height: latest_height }
368+
CreateClient { client_id, client_type, counterparty_chain_id: counterparty_chain_id }
364369
);
365370
}
366371

@@ -660,7 +665,7 @@ module ibc::ibc {
660665
hash::sha2_256(*vector::borrow(&consensus_states, i))
661666
);
662667

663-
event::emit(ClientUpdated { client_id, client_type, height });
668+
event::emit(UpdateClient { client_id, client_type, counterparty_height: height });
664669

665670
i = i + 1;
666671
};
@@ -1032,7 +1037,7 @@ module ibc::ibc {
10321037
}
10331038

10341039
/// Used for sending a packet to the counterparty chain. Note that this doesn't send the packet directly, it prepares the packet
1035-
/// and emits a `SendPacket` event such that it's being picked up by a relayer.
1040+
/// and emits a `PacketSend` event such that it's being picked up by a relayer.
10361041
///
10371042
/// * `ibc_app`: The signer of the calling contract.
10381043
/// * `source_port`: The address of the calling contract.
@@ -1079,7 +1084,7 @@ module ibc::ibc {
10791084
);
10801085

10811086
event::emit(
1082-
SendPacket {
1087+
PacketSend {
10831088
source_channel: source_channel,
10841089
destination_channel: channel::counterparty_channel_id(&channel),
10851090
data: data,
@@ -1101,11 +1106,11 @@ module ibc::ibc {
11011106
) acquires IBCStore {
11021107
assert!(!vector::is_empty(&acknowledgement), E_ACKNOWLEDGEMENT_IS_EMPTY);
11031108

1104-
ensure_channel_state(packet::destination_channel(&packet));
1109+
ensure_channel_state(packet::destination_channel_id(&packet));
11051110

11061111
let commitment_key =
11071112
commitment::batch_receipts_commitment_key(
1108-
packet::destination_channel(&packet),
1113+
packet::destination_channel_id(&packet),
11091114
commitment::commit_packet(&packet)
11101115
);
11111116
inner_write_acknowledgement(commitment_key, packet, acknowledgement);
@@ -1129,7 +1134,7 @@ module ibc::ibc {
11291134
commitment::commit_ack(acknowledgement)
11301135
);
11311136

1132-
event::emit(WriteAcknowledgement { packet, acknowledgement });
1137+
event::emit(WriteAck { packet, acknowledgement });
11331138
}
11341139

11351140
public(friend) fun timeout_packet<T: key + store + drop>(
@@ -1155,8 +1160,8 @@ module ibc::ibc {
11551160
packet_timeout_timestamp
11561161
);
11571162

1158-
let source_channel = packet::source_channel(&packet);
1159-
let destination_channel = packet::destination_channel(&packet);
1163+
let source_channel = packet::source_channel_id(&packet);
1164+
let destination_channel = packet::destination_channel_id(&packet);
11601165
let channel = ensure_channel_state(source_channel);
11611166
let client_id = ensure_connection_state(channel::connection_id(&channel));
11621167
let client_type = client_id_to_type(client_id);
@@ -1583,18 +1588,18 @@ module ibc::ibc {
15831588
string_utils::to_string(&bcs::to_bytes(&addr))
15841589
}
15851590

1586-
public(friend) fun emit_recv_packet(packet: Packet) {
1587-
event::emit(RecvPacket { packet })
1591+
public(friend) fun emit_recv_packet(packet: Packet, maker: address, maker_msg: vector<u8>) {
1592+
event::emit(PacketRecv { packet, maker, maker_msg })
15881593
}
15891594

1590-
public(friend) fun emit_recv_intent_packet(packet: Packet) {
1591-
event::emit(RecvIntentPacket { packet })
1595+
public(friend) fun emit_recv_intent_packet(packet: Packet, maker: address, maker_msg: vector<u8>) {
1596+
event::emit(RecvIntentPacket { packet, maker, maker_msg })
15921597
}
15931598

15941599
public(friend) fun emit_acknowledge_packet(
1595-
packet: Packet, acknowledgement: vector<u8>
1600+
packet: Packet, acknowledgement: vector<u8>, maker: address
15961601
) {
1597-
event::emit(AcknowledgePacket { packet, acknowledgement });
1602+
event::emit(PacketAck { packet, acknowledgement, maker });
15981603
}
15991604

16001605
// #[test(ibc_signer = @ibc)]

0 commit comments

Comments
 (0)