Skip to content

Commit

Permalink
Bytecode Verification (#47)
Browse files Browse the repository at this point in the history
* WIP: encode args script

* take constructor args and artifact path from cli

* Restructure directory, add sol file to type check: WIP

* Add test file: WIP

* Update ts script for struct array, string array, bytes array, uint256 array, bytes32

* pr feedback

* Add final logic to type check bytecode

* Update typecheck example contract and add its deployment script

* Add deployed example contract to json files

* Move ExampleTypeCheck to src

* Update script to compare bytecode without metadata

* update readme

* Add complex type check example

* Add deployed contract to jsons

* pr readme feedback

Co-authored-by: Elliot <[email protected]>

* update script to access root addresses and artifacts

* update typecheking readme

* Add forge script for type checking and check for contracts without metadata

* Add failure test for incorrect artifact path

* Update README

* Add failure test for incorrect deployed bytecode

* update CI

* fix CI

* Update github workflow

* Update README

* Update README

* Update encode script

* Add TypeCheckAddresses doc

* Apply suggestions from code review

Co-authored-by: Ana Julia  <[email protected]>
Co-authored-by: Elliot <[email protected]>

* pr feedback

* update typeCheck contract to be able to run from root project through script

* Update README

* update github workflow

* Add docs

* update docs

* update README to include steps to run from CLI from within FPS

* Apply suggestions from code review

Co-authored-by: Elliot <[email protected]>

---------

Co-authored-by: Elliot <[email protected]>
Co-authored-by: Ana Julia <[email protected]>
  • Loading branch information
3 people authored Apr 4, 2024
1 parent 0c0e157 commit 9bce630
Show file tree
Hide file tree
Showing 28 changed files with 884 additions and 28 deletions.
46 changes: 28 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ jobs:
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Install Node.js"
uses: "actions/setup-node@v3"
with:
Expand All @@ -38,7 +35,7 @@ jobs:
echo "## Lint result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
build:
proposal-simulator-test:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
Expand All @@ -49,16 +46,29 @@ jobs:
- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Show the Foundry config"
run: "forge config"

- name:
"Generate a fuzz seed that changes weekly to avoid burning through RPC
allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV
- name: "Build the contracts and print their size"
run: "forge build --sizes"

- name: "Add build summary"
- name: "Run the tests"
run: "forge test --nmc TypeCheck"

- name: "Add test summary"
run: |
echo "## Build result" >> $GITHUB_STEP_SUMMARY
echo "## Proposal simulator tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
test:
needs: ["lint", "build"]
type-check-test:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
Expand All @@ -71,19 +81,19 @@ jobs:

- name: "Show the Foundry config"
run: "forge config"

- name: "Install Node.js"
uses: "actions/setup-node@v3"
with:
node-version: "lts/*"

- name:
"Generate a fuzz seed that changes weekly to avoid burning through RPC
allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV
- name: "Install the Node.js dependencies"
run: "cd typescript/ && npm install && cd ../"

- name: "Run the tests"
run: "forge test"
- name: "Run typecheck tests"
run: "forge test --mc TypeCheck --ffi --fork-url sepolia"

- name: "Add test summary"
run: |
echo "## Tests result" >> $GITHUB_STEP_SUMMARY
echo "## Type check tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ node_modules/
.env

lcov.info

# typescript
typescript/node_modules/

typescript/package-lock.json
84 changes: 79 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ For guidance on tool usage, please read the [documentation](https://solidity-lab

## Usage

### Step 1: Install
### Proposal Simulation

#### Step 1: Install

Add `forge-proposal-simulator` to your project using Forge:

```sh
forge install https://github.com/solidity-labs-io/forge-proposal-simulator.git
```

### Step 2: Set Remappings
#### Step 2: Set Remappings

Update your remappings.txt to include:

```txt
@forge-proposal-simulator=lib/forge-proposal-simulator/
```

### Step 3: Create Addresses File
#### Step 3: Create Addresses File

Create a JSON file following the instructions provided in
[Addresses.md](docs/overview/architecture/addresses.md). We recommend keeping the
Expand All @@ -35,18 +37,90 @@ Once the file is created, be sure to allow read access to `addresses.json` insid
fs_permissions = [{ access = "read", path = "./addresses/addresses.json"}]
```

### Step 4: Create a Proposal
#### Step 4: Create a Proposal

Choose a model that fits your needs:

- [Multisig Proposal](docs/guides/multisig-proposal.md)
- [Timelock Proposal](docs/guides/timelock-proposal.md)
- [Governor Bravo Proposal](docs/guides/governor-bravo-proposal.md)

### Step 5: Implement Scripts and Tests
#### Step 5: Implement Scripts and Tests

Create scripts and/or tests. Check [Guides](docs/guides/multisig-proposal.md) and [Integration Tests](docs/testing/integration-tests.md).

### Type Checking

Type checking allows verification of deployed bytecode on any contracts with the bytecode present in local artifacts. With this feature, developer `A` can easily deploy some contracts, and developer `B` can verify `A`'s deployments by simply running the type checking script. Additionaly, `A` can also use this feature to verify their own deployments. `A` can take the following steps:

- Follow the steps 1 to 3 on [Proposal Simulation](#proposal-simulation) section
- Add the deployed contracts to `Addresses.json`.
- Create a `TypeCheckAddresses.json` file following the instructions provided in [type-check.md](docs/guides/type-check.md).
- Enter `lib/forge-proposal-simulator/typescript` directory and install npm packages.

```bash
cd lib/forge-proposal-simulator/typescript && npm i
```

- Change directory again to the root repo

```bash
cd ../../../
```

- Add below environment variables to `.env`.

```
ADDRESSES_PATH # Path to addresses.json file
TYPE_CHECK_ADDRESSES_PATH # Path to typeCheckAddresses.json file
ARTIFACT_PATH # Path of artifact folder
```

Example:

```
TYPE_CHECK_ADDRESSES_PATH=addresses/TypeCheckAddresses.json
ADDRESSES_PATH=addresses/Addresses.json
ARTIFACT_PATH=out/
```

- Make sure to allow read access to `Addresses.json`, `TypeCheckAddresses.json` and `artifact` folder inside of `foundry.toml`.

```toml
[profile.default]

fs_permissions = [{ access = "read", path = "./"}]
```

- Run the following command on root repo to type check all contracts added in `TypeCheckAddresses.json`.

```bash
forge script lib/forge-proposal-simulator/script/TypeCheck.s.sol:TypeCheck --ffi --fork-url <deployed_contracts_chain_rpc_url>
```

### Type checking on Example contracts FPS

#### Step 1: Set enviornment variables

```
TYPE_CHECK_ADDRESSES_PATH="addresses/TypeCheckAddresses.json"
ADDRESSES_PATH="addresses/Addresses.json"
ARTIFACT_PATH="out/"
LIB_PATH=""
```

#### Step 2: Run script to test type checking

```bash
forge script script/TypeCheck.s.sol:TypeCheck --ffi --fork-url sepolia
```

You can also run type checking through inline environment variables if not already set in .env

```bash
TYPE_CHECK_ADDRESSES_PATH="addresses/TypeCheckAddresses.json" ADDRESSES_PATH="addresses/Addresses.json" ARTIFACT_PATH="out/" LIB_PATH="" forge script script/TypeCheck.s.sol:TypeCheck --ffi --fork-url sepolia
```

## Contribute

There are many ways you can participate and help build the next version of FPS. Check out the [contribution guide](CONTRIBUTING.md)!
Expand Down
15 changes: 13 additions & 2 deletions addresses/Addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
"name": "BRAVO_PROPOSER",
"chainId": 31337,
"isContract": false

},
{
"addr": "0x293cad26033577eb68137603a34d2dbfd05104d8",
"chainId": 11155111,
"name": "ExampleTypeCheck",
"isContract": true
},
{
"addr": "0x9D7A602541230B2bA04D9aA542fad73B8aaBA4ED",
"chainId": 11155111,
"name": "ExampleTypeCheck_02",
"isContract": true
}
]
]
14 changes: 14 additions & 0 deletions addresses/AddressesIncorrect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"addr": "0x8FB9B57A1Af027ca5f4EF262280fFF880c22D371",
"chainId": 11155111,
"name": "ExampleTypeCheck",
"isContract": true
},
{
"addr": "0x8FB9B57A1Af027ca5f4EF262280fFF880c22D371",
"chainId": 11155111,
"name": "ExampleTypeCheck_02",
"isContract": true
}
]
12 changes: 12 additions & 0 deletions addresses/TypeCheckAddresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "ExampleTypeCheck",
"constructorArgs": "[[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", \"0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5000000000000000000000000\", [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]]], [\"Arg1\", \"Arg2\"], [2, 3], [[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]], [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]]]]",
"artifactPath": "ExampleTypeCheck.sol:ExampleTypeCheck"
},
{
"name": "ExampleTypeCheck_02",
"constructorArgs": "[[[1, 2], [3, 4]], [[[1, 2]], [[3, 4]]], [[[[[1, 2]], [[3, 4]]]], [[[[5, 6]], [[7, 8]]]]], [[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\"], [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\"]]]",
"artifactPath": "ExampleTypeCheck_02.sol:ExampleTypeCheck_02"
}
]
12 changes: 12 additions & 0 deletions addresses/TypeCheckAddressesIncorrect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "ExampleTypeCheck",
"constructorArgs": "[[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", \"0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5000000000000000000000000\", [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]]], [\"Arg1\", \"Arg2\"], [2, 3], [[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]], [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2, [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\", 2]]]]",
"artifactPath": "ExampleTypeCheck_02.sol:ExampleTypeCheck_02"
},
{
"name": "ExampleTypeCheck_02",
"constructorArgs": "[[[1, 2], [3, 4]], [[[1, 2]], [[3, 4]]], [[[[[1, 2]], [[3, 4]]]], [[[[5, 6]], [[7, 8]]]]], [[\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\"], [\"0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5\"]]]",
"artifactPath": "ExampleTypeCheck.sol:ExampleTypeCheck"
}
]
6 changes: 6 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@
## Testing

- [Integration Tests](testing/integration-tests.md)

## Type checking

- [Introduction](type-check/introduction.md)
- [Type Check Example](type-check/example.md)
- [TypeCheckAddresses.json](type-check/type-check.md)
Loading

0 comments on commit 9bce630

Please sign in to comment.