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

Adds scripts and docs for deploying contracts #32

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DEPLOYER_PRIVATE_KEY="<private-key-here>"

LOCAL_RPC_URL="http://localhost:8545"
MAINNET_RPC_URL="https://mainnet.infura.io/ws/v3/<Your-API-Key>"
GOERLI_RPC_URL="https://goerli.infura.io/ws/v3/<Your-API-Key>"
SEPOLIA_RPC_URL="https://sepolia.infura.io/ws/v3/<Your-API-Key>"

# These two variables define the starting point for the Spectre light-client.
INITIAL_SYNC_PERIOD=10 # sync period for the initial committee
INITIAL_COMMITTEE_POSEIDON="0x9ab5d3df6912b5bfeeb8e33b5bddad7c3a4f448fd99804dae38c3641f55680fe" # hex encoded poseidon hash of the initial committee

# This is a fixed property of the chain that Spectre is acting as a light-client for
SLOTS_PER_PERIOD=8192 # 8192 = 256 epochs * 32 slots for mainnet ethereum.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# Spectre
Spectre is a ZK-based block header oracle protocol based on Altair fork light-client sync protocol.

## Deploying contracts

Just scripts are provided to deploy the contracts either to a local testnet, or public networks.

For either make a copy of the `.env.example` file called `.env`. Set the `INITIAL_SYNC_PERIOD`, `INITIAL_COMMITTEE_POSEIDON` and `SLOTS_PER_PERIOD` variables according to the network you want Spectre to act as a light-client for and the starting point.

### Deploying locally

1. Start a local anvil instance with:

```shell
anvil
```

2. Copy one of the private key strings printed into the `DEPLOYER_PRIVATE_KEY` in the `.env` file then run

```shell
just deploy-contracts-local
```

### Deploying to a public network

1. Obtain the required gas token and obtain the private key for the deployer account. Set the `DEPLOYER_PRIVATE_KEY` in the `.env` file.
2. Obtain a public RPC URL for the network and set the variable `<NETWORK>_RPC_URL` in the `.env` file (If using Infura this will require an API key)
3. Run

```shell
just deploy-contracts <NETWORK>
```

where `<NETWORK>` is one of `["GOERLI", "SEPOLIA", "MAINNET"]`.
4 changes: 0 additions & 4 deletions contracts/.env.example

This file was deleted.

4 changes: 1 addition & 3 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
broadcast/

# Docs
docs/
Expand Down
5 changes: 3 additions & 2 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fs_permissions = [{ access = "read", path = "./test/data/"}]
constantOptimizer = true
yul = false

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
goerli = "${GOERLI_RPC_URL}"
sepolia = "${SEPOLIA_RPC_URL}"
local = "${LOCAL_RPC_URL}"
27 changes: 27 additions & 0 deletions contracts/script/DeploySpectre.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Script.sol";

import {Spectre} from "../src/Spectre.sol";
import {Verifier as SyncStepVerifier} from "../snark-verifiers/sync_step.sol";
import {Verifier as CommitteeUpdateVerifier} from "../snark-verifiers/committee_update_aggregated.sol";

contract DeploySpectre is Script {

function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
uint256 initialSyncPeriod = vm.envUint("INITIAL_SYNC_PERIOD");
bytes32 initialCommitteePoseidon = vm.envBytes32("INITIAL_COMMITTEE_POSEIDON");
uint256 slotsPerPeriod = vm.envUint("SLOTS_PER_PERIOD");

vm.startBroadcast(deployerPrivateKey);

SyncStepVerifier stepVerifier = new SyncStepVerifier();
CommitteeUpdateVerifier updateVerifier = new CommitteeUpdateVerifier();

Spectre spectre = new Spectre(address(stepVerifier), address(updateVerifier), initialSyncPeriod, initialCommitteePoseidon, slotsPerPeriod);

vm.stopBroadcast();
}
}
23 changes: 0 additions & 23 deletions contracts/script/SpectreDeployLocal.s.sol

This file was deleted.

6 changes: 0 additions & 6 deletions contracts/script/deploy_local.sh

This file was deleted.

11 changes: 11 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
set dotenv-load # automatically loads .env file in the current directory
set positional-arguments

test:
cargo test --workspace

Expand Down Expand Up @@ -28,6 +31,14 @@ gen-rotation-evm-verifier:
build-contracts:
cd contracts && forge build

deploy-contracts-local:
cd contracts && forge script ./script/DeploySpectre.s.sol:DeploySpectre --fork-url $LOCAL_RPC_URL --broadcast

deploy-contracts network: # network one of [MAINNET, GOERLI, SEPOLIA]
#! /usr/bin/env bash
RPC_URL="$1_RPC_URL"
cd contracts && forge script ./script/DeploySpectre.s.sol:DeploySpectre --rpc-url ${!RPC_URL} --broadcast --verify -vvvv

# downloads spec tests and copies them to the right locations.
download-spec-tests: clean-spec-tests
#!/usr/bin/env bash
Expand Down
Loading