From 68b9075faaf8044c09e1e6e5a717361d1e8dd4c1 Mon Sep 17 00:00:00 2001 From: valefar-on-discord <124839138+valefar-on-discord@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:39:15 -0500 Subject: [PATCH] capping max deposit amount for partial to 2048 (#141) --- ethstaker_deposit/cli/generate_bls_to_execution_change.py | 4 ++-- ethstaker_deposit/cli/generate_keys.py | 4 ++-- ethstaker_deposit/intl/en/utils/validation.json | 2 +- ethstaker_deposit/utils/constants.py | 5 ++--- ethstaker_deposit/utils/validation.py | 8 ++++---- tests/test_cli/test_partial_deposit.py | 2 +- tests/test_utils/test_validation.py | 6 +++--- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ethstaker_deposit/cli/generate_bls_to_execution_change.py b/ethstaker_deposit/cli/generate_bls_to_execution_change.py index af6966ff..3dce6b06 100644 --- a/ethstaker_deposit/cli/generate_bls_to_execution_change.py +++ b/ethstaker_deposit/cli/generate_bls_to_execution_change.py @@ -26,7 +26,7 @@ ) from ethstaker_deposit.utils.constants import ( DEFAULT_BLS_TO_EXECUTION_CHANGES_FOLDER_NAME, - MAX_DEPOSIT_AMOUNT, + MIN_ACTIVATION_AMOUNT, ) from ethstaker_deposit.utils.click import ( captive_prompt_callback, @@ -178,7 +178,7 @@ def generate_bls_to_execution_change( ) num_validators = len(validator_indices) - amounts = [MAX_DEPOSIT_AMOUNT] * num_validators + amounts = [MIN_ACTIVATION_AMOUNT] * num_validators credentials = CredentialList.from_mnemonic( mnemonic=mnemonic, diff --git a/ethstaker_deposit/cli/generate_keys.py b/ethstaker_deposit/cli/generate_keys.py index 29bf410f..a678cdb4 100644 --- a/ethstaker_deposit/cli/generate_keys.py +++ b/ethstaker_deposit/cli/generate_keys.py @@ -18,8 +18,8 @@ validate_withdrawal_address, ) from ethstaker_deposit.utils.constants import ( - MAX_DEPOSIT_AMOUNT, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME, + MIN_ACTIVATION_AMOUNT, ) from ethstaker_deposit.utils.ascii_art import RHINO_0 from ethstaker_deposit.utils.click import ( @@ -123,7 +123,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int, withdrawal_address: HexAddress, pbkdf2: bool, **kwargs: Any) -> None: mnemonic = ctx.obj['mnemonic'] mnemonic_password = ctx.obj['mnemonic_password'] - amounts = [MAX_DEPOSIT_AMOUNT] * num_validators + amounts = [MIN_ACTIVATION_AMOUNT] * num_validators folder = os.path.join(folder, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME) chain_setting = get_chain_setting(chain) if not os.path.exists(folder): diff --git a/ethstaker_deposit/intl/en/utils/validation.json b/ethstaker_deposit/intl/en/utils/validation.json index 14cd1666..04cde9ff 100644 --- a/ethstaker_deposit/intl/en/utils/validation.json +++ b/ethstaker_deposit/intl/en/utils/validation.json @@ -23,7 +23,7 @@ "err_invalid_amount": "Invalid amount provided. Please provide a value of at least 1 ether of how much you wish to deposit.", "err_not_gwei_denomination": "Invalid amount provided. Please provide a value can not have precision beyond 1 gwei.", "err_min_deposit": "Invalid amount provided. Please provide a value of at least 1 ether.", - "err_max_deposit": "Invalid amount provided. Value is too large. Please provide a lesser amount." + "err_max_deposit": "Invalid amount provided. The max deposit amount is 2048 ether. Please provide a lesser amount." }, "validate_bls_withdrawal_credentials": { "err_is_already_01_form": "The given withdrawal credentials is already in 0x01 form. Have you already set the withdrawal address?", diff --git a/ethstaker_deposit/utils/constants.py b/ethstaker_deposit/utils/constants.py index 534337e3..99427ecf 100644 --- a/ethstaker_deposit/utils/constants.py +++ b/ethstaker_deposit/utils/constants.py @@ -18,9 +18,8 @@ ETH2GWEI = 10 ** 9 # TODO: check if user will can deposit a new validator with more than 32 and 0x02 credentials or 0x00 and 0x01 only MIN_DEPOSIT_AMOUNT = 2 ** 0 * ETH2GWEI -MAX_DEPOSIT_AMOUNT = 2 ** 5 * ETH2GWEI -# Deposit max https://github.com/ethereum/consensus-specs/blob/dev/solidity_deposit_contract/deposit_contract.sol#L116 -GWEI_DEPOSIT_LIMIT = 2**64 - 1 +MIN_ACTIVATION_AMOUNT = 2 ** 5 * ETH2GWEI +MAX_DEPOSIT_AMOUNT = 2 ** 11 * ETH2GWEI # File/folder constants WORD_LISTS_PATH = os.path.join('ethstaker_deposit', 'key_handling', 'key_derivation', 'word_lists') diff --git a/ethstaker_deposit/utils/validation.py b/ethstaker_deposit/utils/validation.py index 507effd0..ef0b36ee 100644 --- a/ethstaker_deposit/utils/validation.py +++ b/ethstaker_deposit/utils/validation.py @@ -39,8 +39,8 @@ COMPOUNDING_WITHDRAWAL_PREFIX, ETH2GWEI, EXECUTION_ADDRESS_WITHDRAWAL_PREFIX, - GWEI_DEPOSIT_LIMIT, MIN_DEPOSIT_AMOUNT, + MAX_DEPOSIT_AMOUNT, ) from ethstaker_deposit.utils.crypto import SHA256 from ethstaker_deposit.settings import BaseChainSetting @@ -114,7 +114,7 @@ def validate_deposit(deposit_data_dict: Dict[str, Any], credential: Credential = return False # Verify deposit amount - if not MIN_DEPOSIT_AMOUNT <= amount <= GWEI_DEPOSIT_LIMIT: + if not MIN_DEPOSIT_AMOUNT <= amount <= MAX_DEPOSIT_AMOUNT: return False # Verify deposit signature && pubkey @@ -185,7 +185,7 @@ def validate_withdrawal_address(cts: click.Context, param: Any, address: str, re def validate_partial_deposit_amount(amount: str) -> int: ''' - Verifies that `amount` is a valid gwei denomination and 1 ether <= amount <= GWEI_DEPOSIT_LIMIT gwei + Verifies that `amount` is a valid gwei denomination and 1 ether <= amount <= MAX_DEPOSIT_AMOUNT gwei Amount is expected to be in ether and the returned value will be converted to gwei and represented as an int ''' try: @@ -198,7 +198,7 @@ def validate_partial_deposit_amount(amount: str) -> int: if amount_gwei < 1 * ETH2GWEI: raise ValidationError(load_text(['err_min_deposit'])) - if amount_gwei > GWEI_DEPOSIT_LIMIT: + if amount_gwei > MAX_DEPOSIT_AMOUNT: raise ValidationError(load_text(['err_max_deposit'])) return int(amount_gwei) diff --git a/tests/test_cli/test_partial_deposit.py b/tests/test_cli/test_partial_deposit.py index 006cf582..0b53782f 100644 --- a/tests/test_cli/test_partial_deposit.py +++ b/tests/test_cli/test_partial_deposit.py @@ -23,7 +23,7 @@ ("32"), ("1"), ("432.123456789"), - ("18446744073.709551615"), + ("2048"), ] ) def test_partial_deposit(amount: str) -> None: diff --git a/tests/test_utils/test_validation.py b/tests/test_utils/test_validation.py index ed662da4..8addf301 100644 --- a/tests/test_utils/test_validation.py +++ b/tests/test_utils/test_validation.py @@ -91,9 +91,9 @@ def test_validate_int_range(num: Any, low: int, high: int, valid: bool) -> None: ('1.000000001', True), ('1.0000000001', False), ('32', True), - ('18446744073.709551615', True), - ('18446744073.709551616', False), - ('18446744073.7095516151', False), + ('2048', True), + ('2048.000000001', False), + ('2048.0000000001', False), ('a', False), (' ', False) ]