Skip to content

Commit

Permalink
ci: Add job to run echidna
Browse files Browse the repository at this point in the history
ctb: Echidna script runs all fuzz contracts

ctb: Include metadatahash in compilation for echidna
  • Loading branch information
maurelian committed Nov 24, 2022
1 parent b14ac6b commit 43f33f3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-rockets-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-bedrock': patch
---

Add echidna test commands
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,50 @@ jobs:
command: yarn storage-snapshot && git diff --exit-code .storage-layout
working_directory: packages/contracts-bedrock

contracts-bedrock-echidna:
docker:
- image: ethereumoptimism/ci-builder:latest
resource_class: large
steps:
- checkout
- attach_workspace: {at: "."}
- run:
name: Check if we should run
command: |
shopt -s inherit_errexit
CHANGED=$(check-changed "(contracts-bedrock/contracts)" || echo "TRUE")
if [[ "$CHANGED" = "FALSE" ]]; then
circleci step halt
fi
- run:
name: Compile with metadata hash
command: yarn build:with-metadata
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Aliasing
command: yarn echidna:aliasing || exit 0
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Burn
command: yarn echidna:burn || exit 0
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Encoding
command: yarn echidna:encoding || exit 0
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Portal
command: yarn enchidna:portal || exit 0
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Hashing
command: yarn echidna:hashing || exit 0
working_directory: packages/contracts-bedrock
- run:
name: Echidna Fuzz Resource Metering
command: yarn echidna:metering || exit 0
working_directory: packages/contracts-bedrock

op-bindings-build:
docker:
- image: ethereumoptimism/ci-builder:latest
Expand Down Expand Up @@ -775,6 +819,9 @@ workflows:
- contracts-bedrock-tests:
requires:
- yarn-monorepo
- contracts-bedrock-echidna:
requires:
- yarn-monorepo
- op-bindings-build:
requires:
- yarn-monorepo
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts-bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ yarn build
yarn test
```

#### Running Echidna tests

You must have [Echidna](https://github.com/crytic/echidna) installed.

Contracts targetted for Echidna testing are located in `./contracts/echidna`
Each target contract is tested with a separate yarn command, for example:

```shell
yarn echidna:aliasing
```

### Deployment

#### Configuration
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ fuzz_runs = 16

[profile.ci]
fuzz_runs = 512

[profile.echidna]
bytecode_hash = 'ipfs'
7 changes: 6 additions & 1 deletion packages/contracts-bedrock/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import 'hardhat-deploy'
// Hardhat tasks
import './tasks'

let bytecodeHash = 'none'
if (process.env.FOUNDRY_PROFILE === 'echidna') {
bytecodeHash = 'ipfs'
}

const config: HardhatUserConfig = {
networks: {
hardhat: {
Expand Down Expand Up @@ -371,7 +376,7 @@ const config: HardhatUserConfig = {
],
settings: {
metadata: {
bytecodeHash: 'none',
bytecodeHash,
},
outputSelection: {
'*': {
Expand Down
9 changes: 8 additions & 1 deletion packages/contracts-bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"scripts": {
"build:forge": "forge build",
"build:with-metadata": "hardhat clean && FOUNDRY_PROFILE=echidna hardhat compile",
"build:differential": "tsc scripts/differential-testing.ts --outDir dist --moduleResolution node --esModuleInterop",
"prebuild": "yarn ts-node scripts/verify-foundry-install.ts",
"build": "hardhat compile && yarn autogen:artifacts && yarn build:ts && yarn typechain",
Expand All @@ -36,7 +37,13 @@
"lint:contracts:fix": "yarn prettier --write 'contracts/**/*.sol'",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"lint": "yarn lint:fix && yarn lint:check",
"typechain": "typechain --target ethers-v5 --out-dir dist/types --glob 'artifacts/!(build-info)/**/+([a-zA-Z0-9_]).json'"
"typechain": "typechain --target ethers-v5 --out-dir dist/types --glob 'artifacts/!(build-info)/**/+([a-zA-Z0-9_]).json'",
"echidna:aliasing": "echidna-test --contract FuzzAddressAliasing --format text --crytic-args --hardhat-ignore-compile .",
"echidna:burn": "echidna-test --contract FuzzBurn --format text --crytic-args --hardhat-ignore-compile .",
"echidna:encoding": "echidna-test --contract FuzzEncoding --format text --crytic-args --hardhat-ignore-compile .",
"echidna:portal": "echidna-test --contract FuzzOptimismPortal --format text --crytic-args --hardhat-ignore-compile .",
"echidna:hashing": "echidna-test --contract FuzzHashing --format text --crytic-args --hardhat-ignore-compile .",
"echidna:metering": "echidna-test --contract FuzzResourceMetering --format text --crytic-args --hardhat-ignore-compile ."
},
"dependencies": {
"@eth-optimism/core-utils": "^0.11.0",
Expand Down

0 comments on commit 43f33f3

Please sign in to comment.