Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
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
6 changes: 3 additions & 3 deletions eth2deposit/cli/generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from eth2deposit.settings import (
ALL_CHAINS,
MAINNET,
get_setting,
get_chain_setting,
)


Expand Down Expand Up @@ -105,7 +105,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int,
mnemonic_password = ctx.obj['mnemonic_password']
amounts = [MAX_DEPOSIT_AMOUNT] * num_validators
folder = os.path.join(folder, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME)
setting = get_setting(chain)
chain_setting = get_chain_setting(chain)
if not os.path.exists(folder):
os.mkdir(folder)
click.clear()
Expand All @@ -116,7 +116,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int,
mnemonic_password=mnemonic_password,
num_keys=num_validators,
amounts=amounts,
fork_version=setting.GENESIS_FORK_VERSION,
chain_setting=chain_setting,
start_index=validator_start_index,
)
keystore_filefolders = credentials.export_keystores(password=keystore_password, folder=folder)
Expand Down
16 changes: 9 additions & 7 deletions eth2deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Keystore,
ScryptKeystore,
)
from eth2deposit.settings import DEPOSIT_CLI_VERSION
from eth2deposit.settings import DEPOSIT_CLI_VERSION, BaseChainSetting
from eth2deposit.utils.constants import (
BLS_WITHDRAWAL_PREFIX,
ETH2GWEI,
Expand All @@ -32,7 +32,8 @@ class Credential:
A Credential object contains all of the information for a single validator and the corresponding functionality.
Once created, it is the only object that should be required to perform any processing for a validator.
"""
def __init__(self, *, mnemonic: str, mnemonic_password: str, index: int, amount: int, fork_version: bytes):
def __init__(self, *, mnemonic: str, mnemonic_password: str,
index: int, amount: int, chain_setting: BaseChainSetting):
# Set path as EIP-2334 format
# https://eips.ethereum.org/EIPS/eip-2334
purpose = '12381'
Expand All @@ -46,7 +47,7 @@ def __init__(self, *, mnemonic: str, mnemonic_password: str, index: int, amount:
self.signing_sk = mnemonic_and_path_to_key(
mnemonic=mnemonic, path=self.signing_key_path, password=mnemonic_password)
self.amount = amount
self.fork_version = fork_version
self.chain_setting = chain_setting

@property
def signing_pk(self) -> bytes:
Expand Down Expand Up @@ -74,7 +75,7 @@ def deposit_message(self) -> DepositMessage:

@property
def signed_deposit(self) -> DepositData:
domain = compute_deposit_domain(fork_version=self.fork_version)
domain = compute_deposit_domain(fork_version=self.chain_setting.GENESIS_FORK_VERSION)
signing_root = compute_signing_root(self.deposit_message, domain)
signed_deposit = DepositData(
**self.deposit_message.as_dict(),
Expand All @@ -92,7 +93,8 @@ def deposit_datum_dict(self) -> Dict[str, bytes]:
datum_dict = signed_deposit_datum.as_dict()
datum_dict.update({'deposit_message_root': self.deposit_message.hash_tree_root})
datum_dict.update({'deposit_data_root': signed_deposit_datum.hash_tree_root})
datum_dict.update({'fork_version': self.fork_version})
datum_dict.update({'fork_version': self.chain_setting.GENESIS_FORK_VERSION})
datum_dict.update({'eth2_network_name': self.chain_setting.ETH2_NETWORK_NAME})
datum_dict.update({'deposit_cli_version': DEPOSIT_CLI_VERSION})
return datum_dict

Expand Down Expand Up @@ -126,7 +128,7 @@ def from_mnemonic(cls,
mnemonic_password: str,
num_keys: int,
amounts: List[int],
fork_version: bytes,
chain_setting: BaseChainSetting,
start_index: int) -> 'CredentialList':
if len(amounts) != num_keys:
raise ValueError(
Expand All @@ -136,7 +138,7 @@ def from_mnemonic(cls,
with click.progressbar(key_indices, label='Creating your keys:\t\t',
show_percent=False, show_pos=True) as indices:
return cls([Credential(mnemonic=mnemonic, mnemonic_password=mnemonic_password,
index=index, amount=amounts[index - start_index], fork_version=fork_version)
index=index, amount=amounts[index - start_index], chain_setting=chain_setting)
for index in indices])

def export_keystores(self, password: str, folder: str) -> List[str]:
Expand Down
33 changes: 20 additions & 13 deletions eth2deposit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,45 @@


class BaseChainSetting(NamedTuple):
ETH2_NETWORK_NAME: str
GENESIS_FORK_VERSION: bytes


MAINNET = 'mainnet'
WITTI = 'witti'
ALTONA = 'altona'
MEDALLA = 'medalla'
SPADINA = 'spadina'
ZINKEN = 'zinken'
PYRMONT = 'pyrmont'


# Eth2 Mainnet setting
MainnetSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000000'))
MainnetSetting = BaseChainSetting(ETH2_NETWORK_NAME=MAINNET, GENESIS_FORK_VERSION=bytes.fromhex('00000000'))
# Eth2 spec v0.11.3 testnet
WittiSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000113'))
WittiSetting = BaseChainSetting(ETH2_NETWORK_NAME=WITTI, GENESIS_FORK_VERSION=bytes.fromhex('00000113'))
# Eth2 spec v0.12.1 testnet
AltonaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000121'))
AltonaSetting = BaseChainSetting(ETH2_NETWORK_NAME=ALTONA, GENESIS_FORK_VERSION=bytes.fromhex('00000121'))
# Eth2 "official" public testnet (spec v0.12.2)
MedallaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000001'))
MedallaSetting = BaseChainSetting(ETH2_NETWORK_NAME=MEDALLA, GENESIS_FORK_VERSION=bytes.fromhex('00000001'))
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
SpadinaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000002'))
SpadinaSetting = BaseChainSetting(ETH2_NETWORK_NAME=SPADINA, GENESIS_FORK_VERSION=bytes.fromhex('00000002'))
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
ZinkenSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000003'))
ZinkenSetting = BaseChainSetting(ETH2_NETWORK_NAME=ZINKEN, GENESIS_FORK_VERSION=bytes.fromhex('00000003'))
# Eth2 pre-launch testnet (spec v1.0.0)
PyrmontSetting = BaseChainSetting(ETH2_NETWORK_NAME=PYRMONT, GENESIS_FORK_VERSION=bytes.fromhex('00002009'))


MAINNET = 'mainnet'
WITTI = 'witti'
ALTONA = 'altona'
MEDALLA = 'medalla'
SPADINA = 'spadina'
ZINKEN = 'zinken'
ALL_CHAINS: Dict[str, BaseChainSetting] = {
MAINNET: MainnetSetting,
WITTI: WittiSetting,
ALTONA: AltonaSetting,
MEDALLA: MedallaSetting,
SPADINA: SpadinaSetting,
ZINKEN: ZinkenSetting,
PYRMONT: PyrmontSetting,
}


def get_setting(chain_name: str = MAINNET) -> BaseChainSetting:
def get_chain_setting(chain_name: str = MAINNET) -> BaseChainSetting:
return ALL_CHAINS[chain_name]
3 changes: 2 additions & 1 deletion tests/test_credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from eth2deposit.credentials import CredentialList
from eth2deposit.settings import MedallaSetting


def test_from_mnemonic() -> None:
Expand All @@ -10,6 +11,6 @@ def test_from_mnemonic() -> None:
mnemonic_password="",
num_keys=1,
amounts=[32, 32],
fork_version=bytes.fromhex('00000000'),
chain_setting=MedallaSetting,
start_index=1,
)