Skip to content

Commit

Permalink
capping max deposit amount for partial to 2048 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
valefar-on-discord authored Sep 10, 2024
1 parent e15b4e5 commit 68b9075
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ethstaker_deposit/cli/generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ethstaker_deposit/cli/generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ethstaker_deposit/intl/en/utils/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
5 changes: 2 additions & 3 deletions ethstaker_deposit/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions ethstaker_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_partial_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
("32"),
("1"),
("432.123456789"),
("18446744073.709551615"),
("2048"),
]
)
def test_partial_deposit(amount: str) -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down

0 comments on commit 68b9075

Please sign in to comment.