diff --git a/staking_deposit/cli/generate_bls_to_execution_change.py b/staking_deposit/cli/generate_bls_to_execution_change.py index 5599bea..1cba20a 100644 --- a/staking_deposit/cli/generate_bls_to_execution_change.py +++ b/staking_deposit/cli/generate_bls_to_execution_change.py @@ -179,7 +179,11 @@ def generate_bls_to_execution_change( # Check if the given old bls_withdrawal_credentials is as same as the mnemonic generated for i, credential in enumerate(credentials.credentials): - validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials_list[i], credential) + try: + validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials_list[i], credential) + except ValidationError as e: + click.echo('\n[Error] ' + str(e)) + return btec_file = credentials.export_bls_to_execution_change_json(bls_to_execution_changes_folder, validator_indices) diff --git a/staking_deposit/intl/en/cli/generate_bls_to_execution_change.json b/staking_deposit/intl/en/cli/generate_bls_to_execution_change.json index a3591de..cca5adf 100644 --- a/staking_deposit/intl/en/cli/generate_bls_to_execution_change.json +++ b/staking_deposit/intl/en/cli/generate_bls_to_execution_change.json @@ -15,7 +15,7 @@ }, "arg_bls_withdrawal_credentials_list": { "help": "A list of 32-byte old BLS withdrawal credentials of the certain validator(s)", - "prompt": "Please enter a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas." + "prompt": "Please enter a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas. The withdrawal credentials are in hexadecimal encoded form." }, "arg_validator_start_index": { "help": "The index position for the keys to start generating withdrawal credentials in ERC-2334 format", diff --git a/staking_deposit/intl/en/utils/validation.json b/staking_deposit/intl/en/utils/validation.json index 00579c8..3674fd7 100644 --- a/staking_deposit/intl/en/utils/validation.json +++ b/staking_deposit/intl/en/utils/validation.json @@ -25,5 +25,12 @@ }, "verify_bls_to_execution_change_json": { "msg_bls_to_execution_change_verification": "Verifying your BLSToExecutionChange file:\t" + }, + "normalize_bls_withdrawal_credentials_to_bytes" :{ + "err_incorrect_hex_form": "The given input is not in hexadecimal encoded form." + + }, + "normalize_input_list": { + "err_incorrect_list": "The given input should be a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas." } } diff --git a/staking_deposit/utils/click.py b/staking_deposit/utils/click.py index 8b9b2ae..693ce9a 100644 --- a/staking_deposit/utils/click.py +++ b/staking_deposit/utils/click.py @@ -104,7 +104,7 @@ def captive_prompt_callback( raise ValidationError(confirmation_mismatch_msg()) return processed_input except ValidationError as e: - click.echo(e) + click.echo('\n[Error] ' + str(e)) user_input = click.prompt(prompt(), hide_input=hide_input) return callback diff --git a/staking_deposit/utils/validation.py b/staking_deposit/utils/validation.py index 736a87f..2203fdd 100644 --- a/staking_deposit/utils/validation.py +++ b/staking_deposit/utils/validation.py @@ -210,7 +210,10 @@ def normalize_bls_withdrawal_credentials_to_bytes(bls_withdrawal_credentials: st if bls_withdrawal_credentials.startswith('0x'): bls_withdrawal_credentials = bls_withdrawal_credentials[2:] - bls_withdrawal_credentials_bytes = bytes.fromhex(bls_withdrawal_credentials) + try: + bls_withdrawal_credentials_bytes = bytes.fromhex(bls_withdrawal_credentials) + except Exception: + raise ValidationError(load_text(['err_incorrect_hex_form']) + '\n') return bls_withdrawal_credentials_bytes @@ -226,21 +229,25 @@ def validate_bls_withdrawal_credentials(bls_withdrawal_credentials: str) -> byte bls_withdrawal_credentials_bytes = normalize_bls_withdrawal_credentials_to_bytes(bls_withdrawal_credentials) if is_eth1_address_withdrawal_credentials(bls_withdrawal_credentials_bytes): - raise ValidationError('\n' + load_text(['err_is_already_eth1_form']) + '\n') + raise ValidationError(load_text(['err_is_already_eth1_form']) + '\n') try: assert len(bls_withdrawal_credentials_bytes) == 32 assert bls_withdrawal_credentials_bytes[:1] == BLS_WITHDRAWAL_PREFIX except (ValueError, AssertionError): - raise ValidationError('\n' + load_text(['err_not_bls_form']) + '\n') + raise ValidationError(load_text(['err_not_bls_form']) + '\n') return bls_withdrawal_credentials_bytes def normalize_input_list(input: str) -> Sequence[str]: - input = input.strip('[({})]') - input = re.sub(' +', ' ', input) - return re.split(r'; |, | |,|;', input) + try: + input = input.strip('[({})]') + input = re.sub(' +', ' ', input) + result = re.split(r'; |, | |,|;', input) + except Exception: + raise ValidationError(load_text(['err_incorrect_list']) + '\n') + return result def validate_bls_withdrawal_credentials_list(input_bls_withdrawal_credentials_list: str) -> Sequence[bytes]: @@ -256,4 +263,4 @@ def validate_validator_indices(input_validator_indices: str) -> Sequence[int]: def validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials: bytes, credential: Credential) -> None: if bls_withdrawal_credentials[1:] != SHA256(credential.withdrawal_pk)[1:]: - raise ValidationError('\n' + load_text(['err_not_matching']) + '\n') + raise ValidationError(load_text(['err_not_matching']) + '\n')