diff --git a/eth2deposit/cli/generate_keys.py b/eth2deposit/cli/generate_keys.py index 19c559e19..8b85b3e17 100644 --- a/eth2deposit/cli/generate_keys.py +++ b/eth2deposit/cli/generate_keys.py @@ -21,7 +21,7 @@ from eth2deposit.settings import ( ALL_CHAINS, MAINNET, - get_setting, + get_chain_setting, ) @@ -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() @@ -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) diff --git a/eth2deposit/credentials.py b/eth2deposit/credentials.py index d9a4a0b10..7bbf5c848 100644 --- a/eth2deposit/credentials.py +++ b/eth2deposit/credentials.py @@ -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, @@ -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' @@ -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: @@ -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(), @@ -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 @@ -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( @@ -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]: diff --git a/eth2deposit/settings.py b/eth2deposit/settings.py index 4c7a5ccfd..a1c484dc8 100644 --- a/eth2deposit/settings.py +++ b/eth2deposit/settings.py @@ -5,29 +5,35 @@ 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, @@ -35,8 +41,9 @@ class BaseChainSetting(NamedTuple): 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] diff --git a/tests/test_credentials.py b/tests/test_credentials.py index c6b7042bf..219735a40 100644 --- a/tests/test_credentials.py +++ b/tests/test_credentials.py @@ -1,6 +1,7 @@ import pytest from eth2deposit.credentials import CredentialList +from eth2deposit.settings import MedallaSetting def test_from_mnemonic() -> None: @@ -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, )