Skip to content

Commit

Permalink
chore: add local slither script (#34)
Browse files Browse the repository at this point in the history
Fix #10

Add local yarn `slither` script.
  • Loading branch information
sripwoud authored Aug 7, 2024
1 parent 8fb3d4c commit 8bd1e14
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"**/*.{js,ts,md,json,sol,yml,yaml}": "prettier --write"
"**/*.{js,ts,md,json,sol,yml,yaml}": "yarn prettier --write"
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ or to automatically format the code:
yarn format:write
```

### Linting

```bash
yarn lint
```

Will lint all the packages with [`solhint`](https://github.com/protofire/solhint)

### Static Analysis

```bash
yarn slither
```

Will perform a static analysis of all the contracts with [`slither`](https://github.com/crytic/slither) to identify potential vulnerabilities.
You'll need to [install slither](https://github.com/crytic/slither?tab=readme-ov-file#how-to-install) beforehand.

### Conventional commits

ZK-Kit uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). A [command line utility](https://github.com/commitizen/cz-cli) to commit using the correct syntax can be used by running:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"format": "prettier -c .",
"format:write": "prettier -w .",
"remove:stable-version-field": "ts-node scripts/remove-stable-version-field.ts ${0} && yarn format:write",
"postinstall": "husky && git config --local core.editor cat"
"lint": "yarn workspaces foreach -Ap run lint",
"postinstall": "husky && git config --local core.editor cat",
"slither": "./scripts/check-slither.sh && yarn workspaces foreach -Ap run slither"
},
"keywords": [
"solidity",
Expand Down
3 changes: 2 additions & 1 deletion packages/excubiae/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "solhint 'contracts/**/*.sol'"
"lint": "solhint 'contracts/**/*.sol'",
"slither": "slither . --include-paths contracts --exclude-dependencies --ignore-compile"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/imt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "solhint 'contracts/**/*.sol'"
"lint": "solhint 'contracts/**/*.sol'",
"slither": "slither . --include-paths contracts --exclude-dependencies --ignore-compile"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/lazy-imt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "solhint 'contracts/**/*.sol'"
"lint": "solhint 'contracts/**/*.sol'",
"slither": "slither . --include-paths contracts --exclude-dependencies --ignore-compile"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/lazy-imt/test/LazyIMT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe("LazyIMT", () => {
const staticRoot = await lazyIMTTest.staticRoot(depth)

// If they match, proof is valid
await expect(calculatedRoot).to.be.equal(staticRoot)
expect(calculatedRoot).to.be.equal(staticRoot)
}

// Done with test, revert the tree state
Expand Down
3 changes: 2 additions & 1 deletion packages/lazytower/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "solhint 'contracts/**/*.sol'"
"lint": "solhint 'contracts/**/*.sol'",
"slither": "slither . --include-paths contracts --exclude-dependencies --ignore-compile"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/lean-imt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "solhint 'contracts/**/*.sol'"
"lint": "solhint 'contracts/**/*.sol'",
"slither": "slither . --include-paths contracts --exclude-dependencies --ignore-compile"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
Expand Down
19 changes: 19 additions & 0 deletions scripts/check-slither.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -eu

CYAN="\033[36m"
RED="\033[31m"
RESET="\033[0m"

log() {
printf "%b\n" "$1"
}

main() {
if ! command -v slither >/dev/null; then
log "${RED}error: slither is required but is not installed${RESET}.\nFollow instructions at ${CYAN}https://github.com/crytic/slither?tab=readme-ov-file#how-to-install${RESET} and try again."
exit 1
fi
}

main

0 comments on commit 8bd1e14

Please sign in to comment.