Skip to content

Commit 3027e5f

Browse files
fix(evm): portId not needed, only counterparty (#3135)
2 parents dd272af + 6d109de commit 3027e5f

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

evm/contracts/core/04-channel/IBCChannel.sol

+20-28
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
7878
channel.connectionId = msg_.connectionId;
7979
channel.ordering = msg_.ordering;
8080
channel.version = msg_.version;
81-
channel.portId = msg_.portId.toHexString();
8281
channel.counterpartyPortId = msg_.counterpartyPortId;
8382
initializeChannelSequences(channelId);
8483
commitChannel(channelId, channel);
@@ -91,7 +90,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
9190
msg_.relayer
9291
);
9392
emit IBCChannelLib.ChannelOpenInit(
94-
channel.portId,
93+
msg_.portId.toHexString(),
9594
channelId,
9695
channel.counterpartyPortId,
9796
msg_.connectionId,
@@ -121,8 +120,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
121120
ordering: msg_.channel.ordering,
122121
counterpartyChannelId: 0,
123122
connectionId: getCounterpartyConnection(msg_.channel.connectionId),
124-
portId: msg_.channel.counterpartyPortId,
125-
counterpartyPortId: msg_.channel.portId,
123+
counterpartyPortId: msg_.portId.toHexString(),
126124
version: msg_.counterpartyVersion
127125
});
128126
if (
@@ -140,9 +138,8 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
140138
channels[channelId] = msg_.channel;
141139
initializeChannelSequences(channelId);
142140
commitChannelCalldata(channelId, msg_.channel);
143-
address portId = Hex.hexToAddress(msg_.channel.portId);
144-
claimChannel(portId, channelId);
145-
IIBCModule(portId).onChanOpenTry(
141+
claimChannel(msg_.portId, channelId);
142+
IIBCModule(msg_.portId).onChanOpenTry(
146143
msg_.channel.ordering,
147144
msg_.channel.connectionId,
148145
channelId,
@@ -152,7 +149,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
152149
msg_.relayer
153150
);
154151
emit IBCChannelLib.ChannelOpenTry(
155-
msg_.channel.portId,
152+
msg_.portId.toHexString(),
156153
channelId,
157154
msg_.channel.counterpartyPortId,
158155
msg_.channel.counterpartyChannelId,
@@ -173,13 +170,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
173170
revert IBCErrors.ErrInvalidChannelState();
174171
}
175172
uint32 clientId = ensureConnectionState(channel.connectionId);
173+
address portId = channelOwner[msg_.channelId];
176174
IBCChannel memory expectedChannel = IBCChannel({
177175
state: IBCChannelState.TryOpen,
178176
ordering: channel.ordering,
179177
counterpartyChannelId: msg_.channelId,
180178
connectionId: getCounterpartyConnection(channel.connectionId),
181-
portId: channel.counterpartyPortId,
182-
counterpartyPortId: channel.portId,
179+
counterpartyPortId: portId.toHexString(),
183180
version: msg_.counterpartyVersion
184181
});
185182
if (
@@ -197,14 +194,14 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
197194
channel.version = msg_.counterpartyVersion;
198195
channel.counterpartyChannelId = msg_.counterpartyChannelId;
199196
commitChannel(msg_.channelId, channel);
200-
IIBCModule(Hex.hexToAddress(channel.portId)).onChanOpenAck(
197+
IIBCModule(portId).onChanOpenAck(
201198
msg_.channelId,
202199
msg_.counterpartyChannelId,
203200
msg_.counterpartyVersion,
204201
msg_.relayer
205202
);
206203
emit IBCChannelLib.ChannelOpenAck(
207-
channel.portId,
204+
portId.toHexString(),
208205
msg_.channelId,
209206
channel.counterpartyPortId,
210207
msg_.counterpartyChannelId,
@@ -223,13 +220,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
223220
revert IBCErrors.ErrInvalidChannelState();
224221
}
225222
uint32 clientId = ensureConnectionState(channel.connectionId);
223+
address portId = channelOwner[msg_.channelId];
226224
IBCChannel memory expectedChannel = IBCChannel({
227225
state: IBCChannelState.Open,
228226
ordering: channel.ordering,
229227
counterpartyChannelId: msg_.channelId,
230228
connectionId: getCounterpartyConnection(channel.connectionId),
231-
portId: channel.counterpartyPortId,
232-
counterpartyPortId: channel.portId,
229+
counterpartyPortId: portId.toHexString(),
233230
version: channel.version
234231
});
235232
if (
@@ -245,11 +242,9 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
245242
}
246243
channel.state = IBCChannelState.Open;
247244
commitChannel(msg_.channelId, channel);
248-
IIBCModule(Hex.hexToAddress(channel.portId)).onChanOpenConfirm(
249-
msg_.channelId, msg_.relayer
250-
);
245+
IIBCModule(portId).onChanOpenConfirm(msg_.channelId, msg_.relayer);
251246
emit IBCChannelLib.ChannelOpenConfirm(
252-
channel.portId,
247+
portId.toHexString(),
253248
msg_.channelId,
254249
channel.counterpartyPortId,
255250
channel.counterpartyChannelId,
@@ -270,11 +265,10 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
270265
ensureConnectionState(channel.connectionId);
271266
channel.state = IBCChannelState.Closed;
272267
commitChannel(msg_.channelId, channel);
273-
IIBCModule(Hex.hexToAddress(channel.portId)).onChanCloseInit(
274-
msg_.channelId, msg_.relayer
275-
);
268+
address portId = channelOwner[msg_.channelId];
269+
IIBCModule(portId).onChanCloseInit(msg_.channelId, msg_.relayer);
276270
emit IBCChannelLib.ChannelCloseInit(
277-
channel.portId,
271+
portId.toHexString(),
278272
msg_.channelId,
279273
channel.counterpartyPortId,
280274
channel.counterpartyChannelId
@@ -293,13 +287,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
293287
revert IBCErrors.ErrInvalidChannelState();
294288
}
295289
uint32 clientId = ensureConnectionState(channel.connectionId);
290+
address portId = channelOwner[msg_.channelId];
296291
IBCChannel memory expectedChannel = IBCChannel({
297292
state: IBCChannelState.Closed,
298293
ordering: channel.ordering,
299294
counterpartyChannelId: msg_.channelId,
300295
connectionId: getCounterpartyConnection(channel.connectionId),
301-
portId: channel.counterpartyPortId,
302-
counterpartyPortId: channel.portId,
296+
counterpartyPortId: portId.toHexString(),
303297
version: channel.version
304298
});
305299
if (
@@ -315,11 +309,9 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
315309
}
316310
channel.state = IBCChannelState.Closed;
317311
commitChannel(msg_.channelId, channel);
318-
IIBCModule(Hex.hexToAddress(channel.portId)).onChanCloseConfirm(
319-
msg_.channelId, msg_.relayer
320-
);
312+
IIBCModule(portId).onChanCloseConfirm(msg_.channelId, msg_.relayer);
321313
emit IBCChannelLib.ChannelCloseConfirm(
322-
channel.portId,
314+
portId.toHexString(),
323315
msg_.channelId,
324316
channel.counterpartyPortId,
325317
channel.counterpartyChannelId

evm/contracts/core/25-handler/IBCMsgs.sol

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ library IBCMsgs {
5959
}
6060

6161
struct MsgChannelOpenTry {
62+
address portId;
6263
IBCChannel channel;
6364
string counterpartyVersion;
6465
bytes proofInit;

evm/contracts/core/Types.sol

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct IBCChannel {
3333
IBCChannelOrder ordering;
3434
uint32 connectionId;
3535
uint32 counterpartyChannelId;
36-
string portId;
3736
string counterpartyPortId;
3837
string version;
3938
}

evm/tests/src/04-channel/IBCChannel.t.sol

+10-12
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ contract IBCChannelTests is Test {
106106
ordering: IBCChannelOrder.Unordered,
107107
connectionId: connectionId,
108108
counterpartyChannelId: 0,
109-
portId: address(module).toHexString(),
110109
counterpartyPortId: COUNTERPARTY_PORT_ID,
111110
version: version
112111
});
@@ -133,12 +132,12 @@ contract IBCChannelTests is Test {
133132
) public {
134133
vm.pauseGasMetering();
135134
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
135+
portId: address(module),
136136
channel: IBCChannel({
137137
state: IBCChannelState.TryOpen,
138138
ordering: IBCChannelOrder.Unordered,
139139
connectionId: connectionId,
140140
counterpartyChannelId: counterpartyChannelId,
141-
portId: address(module).toHexString(),
142141
counterpartyPortId: COUNTERPARTY_PORT_ID,
143142
version: version
144143
}),
@@ -150,7 +149,7 @@ contract IBCChannelTests is Test {
150149
lightClient.pushValidMembership();
151150
vm.expectEmit();
152151
emit IBCChannelLib.ChannelOpenTry(
153-
msg_.channel.portId,
152+
msg_.portId.toHexString(),
154153
0,
155154
msg_.channel.counterpartyPortId,
156155
msg_.channel.counterpartyChannelId,
@@ -168,12 +167,12 @@ contract IBCChannelTests is Test {
168167
address relayer
169168
) public {
170169
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
170+
portId: address(module),
171171
channel: IBCChannel({
172172
state: IBCChannelState.Unspecified,
173173
connectionId: connectionId,
174174
ordering: IBCChannelOrder.Unordered,
175175
version: version,
176-
portId: address(module).toHexString(),
177176
counterpartyPortId: COUNTERPARTY_PORT_ID,
178177
counterpartyChannelId: counterpartyChannelId
179178
}),
@@ -193,12 +192,12 @@ contract IBCChannelTests is Test {
193192
address relayer
194193
) public {
195194
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
195+
portId: address(module),
196196
channel: IBCChannel({
197197
state: IBCChannelState.TryOpen,
198198
connectionId: connectionId,
199199
ordering: IBCChannelOrder.Unspecified,
200200
version: version,
201-
portId: address(module).toHexString(),
202201
counterpartyPortId: COUNTERPARTY_PORT_ID,
203202
counterpartyChannelId: counterpartyChannelId
204203
}),
@@ -218,12 +217,12 @@ contract IBCChannelTests is Test {
218217
address relayer
219218
) public {
220219
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
220+
portId: address(module),
221221
channel: IBCChannel({
222222
state: IBCChannelState.TryOpen,
223223
connectionId: connectionId,
224224
ordering: IBCChannelOrder.Unordered,
225225
version: version,
226-
portId: address(module).toHexString(),
227226
counterpartyPortId: COUNTERPARTY_PORT_ID,
228227
counterpartyChannelId: counterpartyChannelId
229228
}),
@@ -243,12 +242,12 @@ contract IBCChannelTests is Test {
243242
address relayer
244243
) public {
245244
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
245+
portId: address(module),
246246
channel: IBCChannel({
247247
state: IBCChannelState.TryOpen,
248248
connectionId: connectionId,
249249
ordering: IBCChannelOrder.Unordered,
250250
version: version,
251-
portId: address(module).toHexString(),
252251
counterpartyPortId: COUNTERPARTY_PORT_ID,
253252
counterpartyChannelId: counterpartyChannelId
254253
}),
@@ -273,11 +272,11 @@ contract IBCChannelTests is Test {
273272
connectionId: connectionId,
274273
ordering: IBCChannelOrder.Unordered,
275274
version: version,
276-
portId: address(module).toHexString(),
277275
counterpartyPortId: COUNTERPARTY_PORT_ID,
278276
counterpartyChannelId: counterpartyChannelId
279277
});
280278
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
279+
portId: address(module),
281280
channel: channel,
282281
counterpartyVersion: counterpartyVersion,
283282
proofInit: hex"",
@@ -358,7 +357,6 @@ contract IBCChannelTests is Test {
358357
connectionId: connectionId,
359358
ordering: IBCChannelOrder.Unordered,
360359
version: version,
361-
portId: address(module).toHexString(),
362360
counterpartyPortId: COUNTERPARTY_PORT_ID,
363361
counterpartyChannelId: counterpartyChannelId
364362
});
@@ -397,12 +395,12 @@ contract IBCChannelTests is Test {
397395
) public {
398396
vm.pauseGasMetering();
399397
IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({
398+
portId: address(module),
400399
channel: IBCChannel({
401400
state: IBCChannelState.TryOpen,
402401
connectionId: connectionId,
403402
ordering: IBCChannelOrder.Unordered,
404403
version: version,
405-
portId: address(module).toHexString(),
406404
counterpartyPortId: COUNTERPARTY_PORT_ID,
407405
counterpartyChannelId: counterpartyChannelId
408406
}),
@@ -423,7 +421,7 @@ contract IBCChannelTests is Test {
423421
lightClient.pushValidMembership();
424422
vm.expectEmit();
425423
emit IBCChannelLib.ChannelOpenConfirm(
426-
msgTry_.channel.portId,
424+
msgTry_.portId.toHexString(),
427425
0,
428426
msgTry_.channel.counterpartyPortId,
429427
counterpartyChannelId,
@@ -460,11 +458,11 @@ contract IBCChannelTests is Test {
460458
connectionId: connectionId,
461459
ordering: IBCChannelOrder.Unordered,
462460
version: version,
463-
portId: address(module).toHexString(),
464461
counterpartyPortId: COUNTERPARTY_PORT_ID,
465462
counterpartyChannelId: counterpartyChannelId
466463
});
467464
IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({
465+
portId: address(module),
468466
channel: channel,
469467
counterpartyVersion: counterpartyVersion,
470468
proofInit: hex"",

0 commit comments

Comments
 (0)