Skip to content

Commit

Permalink
Merge pull request #1323 from celestiaorg/jcs/arbitrum
Browse files Browse the repository at this point in the history
feat: add initial arbitrum docs
  • Loading branch information
Ferret-san authored Dec 18, 2023
2 parents 2a815b6 + c39800d commit 07d96f5
Show file tree
Hide file tree
Showing 9 changed files with 700 additions and 87 deletions.
22 changes: 22 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,28 @@ function sidebarHome() {
text: "Ethereum fallback mechanism",
link: "/developers/ethereum-fallback",
},
{
text: "Arbitrum",
collapsed: true,
items: [
{
text: "Introduction to Arbitrum rollups with Celestia as DA",
link: "/developers/arbitrum-integration",
},
{
text: "Deploy an Arbitrum rollup devnet",
link: "/developers/arbitrum-deploy",
},
{
text: "Deploy a smart contract on Arbitrum rollup",
link: "/developers/arbitrum-smart-contract",
},
{
text: "Deploy a dapp on your Arbitrum rollup devnet",
link: "/developers/arbitrum-dapp-deploy",
},
],
},
{
text: "Optimism",
collapsed: true,
Expand Down
115 changes: 115 additions & 0 deletions developers/arbitrum-dapp-deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
description: Make your own GM Portal dapp on your Arbitrum rollup.
---

# Deploy a dapp on your Arbitrum rollup devnet

First, review the [Arbitrum integration](./arbitrum-integration.md),
[Deploy an Arbitrum rollup devnet](./arbitrum-deploy.md), and
[Deploy a smart contract to your Arbitrum rollup](./arbitrum-smart-contract.md)
pages.

## Dependencies

- a funded account to deploy your smart contract
- an [Arbitrum rollup devnet](./arbitrum-deploy.md) running

## Setup and contract deployment

1. Clone the `gm-portal` from Github and start the frontend:

```bash
cd $HOME
git clone https://github.com/jcstein/gm-portal.git
cd gm-portal && git checkout arbitrum
cd frontend && yarn && yarn dev
```

2. In a new terminal instance, set your private key for the
faucet as a variable and the RPC URL you're using:
```bash
export PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
export ARB_RPC_URL=http://localhost:8547
```
3. Change into the `gm-portal/contracts` directory in the same terminal and deploy
the contract using Foundry:
<!-- markdownlint-disable MD013 -->
```bash
cd $HOME/gm-portal/contracts
forge script script/GmPortal.s.sol:GmPortalScript --rpc-url $ARB_RPC_URL --private-key $PRIVATE_KEY --broadcast
```
<!-- markdownlint-enable MD013 -->
4. In the output of the deployment, find the contract address and set it as a variable:
```bash
export CONTRACT_ADDRESS=<your-contract-address-from-the-output-above>
```
### Interact with the contract
Next, you're ready to interact with the contract from your terminal!

1. Send a "gm" to the contract:

```bash
cast send $CONTRACT_ADDRESS \
"gm(string)" "gm" \
--private-key $PRIVATE_KEY \
--rpc-url $ARB_RPC_URL
```

2. Now that you've posted to the contract, you can read all "gms" (GMs) from the
contract with
this command:
```bash
cast call $CONTRACT_ADDRESS "getAllGms()" --rpc-url $ARB_RPC_URL
```
3. Next, query the total number of gms, which will be returned as a hex value:
```bash
cast call $CONTRACT_ADDRESS "getTotalGms()" --rpc-url $ARB_RPC_URL
```
4. (Optional) In order to interact with the contract on the frontend, you'll
need to fund an account that you have in your Ethereum wallet. Transfer to an
external account with this command:

```bash
export RECEIVER=<receiver ETH address>
cast send --private-key $PRIVATE_KEY $RECEIVER --value 1ether --rpc-url $ARB_RPC_URL
```

:::tip
If you are in a different terminal than the one you set the
private key in, you may need to set it again.
:::

## Update the frontend

Next, you will need to update a few things before you can interact with the
contract on the frontend:

1. Change the contract address on `gm-portal/frontend/src/App.tsx` to your
contract address
2. Match the chain info on `gm-portal/frontend/src/main.tsx` with the chain
config of your L2
3. If you changed the contract, update the ABI in
`gm-portal/frontend/GmPortal.json` from
`gm-portal/contracts/out/GmPortal.sol/GmPortal.json`. This can be done with:

```bash
cd $HOME
cp dev/gm-portal/contracts/out/GmPortal.sol/GmPortal.json dev/gm-portal/frontend
```

## Interact with the frontend

Now, login with your wallet that you funded, and post a GM on your GM portal!

![gm-arb](/img/gm-arb.png)
106 changes: 106 additions & 0 deletions developers/arbitrum-deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
description: A guide on how to install Arbitrum Nitro and deploy an instance on an Ubuntu AMD machine, including the installation of necessary dependencies, cloning the repository, and installing Nitro from source.
---

# Deploy an Arbitrum rollup devnet

We will go over installation of Arbitrum Nitro and deploying an instance on an
Ubuntu AMD machine. This section covers all necessary dependencies needed to be
installed.

## Dependencies

- [Docker](https://docs.docker.com/engine/install/ubuntu/)
running on your machine
- [Docker Compose](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04)
- At least 8 GB RAM

### General

<!-- markdownlint-disable MD013 -->

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install curl tar wget clang pkg-config libssl-dev cmake jq build-essential git make ncdu -y
```

### Rust

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
```

### Golang

```bash
ver="1.20"
cd $HOME
wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz"
rm "go$ver.linux-amd64.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile
source $HOME/.bash_profile
go version
```

### Node

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install 16.20.0
nvm use 16.20.0
node --version
npm install --global yarn
yarn --version
```

<!-- markdownlint-enable MD013 -->

### Other Dependencies

```bash
cargo install --force cbindgen
rustup target add wasm32-unknown-unknown
```

## Clone the repository

<!-- TODO: change git checkout to celestia-development or release. It is locked
to this version so that the tutorial works for anyone using it ATM. -->

```bash
git clone https://github.com/celestiaorg/nitro.git && cd nitro/
git fetch --all
git checkout c6f5ac2
git submodule update --init
git submodule update --init --recursive
```

## Installing Nitro from Source

Now you can install Nitro from source. After the `make` command completes,
you can run the bash script that installs and runs the containers via
docker-compose.

```bash
make build-node-deps
cd nitro-testnode && ./test-node.bash --init --dev
```

Congratulations! You have an Arbitrum Orbit rollup running with Nitro on
your machine.

### Validating with WASM

If you want to run a validator that will validate all blocks in WASM,
add the flag `--validate` to nitro-testnode when starting with
`./test-node.bash --init --dev --validate`.

## Next steps

In the next page we will cover
[deploying a smart contract to your rollup](./arbitrum-smart-contract.md).
112 changes: 112 additions & 0 deletions developers/arbitrum-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
description: An overview of the integration of Arbitrum Orbit and Nitro with Celestia, detailing the key features and benefits, including the Ethereum fallback mechanism.
---

# Introduction to Arbitrum rollups with Celestia as DA

![Celestia_Arbitrum](/img/Celestia_Arbitrum.jpeg)

## Overview

The
[integration of Celestia with Arbitrum Orbit](https://blog.celestia.org/celestia-is-first-modular-data-availability-network-to-integrate-with-arbitrum-orbit/)
and the Nitro tech stack marks the first external contribution to the Arbitrum
Orbit protocol layer, offering developers an additional option for selecting
a data availability layer alongside Arbitrum AnyTrust. The integration allows
developers to deploy an Arbitrum Rollup that uses Celestia for data
availability and settles on Ethereum.

[Arbitrum Orbit](https://docs.arbitrum.io/launch-orbit-chain/orbit-gentle-introduction)
is a framework that enables the creation of customized, self-managed
Arbitrum Rollup and AnyTrust chains. Key highlights of Arbitrum Orbit
include:

1. **Creation of custom chains**: Orbit allows the creation of dedicated chains
that settle to Arbitrum's Layer 2 chains (Arbitrum One, Nova, Goerli, Sepolia),
with customizable features like throughput, privacy, gas token, and governance.
2. **Solving Ethereum's scalability**: Orbit addresses Ethereum's congestion
and high demand for block space by enabling the creation of personal rollups,
which offer scalable, secure alternatives to Ethereum's public chains.
3. **Decentralized application development**: Orbit chains provide dedicated
throughput, EVM+ compatibility, independent roadmaps, and reliable gas prices
enhancing the development and operation of decentralized apps.
4. **Benefits to the Ethereum ecosystem**: Orbit contributes to a multi-chain
future for Ethereum, enhancing scalability, offering flexible security models,
and enabling experimentation with execution environments and governance models.
5. **Versatility and interoperability**: Orbit chains can be used for a range
of purposes, from hosting a single dApp to an ecosystem of dApps, with the
capability to communicate with other Orbit chains.

### Blobstream

:::warning DRAFT
The Blobstream section is a draft, the integration with Blobstream
is a work in progress.
:::

The Celestia and Arbitrum integration also
[includes Blobstream](./blobstream.md),
which relays commitments to Celestia’s data root to an onchain light client
on Ethereum. This allows L2 solutions that settle on Ethereum to benefit
from the scalability Celestia’s data availability layer can provide.

As part of this integration, Blobstream has been incorporated into the
Arbitrum `SequencerInbox.sol` contract.

In the `SequencerInbox.sol` contract, the `validateBatchData`
modifier has been designed to authenticate that the data root is
on Celestia when reading a batch of data. This is achieved by the
[following code by @Ferret-san](https://gist.github.com/Ferret-san/3d3fc1b5738ee8d77ad112c0eb8bbe5f):

Note that the data above is the bytes serialized version of this struct in Go:

```go
type BlobPointer struct {
BlockHeight uint64
Start uint64
SharesLength uint64
Key uint64
NumLeaves uint64
TupleRootNonce uint64
TxCommitment [32]byte
DataRoot [32]byte
SideNodes [][32]byte
}
```

### Ethereum fallback mechanism in Nitro

Another feature of this integration is the
[Ethereum fallback mechanism](./ethereum-fallback.md),
which enables Ethereum L2s (or L3s) to “fall back” to using Ethereum
calldata for data availability in the event of downtime on Celestia Mainnet
Beta.

In the case of Celestia downtime or temporary unavailability, L2s can
fallback to posting transactions as calldata on Ethereum or another DA
layer for data availability instead of posting to Celestia. This mechanism
ensures users can continue to transact securely and seamlessly, preventing
disruptions and helping to ensure user funds do not get stuck in the L2's
bridge on Ethereum. This feature is available for the
[Arbitrum Orbit integration](./ethereum-fallback.md#arbitrum).

By default in [Arbitrum Nitro](https://github.com/OffchainLabs/nitro), the
[Ethereum fallback mechanism in the `BatchPoster` function](https://github.com/OffchainLabs/nitro/blob/master/arbnode/batch_poster.go#L989-L1001)
is handling the process of storing data, with a fallback mechanism
to store data onchain if the primary data availability storage
fails.

The [@celestiaorg/nitro](https://github.com/celestiaorg/nitro) integration
[uses the same fallback mechanism](https://github.com/celestiaorg/nitro/blob/f01968eb3d4e19329e9c92b050e98a8e5772f1f2/arbnode/batch_poster.go#L845-L857).

The fallback logic for Celestia DA is configurable, providing an alternative
to the previous default fallback mechanism. Additionally, a method has been
added to the Arbitrum node software. This method allows the sequencer to call
`VerifyAttestation` to check if a data root has been posted on Blobstream or
not, before it sends the sequencer message (data pointer) to the underlying
chain.

## Next steps

In the next page,
[learn how to deploy an Arbitrum rollup devnet using Celestia as DA](./arbitrum-deploy.md).
Loading

0 comments on commit 07d96f5

Please sign in to comment.