From 8bd1e149ab317f3f380b9d6c15c5ad97436e4df3 Mon Sep 17 00:00:00 2001 From: sripwoud Date: Wed, 7 Aug 2024 22:36:13 +0200 Subject: [PATCH] chore: add local `slither` script (#34) Fix #10 Add local yarn `slither` script. --- .lintstagedrc.json | 2 +- README.md | 17 +++++++++++++++++ package.json | 4 +++- packages/excubiae/package.json | 3 ++- packages/imt/package.json | 3 ++- packages/lazy-imt/package.json | 3 ++- packages/lazy-imt/test/LazyIMT.ts | 2 +- packages/lazytower/package.json | 3 ++- packages/lean-imt/package.json | 3 ++- scripts/check-slither.sh | 19 +++++++++++++++++++ 10 files changed, 51 insertions(+), 8 deletions(-) create mode 100755 scripts/check-slither.sh diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 909fefa..7533b99 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,3 +1,3 @@ { - "**/*.{js,ts,md,json,sol,yml,yaml}": "prettier --write" + "**/*.{js,ts,md,json,sol,yml,yaml}": "yarn prettier --write" } diff --git a/README.md b/README.md index 4d2c091..12d6cc7 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/package.json b/package.json index a144320..ffd4bd0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/excubiae/package.json b/packages/excubiae/package.json index 8e72642..b99ddd3 100644 --- a/packages/excubiae/package.json +++ b/packages/excubiae/package.json @@ -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", diff --git a/packages/imt/package.json b/packages/imt/package.json index 754bcd8..5b36728 100644 --- a/packages/imt/package.json +++ b/packages/imt/package.json @@ -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", diff --git a/packages/lazy-imt/package.json b/packages/lazy-imt/package.json index 98ad51e..e157b7b 100644 --- a/packages/lazy-imt/package.json +++ b/packages/lazy-imt/package.json @@ -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", diff --git a/packages/lazy-imt/test/LazyIMT.ts b/packages/lazy-imt/test/LazyIMT.ts index d34653a..0c70c8f 100644 --- a/packages/lazy-imt/test/LazyIMT.ts +++ b/packages/lazy-imt/test/LazyIMT.ts @@ -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 diff --git a/packages/lazytower/package.json b/packages/lazytower/package.json index e8dbd76..a6e582e 100644 --- a/packages/lazytower/package.json +++ b/packages/lazytower/package.json @@ -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", diff --git a/packages/lean-imt/package.json b/packages/lean-imt/package.json index 643701c..35446ce 100644 --- a/packages/lean-imt/package.json +++ b/packages/lean-imt/package.json @@ -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", diff --git a/scripts/check-slither.sh b/scripts/check-slither.sh new file mode 100755 index 0000000..ca2b2f6 --- /dev/null +++ b/scripts/check-slither.sh @@ -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