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

Bytecode Verification #47

Merged
merged 38 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c9bb0c3
WIP: encode args script
prateek105 Mar 15, 2024
904703f
take constructor args and artifact path from cli
prateek105 Mar 18, 2024
1c0056b
Restructure directory, add sol file to type check: WIP
prateek105 Mar 18, 2024
4319ed6
Add test file: WIP
prateek105 Mar 18, 2024
b8aa246
Update ts script for struct array, string array, bytes array, uint256…
prateek105 Mar 19, 2024
8668a79
pr feedback
prateek105 Mar 19, 2024
7458143
Add final logic to type check bytecode
prateek105 Mar 20, 2024
f5e39b7
Update typecheck example contract and add its deployment script
prateek105 Mar 20, 2024
a3f028c
Add deployed example contract to json files
prateek105 Mar 20, 2024
db18296
Merge branch 'main' into feat/type-checking
prateek105 Mar 20, 2024
50856cb
Move ExampleTypeCheck to src
prateek105 Mar 20, 2024
dbff325
Update script to compare bytecode without metadata
prateek105 Mar 20, 2024
014122d
update readme
prateek105 Mar 20, 2024
c3db8e3
Add complex type check example
prateek105 Mar 21, 2024
a0c6299
Add deployed contract to jsons
prateek105 Mar 21, 2024
69c29c1
pr readme feedback
prateek105 Mar 22, 2024
68ff0d9
update script to access root addresses and artifacts
prateek105 Mar 22, 2024
bad5510
update typecheking readme
prateek105 Mar 22, 2024
c0d6c88
Add forge script for type checking and check for contracts without me…
prateek105 Mar 26, 2024
f92b457
Add failure test for incorrect artifact path
prateek105 Mar 26, 2024
2dcc771
Update README
prateek105 Mar 26, 2024
491ab6f
Add failure test for incorrect deployed bytecode
prateek105 Mar 26, 2024
e499af6
update CI
prateek105 Mar 26, 2024
c17c85d
fix CI
prateek105 Mar 26, 2024
b581ded
Update github workflow
prateek105 Mar 27, 2024
963d72b
Update README
prateek105 Mar 27, 2024
2e9ae50
Update README
prateek105 Mar 28, 2024
fae1733
Update encode script
prateek105 Mar 28, 2024
3e2ad55
Add TypeCheckAddresses doc
prateek105 Mar 28, 2024
e450409
Apply suggestions from code review
prateek105 Apr 2, 2024
8b41f58
pr feedback
prateek105 Apr 2, 2024
2136777
update typeCheck contract to be able to run from root project through…
prateek105 Apr 2, 2024
b519228
Update README
prateek105 Apr 3, 2024
92b3fd0
update github workflow
prateek105 Apr 3, 2024
c41a0e1
Add docs
prateek105 Apr 3, 2024
98e19dc
update docs
prateek105 Apr 3, 2024
ddea628
update README to include steps to run from CLI from within FPS
prateek105 Apr 4, 2024
6fa566c
Apply suggestions from code review
prateek105 Apr 4, 2024
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
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
61 changes: 56 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

prateek105 marked this conversation as resolved.
Show resolved Hide resolved
## 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,67 @@ 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
ElliotFriedman marked this conversation as resolved.
Show resolved Hide resolved
```

- 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/
Comment on lines +82 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

missing lib path here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A user who has installed fps and is type checking his contracts doesn't need to think about lib path. We have this code vm.envOr("LIB_PATH", string("lib/forge-proposal-simulator/")); in script so lib path will be set by default. I have added this LIB_PATH env so that this script can also be run from the fps repo by setting LIB_PATH as "" just like we do in test.

ElliotFriedman marked this conversation as resolved.
Show resolved Hide resolved
```

- 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`.
ElliotFriedman marked this conversation as resolved.
Show resolved Hide resolved

```bash
forge script lib/forge-proposal-simulator/script/TypeCheck.s.sol:TypeCheck --ffi --fork-url <deployed_contracts_chain_rpc_url>
ElliotFriedman marked this conversation as resolved.
Show resolved Hide resolved
```

## 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,
anajuliabit marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
prateek105 marked this conversation as resolved.
Show resolved Hide resolved
]
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
Loading