Skip to content

Commit

Permalink
feat: add ephemery network (#6054)
Browse files Browse the repository at this point in the history
* add: initial ephemery config based on pk910's work in progress

* fix: add missing new line

* fix: rm unused disable es-lint directive

* fix: rename ephemeryBaseChainConfig to baseChainConfig

* fix: update comment to reflect 7 day reset period

* fix: reset period in MS, latest spec linked (EIP), dev comments updated

* fix: config fixes, add ref to config.yaml

* add: case ephemery added in packages/prover
  • Loading branch information
atkinsonholly authored Oct 26, 2023
1 parent d130ccd commit cf13ce9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/cli/src/networks/ephemery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {ephemeryChainConfig as chainConfig} from "@lodestar/config/networks";

export const depositContractDeployBlock = 0;
export const genesisFileUrl = "https://ephemery.dev/latest/genesis.ssz";
export const bootnodesFileUrl = "https://ephemery.dev/latest/bootstrap_nodes.txt";

// Pick from above file
export const bootEnrs = [];
17 changes: 15 additions & 2 deletions packages/cli/src/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ import * as ropsten from "./ropsten.js";
import * as sepolia from "./sepolia.js";
import * as holesky from "./holesky.js";
import * as chiado from "./chiado.js";

export type NetworkName = "mainnet" | "dev" | "gnosis" | "goerli" | "ropsten" | "sepolia" | "holesky" | "chiado";
import * as ephemery from "./ephemery.js";

export type NetworkName =
| "mainnet"
| "dev"
| "gnosis"
| "goerli"
| "ropsten"
| "sepolia"
| "holesky"
| "chiado"
| "ephemery";
export const networkNames: NetworkName[] = [
"mainnet",
"gnosis",
Expand All @@ -28,6 +38,7 @@ export const networkNames: NetworkName[] = [
"sepolia",
"holesky",
"chiado",
"ephemery",

// Leave always as last network. The order matters for the --help printout
"dev",
Expand Down Expand Up @@ -69,6 +80,8 @@ export function getNetworkData(network: NetworkName): {
return holesky;
case "chiado":
return chiado;
case "ephemery":
return ephemery;
default:
throw Error(`Network not supported: ${network}`);
}
Expand Down
61 changes: 61 additions & 0 deletions packages/config/src/chainConfig/networks/ephemery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";

// Ephemery dynamic beacon chain config:
// https://github.com/ephemery-testnet/ephemery-genesis/blob/master/cl-config.yaml

// Ephemery specification:
// https://github.com/taxmeifyoucan/EIPs/blob/d298cdd8eaf47a21e7770e5c6efef870587c924d/EIPS/eip-6916.md

// iteration 0, "base"-genesis
const baseChainConfig: ChainConfig = {
...mainnet,

CONFIG_NAME: "ephemery",

// Genesis
// ---------------------------------------------------------------
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 64,
// Thu Dec 02 2021 19:00:00 GMT+0000
MIN_GENESIS_TIME: 1638471600,
GENESIS_FORK_VERSION: b("0x1000101b"),
GENESIS_DELAY: 300,

// Forking
// ---------------------------------------------------------------
// Altair
ALTAIR_FORK_VERSION: b("0x2000101b"),
ALTAIR_FORK_EPOCH: 0,
// Merge
BELLATRIX_FORK_VERSION: b("0x3000101b"),
BELLATRIX_FORK_EPOCH: 0,
TERMINAL_TOTAL_DIFFICULTY: BigInt("0"),
// Capella
CAPELLA_FORK_VERSION: b("0x4000101b"),
CAPELLA_FORK_EPOCH: 0,
// Deneb
DENEB_FORK_VERSION: b("0x5000101b"),

// Deposit contract
// ---------------------------------------------------------------
DEPOSIT_CHAIN_ID: 39438000,
DEPOSIT_NETWORK_ID: 39438000,
DEPOSIT_CONTRACT_ADDRESS: b("0x4242424242424242424242424242424242424242"),

ETH1_FOLLOW_DISTANCE: 12,
};

// Reset interval (7 days) in milliseconds, based on ephemery-genesis values.env:
// https://github.com/ephemery-testnet/ephemery-genesis/blob/9a28fbef950c8547d78785f8a0ea49a95ce19a48/values.env#L5
const RESET_INTERVAL_MS = 604800000;
const iteration = Math.floor(Date.now() - baseChainConfig.MIN_GENESIS_TIME) / RESET_INTERVAL_MS;

export const ephemeryChainConfig: ChainConfig = {
...baseChainConfig,

MIN_GENESIS_TIME: RESET_INTERVAL_MS * iteration + baseChainConfig.MIN_GENESIS_TIME,
DEPOSIT_CHAIN_ID: baseChainConfig.DEPOSIT_CHAIN_ID + iteration,
DEPOSIT_NETWORK_ID: baseChainConfig.DEPOSIT_NETWORK_ID + iteration,
};
9 changes: 8 additions & 1 deletion packages/config/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {ropstenChainConfig} from "./chainConfig/networks/ropsten.js";
import {sepoliaChainConfig} from "./chainConfig/networks/sepolia.js";
import {holeskyChainConfig} from "./chainConfig/networks/holesky.js";
import {chiadoChainConfig} from "./chainConfig/networks/chiado.js";
import {ephemeryChainConfig} from "./chainConfig/networks/ephemery.js";

export {
mainnetChainConfig,
Expand All @@ -15,9 +16,10 @@ export {
sepoliaChainConfig,
holeskyChainConfig,
chiadoChainConfig,
ephemeryChainConfig,
};

export type NetworkName = "mainnet" | "gnosis" | "goerli" | "ropsten" | "sepolia" | "holesky" | "chiado";
export type NetworkName = "mainnet" | "gnosis" | "goerli" | "ropsten" | "sepolia" | "holesky" | "chiado" | "ephemery";
export const networksChainConfig: Record<NetworkName, ChainConfig> = {
mainnet: mainnetChainConfig,
gnosis: gnosisChainConfig,
Expand All @@ -26,6 +28,7 @@ export const networksChainConfig: Record<NetworkName, ChainConfig> = {
sepolia: sepoliaChainConfig,
holesky: holeskyChainConfig,
chiado: chiadoChainConfig,
ephemery: ephemeryChainConfig,
};

export type GenesisData = {
Expand Down Expand Up @@ -62,4 +65,8 @@ export const genesisData: Record<NetworkName, GenesisData> = {
genesisTime: 1665396300,
genesisValidatorsRoot: "0x9d642dac73058fbf39c0ae41ab1e34e4d889043cb199851ded7095bc99eb4c1e",
},
ephemery: {
genesisTime: ephemeryChainConfig.MIN_GENESIS_TIME + ephemeryChainConfig.GENESIS_DELAY,
genesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
};
1 change: 1 addition & 0 deletions packages/prover/src/utils/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function getChainCommon(network: string): Common {
case "ropsten":
case "sepolia":
case "holesky":
case "ephemery":
// TODO: Not sure how to detect the fork during runtime
return new Common({chain: network, hardfork: Hardfork.Shanghai});
case "minimal":
Expand Down

0 comments on commit cf13ce9

Please sign in to comment.