-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(protocol): restructure solidity code to match compilation ta…
…rgets (#18059) Co-authored-by: dantaik <dantaik@users.noreply.github.com> Co-authored-by: gavin <gavin@taiko.xyz> Co-authored-by: David <david@taiko.xyz>
- Loading branch information
1 parent
078d336
commit adc47f4
Showing
266 changed files
with
1,230 additions
and
1,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,6 @@ __pycache__/ | |
|
||
# VSCode | ||
.vscode/launch.json | ||
packages/protocol/config.js | ||
.vercel | ||
|
||
# Idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Oops, something went wrong.