Skip to content

Commit

Permalink
Always use GENESIS_FORK_VERSION to sign BLSToExecutionChange and fi…
Browse files Browse the repository at this point in the history
…x typo
  • Loading branch information
hwwhww committed Jan 15, 2023
1 parent 7404b69 commit d68a1c7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 44 deletions.
23 changes: 0 additions & 23 deletions staking_deposit/cli/generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
validate_int_range,
)
from staking_deposit.utils.constants import (
BTEC_FORK_VERSIONS,
CAPELLA,
DEFAULT_BLS_TO_EXECUTION_CHANGES_FOLDER_NAME,
MAX_DEPOSIT_AMOUNT,
)
Expand Down Expand Up @@ -72,22 +70,6 @@ def get_password(text: str) -> str:
list(key for key in ALL_CHAINS.keys() if key != PRATER)
),
)
@jit_option(
callback=captive_prompt_callback(
lambda x: closest_match(x, list(BTEC_FORK_VERSIONS.keys())),
choice_prompt_func(
lambda: load_text(['arg_fork', 'prompt'], func=FUNC_NAME),
list(BTEC_FORK_VERSIONS.keys())
),
),
default=CAPELLA,
help=lambda: load_text(['arg_fork', 'help'], func=FUNC_NAME),
param_decls='--fork',
prompt=choice_prompt_func(
lambda: load_text(['arg_fork', 'prompt'], func=FUNC_NAME),
list(key for key in BTEC_FORK_VERSIONS.keys())
),
)
@load_mnemonic_arguments_decorator
@jit_option(
callback=captive_prompt_callback(
Expand Down Expand Up @@ -132,7 +114,6 @@ def generate_bls_to_execution_change(
ctx: click.Context,
bls_to_execution_changes_folder: str,
chain: str,
fork: str,
mnemonic: str,
mnemonic_password: str,
validator_start_index: int,
Expand All @@ -151,9 +132,6 @@ def generate_bls_to_execution_change(
# Get chain setting
chain_setting = get_chain_setting(chain)

# Get FORK_VERSION
fork_version = BTEC_FORK_VERSIONS[fork]

# TODO: generate multiple?
num_validators = 1
amounts = [MAX_DEPOSIT_AMOUNT] * num_validators
Expand All @@ -166,7 +144,6 @@ def generate_bls_to_execution_change(
chain_setting=chain_setting,
start_index=validator_start_index,
hex_eth1_withdrawal_address=execution_address,
btec_fork_version=fork_version,
)

if len(credentials.credentials) != 1:
Expand Down
18 changes: 5 additions & 13 deletions staking_deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class Credential:
"""
def __init__(self, *, mnemonic: str, mnemonic_password: str,
index: int, amount: int, chain_setting: BaseChainSetting,
hex_eth1_withdrawal_address: Optional[HexAddress],
btec_fork_version: Optional[bytes]=None):
hex_eth1_withdrawal_address: Optional[HexAddress]):
# Set path as EIP-2334 format
# https://eips.ethereum.org/EIPS/eip-2334
purpose = '12381'
Expand All @@ -65,7 +64,6 @@ def __init__(self, *, mnemonic: str, mnemonic_password: str,
self.amount = amount
self.chain_setting = chain_setting
self.hex_eth1_withdrawal_address = hex_eth1_withdrawal_address
self.btec_fork_version = btec_fork_version

@property
def signing_pk(self) -> bytes:
Expand Down Expand Up @@ -167,16 +165,13 @@ def get_bls_to_execution_change(self, validator_index: int) -> SignedBLSToExecut
if self.eth1_withdrawal_address is None:
raise ValueError("The execution address should NOT be empty.")

if self.btec_fork_version is None:
raise ValueError("The BLSToExecutionChange signing fork version should NOT be empty.")

message = BLSToExecutionChange(
validator_index=validator_index,
from_bls_pubkey=self.withdrawal_pk,
to_execution_address=self.eth1_withdrawal_address,
)
domain = compute_bls_to_execution_change_domain(
fork_version=self.btec_fork_version,
fork_version=self.chain_setting.GENESIS_FORK_VERSION,
genesis_validators_root=self.chain_setting.GENESIS_VALIDATORS_ROOT,
)
signing_root = compute_signing_root(message, domain)
Expand All @@ -191,15 +186,14 @@ def get_bls_to_execution_change_dict(self, validator_index: int) -> Dict[str, by
result_dict: Dict[str, Any] = {}
signed_bls_to_execution_change = self.get_bls_to_execution_change(validator_index)
message = {
'valdiator_index': signed_bls_to_execution_change.message.validator_index,
'validator_index': signed_bls_to_execution_change.message.validator_index,
'from_bls_pubkey': signed_bls_to_execution_change.message.from_bls_pubkey.hex(),
'to_execution_address': signed_bls_to_execution_change.message.to_execution_address.hex(),
}
result_dict.update({'message': message})
result_dict.update({'signature': signed_bls_to_execution_change.signature})

# meta
result_dict.update({'fork_version': self.btec_fork_version})
result_dict.update({'network_name': self.chain_setting.NETWORK_NAME})
result_dict.update({'genesis_validators_root': self.chain_setting.GENESIS_VALIDATORS_ROOT})
result_dict.update({'deposit_cli_version': DEPOSIT_CLI_VERSION})
Expand All @@ -222,8 +216,7 @@ def from_mnemonic(cls,
amounts: List[int],
chain_setting: BaseChainSetting,
start_index: int,
hex_eth1_withdrawal_address: Optional[HexAddress],
btec_fork_version: Optional[bytes]=None) -> 'CredentialList':
hex_eth1_withdrawal_address: Optional[HexAddress]) -> 'CredentialList':
if len(amounts) != num_keys:
raise ValueError(
f"The number of keys ({num_keys}) doesn't equal to the corresponding deposit amounts ({len(amounts)})."
Expand All @@ -233,8 +226,7 @@ def from_mnemonic(cls,
show_percent=False, show_pos=True) as indices:
return cls([Credential(mnemonic=mnemonic, mnemonic_password=mnemonic_password,
index=index, amount=amounts[index - start_index], chain_setting=chain_setting,
hex_eth1_withdrawal_address=hex_eth1_withdrawal_address,
btec_fork_version=btec_fork_version)
hex_eth1_withdrawal_address=hex_eth1_withdrawal_address)
for index in indices])

def export_keystores(self, password: str, folder: str) -> List[str]:
Expand Down
7 changes: 0 additions & 7 deletions staking_deposit/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
INTL_CONTENT_PATH = os.path.join('staking_deposit', 'intl')


# BLSToExecutionChange signing fork versions
CAPELLA = 'capella'
BTEC_FORK_VERSIONS: Dict[str, bytes] = {
CAPELLA: bytes.fromhex('03000000'),
}


def _add_index_to_options(d: Dict[str, List[str]]) -> Dict[str, List[str]]:
'''
Adds the (1 indexed) index (in the dict) to the first element of value list.
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli/test_generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_existing_mnemonic_bls_withdrawal() -> None:
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--fork', 'capella',
'--mnemonic', 'sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry', # noqa: E501
'--bls_withdrawal_credentials', '00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
Expand Down

0 comments on commit d68a1c7

Please sign in to comment.