diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..589b20ef --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +DEPLOYER_PRIVATE_KEY="" + +LOCAL_RPC_URL="http://localhost:8545" +MAINNET_RPC_URL="https://mainnet.infura.io/ws/v3/" +GOERLI_RPC_URL="https://goerli.infura.io/ws/v3/" +SEPOLIA_RPC_URL="https://sepolia.infura.io/ws/v3/" + +# 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. diff --git a/README.md b/README.md index a3fc52a2..78d7ab73 100644 --- a/README.md +++ b/README.md @@ -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 `_RPC_URL` in the `.env` file (If using Infura this will require an API key) +3. Run + +```shell +just deploy-contracts +``` + +where `` is one of `["GOERLI", "SEPOLIA", "MAINNET"]`. diff --git a/contracts/.env.example b/contracts/.env.example deleted file mode 100644 index f4795498..00000000 --- a/contracts/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ANVIL_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 -MAINNET_RPC_URL= -GOERLI_RPC_URL= diff --git a/contracts/.gitignore b/contracts/.gitignore index 85198aaa..9d91b783 100644 --- a/contracts/.gitignore +++ b/contracts/.gitignore @@ -3,9 +3,7 @@ cache/ out/ # Ignores development broadcast logs -!/broadcast -/broadcast/*/31337/ -/broadcast/**/dry-run/ +broadcast/ # Docs docs/ diff --git a/contracts/foundry.toml b/contracts/foundry.toml index 817004ea..ac99a4c6 100644 --- a/contracts/foundry.toml +++ b/contracts/foundry.toml @@ -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}" diff --git a/contracts/script/DeploySpectre.s.sol b/contracts/script/DeploySpectre.s.sol new file mode 100644 index 00000000..191b4721 --- /dev/null +++ b/contracts/script/DeploySpectre.s.sol @@ -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(); + } +} diff --git a/contracts/script/SpectreDeployLocal.s.sol b/contracts/script/SpectreDeployLocal.s.sol deleted file mode 100644 index 91c64873..00000000 --- a/contracts/script/SpectreDeployLocal.s.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.19; - -import "forge-std/Script.sol"; -import "forge-std/safeconsole.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 SpectreDeployLocal is Script { - bytes proof; - address syncStepVerifierAddress; - - function run() external { - vm.startBroadcast(); - - new SyncStepVerifier(); - new CommitteeUpdateVerifier(); - - - vm.stopBroadcast(); - } -} diff --git a/contracts/script/deploy_local.sh b/contracts/script/deploy_local.sh deleted file mode 100755 index 58e2ed80..00000000 --- a/contracts/script/deploy_local.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -cd $(git rev-parse --show-toplevel) -source .env -LOCAL_RPC_URL="http://localhost:8545" - -forge script script/SpectreDeployLocal.s.sol:SpectreDeployLocal --private-key $ANVIL_PRIVATE_KEY --rpc-url $LOCAL_RPC_URL --broadcast -vvvv diff --git a/justfile b/justfile index 9ca27712..507879ab 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,6 @@ +set dotenv-load # automatically loads .env file in the current directory +set positional-arguments + test: cargo test --workspace @@ -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