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(protocol): restructure solidity code to match compilation targets #18059

Merged
merged 84 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
51f43be
Revert "chore(main): release protocol 1.9.0 (#18051)"
dantaik Sep 10, 2024
b93dadd
revert to use solc 0.8.24
dantaik Sep 10, 2024
5adf65c
Merge branch 'main' into revert_solc_to_0.8.24
dantaik Sep 10, 2024
5826468
restructure
dantaik Sep 10, 2024
2ab2866
mv
dantaik Sep 10, 2024
1670415
mv
dantaik Sep 10, 2024
49eeaa2
mv
dantaik Sep 10, 2024
26b2dcd
move
dantaik Sep 10, 2024
c93c601
restructure
dantaik Sep 10, 2024
7848bcf
move
dantaik Sep 10, 2024
d9175c7
move
dantaik Sep 10, 2024
f544063
more
dantaik Sep 10, 2024
67531f1
more
dantaik Sep 10, 2024
845d809
more
dantaik Sep 10, 2024
20b1193
more
dantaik Sep 10, 2024
9b1d648
more
dantaik Sep 10, 2024
c64f708
more
dantaik Sep 10, 2024
852362b
more
dantaik Sep 10, 2024
ffa8a88
Update pnpm-lock.yaml
dantaik Sep 10, 2024
c10563c
Update pnpm-lock.yaml
dantaik Sep 10, 2024
fd2a3d1
more
dantaik Sep 10, 2024
9272edc
fix
dantaik Sep 10, 2024
b213cfd
Merge branch 'revert_solc_to_0.8.24' into restructure_code
dantaik Sep 10, 2024
460b41f
more
dantaik Sep 10, 2024
2728c85
more
dantaik Sep 10, 2024
58d7ea3
fix
dantaik Sep 10, 2024
1244d03
Create contract_layout.md
dantaik Sep 10, 2024
a1167e5
forge fmt & update contract layout tables
dantaik Sep 10, 2024
8caa812
Merge branch 'main' into restructure_code
dantaik Sep 10, 2024
8e1b04a
Merge branch 'main' into restructure_code
dantaik Sep 10, 2024
06c3e25
fix
dantaik Sep 10, 2024
6fcc1a8
fix
dantaik Sep 10, 2024
6841eba
forge fmt & update contract layout tables
dantaik Sep 10, 2024
6434345
Update package.json
dantaik Sep 10, 2024
66c0552
Update package.json
dantaik Sep 10, 2024
67da9d1
fix
dantaik Sep 10, 2024
f068adf
fix
dantaik Sep 10, 2024
ff9ade1
Update package.json
dantaik Sep 10, 2024
008c329
fix
dantaik Sep 10, 2024
3ace7c4
fix
dantaik Sep 10, 2024
f81f7e6
fix
dantaik Sep 10, 2024
ddfaba1
fix
dantaik Sep 10, 2024
4e76b7d
move
dantaik Sep 10, 2024
92bd360
duplicate layout file for later comparision
dantaik Sep 10, 2024
f704079
Merge branch 'duplicate_layouts' into restructure_code
dantaik Sep 10, 2024
36fe564
fix
dantaik Sep 10, 2024
2e51ff9
chore(protocol): use solc 0.8.27 (#18060)
dantaik Sep 10, 2024
6900ffa
re-generate layout files with diff order
dantaik Sep 10, 2024
0ff3be9
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
7a4a727
forge fmt & update contract layout table
dantaik Sep 10, 2024
706bc28
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
2c978d1
lint
dantaik Sep 10, 2024
5adf10e
Update gen-layouts.sh
dantaik Sep 10, 2024
0389bf2
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
2941a2c
fix
dantaik Sep 10, 2024
0d04352
fix
dantaik Sep 10, 2024
e5440a2
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
9783d41
Update gen-layouts.sh
dantaik Sep 10, 2024
9999eee
Update gen-layouts.sh
dantaik Sep 10, 2024
7790fe4
Update gen-layouts.sh
dantaik Sep 10, 2024
ed9b908
forge fmt & update contract layout table
dantaik Sep 10, 2024
858d40d
Update gen-layouts.sh
dantaik Sep 10, 2024
c5950e2
Update contract_layout_layer1.md
dantaik Sep 10, 2024
2ffb763
a
dantaik Sep 10, 2024
5ade82f
forge fmt & update contract layout table
dantaik Sep 10, 2024
45a9277
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
1195ec4
Merge branch 'layout_gen' into restructure_code
dantaik Sep 10, 2024
a148203
forge fmt & update contract layout tables
dantaik Sep 10, 2024
39f2b9e
Update .solhint.json
dantaik Sep 11, 2024
b06dd56
Update package.json
dantaik Sep 11, 2024
aa2dca4
Merge branch 'main' into restructure_code
dantaik Sep 11, 2024
8d9b054
docs(protocol): improve readme (#18068)
dantaik Sep 11, 2024
a6e739c
forge fmt & update contract layout tables
dantaik Sep 11, 2024
e6728c0
Update .gitignore
davidtaikocha Sep 11, 2024
f9d423a
Update .gitignore
davidtaikocha Sep 11, 2024
994d4a3
feat: add back genesis_config.json
davidtaikocha Sep 11, 2024
cf93e9b
fix: fix genesis tests
davidtaikocha Sep 11, 2024
9823cfa
fix: fix deploy l1 tests
davidtaikocha Sep 11, 2024
a736b13
fix
dantaik Sep 11, 2024
71d98c3
Update deploy_l1_contract.sh
dantaik Sep 11, 2024
c3ddb15
move
dantaik Sep 11, 2024
2361257
fix
dantaik Sep 11, 2024
5d93917
fix
dantaik Sep 11, 2024
dbf5ef9
Update packages/taiko-client/integration_test/deploy_l1_contract.sh
dantaik Sep 11, 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
16 changes: 4 additions & 12 deletions .github/workflows/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,16 @@ jobs:

- name: Unit tests
working-directory: ./packages/protocol
run: pnpm clean && pnpm test

- name: Format solidity && update contract layout table
working-directory: ./packages/protocol
run: pnpm layout && forge fmt
run: pnpm clean && forge fmt && pnpm test:l1 && pnpm layout:l1 && pnpm test:l2 && pnpm layout:l2

- name: Commit contract layout table
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "forge fmt & update contract layout table"
commit_message: "forge fmt & update contract layout tables"

- name: Generate genesis
working-directory: ./packages/protocol
run: pnpm test:genesis

- name: Run snapshot (Foundry)
working-directory: ./packages/protocol
run: pnpm snapshot
run: pnpm genesis:test

- name: Deploy L1 contracts
working-directory: ./packages/protocol
Expand All @@ -60,4 +52,4 @@ jobs:
while ! nc -z localhost 8545; do
sleep 1
done
pnpm test:deploy
pnpm test:deploy:l1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ __pycache__/

# VSCode
.vscode/launch.json
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
packages/protocol/config.js
.vercel

# Idea
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"packages/fork-diff": "0.6.0",
"packages/guardian-prover-health-check": "0.1.0",
"packages/guardian-prover-health-check-ui": "0.2.0",
"packages/protocol": "1.9.0",
"packages/protocol": "1.8.0",
"packages/relayer": "0.12.0",
"packages/snaefell-ui": "1.1.0",
"packages/supplementary-contracts": "1.0.0",
Expand Down
4 changes: 1 addition & 3 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ extend-exclude = [
"go.mod",
"CHANGELOG.md",
"packages/protocol/audit/code4rena-2024-03-taiko-final-report.md",
"packages/protocol/contracts/automata-attestation/**",
"packages/protocol/contracts/thirdparty/**",
"packages/protocol/contracts/compiled/**",
"packages/protocol/contracts/layer1/automata-attestation/**",
"packages/protocol/deployments/**",
# TODO: fix typos and remove these
"packages/taiko-client/**",
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ artifacts
cache
coverage
lib
contracts/test/thirdparty/
contracts/automata-attestation/
test/shared/thirdparty/
contracts/layer1/automata-attestation/
monitors/
1 change: 1 addition & 0 deletions packages/protocol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ yarn-error.log*
package-lock.json
npm-debug.log*
typechain-types
test/genesis/generate/data

# Hardhat files
cache
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rules": {
"avoid-low-level-calls": "off",
"avoid-tx-origin": "off",
"compiler-version": ["error", "0.8.27"],
"compiler-version": ["error", "^0.8.24"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
Expand Down
8 changes: 2 additions & 6 deletions packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
node_modules/
lib/
contracts/test/TestLibRLPReader.sol
**/contracts/thirdparty/**/*.sol
/contracts/automata-attestation/
test/thirdparty/
test/GasComparison.t.sol
test/TestLn.sol
contracts/layer1/automata-attestation/
test/shared/thirdparty/
115 changes: 0 additions & 115 deletions packages/protocol/CHANGELOG.md

Large diffs are not rendered by default.

162 changes: 84 additions & 78 deletions packages/protocol/README.md
Original file line number Diff line number Diff line change
@@ -1,139 +1,145 @@
# Taiko Protocol

This package contains rollup contracts on both L1 and L2, along with other assisting code. Taiko L2's chain ID is [167](https://github.com/ethereum-lists/chains/pull/1611).
This repository contains the Taiko Based Contestable Rollup (BCR) protocol and supporting tools. The project is managed using `pnpm` and `foundry`.

## Getting Started
## Prerequisites

Before compiling smart contracts, ensure all necessary dependencies are installed:
Before compiling the smart contracts, ensure the following are installed and up to date:

```sh
pnpm install
- [Foundry](https://book.getfoundry.sh/)
- [pnpm](https://pnpm.io/)

To install dependencies:

```bash
foundryup && pnpm install
```

Then, compile the smart contracts:
## Compilation and Testing

```sh
pnpm compile
Taiko’s protocol is split between Layer 1 (L1) and Layer 2 (L2). The smart contracts need to be compiled and tested separately for each layer:

### Layer 1 (Ethereum, Duncan Hardfork)

To compile, run tests, and generate the storage layout for L1:

```bash
pnpm compile:l1
pnpm test:l1
pnpm layout:l1
```

If you run into `Error: Unknown version provided`, you should upgrade your foundry installation by running `curl -L https://foundry.paradigm.xyz | bash`.
### Layer 2 (Taiko, Shanghai Hardfork)

## Style Guide
Similarly, for L2:

```bash
pnpm compile:l2
pnpm test:l2
pnpm layout:l2
```

### Compile and Test for Both Layers

To compile and test contracts for both L1 and L2 at once:

```bash
pnpm compile
pnpm test
pnpm layout
```

Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for the source code style guidelines to adhere to.
## Layer 2 Genesis Block

## Generate L2 Genesis JSON's `alloc` Field
### Generating a Dummy Genesis Block

Create a `config.js` with the following structure:
To generate dummy data for the L2 genesis block, create a configuration file at `./test/genesis/data/genesis_config.js` with the following content:

```javascript
module.exports = {
// Owner address of the pre-deployed L2 contracts.
contractOwner: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39",
// Chain ID of the Taiko L2 network.
chainId: 167,
// Account address and pre-mint ETH amount as key-value pairs.
seedAccounts: [
{ "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39": 1024 },
{ "0x79fcdef22feed20eddacbb2587640e45491b757f": 1024 },
],
// Owner Chain ID, Security Council, and Timelock Controller
l1ChainId: 31337,
ownerSecurityCouncil: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39",
ownerTimelockController: "0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39",
// L2 EIP-1559 baseFee calculation related fields.
param1559: {
gasExcess: 1,
},
// Option to pre-deploy an ERC-20 token.
predeployERC20: true,
};
```

Then, execute the generation script:
Then compile the L2 contracts and generate the genesis block:

```sh
pnpm compile && pnpm generate:genesis config.js
```bash
pnpm compile:l2
pnpm genesis:gen
```

The script will output two JSON files under `./deployments`:

- `l2_genesis_alloc.json`: the `alloc` field which will be used in L2 genesis JSON file
- `l2_genesis_storage_layout.json`: the storage layout of those pre-deployed contracts

## Using Foundry
This generates the following JSON files in `./test/genesis/data/`:

This project also integrates with Foundry for building and testing contracts.
- `l2_genesis_alloc.json`: Contains the `alloc` field for the L2 genesis block. Use this in a `geth` or `taiko-geth` genesis block following [this guide](https://geth.ethereum.org/docs/fundamentals/private-network#creating-genesis-block).
- `l2_genesis_storage_layout.json`: Displays the storage layout of the pre-deployed contracts.

- To compile using foundry: `forge build` or `pnpm compile`
- To run foundry tests: `forge test --gas-report -vvv` or `pnpm test:foundry`
To validate the genesis data:

## Generating and Running the L2 Genesis Block

The generation of the L2 genesis block and obtaining its hash involves a series of steps, including constructing the genesis JSON, followed by the actual generation and retrieval of the genesis block hash. A test can be executed to comprehend this process.

### Testing Genesis Block Creation

To understand how the `genesis.json` is built from deployment files and how to generate the genesis block and its hash, you can use the `test:genesis` command. This test serves as a learning tool:

```sh
pnpm test:genesis
```bash
pnpm genesis:test
```

This test, defined in `./genesis/generate_genesis.test.sh`, compiles the contracts, generates the genesis JSON, and initiates a Geth node using Docker to simulate the deployment of the genesis block. Reviewing this script and its output can help you grasp the steps required to create and initiate a genesis block for the Taiko Protocol.

### Generating the Actual Genesis Block

After understanding the process from the test, proceed to generate the actual `genesis.json` and the genesis block:

1. **Build the Genesis JSON:** Use the information learned from the `test:genesis` to build the `genesis.json` file from the files in the `/deployments/` directory. The `generate_genesis.test.sh` script contains the necessary commands to create this file.

2. **Run Geth to Generate the Genesis Block:** You can use Geth to initialize and run a private network with the genesis block. You can start Geth with the following commands:
This runs tests using Docker and `taiko-geth` to simulate the L2 genesis block deployment, and generates a `genesis.json` file in `./test/genesis/data/`.

```sh
geth --datadir ~/taiko-l2-network/node init /deployments/genesis.json
geth --datadir ~/taiko-l2-network/node --networkid 167 --http --http.addr 127.0.0.1 --http.port 8552 --http.corsdomain "*"
```
### Generating an Actual Genesis Block

For details refer to the Geth documentation on [creating a genesis block](https://geth.ethereum.org/docs/fundamentals/private-network#creating-genesis-block).
To generate the actual L2 genesis block, create a `genesis.json` file based on `l2_genesis_alloc.json`, following [this guide](https://geth.ethereum.org/docs/fundamentals/private-network#creating-genesis-block).

3. **Retrieve the Genesis Block Hash:** Connect to the Geth node using the command:
Next, initialize `taiko-geth` with the generated `genesis.json`:

```sh
geth attach ~/taiko-l2-network/node/geth.ipc
```
```bash
geth --datadir ~/taiko-l2-network/node init test/layer2/genesis/data/genesis.json
geth --datadir ~/taiko-l2-network/node --networkid 167 --http --http.addr 127.0.0.1 --http.port 8552 --http.corsdomain "*"
```

In the Geth console, use `eth.getBlock(0)` to obtain the hash of the genesis block.
You can retrieve the genesis block hash by attaching to the `geth` instance:

4. **Update `test_deploy_on_l1.sh` File:** Update the `L2_GENESIS_HASH` variable in the `test_deploy_on_l1.sh` script with the obtained genesis block hash.
```bash
geth attach ~/taiko-l2-network/node/geth.ipc
```

By following these steps, you will successfully generate the L2 genesis block for the Taiko Protocol, retrieve its hash, and prepare for the L1 contract deployment.
Then run:

## Deploying the L1 Contracts
```bash
eth.getBlock(0)
```

To deploy L1 contracts for Taiko Protocol, you can use any Ethereum network. This guide illustrates the process using a Hardhat local network, but it's adaptable to others. The deployment relies on `script/test_deploy_on_l1.sh`, which targets a node at `http://localhost:8545` by default.
Copy the genesis block hash and replace the `L2_GENESIS_HASH` variable in `deploy_protocol_on_l1.sh` with this value.

Here’s how you can proceed:
### Deploying Taiko BCR on Layer 1

1. **Ensure Sufficient ETH:** Check that the address associated with the private key in `script/test_deploy_on_l1.sh` has enough ETH for deploying contracts on the Hardhat network.
To deploy Taiko BCR on L1, start a local L1 network:

2. **Update Contract Addresses:** After running the genesis block generation script (`pnpm test:genesis`), you will receive a list of pre-computed contract addresses. These addresses need to be added to the `test_deploy_on_l1.sh` file. Make sure to update this file with the correct contract addresses before proceeding with the deployment.
```bash
anvil --hardfork cancun
```

3. **Start a Local Development Network:** While this guide uses Hardhat as an example, you can use any Ethereum network. If you choose to use Hardhat, start a local Ethereum network for development and testing:
Make sure you have sufficient ether for transactions, then deploy the contracts:

```sh
pnpm hardhat node
```bash
pnpm test:deploy:l1
```

4. **Deploy Contracts Using Foundry:** Once your network is running, open a new terminal window and execute the deployment scripts using Foundry:
This command runs the deployment script located at `script/deploy_protocol_on_l1.sh`, assuming L1 is accessible at `http://localhost:8545`.

```sh
pnpm test:deploy
```
## Style Guide

This command will deploy the L1 contracts using the settings and addresses you’ve provided in the `test_deploy_on_l1.sh` script.
Refer to [CONTRIBUTING.md](https://www.notion.so/CONTRIBUTING.md) for code style guidelines.

## Running slither
Before committing code, format and lint it using:

1. Install the latest [slither](https://github.com/crytic/slither?tab=readme-ov-file#how-to-install).
2. From `protocol/`, execute `slither . --checklist > checklist.md` to re-generate the checklist.
```bash
pnpm fmt:sol
```
Loading