Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lean-imt): move from hardhat to forge #23

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@ jobs:
with:
path: node_modules
key: ${{ needs.deps.outputs.cache-key }}
# TODO: right now forge and node tooling coexist, eventually keep only forge action
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- run: yarn compile

- name: Upload compilation results
- name: Upload compilation results (hardhat)
uses: actions/upload-artifact@v4
with:
name: all-artifacts
path: packages/**/artifacts/**
- name: Upload compilation results (forge)
uses: actions/upload-artifact@v4
with:
name: all-artifacts-forge
path: packages/**/out/**

style:
needs: deps
Expand All @@ -93,6 +102,11 @@ jobs:

steps:
- uses: actions/checkout@v4
# TODO: right now forge and node tooling coexist, eventually keep only forge action
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- uses: actions/setup-node@v4
with:
node-version: 20
Expand All @@ -104,6 +118,10 @@ jobs:
with:
name: all-artifacts
path: packages/
- uses: actions/download-artifact@v4
with:
name: all-artifacts-forge
path: packages/

- if: contains(needs.changed-files.outputs.modified_files, matrix.dir)
name: Test
Expand Down Expand Up @@ -134,51 +152,30 @@ jobs:
echo "matrix=$matrix" >> $GITHUB_OUTPUT

slither:
if: needs.changed-files.outputs.any_changed == 'true'
needs: [changed-files, set-matrix, deps]
if: contains(needs.changed-files.outputs.modified_files, 'lean-imt')
Copy link
Member Author

@sripwoud sripwoud Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow slither was buggy when the monorepo combines contracts that are compiled with either hardhat or forge. As slither in the ci is new, and because eventually we'll have only forge, I suggest restricting the ci check to the forge pkgs as a temp fix.

needs: [changed-files, compile]
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
strategy:
matrix:
dir: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4

# FIXME this does not work as a way to restore compilation results for slither job but it does for the compile job ??
#- uses: actions/download-artifact@v4
# with:
# name: all-artifacts
# path: packages/

- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/cache/restore@v4
- uses: actions/download-artifact@v4
with:
path: node_modules
key: ${{ needs.deps.outputs.cache-key }}
- if: contains(needs.changed-files.outputs.modified_files, matrix.dir)
name: Compile contracts
run: |
workspace=$(jq -r '.name' packages/${{ matrix.dir }}/package.json)
yarn workspace "$workspace" run compile
name: all-artifacts-forge
path: packages/

- if: contains(needs.changed-files.outputs.modified_files, matrix.dir)
name: Run slither
- name: Run slither
uses: crytic/[email protected]
id: slither
with:
ignore-compile: true
node-version: 20
fail-on: none
sarif: results.sarif
slither-args: --filter-paths "test" --exclude-dependencies --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
target: packages/${{ matrix.dir }}

- if: contains(needs.changed-files.outputs.modified_files, matrix.dir)
name: Upload SARIF files
- name: Upload SARIF files
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ typechain-types

.envrc
.tool-versions

# forge build output
out
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "packages/lean-imt/lib/poseidon-solidity"]
path = packages/lean-imt/lib/poseidon-solidity
url = https://github.com/vimwitch/poseidon-solidity
[submodule "packages/lean-imt/lib/forge-std"]
path = packages/lean-imt/lib/forge-std
url = https://github.com/foundry-rs/forge-std
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ yarn-error.log*

# others
target

# forge lib
packages/lean-imt/lib
4 changes: 4 additions & 0 deletions packages/lean-imt/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[profile.default]
remappings = [
"poseidon-solidity/=lib/poseidon-solidity/contracts/",
]
23 changes: 0 additions & 23 deletions packages/lean-imt/hardhat.config.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/lean-imt/lib/forge-std
Submodule forge-std added at 07263d
1 change: 1 addition & 0 deletions packages/lean-imt/lib/poseidon-solidity
Submodule poseidon-solidity added at 8205c9
34 changes: 4 additions & 30 deletions packages/lean-imt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,14 @@
"name": "lean-imt.sol",
"private": true,
"scripts": {
"start": "hardhat node",
"compile": "hardhat compile",
"test": "hardhat test",
"compile": "forge build",
"test": "forge test",
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"test:coverage": "forge coverage",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that the current latest version of forge does not allow excluding the t.sol files from coverage.
This was fixed very recently foundry-rs/foundry#2988

"lint": "solhint 'contracts/**/*.sol'"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.7",
"@zk-kit/lean-imt": "^2.0.1",
"chai": "^4.2.0",
"ethers": "^6.4.0",
"hardhat": "^2.19.4",
"hardhat-gas-reporter": "^1.0.8",
"poseidon-lite": "^0.2.0",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.1.0",
"solidity-coverage": "^0.8.0",
"ts-node": "^10.9.2",
"typechain": "^8.3.0",
"typescript": "^5.3.3"
},
"dependencies": {
"poseidon-solidity": "0.0.5"
"solhint-plugin-prettier": "^0.1.0"
}
}
1 change: 1 addition & 0 deletions packages/lean-imt/slither.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "filter_paths": "lib" }
File renamed without changes.
44 changes: 0 additions & 44 deletions packages/lean-imt/tasks/deploy-imt-test.ts

This file was deleted.

Loading
Loading