Skip to content

Commit

Permalink
feat: cleanup + docs (succinctlabs#17)
Browse files Browse the repository at this point in the history
* feat: mega cleanup

* add

* add

* add

* add

* Add

* clean

* add
  • Loading branch information
ratankaliani authored Dec 21, 2024
1 parent d7133af commit dbddea9
Show file tree
Hide file tree
Showing 20 changed files with 406 additions and 166 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/book.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Documentation and mdbook related jobs.
# Reference: https://github.com/paradigmxyz/reth/blob/main/.github/workflows/book.yml

name: book

on:
push:
branches: [main]
pull_request:
branches: [main]
paths:
- "book/**"
merge_group:

jobs:
lint:
runs-on: ubuntu-latest
name: lint
timeout-minutes: 60

steps:
- uses: actions/checkout@v4

- name: Install mdbook-linkcheck
run: |
mkdir mdbook-linkcheck
curl -sSL -o mdbook-linkcheck.zip https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip
unzip mdbook-linkcheck.zip -d ./mdbook-linkcheck
chmod +x $(pwd)/mdbook-linkcheck/mdbook-linkcheck
echo $(pwd)/mdbook-linkcheck >> $GITHUB_PATH
- name: Run linkcheck
run: mdbook-linkcheck --standalone

build:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: Install mdbook
run: |
mkdir mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo $(pwd)/mdbook >> $GITHUB_PATH
- name: Install mdbook-template
run: |
mkdir mdbook-template
curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template
echo $(pwd)/mdbook-template >> $GITHUB_PATH
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Build book
run: mdbook build

- name: Archive artifact
shell: sh
run: |
chmod -c -R +rX "target/book" |
while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
tar \
--dereference --hard-dereference \
--directory "target/book" \
-cvf "$RUNNER_TEMP/artifact.tar" \
--exclude=.git \
--exclude=.github \
.
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: github-pages
path: ${{ runner.temp }}/artifact.tar
retention-days: 1
if-no-files-found: error

deploy:
# Only deploy if a push to main
if: github.ref_name == 'main' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: [lint, build]

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

timeout-minutes: 60

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
53 changes: 53 additions & 0 deletions .github/workflows/foundry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
pull_request:
branches:
- "**"
push:
branches:
- main
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Show Forge version
working-directory: contracts/
run: |
forge --version
- name: Run Forge fmt
working-directory: contracts/
run: |
forge fmt --check src/ test/ script/
id: fmt

- name: Run Forge build
working-directory: contracts/
run: |
forge build --sizes
id: build

# - name: Run Forge tests
# working-directory: contracts/
# run: |
# forge test -vvv
# id: test
128 changes: 1 addition & 127 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,130 +4,4 @@

SP1 Helios verifies the consensus of a source chain in the execution environment of a destination chain. For example, you can run an SP1 Helios light client on Polygon that verifies Ethereum Mainnet's consensus.

## Deployment Instructions

### Prerequisites

- [Foundry](https://book.getfoundry.sh/getting-started/installation)
- [SP1](https://docs.succinct.xyz/getting-started/install.html)

### 1) Consensus RPC Setup

To run SP1 Helios, you need a Beacon Chain node for your source chain. For example, to run an Ethereum mainnet light client, you need an Ethereum mainnet beacon node.

The beacon chain node must support the RPC methods for the [Altair light client protocol](https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md). As of 10/15/24, Nimbus is the only consensus client that supports these "light sync" endpoints by default.

There are a few options for setting up a consensus RPC with "light sync" endpoints:

1. Get an RPC from a provider running Nimbus nodes. [Chainstack](https://chainstack.com/) is currently the only provider we're aware of that supports this. Set up a node on Chainstack and use the consensus client endpoint for an Ethereum mainnet node.
2. Run a Nimbus eth2 beacon node. Instructions [here](https://nimbus.guide/el-light-client.html).
3. There is a community-maintained list of Ethereum Beacon Chain light sync endpoints [here](https://s1na.github.io/light-sync-endpoints). These endpoints are not guaranteed to work, and are often unreliable.

The RPC you just set up will be used as the `SOURCE_CONSENSUS_RPC_URL` in the next step.

### 2) Environment Setup

In the root directory, create a file called `.env` (mirroring `.env.example`) and set the following environment variables:

| Parameter | Description |
|-----------|-------------|
| `SOURCE_CHAIN_ID` | Chain ID for the source chain. |
| `SOURCE_CONSENSUS_RPC_URL` | RPC URL for the source chain. See how to get this in the [Consensus RPC Setup](#1-consensus-rpc-setup) section |
| `DEST_RPC_URL` | RPC URL for the destination chain (where the light client contract will be deployed). |
| `DEST_CHAIN_ID` | Chain ID for the destination chain (where the light client contract will be deployed). |
| `PRIVATE_KEY` | Private key for the account that will be deploying the contract. |
| `SP1_PROVER` | Default: `mock`. `network` will generate real proofs using the Succinct Prover Network. |
| `ETHERSCAN_API_KEY` | API key for Etherscan verification. |

#### Optional Parameters

| Parameter | Description |
|-----------|-------------|
| `GUARDIAN_ADDRESS` | Defines the owner for the light client. Defaults to the account owner of `PRIVATE_KEY`. |
| `SP1_PRIVATE_KEY` | Required in `network` mode. The private key of the account that will be requesting proofs from the Succinct Prover Network. Get access [here](https://docs.succinct.xyz/generating-proofs/prover-network). |
| `SP1_VERIFIER_ADDRESS` | Required in `network` mode. The address of the verifier contract. You can find the deployed verifiers [here](https://docs.succinct.xyz/onchain-verification/contract-addresses.html). |
| `LOOP_DELAY_MINS` | The delay between each loop of the operator in minutes. Defaults to `5`. |

### 3) Deploy Contract

Deploy the SP1 Helios contract.

```bash
# Load environment variables
source .env

cd contracts

# Install dependencies
forge install

# Deploy contract. The forge script determines the initial genesis state based on your .env
forge script script/Deploy.s.sol --ffi --rpc-url $DEST_RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY --broadcast --verify
```

When the script completes, take note of the light client contract address printed by the script. In the example logs below, it's `0x5026D3675af919f1AeE2ceD1F0a9F4903dDB1bAA`.

```shell
ratankaliani@Ratan-Mac-Pro-Succinct contracts % forge script script/Deploy.s.sol --rpc-url $DEST_RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY --broadcast --verify --ffi

[⠊] Compiling...
[⠃] Compiling 1 files with Solc 0.8.26
[⠊] Solc 0.8.26 finished in 807.42ms
...

== Return ==
0: address 0x5026D3675af919f1AeE2ceD1F0a9F4903dDB1bAA

...
```

Add the contract address to the `.env` file in your root directory.

| Parameter | Description |
|-----------|-------------|
| `CONTRACT_ADDRESS` | Address of the light client contract deployed |


**Note:** if you see the error, check that your account has sufficient funds or check that the private key is valid.

### 4) Run Light Client

You should now have the following environment variables set in the `.env` file in your root directory.

| Parameter | Description |
|-----------|-------------|
| `SOURCE_CHAIN_ID` | Chain ID for the source chain. |
| `SOURCE_CONSENSUS_RPC_URL` | RPC URL for the source chain. See how to get this in the [Consensus RPC Setup](#1-consensus-rpc-setup) section |
| `DEST_RPC_URL` | RPC URL for the destination chain (where the light client contract will be deployed). |
| `DEST_CHAIN_ID` | Chain ID for the destination chain (where the light client contract will be deployed). |
| `PRIVATE_KEY` | Private key for the account that will be deploying the contract. |
| `GUARDIAN_ADDRESS` | Optional. Defines the owner for the light client. Defaults to the account owner of `PRIVATE_KEY`. |
| `SP1_PROVER` | Default: `mock`. `network` will generate real proofs using the Succinct Prover Network. |
| `ETHERSCAN_API_KEY` | API key for Etherscan verification. |
| `CONTRACT_ADDRESS` | Address of the light client contract deployed in the previous stage. |

-----

To run the operator, which generates proofs and keeps the light client updated with chain state, run the following command.

Note: When `SP1_PROVER=mock`, the operator will not generate real proofs.

```bash
RUST_LOG=info cargo run --release --bin operator
```

If successful, you should see logs indicating that the consensus state is being updated.

```shell
[2024-10-15T21:01:19Z INFO operator] Starting SP1 Helios operator
[2024-10-15T21:01:20Z WARN helios::consensus] checkpoint too old, consider using a more recent block
[2024-10-15T21:01:20Z INFO operator] Contract is up to date. Nothing to update.
[2024-10-15T21:01:20Z INFO operator] Sleeping for 5 minutes
...
...
[2024-10-15T21:06:35Z INFO operator] New head: 6107648
[2024-10-15T21:06:50Z INFO operator] Transaction hash: 0x4a0dfa2922704295ed59bf16840454858a4d17225cdf613387de7605b5a41520
[2024-10-15T21:06:50Z INFO operator] Sleeping for 5 minutes
```

Congratulations 🎉, you're successfully running an SP1 Helios light client!
[Docs](https://succinctlabs.github.io/sp1-helios/)
17 changes: 17 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[book]
authors = ["Ratan Kaliani"]
language = "en"
multilingual = false
src = "book"
title = "SP1 Helios"
description = "A book on all things SP1 Helios"

[build]
build-dir = "target/book"

[preprocessor.template]
before = ["links"]

[preprocessor.index]

[preprocessor.links]
7 changes: 7 additions & 0 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Summary

- [Introduction](./introduction.md)
- [Deployment](./deployment.md)
- [Components](./components.md)
- [FAQ](./faq.md)
- [Reproducible Builds](./reproducible-builds.md)
10 changes: 10 additions & 0 deletions book/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Components

An SP1 Helios implementation has a few key components:
- An `SP1Helios` contract. Contains the logic for verifying SP1 Helios proofs, storing the latest data from the Ethereum beacon chain, including the headers, execution state roots and sync committees.
- An `SP1Verifier` contract. Verifies arbitrary SP1 programs. Most chains will have canonical deployments
upon SP1's mainnet launch. Until then, users can deploy their own `SP1Verifier` contracts to verify
SP1 programs on their chain. The SP1 Helios implementation will use the `SP1Verifier` contract to verify
the proofs of the SP1 Helios program.
- The SP1 Helios program. An SP1 program that verifies the consensus of a source chain in the execution environment of a destination chain using the `helios` library.
- The operator. A Rust script that fetches the latest data from a deployed `SP1Helios` contract and an Ethereum beacon chain, determines the block to request, requests for/generates a proof, and relays the proof to the `SP1Helios` contract.
Loading

0 comments on commit dbddea9

Please sign in to comment.