Skip to content

Commit

Permalink
ctb: Add echidna test for AddressAliasing
Browse files Browse the repository at this point in the history
ctb: Used a config file for echidna
  • Loading branch information
maurelian committed Dec 7, 2022
1 parent 74fd040 commit 1594678
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .changeset/healthy-teachers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/ci-builder': patch
'@eth-optimism/contracts-bedrock': patch
---

Add echidna test for AliasHelper
49 changes: 25 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ jobs:
command: yarn storage-snapshot && git diff --exit-code .storage-layout
working_directory: packages/contracts-bedrock

contracts-bedrock-echidna:
bedrock-echidna-build:
docker:
- image: ethereumoptimism/ci-builder:latest
resource_class: large
Expand All @@ -282,30 +282,27 @@ jobs:
name: Compile with metadata hash
command: yarn build:with-metadata
working_directory: packages/contracts-bedrock
- persist_to_workspace:
root: .
paths:
- "node_modules"
- packages/contracts-bedrock

bedrock-echidna-run:
docker:
- image: ethereumoptimism/ci-builder:latest
parameters:
echidna_target:
description: Which echidna fuzz contract to run
type: string
steps:
- checkout
- attach_workspace: {at: "."}
- 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
name: Echidna Fuzz <<parameters.echidna_target>>
command: yarn echidna:<<parameters.echidna_target>>
working_directory: packages/contracts-bedrock
no_output_timeout: 15m

op-bindings-build:
docker:
Expand Down Expand Up @@ -813,9 +810,13 @@ workflows:
- contracts-bedrock-tests:
requires:
- yarn-monorepo
- contracts-bedrock-echidna:
- bedrock-echidna-build:
requires:
- yarn-monorepo
- bedrock-echidna-run:
echidna_target: aliasing
requires:
- bedrock-echidna-build
- op-bindings-build:
requires:
- yarn-monorepo
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ op-exporter


__pycache__

# Ignore echidna artifacts
crytic-export
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore:
- "**/*.t.sol"
- "op-bindings/bindings/*.go"
- "packages/contracts-bedrock/contracts/vendor/WETH9.sol"
- "packages/contracts-bedrock/contracts/echidna"
coverage:
status:
patch:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pragma solidity 0.8.15;

import { AddressAliasHelper } from "../vendor/AddressAliasHelper.sol";

contract EchidnaFuzzAddressAliasing {
bool failedRoundtrip;

/**
* @notice Takes an address to be aliased with AddressAliasHelper and then unaliased
* and updates the test contract's state indicating if the round trip encoding
* failed.
*/
function testRoundTrip(address addr) public {
// Alias our address
address aliasedAddr = AddressAliasHelper.applyL1ToL2Alias(addr);

// Unalias our address
address undoneAliasAddr = AddressAliasHelper.undoL1ToL2Alias(aliasedAddr);

// If our round trip aliasing did not return the original result, set our state.
if (addr != undoneAliasAddr) {
failedRoundtrip = true;
}
}

/**
* @notice Verifies that testRoundTrip(...) did not ever fail.
*/
function echidna_round_trip_aliasing() public view returns (bool) {
// ASSERTION: The round trip aliasing done in testRoundTrip(...) should never fail.
return !failedRoundtrip;
}
}
6 changes: 6 additions & 0 deletions packages/contracts-bedrock/echidna.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cryticArgs: ["--hardhat-ignore-compile"]
format: text

# Set the timeout to 3 minutes to keep CI from getting too long.
# The tool also adds 2 or 3 minutes before/after the actual timeout window.
timeout: 180
2 changes: 2 additions & 0 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ build_info = true
build_info_path = 'artifacts/build-info'
ffi = true
fuzz_runs = 16
no_match_contract = 'EchidnaFuzz'


[profile.ci]
fuzz_runs = 512
Expand Down
14 changes: 7 additions & 7 deletions packages/contracts-bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {
"build:forge": "forge build",
"build:with-metadata": "hardhat clean && FOUNDRY_PROFILE=echidna hardhat compile",
"build:with-metadata": "FOUNDRY_PROFILE=echidna yarn build:forge",
"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 @@ -38,12 +38,12 @@
"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'",
"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 ."
"echidna:aliasing": "echidna-test --contract EchidnaFuzzAddressAliasing --config ./echidna.yaml .",
"echidna:burn": "echidna-test --contract EchidnaFuzzBurn --config ./echidna.yaml .",
"echidna:encoding": "echidna-test --contract EchidnaFuzzEncoding --config ./echidna.yaml .",
"echidna:portal": "echidna-test --contract EchidnaFuzzOptimismPortal --config ./echidna.yaml .",
"echidna:hashing": "echidna-test --contract EchidnaFuzzHashing --config ./echidna.yaml .",
"echidna:metering": "echidna-test --contract EchidnaFuzzResourceMetering --config ./echidna.yaml ."
},
"dependencies": {
"@eth-optimism/core-utils": "^0.11.0",
Expand Down

0 comments on commit 1594678

Please sign in to comment.