Skip to content

Commit 5617641

Browse files
committed
introduce slither and clarify some trusted calls
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent c591d09 commit 5617641

File tree

9 files changed

+66
-26
lines changed

9 files changed

+66
-26
lines changed

.gas-snapshot

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ IBCTest:testBenchmarkRecvPacket() (gas: 158899)
88
IBCTest:testBenchmarkSendPacket() (gas: 128432)
99
IBCTest:testBenchmarkUpdateMockClient() (gas: 160229)
1010
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 947, ~: 947)
11-
TestICS02:testCreateClient() (gas: 36551707)
12-
TestICS02:testInvalidCreateClient() (gas: 36448926)
13-
TestICS02:testInvalidUpdateClient() (gas: 36447834)
14-
TestICS02:testRegisterClient() (gas: 36103500)
15-
TestICS02:testRegisterClientDuplicatedClientType() (gas: 36088809)
16-
TestICS02:testRegisterClientInvalidClientType() (gas: 36118270)
17-
TestICS02:testUpdateClient() (gas: 36616034)
11+
TestICS02:testCreateClient() (gas: 36498151)
12+
TestICS02:testInvalidCreateClient() (gas: 36395370)
13+
TestICS02:testInvalidUpdateClient() (gas: 36394278)
14+
TestICS02:testRegisterClient() (gas: 36049944)
15+
TestICS02:testRegisterClientDuplicatedClientType() (gas: 36035253)
16+
TestICS02:testRegisterClientInvalidClientType() (gas: 36064714)
17+
TestICS02:testUpdateClient() (gas: 36562478)
1818
TestICS03Handshake:testConnOpenAck() (gas: 1858230)
1919
TestICS03Handshake:testConnOpenConfirm() (gas: 2054143)
2020
TestICS03Handshake:testConnOpenInit() (gas: 1429838)
@@ -46,23 +46,23 @@ TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3259727)
4646
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3278877)
4747
TestICS04Packet:testSendPacket() (gas: 6412442)
4848
TestICS04Packet:testTimeoutOnClose() (gas: 3553289)
49-
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46737910)
50-
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455585)
51-
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5266374)
52-
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5235544)
53-
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405811)
54-
TestICS04Upgrade:testUpgradeFull() (gas: 57775990)
55-
TestICS04Upgrade:testUpgradeInit() (gas: 3068711)
56-
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471930)
57-
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3902151)
58-
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5238138)
59-
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5612071)
60-
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070658)
61-
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17677097)
62-
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21313205)
63-
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44260340)
64-
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56489888)
65-
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45099675)
49+
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46742362)
50+
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3456630)
51+
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5266752)
52+
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5236270)
53+
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4407259)
54+
TestICS04Upgrade:testUpgradeFull() (gas: 57784890)
55+
TestICS04Upgrade:testUpgradeInit() (gas: 3069408)
56+
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471936)
57+
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3903220)
58+
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5238516)
59+
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5612449)
60+
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4071036)
61+
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17681581)
62+
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21317741)
63+
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44264108)
64+
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56493668)
65+
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45102699)
6666
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61690)
6767
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565532)
6868
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473992)

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ jobs:
4747
- name: Run tests with minimal solidity version
4848
run: make SOLC_VERSION=${{ env.MINIMAL_SOLC_VERSION }} test
4949

50+
slither:
51+
name: Slither analysis
52+
needs: contract-test
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
- uses: crytic/slither-action@v0.4.0
57+
with:
58+
node-version: 20.13
59+
slither-version: 0.10.1
60+
5061
e2e-test:
5162
name: E2E test
5263
needs: contract-test

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ test:
2929
coverage:
3030
@forge coverage --use solc:$(SOLC_VERSION)
3131

32+
.PHONY: slither
33+
slither:
34+
@slither .
35+
3236
######## Protobuf ########
3337

3438
.PHONY: proto-sol

contracts/core/03-connection/IBCConnection.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
208208
bytes memory proof,
209209
bytes memory clientStateBytes
210210
) private {
211+
// slither-disable-start reentrancy-no-eth
211212
if (
212213
checkAndGetClient(connection.client_id).verifyMembership(
213214
connection.client_id,
@@ -220,6 +221,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
220221
clientStateBytes
221222
)
222223
) {
224+
// slither-disable-end reentrancy-no-eth
223225
return;
224226
}
225227
revert IBCConnectionFailedVerifyClientState(connection.client_id, path, clientStateBytes, proof, height);
@@ -232,6 +234,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
232234
bytes memory proof,
233235
bytes memory consensusStateBytes
234236
) private {
237+
// slither-disable-start reentrancy-no-eth
235238
if (
236239
checkAndGetClient(connection.client_id).verifyMembership(
237240
connection.client_id,
@@ -246,6 +249,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
246249
consensusStateBytes
247250
)
248251
) {
252+
// slither-disable-end reentrancy-no-eth
249253
return;
250254
}
251255
revert IBCConnectionFailedVerifyClientConsensusState(
@@ -266,6 +270,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
266270
string memory counterpartyConnectionId,
267271
ConnectionEnd.Data memory counterpartyConnection
268272
) private {
273+
// slither-disable-start reentrancy-no-eth
269274
if (
270275
checkAndGetClient(connection.client_id).verifyMembership(
271276
connection.client_id,
@@ -278,6 +283,7 @@ abstract contract IBCConnection is IBCHost, IBCSelfStateValidator, IIBCConnectio
278283
ConnectionEnd.encode(counterpartyConnection)
279284
)
280285
) {
286+
// slither-disable-end reentrancy-no-eth
281287
return;
282288
}
283289
revert IBCConnectionFailedVerifyConnectionState(

contracts/core/04-channel/IBCChannelHandshake.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
324324
string memory channelId,
325325
bytes memory channelBytes
326326
) private {
327+
// slither-disable-start reentrancy-no-eth
327328
if (
328329
checkAndGetClient(connection.client_id).verifyMembership(
329330
connection.client_id,
@@ -336,6 +337,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
336337
channelBytes
337338
)
338339
) {
340+
// slither-disable-end reentrancy-no-eth
339341
return;
340342
}
341343
revert IBCChannelFailedVerifyChannelState(

contracts/core/04-channel/IBCChannelPacketSendRecv.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ contract IBCChannelPacketSendRecv is
310310
bytes memory path,
311311
bytes32 commitment
312312
) private {
313+
// slither-disable-start reentrancy-no-eth
313314
if (
314315
checkAndGetClient(connection.client_id).verifyMembership(
315316
connection.client_id,
@@ -322,6 +323,7 @@ contract IBCChannelPacketSendRecv is
322323
abi.encodePacked(commitment)
323324
)
324325
) {
326+
// slither-disable-end reentrancy-no-eth
325327
return;
326328
}
327329
revert IBCChannelFailedVerifyPacketCommitment(connection.client_id, path, commitment, proof, height);
@@ -334,6 +336,7 @@ contract IBCChannelPacketSendRecv is
334336
bytes memory path,
335337
bytes32 acknowledgementCommitment
336338
) private {
339+
// slither-disable-start reentrancy-no-eth
337340
if (
338341
checkAndGetClient(connection.client_id).verifyMembership(
339342
connection.client_id,
@@ -346,6 +349,7 @@ contract IBCChannelPacketSendRecv is
346349
abi.encodePacked(acknowledgementCommitment)
347350
)
348351
) {
352+
// slither-disable-end reentrancy-no-eth
349353
return;
350354
}
351355
revert IBCChannelFailedVerifyPacketAcknowledgement(

contracts/core/04-channel/IBCChannelPacketTimeout.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ contract IBCChannelPacketTimeout is IBCModuleManager, IIBCChannelPacketTimeout,
7575
revert IBCChannelPacketMaybeAlreadyReceived(msg_.packet.sequence, msg_.nextSequenceRecv);
7676
}
7777
if (
78+
// slither-disable-next-line reentrancy-no-eth
7879
!client.verifyMembership(
7980
connection.client_id,
8081
msg_.proofHeight,
@@ -104,6 +105,7 @@ contract IBCChannelPacketTimeout is IBCModuleManager, IIBCChannelPacketTimeout,
104105
msg_.packet.destinationPort, msg_.packet.destinationChannel, msg_.packet.sequence
105106
);
106107
if (
108+
// slither-disable-next-line reentrancy-no-eth
107109
!client.verifyNonMembership(
108110
connection.client_id,
109111
msg_.proofHeight,
@@ -188,6 +190,7 @@ contract IBCChannelPacketTimeout is IBCModuleManager, IIBCChannelPacketTimeout,
188190
upgrade_sequence: msg_.counterpartyUpgradeSequence
189191
});
190192
if (
193+
// slither-disable-next-line reentrancy-no-eth
191194
!client.verifyMembership(
192195
connection.client_id,
193196
msg_.proofHeight,
@@ -215,6 +218,7 @@ contract IBCChannelPacketTimeout is IBCModuleManager, IIBCChannelPacketTimeout,
215218
revert IBCChannelPacketMaybeAlreadyReceived(msg_.packet.sequence, msg_.nextSequenceRecv);
216219
}
217220
if (
221+
// slither-disable-next-line reentrancy-no-eth
218222
!client.verifyMembership(
219223
connection.client_id,
220224
msg_.proofHeight,
@@ -243,6 +247,7 @@ contract IBCChannelPacketTimeout is IBCModuleManager, IIBCChannelPacketTimeout,
243247
msg_.packet.destinationPort, msg_.packet.destinationChannel, msg_.packet.sequence
244248
);
245249
if (
250+
// slither-disable-next-line reentrancy-no-eth
246251
!client.verifyNonMembership(
247252
connection.client_id,
248253
msg_.proofHeight,

contracts/core/04-channel/IBCChannelUpgrade.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,15 @@ abstract contract IBCChannelUpgradeBase is
282282
bytes memory path,
283283
bytes memory value
284284
) internal {
285+
// slither-disable-start reentrancy-no-eth
285286
if (
286287
ILightClient(clientImpls[connection.client_id]).verifyMembership(
287288
connection.client_id, height, 0, 0, proof, connection.counterparty.prefix.key_prefix, path, value
288289
)
289290
) {
290291
return;
291292
}
293+
// slither-disable-end reentrancy-no-eth
292294
revert IBCChannelUpgradeFailedVerifyMembership(connection.client_id, string(path), value, proof, height);
293295
}
294296

@@ -332,7 +334,7 @@ abstract contract IBCChannelUpgradeBase is
332334
counterpartyChannel
333335
);
334336
}
335-
337+
// slither-disable-next-line reentrancy-no-eth
336338
verifyMembership(
337339
connection,
338340
proofs.proofHeight,
@@ -373,7 +375,9 @@ contract IBCChannelUpgradeInitTryAck is IBCChannelUpgradeBase, IIBCChannelUpgrad
373375
channel.upgrade_sequence++;
374376
updateChannelCommitment(msg_.portId, msg_.channelId, channel);
375377

376-
upgrade.fields = msg_.proposedUpgradeFields;
378+
upgrade.fields.ordering = msg_.proposedUpgradeFields.ordering;
379+
upgrade.fields.connection_hops = new string[](1);
380+
upgrade.fields.connection_hops[0] = msg_.proposedUpgradeFields.connection_hops[0];
377381
upgrade.fields.version = lookupUpgradableModuleByPort(msg_.portId).onChanUpgradeInit(
378382
msg_.portId, msg_.channelId, channel.upgrade_sequence, msg_.proposedUpgradeFields
379383
);

slither.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,deprecated-standards,erc20-indexed,function-init-state,pragma,reentrancy-unlimited-gas,immutable-states,var-read-using-this",
3+
"filter_paths": "(tests/|node_modules/|contracts/proto/)"
4+
}

0 commit comments

Comments
 (0)