Skip to content

Commit c33e5b7

Browse files
authored
Merge pull request #11 from datachainlab/install-slither
Install slither
2 parents 9a44c10 + 75becac commit c33e5b7

File tree

9 files changed

+102
-21
lines changed

9 files changed

+102
-21
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = async ({ github, context, header, body }) => {
2+
const body2 = body
3+
.replaceAll("%8D", "\r")
4+
.replaceAll("%0A", "\n")
5+
.replaceAll("%25", "%");
6+
const comment = [header, body2].join("\n");
7+
8+
const { data: comments } = await github.rest.issues.listComments({
9+
owner: context.repo.owner,
10+
repo: context.repo.repo,
11+
issue_number: context.payload.number,
12+
});
13+
14+
const botComment = comments.find(
15+
(comment) =>
16+
// github-actions bot user
17+
comment.user.id === 41898282 && comment.body.startsWith(header)
18+
);
19+
20+
const requestBody = {
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
body: comment,
24+
};
25+
if (botComment) {
26+
requestBody.comment_id = botComment.id;
27+
await github.rest.issues.updateComment(requestBody);
28+
} else {
29+
requestBody.issue_number = context.payload.number;
30+
await github.rest.issues.createComment(requestBody);
31+
}
32+
};

.github/workflows/slither.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Slither
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
slither:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Run Slither Analysis
16+
uses: crytic/slither-action@v0.4.1
17+
id: slither
18+
with:
19+
slither-config: slither.config.json
20+
sarif: results.sarif
21+
fail-on: none
22+
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
23+
24+
- name: Format slither output
25+
id: formatted_slither
26+
run: |
27+
value=$(echo "${{ steps.slither.outputs.stdout }}" | sed -e '1d')
28+
value="${value//'%'/'%25'}"
29+
value="${value//$'\n'/'%0A'}"
30+
value="${value//$'\r'/'%0D'}"
31+
echo "value=${value}" >> $GITHUB_OUTPUT
32+
count=$(jq '[.runs[].results[]] | length' results.sarif 2>/dev/null || echo 0)
33+
echo "results_count=${count}" >> $GITHUB_OUTPUT
34+
35+
- name: Create/update checklist as PR comment
36+
if: ${{ github.event_name == 'pull_request' && steps.formatted_slither.outputs.results_count != '0' }}
37+
uses: actions/github-script@v6
38+
with:
39+
script: |
40+
const script = require(".github/scripts/slither_pr_comment")
41+
const header = '# Slither report'
42+
const body = `${{ steps.formatted_slither.outputs.value }}`
43+
const comment = [header, body].join("\n");
44+
await script({github, context, header, body})

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ else
1919
@echo "'SOURCE={ContractName}' is required, e.g. make abi SOURCE=CrossSimpleModule"
2020
@exit 1
2121
endif
22+
23+
.PHONY: slither
24+
slither:
25+
slither .

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ interface IContractModule {
3939
To generate encoders and decoders in solidity from proto files, you need to use the code generator [solidity-protobuf](https://github.com/datachainlab/solidity-protobuf).
4040

4141
Currently, [this version](https://github.com/datachainlab/solidity-protobuf/commit/3def6706178e5407497f3d01b8f0ceb17b32108d) is required.
42+
43+
Install Slither and use it for static analysis.
44+
45+
```
46+
pip3 install slither-analyzer
47+
make slither
48+
```

slither.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"exclude_dependencies": true,
3+
"exclude_informational": true,
4+
"filter_paths": "node_modules|src/proto"
5+
}

src/Migrations.sol

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/core/CrossSimpleModule.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ contract CrossSimpleModule is CrossModule, SimpleContractRegistry, TxAtomicSimpl
2121
pure
2222
returns (bytes memory acknowledgement)
2323
{
24-
PacketAcknowledgementCall.Data memory ack;
25-
ack.status = status;
24+
PacketAcknowledgementCall.Data memory ack = PacketAcknowledgementCall.Data({
25+
status: status
26+
});
2627
return packPacketAcknowledgementCall(ack);
2728
}
2829
}

src/core/IBCKeeper.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {IIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-
55

66
// IBCKeeper keeps the contracts of IBC
77
abstract contract IBCKeeper {
8-
IIBCHandler ibcHandler;
8+
IIBCHandler internal immutable ibcHandler;
99

1010
constructor(IIBCHandler handler_) {
1111
ibcHandler = handler_;

src/core/TxAtomicSimple.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ abstract contract TxAtomicSimple is IBCKeeper, PacketHandler, ContractRegistry {
3131
);
3232
PacketDataCall.Data memory pdc = PacketDataCall.decode(anyPayload.value);
3333

34-
PacketAcknowledgementCall.Data memory ack;
34+
PacketAcknowledgementCall.Data memory ack = PacketAcknowledgementCall.Data({
35+
status: PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_UNKNOWN
36+
});
3537
try module.onContractCall(
3638
CrossContext(pdc.tx_id, txIndexParticipant, pdc.tx.signers), pdc.tx.call_info
3739
) returns (bytes memory ret) {
3840
ack.status = PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_OK;
41+
// slither-disable-next-line reentrancy-events
3942
emit OnContractCall(pdc.tx_id, txIndexParticipant, true, ret);
4043
} catch (bytes memory) {
4144
ack.status = PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_FAILED;
45+
// slither-disable-next-line reentrancy-events
4246
emit OnContractCall(pdc.tx_id, txIndexParticipant, false, new bytes(0));
4347
}
4448

@@ -72,7 +76,7 @@ abstract contract TxAtomicSimple is IBCKeeper, PacketHandler, ContractRegistry {
7276
pure
7377
returns (bytes memory)
7478
{
75-
HeaderField.Data[] memory fields;
79+
HeaderField.Data[] memory fields = new HeaderField.Data[](0);
7680
return Acknowledgement.encode(
7781
Acknowledgement.Data({
7882
is_success: true,

0 commit comments

Comments
 (0)